Created by: tomvalorsa
This PR adds a small fix to ensure that all npm scripts in template.json
are converted to yarn correctly. Previously with scripts that had chained commands (i.e. npm run this && npm run that
) only the first instance of npm
/npm run
would be replaced with yarn
. This is to address #8795 (closed) (which has since been closed/locked as I forgot to keep it alive with another comment - sorry for any inconvenience!).
- 1st commit adds a global flag to the regex that handles the replacing to fix this issue
- 2nd commit splits the replace function out into a util and adds some tests, as I felt a bit cheeky making a 1 char PR :)
N.B. the tests in the second commit have been placed near the code in question, but I’m happy to move them to wherever suits. I could only get these tests to run by passing the path to jest specifically, so I get the feeling that they sit outside of the normal test setup of this repo.
To run tests from root dir I used:
npx jest ./packages/react-scripts/scripts/utils/__tests__/replaceNpmScriptsWithYarn.test.js
(reverting to the original code without the g
flag breaks the second test as expected)