Skip to content

Commit

Permalink
Fix: Better npm_config_argv emulation
Browse files Browse the repository at this point in the history
**Summary**

Fixes #2226. Better emulates `npm_config_argv` by passing
`process.argv.slice(2)` as the `original` portion and both the
command name and the script name in `cooked` portion.

**Test case**

Added integration tests.
  • Loading branch information
BYK committed Sep 15, 2017
1 parent 8b665e3 commit 293b66e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,17 @@ export function main({
setHelpMode();
}

let command;
if (!commandName) {
commandName = 'install';
isKnownCommand = true;
}

if (isKnownCommand) {
command = commands[commandName];
} else {
if (!isKnownCommand) {
// if command is not recognized, then set default to `run`
args.unshift(commandName);
command = commands.run;
commandName = 'run';
}
const command = commands[commandName];

let warnAboutRunDashDash = false;
// we are using "yarn <script> -abc" or "yarn run <script> -abc", we want -abc to be script options, not yarn options
Expand Down Expand Up @@ -448,6 +446,7 @@ export function main({
config
.init({
cwd,
commandName,

binLinks: commander.binLinks,
modulesFolder: commander.modulesFolder,
Expand All @@ -469,8 +468,6 @@ export function main({
networkTimeout: commander.networkTimeout,
nonInteractive: commander.nonInteractive,
scriptsPrependNodePath: commander.scriptsPrependNodePath,

commandName: commandName === 'run' ? commander.args[0] : commandName,
})
.then(() => {
// option "no-progress" stored in yarn config
Expand Down
4 changes: 2 additions & 2 deletions src/util/execute-lifecycle-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export async function makeEnv(
// parser used by npm. Since we use other parser, we just roughly emulate it's output. (See: #684)
env.npm_config_argv = JSON.stringify({
remain: [],
cooked: [config.commandName],
original: [config.commandName],
cooked: config.commandName === 'run' ? [config.commandName, stage] : [config.commandName],
original: process.argv.slice(2),
});

const manifest = await config.maybeReadManifest(cwd);
Expand Down

0 comments on commit 293b66e

Please sign in to comment.