You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This example now works correctly (as you would expect...)
$ pnpm exec print_init_cwd
INIT_CWD: <works...>
Interestingly, the tsc example above still doesn't work.
It seems npm is leaving the PWD variable as being the path from which npm was invoked;
pnpm has PWD set to the root of the current package (the closest package.json).
I guess tsc is checking that variable to find current context...
But that's a separate issue; it's debatable which is more correct here - and not something that needs to be consistent in my opinion (it's up to the script itself to work out it's context - which is probably why the INIT_CWD was added to npm in the first place).
Verify latest release
pnpm version
No response
Which area(s) of pnpm are affected? (leave empty if unsure)
CLI, Package manager compatibility
Link to the code that reproduces this issue or a replay of the bug
No response
Reproduction steps
Create a new package in your workspace, with:
package.json:
print_init_cwd.js:
Install the package as a dependency to another workspace package:
$ cd /path/to/other_package $ pnpm add test_init_cwd
Exec the installed script:
$ pnpm exec print_init_cwd INIT_CWD: undefined
Exec the installed script (npm):
$ npx print_init_cwd INIT_CWD: /path/to/other_package $ cd ./a/b/c $ npx print_init_cwd INIT_CWD: /path/to/other_package/a/b/c
Another example, would be to have typescript installed in a package, and then do:
Describe the Bug
npm / yarn define
INIT_CWD
as being the directory from which you run the script.I think pnpm should be doing the same for consistency.
https://docs.npmjs.com/cli/v9/commands/npm-run-script#description
If you want your 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
https://yarnpkg.com/advanced/lifecycle-scripts#environment-variables
$INIT_CWD: Directory from which the script has been invoked. This isn't the same as the cwd, which for scripts is always equal to the closest package root.
Related:
#2897
#5464
#4441
Expected Behavior
pnpm to set
INIT_CWD
in the same way that npm / yarn setINIT_CWD
Which Node.js version are you using?
18.14.1
Which operating systems have you used?
If your OS is a Linux based, which one it is? (Include the version if relevant)
Ubuntu22.04
The text was updated successfully, but these errors were encountered: