persist-env

0.0.2 • Public • Published

Build Status NPM Version Dependencies Greenkeeper badge License

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

> my-project@1.0.0 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

Readme

Keywords

Package Sidebar

Install

npm i persist-env

Weekly Downloads

1

Version

0.0.2

License

MIT

Last publish

Collaborators

  • johngeorgewright