I'm trying to merge two npm scripts into one, but the result is incorrect and causes issues with passing flags. I can't use the dotenv package, and using ampersands isn't solving the problem.
Here's what I have in my package.json file -
"define:local": "cross-env NODE_ENV=local FOO=bar BAZ=foo",
"local:dev": "npm run define:local tsnd --inspect --respawn path/to/mycode.ts"
When I execute npm run local
, the output in the terminal is
cross-env NODE_ENV=local FOO=bar BAZ=foo "tsnd" "path/to/mycode.ts"
. This results in the flags not being passed correctly to tsnd, causing issues during local development. Additionally, it puts quotes around the tsnd command and file path inexplicably.
However, if I run local:dev
without define:local
(e.g.,
tsnd --inspect --respawn path/to/mycode.ts
), the output is tsnd --inspect --respawn path/to/mycode.ts
as expected, without any quotes and with the flags included.
Moreover, attempting to use ampersands in the command to combine the two scripts results in the cross-env command failing, and the environment variables aren't defined.
How can I merge these two scripts while preserving the flags and environment variables?