docs: Clarify script working directory behavior (fixes #8305)#8308
Merged
owlstronaut merged 6 commits intonpm:latestfrom May 21, 2025
Merged
Conversation
owlstronaut
requested changes
May 19, 2025
Contributor
owlstronaut
left a comment
There was a problem hiding this comment.
I like the change in general, just a little cleanup and we'll run the tests on it
Comment on lines
+239
to
+240
| In npm v7 and later, scripts are always executed from the root of the package folder, regardless of your current working directory. This behavior is now reliable and consistent. | ||
|
|
Contributor
There was a problem hiding this comment.
Suggested change
| In npm v7 and later, scripts are always executed from the root of the package folder, regardless of your current working directory. This behavior is now reliable and consistent. |
This can be removed, repeat of the above section.
| script to use different behavior based on what subdirectory you're in, you | ||
| can use the `INIT_CWD` environment variable, which holds the full path you | ||
| were in when you ran `npm run`. | ||
|
|
Contributor
There was a problem hiding this comment.
Suggested change
Extra space
Contributor
Author
@owlstronaut |
Contributor
Author
|
@owlstronaut |
owlstronaut
requested changes
May 20, 2025
Co-authored-by: Michael Smith <owlstronaut@github.com>
owlstronaut
approved these changes
May 21, 2025
Contributor
|
unrelated failures, merging |
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.
This pull request updates the documentation for npm scripts, specifically the
scripts.mdfile.What:
process.cwd()could be used as a safeguard.INIT_CWDenvironment variable is mentioned as a way for scripts to access the original working directory.Why:
This change aims to provide clearer and more accurate documentation regarding the working directory of npm scripts, addressing potential confusion, especially for users working with or migrating from older npm versions. This helps resolve the points raised in issue #8305.
References
Fixes #8305