Skip to content

Commit ad8ed1b

Browse files
LitoMoreSBoudrias
authored andcommitted
Suggest yarn when installed with yarn (#132)
1 parent 5f06620 commit ad8ed1b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

index.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const semverDiff = importLazy('semver-diff');
1010
const latestVersion = importLazy('latest-version');
1111
const isNpm = importLazy('is-npm');
1212
const isInstalledGlobally = importLazy('is-installed-globally');
13+
const isYarnGlobal = importLazy('is-yarn-global');
14+
const hasYarn = importLazy('has-yarn');
1315
const boxen = importLazy('boxen');
1416
const xdgBasedir = importLazy('xdg-basedir');
1517
const isCi = importLazy('is-ci');
@@ -126,11 +128,22 @@ class UpdateNotifier {
126128

127129
options = {
128130
isGlobal: isInstalledGlobally(),
131+
isYarnGlobal: isYarnGlobal()(),
129132
...options
130133
};
131134

135+
let installCommand;
136+
137+
if (options.isYarnGlobal) {
138+
installCommand = `yarn global add ${this.packageName}`;
139+
} else if (hasYarn()()) {
140+
installCommand = `yarn add ${this.packageName}`;
141+
} else {
142+
installCommand = `npm i ${options.isGlobal ? '-g ' : ''}${this.packageName}`;
143+
}
144+
132145
options.message = options.message || 'Update available ' + chalk().dim(this.update.current) + chalk().reset(' → ') +
133-
chalk().green(this.update.latest) + ' \nRun ' + chalk().cyan('npm i ' + (options.isGlobal ? '-g ' : '') + this.packageName) + ' to update';
146+
chalk().green(this.update.latest) + ' \nRun ' + chalk().cyan(installCommand) + ' to update';
134147

135148
options.boxenOpts = options.boxenOpts || {
136149
padding: 1,

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
"boxen": "^3.0.0",
3737
"chalk": "^2.0.1",
3838
"configstore": "^4.0.0",
39+
"has-yarn": "^2.1.0",
3940
"import-lazy": "^2.1.0",
4041
"is-ci": "^2.0.0",
4142
"is-installed-globally": "^0.1.0",
4243
"is-npm": "^3.0.0",
44+
"is-yarn-global": "^0.3.0",
4345
"latest-version": "^5.0.0",
4446
"semver-diff": "^2.0.0",
4547
"xdg-basedir": "^3.0.0"

0 commit comments

Comments
 (0)