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

Add localOnly argument to generator lookup #113

Merged
merged 3 commits into from
Jun 24, 2019

Conversation

sripberger
Copy link
Contributor

I've noticed that, when building a list of generators, yo will list any globally-installed generators, in addition to any it can find in local node_modules directories. I understand why it does this, of course, but there are situations where I'd like to change this behavior and only display local generators, and I'm sure I"m probably not alone in this.

For my particular use case, I'm creating NPM package projects, each with a script that runs yo to pick from a list of generators that developers can use to quickly add files for new classes, tests, and so on.

As any veteran NPM user can attest, installing both yo and the project-specific generators locally is far more ideal than trying to have all of these projects share the same copies of these dependencies as globally-installed modules. The former approach allows me to make breaking changes to generated code, and update the dependencies in each project as time and project-specific needs permit. The latter approach? Not so much.

Fortunately the former approach is relatively easy to accomplish. All I have to do is install yo and whatever generators I need as devDependencies in each project. Npm scripts will use this locally-installed yo, as it will with any other locally-installed CLI.

However, if the user is using yeoman for anything else, chances are they'll have some globally-installed generators as well, and these will show up in the generator list, even when running the locally-installed yo. This creates potential for a lot of clutter and confusion that I'd prefer to avoid.

What I'd like to do is add a --local-only flag to yo for this purpose. To make that happen I'll first need to make some changes to yeoman-environment. In this PR I've added a localOnly argument to a couple of the resolver methods that need it. This changes the signature of the #lookup method, but does so in a way that is backwards compatible with the old signature.

I also have changes ready for yo itself to add the flag and pass it through to this new argument, but I'll hold off on making the PR for that for now. If and when this environment change is published I'll gladly contribute that as well.

Thanks!

@SBoudrias
Copy link
Member

Thanks for sending this PR.

I think that's a valid feature request. Thanks for the clear use case explanation! This helps a lot making a decision without having to do ton of back and forth 😄

@SBoudrias SBoudrias merged commit 212305d into yeoman:master Jun 24, 2019
@sripberger sripberger deleted the lookup-local-only branch July 2, 2019 15:01
@sripberger sripberger mentioned this pull request Jul 2, 2019
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants