Repository navigation
fix: preserve process.cwd() after SETLOCAL in cmd shims - #192
Closed
dyk1454683243-sudo wants to merge 1 commit into
Closed
dyk1454683243-sudo wants to merge 1 commit into
dyk1454683243-sudo wants to merge 1 commit into
Conversation
The goto-undefined launch line exits batch context so leftover SETLOCAL frames (including a parent setlocal + cd) restore the pre-cd directory before Node starts. Re-apply %CD% after that exit; it is expanded on the same line before endLocal runs. Fixes npm#69 Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
Author
|
Withdrawing this PR while I clean up a high-volume open-PR backlog. Sorry for the noise — happy to come back later with a focused change if useful. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #69
Cause
Shebang
.cmdshims isolate_progwithSETLOCAL, then launch Node with:goto #_undefined_#is the existing “Terminate Batch Job?” workaround: it leaves batch context so Node is not a child of the.cmd. Leaving that context implied-ENDLOCALs leftover frames.SETLOCALsaves the current directory as well as the environment. The issue’s parent script is:When the shim exits batch context, the parent
setlocalis popped too, so thecdis undone and Node’sprocess.cwd()is the pre-cddirectory. Same-line%CD%is still the post-cdpath, because cmd.exe expands percents before any command on the line runs.This is still the generated launch line on current
main. No open PR already claimed #69.Fix
After the goto, re-apply the already-expanded directory:
cdhas to come aftergoto. A restore before the goto is undone by the impliedENDLOCAL.SETLOCALand the goto trick (Ctrl+C / issue Invocation fails if %0 is "prog" instead of "path\to\prog" and prog was quoted when invoked #10 / cli#969)setlocal(e.g.JAVA_HOMEin On windows generated *.cmd file overwrites console window title cli#4239) are a separate problem and are not addressed hereTests
.cmd/SETLOCAL/:find_dp0/ parentsetlocal+cdpattern: withoutcd /d "%CD%"the simulated Node cwd is the pre-cddirectory; with it, cwd isC:\abcdefgcd /d "%CD%"aftergoto #_undefined_#test.batdoessetlocal+cd+ shim;aaaa.jswritesprocess.cwd()(skipped on non-Windows CI)