Add localOnly argument to generator lookup #113
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 localnode_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-installedyo
, 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 toyo
for this purpose. To make that happen I'll first need to make some changes toyeoman-environment
. In this PR I've added alocalOnly
argument to a couple of theresolver
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 thisenvironment
change is published I'll gladly contribute that as well.Thanks!