Berry: [Bug] Scripts don't accept & operator

Created on 12 May 2020  路  3Comments  路  Source: yarnpkg/berry

Describe the bug

In order to run cypress tests, I use the & operator to background the execution of the process as described here. This worked fine in Yarn 1, but in Yarn 2 if any script contains this operator I get

Syntax Error: Expected "$", "$(", "${", "&&", "'", ";", "<", "<<<", ">", ">>", "\"", "\\", "|", "|&", "||", [ \t], or end of input but "&" found (line 1, column 10).
    at tt (/Users/wainwb01/repos/planv7/.yarn/releases/yarn-berry.js:28:320521)
    at Object.parse (/Users/wainwb01/repos/planv7/.yarn/releases/yarn-berry.js:28:330627)
    at Object.t.parseShell (/Users/wainwb01/repos/planv7/.yarn/releases/yarn-berry.js:28:315544)
    at Object.t.execute (/Users/wainwb01/repos/planv7/.yarn/releases/yarn-berry.js:16:19878)
    at A.configuration.reduceHook.script (/Users/wainwb01/repos/planv7/.yarn/releases/yarn-berry.js:16:5595)
    at /Users/wainwb01/repos/planv7/.yarn/releases/yarn-berry.js:16:5724
    at async s.mktempPromise (/Users/wainwb01/repos/planv7/.yarn/releases/yarn-berry.js:2:5648)
    at async Object.B [as executePackageScript] (/Users/wainwb01/repos/planv7/.yarn/releases/yarn-berry.js:16:5355)
    at async c.execute (/Users/wainwb01/repos/planv7/.yarn/releases/yarn-berry.js:50:58654)
    at async c.validateAndExecute (/Users/wainwb01/repos/planv7/.yarn/releases/yarn-berry.js:16:50176)   

To Reproduce
Add "&" to any "script" in your package.json then run the script

bug help wanted

Most helpful comment

Note that until we implement support for the & operator in our portable shell (which guarantees that things behave the same way on all platforms - e.g. environment variables - YARN_CHECKSUM_BEHAVIOR=ignore yarn install), you can run the script with another shell as an escape hatch:

{
  "scripts": {
    "build": "bash -c 'yarn build:css & yarn build:js'"  
  }
}

All 3 comments

Same on my side on Windows: Following script is failing:

eslint --cache --fix ./ >/dev/null 2>&1 || true

Error:

Syntax Error: Expected "$", "$(", "${", "'", "\"", "\", or [ \t] but "&" found (line 1, column 38).

I'm experiencing the same issue, my environment:

node --version && yarn --version
v12.16.3
2.1.1

So will be the entire Drupal community if they try to run their "build" or "watch" script from this package.json with Yarn 2.

I hope this get a fix soon. Thank you so much for all the hard work.

Note that until we implement support for the & operator in our portable shell (which guarantees that things behave the same way on all platforms - e.g. environment variables - YARN_CHECKSUM_BEHAVIOR=ignore yarn install), you can run the script with another shell as an escape hatch:

{
  "scripts": {
    "build": "bash -c 'yarn build:css & yarn build:js'"  
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

wojtekmaj picture wojtekmaj  路  3Comments

thealjey picture thealjey  路  4Comments

danreg picture danreg  路  3Comments

mormahr picture mormahr  路  3Comments

joshmeads picture joshmeads  路  4Comments