yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.43k stars 1.11k forks source link

[Bug]: Using "{" and "}" in package.json script throws Syntax Error: Expected any character but end of input found #3865

Open ceefour opened 2 years ago

ceefour commented 2 years ago

Self-service

Describe the bug

See repro. Will throw:

$ yarn prettier:watch
Syntax Error: Expected any character but end of input found (line 1, column 81).
    at zM (/home/ceefour/project/tmra/tmra-next/.yarn/releases/yarn-3.1.1.cjs:158:2926)
    at mke (/home/ceefour/project/tmra/tmra-next/.yarn/releases/yarn-3.1.1.cjs:158:19836)
    at Aw (/home/ceefour/project/tmra/tmra-next/.yarn/releases/yarn-3.1.1.cjs:383:10983)
    at Fw (/home/ceefour/project/tmra/tmra-next/.yarn/releases/yarn-3.1.1.cjs:407:1897)
    at h (/home/ceefour/project/tmra/tmra-next/.yarn/releases/yarn-3.1.1.cjs:425:2692)
    at /home/ceefour/project/tmra/tmra-next/.yarn/releases/yarn-3.1.1.cjs:425:2876
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Wt.mktempPromise (/home/ceefour/project/tmra/tmra-next/.yarn/releases/yarn-3.1.1.cjs:317:62926)
    at async Object.Uw (/home/ceefour/project/tmra/tmra-next/.yarn/releases/yarn-3.1.1.cjs:425:2498)
    at async LC.execute (/home/ceefour/project/tmra/tmra-next/.yarn/releases/yarn-3.1.1.cjs:561:2054)

The use case is something like this: (which works with npm run prettier:watch)

    "prettier:watch": "onchange '**/*.{js,jsx,ts,tsx}' -- prettier --write --ignore-unknown {{changed}}",

The workaround as of yarn 3.1.1 is to use:

    "prettier:watch": "onchange '**/*.{js,jsx,ts,tsx}' -- prettier --write --ignore-unknown \\{\\{changed\\}\\}",

To reproduce

await packageJsonAndInstall({
  scripts: {hello: 'echo {{hello}}'},
});

await expect(yarn('hello')).resolves.not.toThrow(`Syntax Error`);

Environment

System:
    OS: Linux 5.8 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  Binaries:
    Node: 16.13.1 - /tmp/xfs-bf325123/node
    Yarn: 3.1.1 - /tmp/xfs-bf325123/yarn
    npm: 6.14.15 - /usr/bin/npm
  npmPackages:
    jest: ^26.6.3 => 26.6.3

Additional context

No response

yarnbot commented 2 years ago

Hi! 👋

This issue looks stale, and doesn't feature the reproducible label - which implies that you didn't provide a working reproduction using Sherlock. As a result, it'll be closed in a few days unless a maintainer explicitly vouches for it or you edit your first post to include a formal reproduction (you can use the playground for that).

Note that we require Sherlock reproductions for long-lived issues (rather than standalone git repositories or similar) because we're a small team. Sherlock gives us the ability to check which bugs are still affecting the master branch at any given point, and decreases the amount of code we need to run on our own machines (thus leading to faster bug resolutions). It helps us help you! 😃

If you absolutely cannot reproduce a bug on Sherlock (for example because it's a Windows-only issue), a maintainer will have to manually add the upholded label. Thanks for helping us triaging our repository! 🌟

yarnbot commented 2 years ago

This issue reproduces on master:

Error: expect(received).resolves.not.toThrow()

Received promise rejected instead of resolved
Rejected to value: [Error: Command failed: /usr/bin/node /github/workspace/scripts/actions/../run-yarn.js hello

Syntax Error: Expected any character but end of input found (line 1, column 15).
    at peg$buildStructuredError (/github/workspace/packages/yarnpkg-parsers/sources/grammars/shell.js:457:12)
    at peg$parse (/github/workspace/packages/yarnpkg-parsers/sources/grammars/shell.js:3593:11)
    at parseShell (/github/workspace/packages/yarnpkg-parsers/sources/shell.ts:5:12)
    at execute (/github/workspace/packages/yarnpkg-shell/sources/index.ts:1026:15)
    at executor (/github/workspace/packages/yarnpkg-core/sources/scriptUtils.ts:420:20)
    at /github/workspace/packages/yarnpkg-core/sources/scriptUtils.ts:429:18
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at NodeFS.mktempPromise (/github/workspace/packages/yarnpkg-fslib/sources/xfs.ts:111:18)
    at Object.executePackageScript (/github/workspace/packages/yarnpkg-core/sources/scriptUtils.ts:412:10)
    at RunCommand.execute (/github/workspace/packages/plugin-essentials/sources/commands/run.ts:79:14)
]
    at expect (/github/workspace/.yarn/cache/expect-npm-24.8.0-8c7640c562-0c0da74930.zip/node_modules/expect/build/index.js:138:15)
    at module.exports (evalmachine.<anonymous>:6:7)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-ccfa417b92.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-ccfa417b92.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
    at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-ccfa417b92.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-ccfa417b92.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)
maranomynet commented 2 years ago

This bug is also biting me pretty hard.

flying-sheep commented 1 year ago

For me, this line triggers it:

{
    "scripts": {
        "lint": "eslint '{*.js,*.ts,src/**/*.ts*'}"
    }
}

the version installed by yarn set version from sources --no-minify seems to be unaffected, so maybe it got fixed between https://github.com/yarnpkg/berry/compare/%40yarnpkg/cli/3.3.0...f9e08385568e767e00b65e44dc9f5fc166e5b02a?

Maybe fixed by this? https://github.com/yarnpkg/berry/pull/4288

derekmurawsky commented 1 year ago

We are still having this issue using version 3.4.1. It's particularly painful with our turborepo scripts which use { and } to support their filtering. See https://turbo.build/repo/docs/core-concepts/monorepos/filtering for more examples. Anything I can do to help move this forward? Happy to be a guineapig.

derekmurawsky commented 1 year ago

Confirmed this issue still exists in 3.5.

yarinsa commented 1 year ago

Still exists at 3.5.1 trying to use env var ${CONSOLE_PORT:=3000}

nephix commented 1 year ago

I'm having the same issue when trying to access env vars:

    "start": "next start -p ${PORT:=3000}",
wesleybl commented 1 year ago

I still see this problem to this day, in version 3.6.1.

@arcanis the PR #4288 shouldn't I have fixed that?

Friend-LGA commented 9 months ago

Still the case for yarn 4.0.2

It is not possible to write script such

"test": "pwsh -Command { Get-ChildItem -Exclude 'node_modules' -Dir }"