Skip to content

Commit

Permalink
Implements "yarn node" (#5388)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis authored Feb 21, 2018
1 parent 1a4e9ff commit 0fb0fc0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/cli/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as link from './link.js';
import * as login from './login.js';
import * as logout from './logout.js';
import * as list from './list.js';
import * as node from './node.js';
import * as outdated from './outdated.js';
import * as owner from './owner.js';
import * as pack from './pack.js';
Expand Down Expand Up @@ -70,6 +71,7 @@ const commands = {
login,
logout,
list,
node,
outdated,
owner,
pack,
Expand Down
23 changes: 23 additions & 0 deletions src/cli/commands/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @flow

import type Config from '../../config.js';
import type {Reporter} from '../../reporters/index.js';
import * as child from '../../util/child.js';
import {NODE_BIN_PATH} from '../../constants';

export function setFlags(commander: Object) {}

export function hasWrapper(commander: Object, args: Array<string>): boolean {
return true;
}

export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
try {
await child.spawn(NODE_BIN_PATH, args, {
stdio: 'inherit',
cwd: config.cwd,
});
} catch (err) {
throw err;
}
}
14 changes: 11 additions & 3 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,18 @@ export function main({
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
if (command === commands.run || command === commands.create) {
// we are using "yarn <script> -abc", "yarn run <script> -abc", or "yarn node -abc", we want -abc
// to be script options, not yarn options
const PROXY_COMMANDS = new Set([`run`, `create`, `node`]);
if (PROXY_COMMANDS.has(commandName)) {
if (endArgs.length === 0) {
endArgs = ['--', ...args.splice(1)];
// the "run" and "create" command take one argument that we want to parse as usual (the
// script/package name), hence the splice(1)
if (command === commands.run || command === commands.create) {
endArgs = ['--', ...args.splice(1)];
} else {
endArgs = ['--', ...args];
}
} else {
warnAboutRunDashDash = true;
}
Expand Down

0 comments on commit 0fb0fc0

Please sign in to comment.