better-npm-run: No longer works as advised
Since https://github.com/benoror/better-npm-run/pull/55 was merged, better-npm-run
no longer sets environment from the env
field defined in betterScripts
if already set by parent process. This breaks several of our tasks since we use better-npm-run
specifically to manage environment variables on a per-task basis.
For example, with a script defined as:
"foo": {
"command": "echo $NODE_ENV",
"env": {
"NODE_ENV": "foo"
}
}
and then run it using:
NODE_ENV=bar npm run foo
the expected behaviour is that NODE_ENV
is set to foo
, however it is now set to bar
.
While I agree with the pull request comment that this behaviour was not clearly documented, from my understanding it’s the whole point of this library, which is now broken.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 4
- Comments: 27 (9 by maintainers)
Commits related to this issue
- Proposed solution for issue #56 Should solve https://github.com/benoror/better-npm-run/issues/56 — committed to hrimhari/better-npm-run by hrimhari 8 years ago
@rochdev update published to NPM as
v0.0.13
. Thanks again for reporting the issue!Looks to me like https://github.com/benoror/better-npm-run/pull/59 reverts the behaviour to be as intended, while still supporting @just-boris use case.
@just-boris From your description I think what I’ve proposed earlier would work for your use case without even needing
better-npm-run
. You could also take a look at how Heroku and similar PaaS are doing it (they all use the PORT variable to configure services)@just-boris to make sure I understand your use-case, are you saying you want the
.env
file to override thebetterScripts
environment variables? Or that thebetterScripts
environment variables override.env
file?For clarification, if you take the example from the readme.md:
The new behavior now forces NODE_ENV to whatever is in the .env file or the environment which could be
development
. It makesnpm run build:prod
effectively broken.