-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Remove hardcoded node_modules in gulpfile. #8890
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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 guess npx is ok, because it should run the version in
node_modules/.bin
if it exists, and only install the package if it doesn't already exist. This is important because installing the package from npm could end up installing the wrong version.But it really shouldn't be necessary to use npx in any case. Previously we were using
node_modules/cloc/lib/cloc
, which is not guaranteed to work. The cloc package can be hoisted somewhere else for various reasons. This is not true ofnode_modules/.bin
, though. The .bins should always be present, as long as the package has actually been installed. Sonode_modules/.bin/cloc
should be equivalent tonpx cloc
except that the former won't ever install cloc or execute some random thing with that name from your path.And if we do need to run
node_modules/clock/lib/cloc
directly (rather than the thing in .bin), you can just ask node to resolve it first. Something like this (not tested):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.
Kevin, the original problem that prompted this change was a literal
node_modules/.bin/something
in the gulpfile, which is only correct if you're not on Windows. This PR seems like a good opportunity to pick one consistent means of path construction and stick to it.I never realized that
npx
will install missing packages -- kind of neat I guess? -- but if that's any kind of concern, there's a--no-install
flag that you could use on all these invocations.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.
@thw0rted Windows stores the binaries in
node_modules/.bin
, too. One potential gotcha, though, is that, on Windows, the programs in .bin are actually cmd scripts with a .cmd extension. So doingchild_process.exec("node_modules/.bin/cloc", ...)
won't work because there's no file calledcloc
and possibly also because cloc.cmd is not an executable. Long story short, addshell: true
as an option to theexec
call and you'll be good to go.Is all this better than just using
npx
? Especially with--no-install
? I guess not. After reading up on it some more, npx is better suited to this than I remembered. Carry on. :)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 was referring to the path separator.
node_modules/.bin/cloc
does not work but I believe in my testingnode_modules\\.bin\\.cloc
worked. Anyway, I like hownpx
shows intent, handles nesting, global installs, etc. Ever since I discovered it a few years ago I've been trying to spread the word 😁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.
Weird, Windows is usually ok with forward slashes. 🤷