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
Merged

Conversation

LitoMore
Copy link
Contributor

@LitoMore LitoMore commented Jan 9, 2018

Fixes #118
Resolve #146

@LitoMore LitoMore changed the title Suggest yarn when intalled with yarn (global install) Suggest yarn when installed with yarn (global install) Jan 9, 2018
@sindresorhus
Copy link
Member

This is not what was suggested in #118 (comment) This is not going to be accepted if it requires any fs calls. That's not worth the overhead.

index.js Outdated

try {
const realpath = fs.realpathSync(which().sync(cliName, {nothrow: true}));
if (realpath.match(/yarn\/global/)) {
Copy link
Collaborator

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'));

Copy link
Contributor Author

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.

@LitoMore
Copy link
Contributor Author

LitoMore commented Jan 11, 2018

@sindresorhus Thank you for your advice.

process.cwd() is a better way to get the path.

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;
Copy link
Member

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?

Copy link
Contributor Author

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.

@LitoMore
Copy link
Contributor Author

LitoMore commented Jan 12, 2018

Should we create a new package is-yarn-global then require it?

index.js Outdated
@@ -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.

👌

index.js Outdated
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?

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;
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.

@LitoMore
Copy link
Contributor Author

@sindresorhus I could be wrong, I think is-yarn-global is better than global-dirs, is-yarn-global it without any fs calls and new dependencies. Use is-yarn-global or global-dirs it's up to you.

@sindresorhus
Copy link
Member

sindresorhus commented Jan 23, 2018

I could be wrong, I think is-yarn-global is better than global-dirs, is-yarn-global it without any fs calls and new dependencies. Use is-yarn-global or global-dirs it's up to you.

Good point, yes, go for is-yarn-global.

@LitoMore
Copy link
Contributor Author

LitoMore commented Feb 8, 2018

@sindresorhus is-yarn-global has been landed on this pull request, please review :)

@LitoMore
Copy link
Contributor Author

LitoMore commented Jun 5, 2018

@sindresorhus Code updated, please review

@LitoMore
Copy link
Contributor Author

LitoMore commented Jul 7, 2018

ping @SBoudrias @sindresorhus I updated my code, but the review status does not change.

Any progress with this pull request?

@LitoMore
Copy link
Contributor Author

LitoMore commented Sep 6, 2018

@sindresorhus Hey Sindre! Please review! Thanks!

@joshmanders
Copy link

Any update on this?

@sindresorhus
Copy link
Member

This got lost in my review queue.

@LitoMore Can you fix the merge conflicts?

@LitoMore
Copy link
Contributor Author

@sindresorhus Code updated.

index.js Outdated
...options
};
const installCommand = options.isYarnGlobal ? `yarn global add ${this.packageName}` : `npm i ${options.isGlobal ? '-g ' : ''}${this.packageName}`;
Copy link
Member

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?

Copy link
Contributor Author

@LitoMore LitoMore Apr 8, 2019

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?

Copy link
Member

Choose a reason for hiding this comment

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

@LitoMore
Copy link
Contributor Author

LitoMore commented Apr 8, 2019

@sindresorhus Code updated.

@LitoMore LitoMore changed the title Suggest yarn when installed with yarn (global install) Suggest yarn when installed with yarn Apr 8, 2019
index.js Outdated Show resolved Hide resolved
@SBoudrias SBoudrias merged commit ad8ed1b into yeoman:master May 10, 2019
@LitoMore LitoMore deleted the yarn-support branch May 10, 2019 08:20
@bluelovers
Copy link

current path is yarn project not mean this cli install by current local

should not Suggest yarn add

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants