persist-env
v0.0.2
Published
Persist NPM environment variables between scripts
Downloads
2
Readme
persist-env
Persist NPM config between scripts
Problem
Running npm run ...blah
resets any configuration variables (environment variables
starting with $npm_package_config_
). Therefore a script like so:
npm_package_config_foo=bar; npm run test
... means that process.env.npm_package_config_foo
variable will not be "bar"
but infact it's previous value.
Prefixing your commands with this script replaces all of your npm run ...blah
with the script referenced in your package file.
I.e. image your package looks something like:
{
"name": "my-project",
"version": "1.0.0",
"config": {
"db_name": "my_db"
},
"scripts": {
"migrate": "echo $npm_package_config_db_name",
"test": "npm_package_config_db_name=\"${npm_package_config_db_name}_test\"; prst npm run migrate && echo done"
}
}
Then running the test command will produce the following:
$> npm test
> [email protected] test /some/path
> npm_package_config_db_name="${npm_package_config_db_name}-test"; prst npm run migrate && echo done
my_db_test
done
Installation
npm i -D persist-env