Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: add react-scripts patch

ammarahm-edc45118515c7b
diff --git a/packages/editor-mobile/package.json b/packages/editor-mobile/package.json
index 38175406c..52906f0af 100644
--- a/packages/editor-mobile/package.json
+++ b/packages/editor-mobile/package.json
@@ -32,7 +32,8 @@
"start": "env-cmd -e all react-scripts start",
"build": "env-cmd -e all react-scripts build && rm -rf build.bundle && mv build build.bundle",
"test": "react-scripts test",
- "eject": "react-scripts eject"
+ "eject": "react-scripts eject",
+ "postinstall": "patch-package"
},
"homepage": ".",
"browserslist": {
diff --git a/packages/editor-mobile/patches/react-scripts+5.0.1.patch b/packages/editor-mobile/patches/react-scripts+5.0.1.patch
new file mode 100644
index 000000000..1f4d4562d
--- /dev/null
+++ b/packages/editor-mobile/patches/react-scripts+5.0.1.patch
@@ -0,0 +1,139 @@
+diff --git a/node_modules/react-scripts/config/webpack.config.js b/node_modules/react-scripts/config/webpack.config.js
+index e465d8e..5236a94 100644
+--- a/node_modules/react-scripts/config/webpack.config.js
++++ b/node_modules/react-scripts/config/webpack.config.js
+@@ -106,6 +106,9 @@ module.exports = function (webpackEnv) {
+ const isEnvProductionProfile =
+ isEnvProduction && process.argv.includes('--profile');
+
++ const isEnvProductionTest =
++ isEnvProduction && process.argv.includes('--test');
++
+ // We will provide `paths.publicUrlOrPath` to our app
+ // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
+ // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
+@@ -256,7 +259,7 @@ module.exports = function (webpackEnv) {
+ level: 'none',
+ },
+ optimization: {
+- minimize: isEnvProduction,
++ minimize: isEnvProduction && !isEnvProductionTest,
+ minimizer: [
+ // This is only used in production mode
+ new TerserPlugin({
+@@ -304,6 +307,13 @@ module.exports = function (webpackEnv) {
+ },
+ resolve: {
+ // This allows you to set a fallback for where webpack should look for modules.
++ fallback: {
++ crypto: false,
++ module: false,
++ dgram: false,
++ path: false,
++ url: false,
++ },
+ // We placed these paths second because we want `node_modules` to "win"
+ // if there are any conflicts. This matches Node resolution mechanism.
+ // https://github.com/facebook/create-react-app/issues/253
+@@ -320,13 +330,17 @@ module.exports = function (webpackEnv) {
+ .map(ext => `.${ext}`)
+ .filter(ext => useTypeScript || !ext.includes('ts')),
+ alias: {
++ "react": path.resolve(path.join(__dirname,'../../react')),
++ "react-dom": path.resolve(path.join(__dirname,'../../react-dom')),
++ "@mdi/js": path.resolve(path.join(__dirname,'../../@mdi/js')),
++ "@mdi/react": path.resolve(path.join(__dirname,'../../@mdi/react')),
+ // Support React Native Web
+ // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
+ 'react-native': 'react-native-web',
+ // Allows for better profiling with ReactDevTools
+ ...(isEnvProductionProfile && {
+ 'react-dom$': 'react-dom/profiling',
+- 'scheduler/tracing': 'scheduler/tracing-profiling',
++ 'scheduler/tracing': 'scheduler/tracing-profiling'
+ }),
+ ...(modules.webpackAliases || {}),
+ },
+@@ -336,14 +350,14 @@ module.exports = function (webpackEnv) {
+ // To fix this, we prevent you from importing files out of src/ -- if you'd like to,
+ // please link the files into your node_modules/ and let module-resolution kick in.
+ // Make sure your source files are compiled, as they will not be processed in any way.
+- new ModuleScopePlugin(paths.appSrc, [
+- paths.appPackageJson,
+- reactRefreshRuntimeEntry,
+- reactRefreshWebpackPluginRuntimeEntry,
+- babelRuntimeEntry,
+- babelRuntimeEntryHelpers,
+- babelRuntimeRegenerator,
+- ]),
++ // new ModuleScopePlugin(paths.appSrc, [
++ // paths.appPackageJson,
++ // reactRefreshRuntimeEntry,
++ // reactRefreshWebpackPluginRuntimeEntry,
++ // babelRuntimeEntry,
++ // babelRuntimeEntryHelpers,
++ // babelRuntimeRegenerator,
++ // ]),
+ ],
+ },
+ module: {
+@@ -353,7 +367,7 @@ module.exports = function (webpackEnv) {
+ shouldUseSourceMap && {
+ enforce: 'pre',
+ exclude: /@babel(?:\/|\\{1,2})runtime/,
+- test: /\.(js|mjs|jsx|ts|tsx|css)$/,
++ test: /\.(cjs|js|mjs|jsx|ts|tsx|css)$/,
+ loader: require.resolve('source-map-loader'),
+ },
+ {
+@@ -408,13 +422,13 @@ module.exports = function (webpackEnv) {
+ },
+ ],
+ issuer: {
+- and: [/\.(ts|tsx|js|jsx|md|mdx)$/],
++ and: [/\.(ts|tsx|cjs|js|jsx|md|mdx)$/],
+ },
+ },
+ // Process application JS with Babel.
+ // The preset includes JSX, Flow, TypeScript, and some ESnext features.
+ {
+- test: /\.(js|mjs|jsx|ts|tsx)$/,
++ test: /\.(cjs|js|mjs|jsx|ts|tsx)$/,
+ include: paths.appSrc,
+ loader: require.resolve('babel-loader'),
+ options: {
+@@ -453,6 +467,9 @@ module.exports = function (webpackEnv) {
+ isEnvDevelopment &&
+ shouldUseReactRefresh &&
+ require.resolve('react-refresh/babel'),
++ isEnvProduction &&
++ !isEnvProductionTest &&
++ require.resolve("babel-plugin-jsx-remove-data-test-id")
+ ].filter(Boolean),
+ // This is a feature of `babel-loader` for webpack (not Babel itself).
+ // It enables caching results in ./node_modules/.cache/babel-loader/
+@@ -460,13 +477,13 @@ module.exports = function (webpackEnv) {
+ cacheDirectory: true,
+ // See #6846 for context on why cacheCompression is disabled
+ cacheCompression: false,
+- compact: isEnvProduction,
++ compact: isEnvProduction && !isEnvProductionTest,
+ },
+ },
+ // Process any JS outside of the app with Babel.
+ // Unlike the application JS, we only compile the standard ES features.
+ {
+- test: /\.(js|mjs)$/,
++ test: /\.(cjs|js|mjs)$/,
+ exclude: /@babel(?:\/|\\{1,2})runtime/,
+ loader: require.resolve('babel-loader'),
+ options: {
+@@ -594,7 +611,7 @@ module.exports = function (webpackEnv) {
+ // its runtime that would otherwise be processed through "file" loader.
+ // Also exclude `html` and `json` extensions so they get processed
+ // by webpacks internal loaders.
+- exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
++ exclude: [/^$/, /\.(cjs|js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
+ type: 'asset/resource',
+ },
+ // ** STOP ** Are you adding a new loader?