Skip to content

Commit

Permalink
add .yarnrc env config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian McKenzie committed Apr 21, 2017
1 parent e7e2aa7 commit 74a182a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions __tests__/fixtures/lifecycle-scripts/yarnrc-env/.yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env:
FOO "BAR"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(process.env.FOO);
9 changes: 9 additions & 0 deletions __tests__/fixtures/lifecycle-scripts/yarnrc-env/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "yarn-config-env",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"preinstall" : "node log-command.js"
}
}
5 changes: 5 additions & 0 deletions __tests__/lifecycle-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ test('should run both prepublish and prepare when installing, but not prepublish

expect(stdout).not.toMatch(/^running the prepublishOnly hook$/m);
});

test('should allow setting environment variables via yarnrc', async () => {
const stdout = await execCommand('install', 'yarnrc-env');
expect(stdout).toMatch(/^BAR$/m);
});
3 changes: 3 additions & 0 deletions src/util/execute-lifecycle-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ async function makeEnv(stage: string, cwd: string, config: Config): {
} {
const env = Object.assign({}, process.env);

// Merge in the `env` object specified in .yarnrc
Object.assign(env, config.getOption('env') || {});

env.npm_lifecycle_event = stage;
env.npm_node_execpath = env.NODE || process.execPath;
env.npm_execpath = env.npm_execpath || process.mainModule.filename;
Expand Down

0 comments on commit 74a182a

Please sign in to comment.