Skip to content

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

@ceefour

Description

@ceefour

Self-service

  • I'd be willing to implement a fix

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreproducibleThis issue can be successfully reproducedshellThis issue is about @yarnpkg/shell

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions