From e31352b8b2227257400b5b06228295fe6bfd6ba0 Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Fri, 26 Apr 2019 00:25:47 +0430 Subject: [PATCH 01/13] update compatibility table --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index eba8c8c..2988ef1 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,7 @@ you can find more detail in [this file][css-patch] | 1.x.x | 0.1.0 | | 2.0.0 - 2.1.1 | 0.1.2 | | 2.1.2 | 0.1.4 | +| 3.0.0 | 0.2.0 | ## Thanks From 623eda98a04a9e52728e0e3134dc36e49de1ba33 Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Fri, 26 Apr 2019 00:26:19 +0430 Subject: [PATCH 02/13] 0.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 59d2be8..32aa5f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "monkey-react-scripts", - "version": "0.2.0", + "version": "0.2.1", "description": "Monkey react script runner", "main": "index.js", "repository": "git@github.com:monkey-patches/monkey-react-scripts.git", From 8d91478369018e7de8f9c8d888cffd64f9220c5a Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Sat, 5 Oct 2019 06:02:12 +0330 Subject: [PATCH 03/13] update to be more like creat-react-app@2.3 --- bin/monkey-react-scripts.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/bin/monkey-react-scripts.js b/bin/monkey-react-scripts.js index 2ced6f6..e10a0f2 100755 --- a/bin/monkey-react-scripts.js +++ b/bin/monkey-react-scripts.js @@ -1,11 +1,18 @@ #!/usr/bin/env node 'use strict'; +// Makes the script crash on unhandled rejections instead of silently +// ignoring them. In the future, promise rejections that are not handled will +// terminate the Node.js process with a non-zero exit code. +process.on('unhandledRejection', err => { + throw err; +}); + const spawn = require('react-dev-utils/crossSpawn'); const args = process.argv.slice(2); const scriptIndex = args.findIndex( - x => x === 'build' || x === 'eject' || x === 'start' || x === 'test' + x => x === 'build' || x === 'eject' || x === 'start' || x === 'test' ); const script = scriptIndex === -1 ? args[0] : args[scriptIndex]; const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []; @@ -15,24 +22,24 @@ switch (script) { case 'start': case 'test': { const result = spawn.sync( - 'node', - nodeArgs - .concat(require.resolve('../scripts/' + script)) - .concat(args.slice(scriptIndex + 1)), - {stdio: 'inherit'} + 'node', + nodeArgs + .concat(require.resolve('../scripts/' + script)) + .concat(args.slice(scriptIndex + 1)), + { stdio: 'inherit' } ); if (result.signal) { if (result.signal === 'SIGKILL') { console.log( - 'The build failed because the process exited too early. ' + - 'This probably means the system ran out of memory or someone called ' + - '`kill -9` on the process.' + 'The build failed because the process exited too early. ' + + 'This probably means the system ran out of memory or someone called ' + + '`kill -9` on the process.' ); } else if (result.signal === 'SIGTERM') { console.log( - 'The build failed because the process exited too early. ' + - 'Someone might have called `kill` or `killall`, or the system could ' + - 'be shutting down.' + 'The build failed because the process exited too early. ' + + 'Someone might have called `kill` or `killall`, or the system could ' + + 'be shutting down.' ); } process.exit(1); From 000d947691f2e6cd5c28a4ca89665e695ca1f2ca Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Sat, 5 Oct 2019 06:02:22 +0330 Subject: [PATCH 04/13] 0.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 32aa5f8..8f4cc8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "monkey-react-scripts", - "version": "0.2.1", + "version": "0.2.2", "description": "Monkey react script runner", "main": "index.js", "repository": "git@github.com:monkey-patches/monkey-react-scripts.git", From d28308815a432b75cd1692c240973d9124d53723 Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Sat, 5 Oct 2019 06:12:01 +0330 Subject: [PATCH 05/13] fix dependencies --- package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index 8f4cc8c..0d3c663 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,6 @@ "monkey-react-scripts": "./bin/monkey-react-scripts.js" }, "peerDependencies": { - "react-scripts": ">=1.0.0" - }, - "dependencies": { - "react-dev-utils": "^5.0.0" + "react-scripts": ">=2.0.0" } } From 77d64d2fd79d2d9fb59474ca946881de6dd9c00c Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Sat, 5 Oct 2019 06:12:06 +0330 Subject: [PATCH 06/13] 0.2.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0d3c663..9a3e3c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "monkey-react-scripts", - "version": "0.2.2", + "version": "0.2.3", "description": "Monkey react script runner", "main": "index.js", "repository": "git@github.com:monkey-patches/monkey-react-scripts.git", From 2b0b40cbc3f4f771014f084a22a580f21a7f0dbc Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Thu, 5 Dec 2019 23:52:09 +0330 Subject: [PATCH 07/13] update to be more like creat-react-app@3.3 --- bin/monkey-react-scripts.js | 56 +++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/bin/monkey-react-scripts.js b/bin/monkey-react-scripts.js index e10a0f2..f0e4e23 100755 --- a/bin/monkey-react-scripts.js +++ b/bin/monkey-react-scripts.js @@ -17,37 +17,31 @@ const scriptIndex = args.findIndex( const script = scriptIndex === -1 ? args[0] : args[scriptIndex]; const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []; -switch (script) { - case 'build': - case 'start': - case 'test': { - const result = spawn.sync( - 'node', - nodeArgs - .concat(require.resolve('../scripts/' + script)) - .concat(args.slice(scriptIndex + 1)), - { stdio: 'inherit' } - ); - if (result.signal) { - if (result.signal === 'SIGKILL') { - console.log( - 'The build failed because the process exited too early. ' + - 'This probably means the system ran out of memory or someone called ' + - '`kill -9` on the process.' - ); - } else if (result.signal === 'SIGTERM') { - console.log( - 'The build failed because the process exited too early. ' + - 'Someone might have called `kill` or `killall`, or the system could ' + - 'be shutting down.' - ); - } - process.exit(1); +if (['build', 'start', 'test'].includes(script)) { + const result = spawn.sync( + 'node', + nodeArgs + .concat(require.resolve('../scripts/' + script)) + .concat(args.slice(scriptIndex + 1)), + { stdio: 'inherit' } + ); + if (result.signal) { + if (result.signal === 'SIGKILL') { + console.log( + 'The build failed because the process exited too early. ' + + 'This probably means the system ran out of memory or someone called ' + + '`kill -9` on the process.' + ); + } else if (result.signal === 'SIGTERM') { + console.log( + 'The build failed because the process exited too early. ' + + 'Someone might have called `kill` or `killall`, or the system could ' + + 'be shutting down.' + ); } - process.exit(result.status); - break; + process.exit(1); } - default: - console.log('Unknown script "' + script + '".'); - break; + process.exit(result.status); +} else { + console.log('Unknown script "' + script + '".'); } From a2dadb0a07644df40566b50f71f0702158fa3df8 Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Thu, 5 Dec 2019 23:52:48 +0330 Subject: [PATCH 08/13] 0.2.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9a3e3c1..c8e0bf8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "monkey-react-scripts", - "version": "0.2.3", + "version": "0.2.4", "description": "Monkey react script runner", "main": "index.js", "repository": "git@github.com:monkey-patches/monkey-react-scripts.git", From e6d18d9fd02978631045388a6ace4e65a29bcc44 Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Sat, 24 Oct 2020 17:26:35 +0330 Subject: [PATCH 09/13] support react-scripts 4 --- README.md | 1 + bin/monkey-react-scripts.js | 2 +- scripts/test.js | 21 ++++++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2988ef1..7c4766b 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,7 @@ you can find more detail in [this file][css-patch] | 2.0.0 - 2.1.1 | 0.1.2 | | 2.1.2 | 0.1.4 | | 3.0.0 | 0.2.0 | +| 4.0.0 | 0.3.0 | ## Thanks diff --git a/bin/monkey-react-scripts.js b/bin/monkey-react-scripts.js index f0e4e23..7996e86 100755 --- a/bin/monkey-react-scripts.js +++ b/bin/monkey-react-scripts.js @@ -19,7 +19,7 @@ const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []; if (['build', 'start', 'test'].includes(script)) { const result = spawn.sync( - 'node', + process.execPath, nodeArgs .concat(require.resolve('../scripts/' + script)) .concat(args.slice(scriptIndex + 1)), diff --git a/scripts/test.js b/scripts/test.js index 6b658ff..0446be0 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -18,8 +18,27 @@ require('react-scripts/config/jest/babelTransform.js') if (fs.existsSync(webpackMonkeyPath)) { console.log(chalk.yellow('WARNING! .babelrc file is enabled!')); const babelJest = require('babel-jest'); + + const hasJsxRuntime = (() => { + if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') { + return false; + } + + try { + require.resolve('react/jsx-runtime'); + return true; + } catch (e) { + return false; + } + })(); + patchModule('react-scripts/config/jest/babelTransform.js', babelJest.createTransformer({ - presets: [require.resolve('babel-preset-react-app')], + presets: [ + require.resolve('babel-preset-react-app'), + { + runtime: hasJsxRuntime ? 'automatic' : 'classic', + }, + ], babelrc: true, configFile: false, })); From e1f5f066ba039da63f83431f0bbd4a9617209d46 Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Sat, 24 Oct 2020 17:27:43 +0330 Subject: [PATCH 10/13] 0.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c8e0bf8..d00bc2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "monkey-react-scripts", - "version": "0.2.4", + "version": "0.3.0", "description": "Monkey react script runner", "main": "index.js", "repository": "git@github.com:monkey-patches/monkey-react-scripts.git", From c8ecc5ad753606ac6308c823a4e0e6c0d9b75181 Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Sat, 24 Oct 2020 17:45:36 +0330 Subject: [PATCH 11/13] update readme and snippets --- README.md | 4 ++-- snippets/README.md | 3 +++ snippets/cra-3.x.x.md | 35 +++++++++++++++++++++++++++++++++++ snippets/cra-4.x.x.md | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 snippets/cra-3.x.x.md create mode 100644 snippets/cra-4.x.x.md diff --git a/README.md b/README.md index 7c4766b..e65e17b 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Note: returned value of `require` function is mutable. so you can mutate that be ## Snippets -You can use [snippets](snippets/cra-2.x.x.md) if you want. +You can use [snippets](snippets/cra-4.x.x.md) if you want. snippets: @@ -91,7 +91,7 @@ Also, you can find complete examples at [monkey-react-scripts-example] repo The `.babelrc` file is enabled for tests if you have `webpack.monkey.js` file. also, you can enable `.babelrc` for build and start: -- edit `webpack.monkey.js` like this (copy `findRule`, `findBabelRule` from [snippets](snippets/cra-2.x.x.md)): +- edit `webpack.monkey.js` like this (copy `findRule`, `findBabelRule` from [snippets](snippets/cra-4.x.x.md)): ```js function findRule(webpackConfig, callback) { diff --git a/snippets/README.md b/snippets/README.md index 80b572f..05cfe48 100644 --- a/snippets/README.md +++ b/snippets/README.md @@ -4,3 +4,6 @@ You need know what happen in monkey brain. So Snippets is better than helpers - [snippets for cra@0.9.x](cra-0.9.x.md) - [snippets for cra@1.x.x](cra-1.x.x.md) +- [snippets for cra@2.x.x](cra-2.x.x.md) +- [snippets for cra@3.x.x](cra-3.x.x.md) +- [snippets for cra@4.x.x](cra-4.x.x.md) diff --git a/snippets/cra-3.x.x.md b/snippets/cra-3.x.x.md new file mode 100644 index 0000000..b8a6d10 --- /dev/null +++ b/snippets/cra-3.x.x.md @@ -0,0 +1,35 @@ +# Code snippets for create-react-app 1.x.x +useful codes you can copy and use in webpack.monkey.js file. + +In real project I copy some of them in other file and use require function: + +## webpack plugin + +Add webpack plugin +```js +function addPlugin(webpackConfig, plugin) { + webpackConfig.plugins.push(plugin); +} +``` +## Find Rule + +```js +function findRule(webpackConfig, callback) { + const rules = webpackConfig.module.rules[2].oneOf; + const index = rules.findIndex(callback); + if (index === -1) throw Error('Loader not found'); + return rules[index] +} +``` + +## find Babel rule +requirement: `findRule` +```js +function findBabelRule(webpackConfig, plugins) { + // find babel rule + const babelRule = findRule(webpackConfig, (rule) => { + return ('' + rule.test === '' + /\.(js|jsx)$/) + }); + return babelRule; +} +``` diff --git a/snippets/cra-4.x.x.md b/snippets/cra-4.x.x.md new file mode 100644 index 0000000..277b70f --- /dev/null +++ b/snippets/cra-4.x.x.md @@ -0,0 +1,35 @@ +# Code snippets for create-react-app 1.x.x +useful codes you can copy and use in webpack.monkey.js file. + +In real project I copy some of them in other file and use require function: + +## webpack plugin + +Add webpack plugin +```js +function addPlugin(webpackConfig, plugin) { + webpackConfig.plugins.push(plugin); +} +``` +## Find Rule + +```js +function findRule(webpackConfig, callback) { + const rules = webpackConfig.module.rules[1].oneOf; + const index = rules.findIndex(callback); + if (index === -1) throw Error('Loader not found'); + return rules[index] +} +``` + +## find Babel rule +requirement: `findRule` +```js +function findBabelRule(webpackConfig, plugins) { + // find babel rule + const babelRule = findRule(webpackConfig, (rule) => { + return ('' + rule.test === '' + /\.(js|jsx)$/) + }); + return babelRule; +} +``` From d68c010b8e8d424aa609a3ae8a13934da975970b Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Sun, 27 Feb 2022 01:01:29 +0330 Subject: [PATCH 12/13] support react-scripts 5 --- README.md | 1 + package.json | 2 +- scripts/test.js | 28 ++++++++++++++++------------ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e65e17b..392cabb 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,7 @@ you can find more detail in [this file][css-patch] | 2.1.2 | 0.1.4 | | 3.0.0 | 0.2.0 | | 4.0.0 | 0.3.0 | +| 5.0.0 | 5.0.0-0 | ## Thanks diff --git a/package.json b/package.json index d00bc2a..6a69cb2 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,6 @@ "monkey-react-scripts": "./bin/monkey-react-scripts.js" }, "peerDependencies": { - "react-scripts": ">=2.0.0" + "react-scripts": ">=5.0.0" } } diff --git a/scripts/test.js b/scripts/test.js index 0446be0..5ff792e 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -16,8 +16,8 @@ const webpackMonkeyPath = path.resolve(appPath, 'webpack.monkey.js'); require('react-scripts/config/jest/babelTransform.js') if (fs.existsSync(webpackMonkeyPath)) { - console.log(chalk.yellow('WARNING! .babelrc file is enabled!')); - const babelJest = require('babel-jest'); + console.log(chalk.yellow('WARNING! .babelrc file is enabled!')); + const babelJest = require('babel-jest').default; const hasJsxRuntime = (() => { if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') { @@ -32,16 +32,20 @@ if (fs.existsSync(webpackMonkeyPath)) { } })(); - patchModule('react-scripts/config/jest/babelTransform.js', babelJest.createTransformer({ - presets: [ - require.resolve('babel-preset-react-app'), - { - runtime: hasJsxRuntime ? 'automatic' : 'classic', - }, - ], - babelrc: true, - configFile: false, - })); + const babelTransform = babelJest.createTransformer({ + presets: [ + [ + require.resolve('babel-preset-react-app'), + { + runtime: hasJsxRuntime ? 'automatic' : 'classic', + }, + ], + ], + babelrc: true, + configFile: false, + }); + + patchModule('react-scripts/config/jest/babelTransform.js', babelTransform); } require('react-scripts/scripts/test'); \ No newline at end of file From 347fe767c86f871aa597c13af77f9b7a73bfc824 Mon Sep 17 00:00:00 2001 From: Seyyed Morteza Moosavi Date: Sun, 27 Feb 2022 01:01:35 +0330 Subject: [PATCH 13/13] 5.0.0-0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6a69cb2..0842bd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "monkey-react-scripts", - "version": "0.3.0", + "version": "5.0.0-0", "description": "Monkey react script runner", "main": "index.js", "repository": "git@github.com:monkey-patches/monkey-react-scripts.git",