Skip to content

Commit e6d18d9

Browse files
committed
support react-scripts 4
1 parent a2dadb0 commit e6d18d9

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ you can find more detail in [this file][css-patch]
220220
| 2.0.0 - 2.1.1 | 0.1.2 |
221221
| 2.1.2 | 0.1.4 |
222222
| 3.0.0 | 0.2.0 |
223+
| 4.0.0 | 0.3.0 |
223224

224225
## Thanks
225226

bin/monkey-react-scripts.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
1919

2020
if (['build', 'start', 'test'].includes(script)) {
2121
const result = spawn.sync(
22-
'node',
22+
process.execPath,
2323
nodeArgs
2424
.concat(require.resolve('../scripts/' + script))
2525
.concat(args.slice(scriptIndex + 1)),

scripts/test.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,27 @@ require('react-scripts/config/jest/babelTransform.js')
1818
if (fs.existsSync(webpackMonkeyPath)) {
1919
console.log(chalk.yellow('WARNING! .babelrc file is enabled!'));
2020
const babelJest = require('babel-jest');
21+
22+
const hasJsxRuntime = (() => {
23+
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
24+
return false;
25+
}
26+
27+
try {
28+
require.resolve('react/jsx-runtime');
29+
return true;
30+
} catch (e) {
31+
return false;
32+
}
33+
})();
34+
2135
patchModule('react-scripts/config/jest/babelTransform.js', babelJest.createTransformer({
22-
presets: [require.resolve('babel-preset-react-app')],
36+
presets: [
37+
require.resolve('babel-preset-react-app'),
38+
{
39+
runtime: hasJsxRuntime ? 'automatic' : 'classic',
40+
},
41+
],
2342
babelrc: true,
2443
configFile: false,
2544
}));

0 commit comments

Comments
 (0)