Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest yarn when installed with yarn #132

Merged
merged 12 commits into from
May 10, 2019
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,24 @@ class UpdateNotifier {
};
});
}
isYarnGlobal() {
const isWindows = process.platform === 'win32' || process.env.OSTYPE === 'cygwin' || process.env.OSTYPE === 'msys';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should only be const isWindows = process.platform === 'win32';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

const yarnPath = isWindows ? path.join('Yarn', 'config', 'global') : path.join('.config', 'yarn', 'global');
if (process.cwd().includes(yarnPath)) {
return true;
}
return false;
}
notify(opts) {
if (!process.stdout.isTTY || isNpm() || !this.update) {
return this;
}

opts = Object.assign({isGlobal: isInstalledGlobally()}, opts);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isInstalledGlobally already supports Yarn, but it doesn't return which one it is. For that, you could use https://github.com/sindresorhus/global-dirs#packages

Copy link
Contributor Author

@LitoMore LitoMore Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sindresorhus I created a package is-yarn-global, it without any fs calls and dependencies. What about this?

const installCommand = this.isYarnGlobal() ? 'yarn global upgrade ' + this.packageName : 'npm i ' + (opts.isGlobal ? '-g ' : '') + this.packageName;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yarn global upgrade <package> will not upgrade package to latest version. Should be yarn global add <package> or yarn global upgrade <package>@latest.


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';
chalk().green(this.update.latest) + ' \nRun ' + chalk().cyan(installCommand) + ' to update';

opts.boxenOpts = opts.boxenOpts || {
padding: 1,
Expand Down