Ability to tweak environment variables for scripts from package.json #2800

Closed
eldargab opened this Issue Sep 13, 2012 · 6 comments

Projects

None yet

5 participants

@eldargab

Currently there is no (at least I don't know) cross platform way to tweak environment variables. For example,

{
  "scripts": {
    "test": "NODE_ENV=test mocha -R spec"
  }
}

will fail on windows, while some third party tools can require environment tweaking.

The proposal is to extend script field and give it an ability to receive config object like

{
  "scripts": {
    "test": {
      "vars": {
        "NODE_ENV": "test"
      },
      "cmd": "mocha -R spec"
    }
  }
}
@domenic
Member
domenic commented Mar 25, 2013

This is not npm's job. You can run custom Node scripts to set environment variables using process.env if you'd like, or use something that isn't environment variables (like JSON).

@domenic domenic closed this Mar 25, 2013
@eldargab

People do use environment variables, for example it's not nice to test connect.errorHandler() without NODE_ENV=test. Npm already adds ./node_modules/.bin to the PATH and runs shell commands. Without tweaking environment this functionality is just incomplete.

@domenic
Member
domenic commented Mar 25, 2013

That's really a limitation of your testing environment and of the connect package. Again, not npm's job. You can write custom scripts to work around connect's limitations, e.g. in your tests modify process.env.

@davelester davelester referenced this issue in mozilla/openbadges-backpack Apr 1, 2013
Open

npm test fails on Windows #810

@inf3rno
inf3rno commented Feb 13, 2015

+1

@bebraw bebraw referenced this issue in survivejs/react-book May 5, 2015
@bebraw bebraw Point directly at `config/index.js` at package.json
Looks like just `config` can be problematic on some platforms.
f2f4b35
@zixia
zixia commented May 25, 2016

This npm module helps:
https://www.npmjs.com/package/cross-env

cross-env solve this problem perfectly, hope helps.

@elhigu
elhigu commented Jun 14, 2016

@zixia I wish it would also solve problem of using environment variables in package.json scripts e.g.

  "scripts": {
    "test": "istanbul --config=test/.istanbul.yml cover node_modules/mocha/bin/_mocha -- --check-leaks -t $MOCHA_TIMEOUT -b -R spec test/index.js"
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment