'$(pwd) doesn't resolve properly when running from npm script
The issue:
$(pdw) does not resolve properly when running as part of npm script.
running a script with param including $(pwd) in the terminal seems to be working fine though. e.g.:
Simplified example:
package.json
{
...
"scripts": {
"test-pwd": "echo $(pwd)"
},
...
}
# this command works correctly
echo $(pwd)
# output: /c/Users/<User>/path/to/repo
# this commad doesn't work
yarn test-pwd
# output: $(pwd)
my actual code:
npx @bazel/bazelisk run //tools/ci:pwd_script_py -- --root-dir=$(pwd)
^ this works fine
But this is my actual setup:
{
...
"scripts": {
"s1": "...",
"s2": "...",
"pwd-script": "npx @bazel/bazelisk run //tools/ci:pwd_script_py -- --root-dir=$(pwd)"
"start:all": "s1 && s2 && pwd-script",
},
...
}
when I run yarn start:all or yarn pwd-script, the scripts break as root-dir evaluates to literal string $(pwd) instead of C:\path\to\repo
Environment:
- Win 11
- Win Terminal -> Git Bash
- node 16.14.1
- npm 8.5
This setup seems to be working fine in Linux & OSX environments, but I also need to get it working under Windows env
Also, it is not easily done to move that $(pwd) into the underlying python script as the script is being run in a sandbox.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
