-
-
Notifications
You must be signed in to change notification settings - Fork 107
Replace node --version probe with no-fork PATH walk #1129
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,24 @@ end | |
|
|
||
| def shakapacker_node_binary | ||
| node_bin = "node" | ||
| return node_bin if system(node_bin, "--version", out: File::NULL, err: File::NULL) | ||
| # Walk ENV["PATH"] directly instead of forking a `node --version` | ||
| # subprocess on every binstub invocation. On Windows, also probe | ||
| # PATHEXT-style extensions because executables there end in | ||
| # .exe/.cmd/.bat. | ||
| extensions = if Gem.win_platform? | ||
| ["", *(ENV["PATHEXT"] || ".COM;.EXE;.BAT;.CMD").split(";")] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| else | ||
| [""] | ||
| end | ||
|
|
||
| ENV["PATH"].to_s.split(File::PATH_SEPARATOR).each do |dir| | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This PATH walk changes behavior versus the previous Useful? React with 👍 / 👎. |
||
| next if dir.empty? | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Skipping empty PATH segments changes command-resolution semantics versus the previous Useful? React with 👍 / 👎. |
||
|
|
||
| extensions.each do |ext| | ||
| candidate = File.join(dir, "#{node_bin}#{ext}") | ||
| return node_bin if File.file?(candidate) && File.executable?(candidate) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Subtle behavioral change worth calling out: Whether that tradeoff is acceptable depends on how likely those scenarios are in practice. For most dev environments it'll never matter, but it's worth a comment or doc note if this is intended.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Subtle semantic change from the old |
||
| end | ||
| end | ||
|
|
||
| warn "[Shakapacker] Could not find Node.js executable #{node_bin.inspect}. " \ | ||
| "Install Node.js and try again." | ||
|
|
||
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.
When
ENV["PATHEXT"]is set but empty (e.g.PATHEXT=""),"".split(";")returns[], soextensionsbecomes[""]— only the barenodename is checked, andnode.exe/node.cmdare skipped. Practically this won't happen on any real Windows install (empty PATHEXT breaks far more things), but if you want to be defensive the fallback condition could be:Not a blocker — just a heads-up.