Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Better npm_config_argv emulation #4479

Merged
merged 6 commits into from
Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
try {
const argv = JSON.parse(process.env['npm_config_argv']);

console.log(`##${argv.cooked[0]}##`);
} catch (err) {
console.log(`##${err.toString()}##`);
}
console.log(process.env['npm_config_argv']);
8 changes: 4 additions & 4 deletions __tests__/lifecycle-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ test.concurrent(
execCommand('test', 'npm_config_argv_env_vars', env),
]);

expect(stdouts[0]).toContain('##install##');
expect(stdouts[1]).toContain('##install##');
expect(stdouts[2]).toContain('##test##');
expect(stdouts[3]).toContain('##test##');
expect(stdouts[0]).toContain('"install"');
expect(stdouts[1]).toContain('"install"');
expect(stdouts[2]).toContain('"run","test"');
expect(stdouts[3]).toContain('"run","test"');
},
);

Expand Down
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