From 97d0b9796c10cab39e1cd10f60208cbc6a9a799e Mon Sep 17 00:00:00 2001 From: tdeschryver Date: Mon, 9 Oct 2017 07:51:13 +0200 Subject: [PATCH] Add is-installed-globally for auto-detection (#114) --- index.js | 3 ++- package.json | 1 + test/notify.js | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a5fff01..58f2459 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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'; diff --git a/package.json b/package.json index e96cc70..3af4a5b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/notify.js b/test/notify.js index 9fac85f..ab24d5d 100644 --- a/test/notify.js +++ b/test/notify.js @@ -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), `