From eb677e7454be0412ed817ccb5d9faecec69f8010 Mon Sep 17 00:00:00 2001 From: smacpherson64 Date: Tue, 24 Oct 2017 11:03:42 -0500 Subject: [PATCH 1/6] Updating env.js to use `REACT_APP_NODE_PATH` Changing `NODE_PATH` to `REACT_APP_NODE_PATH` --- packages/react-scripts/config/env.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/config/env.js b/packages/react-scripts/config/env.js index ebef79ed9..dc90bf990 100644 --- a/packages/react-scripts/config/env.js +++ b/packages/react-scripts/config/env.js @@ -57,7 +57,7 @@ dotenvFiles.forEach(dotenvFile => { // https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421 // We also resolve them to make sure all tools using them work consistently. const appDirectory = fs.realpathSync(process.cwd()); -process.env.NODE_PATH = (process.env.NODE_PATH || '') +process.env.REACT_APP_NODE_PATH = (process.env.REACT_APP_NODE_PATH || '') .split(path.delimiter) .filter(folder => folder && !path.isAbsolute(folder)) .map(folder => path.resolve(appDirectory, folder)) From 221ca0ca8922427d7f86082e2df3459cfce0014a Mon Sep 17 00:00:00 2001 From: smacpherson64 Date: Tue, 24 Oct 2017 11:05:03 -0500 Subject: [PATCH 2/6] Updating dev config to use `REACT_APP_NODE_PATH` Changing Dev Config to use `REACT_APP_NODE_PATH` instead of `NODE_PATH` --- packages/react-scripts/config/webpack.config.dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index 07c0a3adf..f265566bc 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -85,7 +85,7 @@ module.exports = { // https://github.com/facebookincubator/create-react-app/issues/253 modules: ['node_modules', paths.appNodeModules].concat( // It is guaranteed to exist because we tweak it in `env.js` - process.env.NODE_PATH.split(path.delimiter).filter(Boolean) + process.env.REACT_APP_NODE_PATH.split(path.delimiter).filter(Boolean) ), // These are the reasonable defaults supported by the Node ecosystem. // We also include JSX as a common component filename extension to support From 6f81b340dd2080868b262d621bf0630990b0d5ee Mon Sep 17 00:00:00 2001 From: smacpherson64 Date: Tue, 24 Oct 2017 11:05:57 -0500 Subject: [PATCH 3/6] Update prod config to use `REACT_APP_NODE_PATH` Setting prod config to use `REACT_APP_NODE_PATH` instead of `NODE_PATH` --- packages/react-scripts/config/webpack.config.prod.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index 9582ee731..21800949e 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -89,7 +89,7 @@ module.exports = { // https://github.com/facebookincubator/create-react-app/issues/253 modules: ['node_modules', paths.appNodeModules].concat( // It is guaranteed to exist because we tweak it in `env.js` - process.env.NODE_PATH.split(path.delimiter).filter(Boolean) + process.env.REACT_APP_NODE_PATH.split(path.delimiter).filter(Boolean) ), // These are the reasonable defaults supported by the Node ecosystem. // We also include JSX as a common component filename extension to support From 6349ccd12abea31e7896ec529911f8f0c11c51ef Mon Sep 17 00:00:00 2001 From: smacpherson64 Date: Tue, 24 Oct 2017 12:00:52 -0500 Subject: [PATCH 4/6] Updating createJestConfig module resolution path Updating createJestConfig to use `REACT_APP_NODE_PATH` and `node_modules` as the base for module resolution. --- packages/react-scripts/scripts/utils/createJestConfig.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index c5886ce0c..081b5bfd6 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -12,6 +12,7 @@ const fs = require('fs'); const chalk = require('chalk'); const paths = require('../../config/paths'); +const envs = require('../../config/env'); module.exports = (resolve, rootDir) => { // Use this instead of `paths.testsSetup` to avoid putting @@ -41,6 +42,9 @@ module.exports = (resolve, rootDir) => { transformIgnorePatterns: [ '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$', ], + moduleDirectories: ['node_modules'].concat( + process.env.REACT_APP_NODE_PATH.split(paths.appPath).filter(Boolean) + ), moduleNameMapper: { '^react-native$': 'react-native-web', }, From 6afaae8e7f68bc11b378b9a2a77a3ba512498a36 Mon Sep 17 00:00:00 2001 From: smacpherson64 Date: Tue, 24 Oct 2017 12:01:33 -0500 Subject: [PATCH 5/6] Minor syntax update --- packages/react-scripts/scripts/utils/createJestConfig.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index 081b5bfd6..a81c2580d 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -44,7 +44,7 @@ module.exports = (resolve, rootDir) => { ], moduleDirectories: ['node_modules'].concat( process.env.REACT_APP_NODE_PATH.split(paths.appPath).filter(Boolean) - ), + ), moduleNameMapper: { '^react-native$': 'react-native-web', }, From ae782979f5664a11b22524c7dc99fee18ca10936 Mon Sep 17 00:00:00 2001 From: smacpherson64 Date: Tue, 24 Oct 2017 12:59:05 -0500 Subject: [PATCH 6/6] Adjusting for linting, and updating logic to match Adjusting code to avoid linting issue where `env` variable was defined but not used. Updated logic of the moduleDirectories to be closer to how the dev and prod configs are setup allowing for splitting based upon a path delimiter as well as making the path relative. EG: The line: `{full-path}/some/path;{full-path}/some/other/path`: Should result in: ['/some/path', '/some/other/path'] by removing {full-path} and split based upon the `;` delimiter. --- .../scripts/utils/createJestConfig.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index a81c2580d..6c248ef49 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -11,8 +11,13 @@ const fs = require('fs'); const chalk = require('chalk'); +const path = require('path'); const paths = require('../../config/paths'); -const envs = require('../../config/env'); +const getClientEnvironment = require('../../config/env'); + +// Using development config publicUrl option when injecting environment variables. +const publicUrl = ''; +getClientEnvironment(publicUrl); module.exports = (resolve, rootDir) => { // Use this instead of `paths.testsSetup` to avoid putting @@ -42,8 +47,14 @@ module.exports = (resolve, rootDir) => { transformIgnorePatterns: [ '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$', ], - moduleDirectories: ['node_modules'].concat( - process.env.REACT_APP_NODE_PATH.split(paths.appPath).filter(Boolean) + moduleDirectories: ['node_modules', paths.appNodeModules].concat( + // moduleDirectories uses a relative path + // Removing injected full path from REACT_APP_NODE_PATH (from env.js) + process.env.REACT_APP_NODE_PATH + .split(paths.appPath) + .join('') + .split(path.delimiter) + .filter(Boolean) ), moduleNameMapper: { '^react-native$': 'react-native-web',