-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charlike Mike Reagent <[email protected]>
- Loading branch information
Charlike Mike Reagent
committed
Nov 3, 2018
1 parent
cc0d85e
commit db17bdb
Showing
5 changed files
with
273 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
export default () => {}; | ||
// import proc from 'process'; | ||
import unpdateNotifier from 'update-notifier'; | ||
import isInstalledGlobally from 'is-installed-globally'; | ||
import { exec } from '@tunnckocore/execa'; | ||
|
||
export default async function updater(options) { | ||
const opts = Object.assign({}, options); | ||
|
||
if (!opts.pkg.name || !opts.pkg.version) { | ||
throw new Error('unpdateNotifier: pkg.name and pkg.version are required'); | ||
} | ||
|
||
opts.callback = (err, info) => { | ||
if (err) { | ||
throw err; | ||
} | ||
if (info.type !== 'latest') { | ||
autoupdate(opts.pkg, opts.manager); | ||
} | ||
}; | ||
|
||
return unpdateNotifier(opts); | ||
} | ||
|
||
async function autoupdate(pkg, manager) { | ||
const isNpm = manager === 'npm'; | ||
|
||
if (isNpm || manager === 'pnpm') { | ||
await exec( | ||
`${isNpm ? 'npm' : 'pnpm'} install ${ | ||
isInstalledGlobally ? '--global' : '' | ||
} ${pkg.name}`, | ||
); | ||
} | ||
|
||
if (manager === 'yarn') { | ||
const g = isInstalledGlobally ? 'global' : ''; | ||
await exec([ | ||
// ensure it is cleanest one | ||
`yarn ${g} remove ${pkg.name}`, | ||
|
||
// install it after that ensurance | ||
`yarn ${g} add ${pkg.name}`, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
import test from 'asia'; | ||
import mod from '../src'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"todo":{"skip":false,"todo":false,"run":false,"isPending":false,"isRejected":false,"isFulfilled":true,"id":1,"str":"(t) => {\n t.strictEqual(typeof mod, 'function');\n}","title":"todo"}} |
Oops, something went wrong.