Skip to content

Commit

Permalink
fix(workspaces): Passes arguments follwing "--" when running a worksp…
Browse files Browse the repository at this point in the history
…ace script

Passes arguments follwing `--` when running a workspace script (`yarn workspace pkg run command --
arg`). Previously these parameters were being trimmed off and ignored.

fixes yarnpkg#7776
  • Loading branch information
rally25rs committed Dec 29, 2019
1 parent 039bafd commit 0507b95
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa

## Master

- Passes arguments follwing `--` when running a workspace script (`yarn workspace pkg run command -- arg`)

[#7776](https://github.com/yarnpkg/yarn/pull/7776) - [**Jeff Valore**](https://twitter.com/rally25rs)

- Prints workspace names with `yarn workspaces` (silence with `-s`)

[#7722](https://github.com/yarnpkg/yarn/pull/7722) - [**Orta**](https://twitter.com/orta)
Expand Down
9 changes: 2 additions & 7 deletions __tests__/commands/workspace.js
Expand Up @@ -38,12 +38,8 @@ async function runWorkspace(
}
}

// The unit tests don't use commander.js for argument parsing.
// `originalArgs` is normally passed by index.js so we just simulate it in the tests.

test('workspace run command', (): Promise<void> => {
const originalArgs = ['workspace-1', 'run', 'script'];
return runWorkspace({originalArgs}, ['workspace-1', 'run', 'script'], 'run-basic', config => {
return runWorkspace({}, ['workspace-1', 'run', 'script'], 'run-basic', config => {
expect(spawn).toHaveBeenCalledWith(NODE_BIN_PATH, [YARN_BIN_PATH, 'run', 'script'], {
stdio: 'inherit',
cwd: path.join(fixturesLoc, 'run-basic', 'packages', 'workspace-child-1'),
Expand All @@ -52,8 +48,7 @@ test('workspace run command', (): Promise<void> => {
});

test('workspace run command forwards raw arguments', (): Promise<void> => {
const originalArgs = ['workspace-1', 'run', 'script', 'arg1', '--flag1'];
return runWorkspace({originalArgs}, ['workspace-1', 'run', 'script'], 'run-basic', config => {
return runWorkspace({}, ['workspace-1', 'run', 'script', 'arg1', '--flag1'], 'run-basic', config => {
expect(spawn).toHaveBeenCalledWith(NODE_BIN_PATH, [YARN_BIN_PATH, 'run', 'script', 'arg1', '--flag1'], {
stdio: 'inherit',
cwd: path.join(fixturesLoc, 'run-basic', 'packages', 'workspace-child-1'),
Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/workspace.js
Expand Up @@ -21,19 +21,19 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
throw new MessageError(reporter.lang('workspaceRootNotFound', config.cwd));
}

if (flags.originalArgs < 1) {
if (args.length < 1) {
throw new MessageError(reporter.lang('workspaceMissingWorkspace'));
}

if (flags.originalArgs < 2) {
if (args.length < 2) {
throw new MessageError(reporter.lang('workspaceMissingCommand'));
}

const manifest = await config.findManifest(workspaceRootFolder, false);
invariant(manifest && manifest.workspaces, 'We must find a manifest with a "workspaces" property');

const workspaces = await config.resolveWorkspaces(workspaceRootFolder, manifest);
const [workspaceName, ...rest] = flags.originalArgs || [];
const [workspaceName, ...rest] = args || [];

if (!Object.prototype.hasOwnProperty.call(workspaces, workspaceName)) {
throw new MessageError(reporter.lang('workspaceUnknownWorkspace', workspaceName));
Expand Down

0 comments on commit 0507b95

Please sign in to comment.