Skip to content

Commit

Permalink
Add is-installed-globally for auto-detection (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver authored and sindresorhus committed Oct 9, 2017
1 parent 6008ccf commit 97d0b97
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -9,6 +9,7 @@ const chalk = importLazy('chalk');
const semverDiff = importLazy('semver-diff');
const latestVersion = importLazy('latest-version');
const isNpm = importLazy('is-npm');
const isInstalledGlobally = importLazy('is-installed-globally');
const boxen = importLazy('boxen');
const xdgBasedir = importLazy('xdg-basedir');
const ONE_DAY = 1000 * 60 * 60 * 24;
Expand Down Expand Up @@ -109,7 +110,7 @@ class UpdateNotifier {
return this;
}

opts = Object.assign({isGlobal: true}, opts);
opts = Object.assign({isGlobal: isInstalledGlobally()}, opts);

opts.message = opts.message || 'Update available ' + chalk().dim(this.update.current) + chalk().reset(' → ') +
chalk().green(this.update.latest) + ' \nRun ' + chalk().cyan('npm i ' + (opts.isGlobal ? '-g ' : '') + this.packageName) + ' to update';
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -37,6 +37,7 @@
"chalk": "^2.0.1",
"configstore": "^3.0.0",
"import-lazy": "^2.1.0",
"is-installed-globally": "^0.1.0",
"is-npm": "^1.0.0",
"latest-version": "^3.0.0",
"semver-diff": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion test/notify.js
Expand Up @@ -43,7 +43,7 @@ test.afterEach(() => {

test('use pretty boxen message by default', t => {
const notifier = new Control();
notifier.notify({defer: false});
notifier.notify({defer: false, isGlobal: true});

t.is(stripAnsi(errorLogs), `
Expand Down

0 comments on commit 97d0b97

Please sign in to comment.