-
-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Suggest yarn when installed with yarn #132
Conversation
This is not what was suggested in #118 (comment) This is not going to be accepted if it requires any |
index.js
Outdated
|
||
try { | ||
const realpath = fs.realpathSync(which().sync(cliName, {nothrow: true})); | ||
if (realpath.match(/yarn\/global/)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be wrong, but this literal RegExp doesn't look to be Windows-friendly (hardcoded forward slash).
Perhaps we could simplify this to:
return realpath.includes(path.join('yarn', 'global'));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I will try it in Windows.
@sindresorhus Thank you for your advice.
|
index.js
Outdated
notify(opts) { | ||
if (!process.stdout.isTTY || isNpm() || !this.update) { | ||
return this; | ||
} | ||
|
||
opts = Object.assign({isGlobal: isInstalledGlobally()}, opts); | ||
const installCommand = this.isYarn() ? 'yarn global upgrade ' + this.packageName : 'npm i ' + (opts.isGlobal ? '-g ' : '') + this.packageName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably do the global check on yarn too no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have to.
Should we create a new package |
index.js
Outdated
@@ -107,15 +107,24 @@ class UpdateNotifier { | |||
}; | |||
}); | |||
} | |||
isYarnGlobal() { | |||
const isWindows = process.platform === 'win32' || process.env.OSTYPE === 'cygwin' || process.env.OSTYPE === 'msys'; |
There was a problem hiding this comment.
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';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
index.js
Outdated
return true; | ||
} | ||
return false; | ||
} | ||
notify(opts) { | ||
if (!process.stdout.isTTY || isNpm() || !this.update) { | ||
return this; | ||
} | ||
|
||
opts = Object.assign({isGlobal: isInstalledGlobally()}, opts); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
index.js
Outdated
notify(opts) { | ||
if (!process.stdout.isTTY || isNpm() || !this.update) { | ||
return this; | ||
} | ||
|
||
opts = Object.assign({isGlobal: isInstalledGlobally()}, opts); | ||
const installCommand = this.isYarnGlobal() ? 'yarn global upgrade ' + this.packageName : 'npm i ' + (opts.isGlobal ? '-g ' : '') + this.packageName; |
There was a problem hiding this comment.
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
.
@sindresorhus I could be wrong, I think is-yarn-global is better than global-dirs, |
Good point, yes, go for |
@sindresorhus |
@sindresorhus Code updated, please review |
ping @SBoudrias @sindresorhus I updated my code, but the review status does not change. Any progress with this pull request? |
@sindresorhus Hey Sindre! Please review! Thanks! |
Any update on this? |
This got lost in my review queue. @LitoMore Can you fix the merge conflicts? |
@sindresorhus Code updated. |
index.js
Outdated
...options | ||
}; | ||
const installCommand = options.isYarnGlobal ? `yarn global add ${this.packageName}` : `npm i ${options.isGlobal ? '-g ' : ''}${this.packageName}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also show local Yarn command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also show local Yarn command?
@sindresorhus How do we know if it is using Yarn or NPM locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sindresorhus Code updated. |
Fixes #118
Resolve #146