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(workspaces): Pass args following "--" when running workspace scripts #7786

Merged
merged 4 commits into from Jan 22, 2020

Conversation

rally25rs
Copy link
Contributor

fixes #7776

Summary

Arguments following a -- when running yarn workspaces run ... and yarn workspace package run ... were not being forwarded to the scripts.

Removed the commander.originalArgs nonsense that I introduced in a previous PR, and changed the workspace and workspaces commands to use args as already passed instead.

The yarn run command used args so it makes sense for workspace run to use args too.

I had to modify src/index.js's check for commands that should forward args and add workspace and workspaces to it. Again this is in-line with what already happened for the normal yarn run command.

As an added bonus, the normal scripts don't require "--" warning that yarn run normally prints, is now printed for workspace commands (it was not printed before this PR).

$ yarn workspaces run start -- one two
yarn workspaces v1.22.0-0
warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.

> pkg1
yarn run v1.22.0-0
$ ./start.sh one two
one two
Done in 0.07s.
Done in 0.32s.

Test plan

  • Added unit tests to __tests__/index.js

  • A manual test can be performed by setting up a basic workspace project:

package.json

{
  "name": "yarn-7776",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "private": true,
  "workspaces": [
    "packages/*"
  ]
}

packages/pkg1/package.json

{
  "name": "pkg1",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "start": "./start.sh"
  }
}

packages/pkg1/start.sh

#!/bin/bash
echo "ARGS: $@"

then run the yarn commands

yarn workspace pkg1 run start -- one two three
yarn workspace pkg1 run start one two three
yarn workspaces run start -- one two three
yarn workspaces run start one two three

The output from each should be ARGS: one two three

…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
… running a workspace 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
@rally25rs
Copy link
Contributor Author

@arcanis do you know what the errors on circleci are all about?

    Error: Cannot find module '/tmp/tmp-124nBkpXZbh4tC6/JSON.stringify((() => require('no-deps'))())'

isn't very helpful... 😕

@arcanis
Copy link
Member

arcanis commented Dec 29, 2019

My guess is that yarn node -p '...' is now incorrectly interpreted as yarn node '...', hence the Module not found on a JS script.

@rally25rs
Copy link
Contributor Author

Ah, yeah, thanks for that help. The old logic had

      if (command === commands.run || command === commands.create) {
        preservedArgs += 1;

but in my changes I had applied having 1 preservedArgs to node as well. oops 🤦‍♂

@arcanis arcanis merged commit 1b334e6 into yarnpkg:master Jan 22, 2020
VincentBailly pushed a commit to VincentBailly/yarn that referenced this pull request Jun 10, 2020
…pts (yarnpkg#7786)

* fix(workspaces): Passes arguments follwing "--" when running a workspace 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

* fix spelling in changelog

* fix(workspaces): fix(workspaces): Passes arguments follwing "--" when running a workspace 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

* don't ignore a parameter when running 'node' command
VincentBailly pushed a commit to VincentBailly/yarn that referenced this pull request Jun 10, 2020
…pts (yarnpkg#7786)

* fix(workspaces): Passes arguments follwing "--" when running a workspace 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

* fix spelling in changelog

* fix(workspaces): fix(workspaces): Passes arguments follwing "--" when running a workspace 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

* don't ignore a parameter when running 'node' command
@rally25rs rally25rs deleted the fix-workspace-arg-passing-7776 branch September 6, 2020 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Yarn workspace does not propagate flags
2 participants