-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emulate
npm_config_argv
environment variable for lifecycle scripts (c…
…loses #684)
- Loading branch information
Showing
6 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
__tests__/fixtures/lifecycle-scripts/npm_config_argv_env_vars/log-command.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
try { | ||
const argv = JSON.parse(process.env['npm_config_argv']); | ||
|
||
console.log(`##${argv.cooked[0]}##`); | ||
} catch (err) { | ||
console.log(`##${err.toString()}##`); | ||
} |
10 changes: 10 additions & 0 deletions
10
__tests__/fixtures/lifecycle-scripts/npm_config_argv_env_vars/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "npm_config_argv_env_vars", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"prepublish" : "node log-command.js", | ||
"pretest" : "node log-command.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* @flow */ | ||
|
||
import makeTemp from './_temp'; | ||
import * as fs from '../src/util/fs.js'; | ||
|
||
const path = require('path'); | ||
const exec = require('child_process').exec; | ||
|
||
const fixturesLoc = path.join(__dirname, './fixtures/lifecycle-scripts'); | ||
const yarnBin = path.join(__dirname, '../bin/yarn.js'); | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; | ||
|
||
async function execCommand(cmd: string, packageName: string): Promise<string> { | ||
const srcPackageDir = path.join(fixturesLoc, packageName); | ||
const packageDir = await makeTemp(packageName); | ||
|
||
await fs.copy(srcPackageDir, packageDir); | ||
|
||
return new Promise((resolve, reject) => { | ||
const env = Object.assign({}, process.env); | ||
|
||
delete env.npm_config_argv; | ||
|
||
exec(`node ${yarnBin} ${cmd}`, {cwd:packageDir, env}, (err, stdout) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(stdout.toString()); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
test('should expose `npm_config_argv` environment variable to lifecycle scripts for back compatibility with npm (#684)', | ||
async () => { | ||
let stdout = await execCommand('install', 'npm_config_argv_env_vars'); | ||
expect(stdout).toContain('##install##'); | ||
|
||
stdout = await execCommand('', 'npm_config_argv_env_vars'); | ||
expect(stdout).toContain('##install##'); | ||
|
||
stdout = await execCommand('test', 'npm_config_argv_env_vars'); | ||
expect(stdout).toContain('##test##'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters