diff --git a/CHANGELOG.md b/CHANGELOG.md index 5eb68a8014..ec23d03f50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/__tests__/commands/workspace.js b/__tests__/commands/workspace.js index a50442d22e..17d5c66d0c 100644 --- a/__tests__/commands/workspace.js +++ b/__tests__/commands/workspace.js @@ -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 => { - 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'), @@ -52,8 +48,7 @@ test('workspace run command', (): Promise => { }); test('workspace run command forwards raw arguments', (): Promise => { - 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'), diff --git a/src/cli/commands/workspace.js b/src/cli/commands/workspace.js index f6708cd8d5..4be65c6ed1 100644 --- a/src/cli/commands/workspace.js +++ b/src/cli/commands/workspace.js @@ -21,11 +21,11 @@ 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')); } @@ -33,7 +33,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg 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));