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

Glob matching does not work when specified in script using Yarn 2 #200

Open
Robin-Hoodie opened this issue Feb 20, 2021 · 9 comments · May be fixed by #260
Open

Glob matching does not work when specified in script using Yarn 2 #200

Robin-Hoodie opened this issue Feb 20, 2021 · 9 comments · May be fixed by #260

Comments

@Robin-Hoodie
Copy link

Robin-Hoodie commented Feb 20, 2021

Running a script echo: run-p echo:* defined in package.json will not work on Yarn 2.

Example package.json:

{
  "name": "test-yarn1",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "echo:bar": "echo 'bar'",
    "echo:foo": "echo 'foo'",
    "echo": "run-p echo:*"
  },
  "devDependencies": {
    "npm-run-all": "^4.1.5"
  }
}

To reproduce:

  • Create a dir
  • Run yarn init -y
  • Run yarn add -D npm-run-all
  • Add 3 scripts to package.json:
    • "echo:foo": "echo 'foo'"
    • "echo:bar": "echo 'bar'"
    • "echo": "run-p echo:*"
  • Run yarn set version berry
  • Run yarn echo

=> No matches found: "echo:*"

Oddly enough, running yarn run-p echo:* directly does still work

Reproduction repo: https://github.com/Robin-Hoodie/yarn2-npm-run-all-repro

@nigelzor
Copy link

I just ran into this myself. If you quote the * then yarn won't try to handle the wildcard and run -p will work as expected.

Try this:

  "scripts": {
    "echo:bar": "echo 'bar'",
    "echo:foo": "echo 'foo'",
    "echo": "run-p 'echo:*'"
  }

@Robin-Hoodie
Copy link
Author

Thanks for the tip, that works!

I do think the root cause of this should be fixed however (whether here or in Yarn 2)
If not that, at minimum some documentation can be added

@arthurfiorette
Copy link

arthurfiorette commented Oct 13, 2021

I ended up falling for that too. Please add it to the documentation

jrolfs added a commit to jrolfs/jamie.rolfs.sh that referenced this issue Jan 24, 2022
@BasixKOR
Copy link

BasixKOR commented Feb 7, 2022

I don't think this is a bug for both sides. Please don't get mad at me; I was also confused by the error. However, * is a valid shell syntax for globs, and Yarn implements a bash-like shell that presumably expands the wildcard.

It seems like expanding the wildcard is the expected behaviour of Yarn, and it doesn't look like npm-run-all can solve it either.

@waptik
Copy link

waptik commented Apr 21, 2022

I just ran into this myself. If you quote the * then yarn won't try to handle the wildcard and run -p will work as expected.

Try this:

  "scripts": {
    "echo:bar": "echo 'bar'",
    "echo:foo": "echo 'foo'",
    "echo": "run-p 'echo:*'"
  }

Thanks very much for this. I had to line up all related script commands on one line as I didn't know what to do.

@mathieutu
Copy link

Hey, just had the issue too.

it doesn't look like npm-run-all can solve it either.

Agree, but adding it to the doc could be a good help, it avoids people to look for this issue 🙂.

@BensThoughts
Copy link

Ditto to all of the above. Thank goodness for github issues and threads like these. This was the first thing that broke when I updated to yarn 2, given that the docs say it will work with yarn this was a little confusing to find the solution here.

@kachkaev
Copy link

kachkaev commented Nov 5, 2022

Adding double quotes works for me in Yarn 4.0.0-rc.27:

  "scripts": {
    "echo:bar": "echo \"bar\"",
    "echo:foo": "echo \"foo\"",
-   "echo": "npm-run-all echo:*"
+   "echo": "npm-run-all \"echo:*\""
  }

Otherwise, it says No matches found: "echo:*". Using double quotes for compatibility with cmd.exe.

SuibianP added a commit to SuibianP/nusmods that referenced this issue Aug 18, 2023
Yarn 2+ expands glob patterns using its own shell and fails the `lint` script.

Quote the pattern to prevent premature expansion. Escaped double quotes are used
for compatibility with cmd.exe.

Related-Bug: mysticatea/npm-run-all#200 yarnpkg/berry#1814
SuibianP added a commit to SuibianP/nusmods that referenced this issue Aug 18, 2023
Yarn 2+ expands glob patterns using its own shell and fails the `lint` script.

Quote the pattern to prevent premature expansion. Escaped double quotes are used
for compatibility with cmd.exe.

Related-Bug: mysticatea/npm-run-all#200 yarnpkg/berry#1814
@Thanaen
Copy link

Thanaen commented Nov 13, 2023

I find it odd that this works for all the other manager packages (npm, yarn classic, pnpm, bun), but not for modern Yarn. 😅

SorsOps added a commit to tokens-studio/types that referenced this issue Dec 1, 2023
turadg added a commit to Agoric/agoric-sdk that referenced this issue Dec 13, 2023
turadg added a commit to Agoric/agoric-sdk that referenced this issue Dec 13, 2023
turadg added a commit to Agoric/agoric-sdk that referenced this issue Dec 14, 2023
turadg added a commit to Agoric/agoric-sdk that referenced this issue Dec 22, 2023
turadg added a commit to Agoric/agoric-sdk that referenced this issue Dec 22, 2023
turadg added a commit to Agoric/agoric-sdk that referenced this issue Dec 27, 2023
savitris added a commit to frameless/strapi that referenced this issue Feb 19, 2024
turadg added a commit to Agoric/agoric-sdk that referenced this issue Aug 22, 2024
turadg added a commit to Agoric/agoric-sdk that referenced this issue Aug 22, 2024
turadg added a commit to Agoric/agoric-sdk that referenced this issue Aug 22, 2024
turadg added a commit to Agoric/agoric-sdk that referenced this issue Aug 22, 2024
turadg added a commit to Agoric/agoric-sdk that referenced this issue Aug 23, 2024
turadg added a commit to Agoric/agoric-sdk that referenced this issue Aug 23, 2024
turadg added a commit to Agoric/agoric-sdk that referenced this issue Aug 23, 2024
turadg added a commit to Agoric/agoric-sdk that referenced this issue Aug 27, 2024
turadg added a commit to Agoric/agoric-sdk that referenced this issue Sep 6, 2024
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 a pull request may close this issue.

9 participants