Skip to content

Commit 625334f

Browse files
committed
Allow imports to be resolved from application root path
NOTE: This version is configured differently than our previous versions in an attempt to preserve the existing CRA/Jest behavior. The new approach will need to be tested to make sure it works correctly.
1 parent 95c61dd commit 625334f

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

packages/react-scripts/config/webpack.config.dev.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ module.exports = function(publicPath) {
9696
// We use `fallback` instead of `root` because we want `node_modules` to "win"
9797
// if there any conflicts. This matches Node resolution mechanism.
9898
// https://github.com/facebookincubator/create-react-app/issues/253
99-
fallback: paths.nodePaths,
99+
// ZEAL: Allow imports to be resolved from application root path
100+
fallback: [...paths.nodePaths, paths.appSrc],
100101
// These are the reasonable defaults supported by the Node ecosystem.
101102
// We also include JSX as a common component filename extension to support
102103
// some tools, although we do not recommend using it, see:

packages/react-scripts/config/webpack.config.prod.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ module.exports = {
8686
// We use `fallback` instead of `root` because we want `node_modules` to "win"
8787
// if there any conflicts. This matches Node resolution mechanism.
8888
// https://github.com/facebookincubator/create-react-app/issues/253
89-
fallback: paths.nodePaths,
89+
// ZEAL: Allow imports to be resolved from application root path
90+
fallback: [...paths.nodePaths, paths.appSrc],
9091
// These are the reasonable defaults supported by the Node ecosystem.
9192
// We also include JSX as a common component filename extension to support
9293
// some tools, although we do not recommend using it, see:

packages/react-scripts/utils/createJestConfig.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ module.exports = (resolve, rootDir, isEjecting) => {
2626
const config = {
2727
// ZEAL: Coverage report to inlcude all client src code
2828
collectCoverageFrom: ['client/**/*.{js,jsx}'],
29-
// ZEAL: Configure resolving imports from client root
30-
moduleDirectories: [paths.appSrc, paths.appNodeModules, paths.ownNodeModules],
31-
moduleNameMapper: {
32-
'^.+\\.(css|scss)$': resolve('config/jest/CSSStub.js')
33-
},
29+
// ZEAL: Allow imports to be resolved from application root path
30+
moduleDirectories: ['node_modules', paths.appSrc],
3431
setupFiles: [resolve('config/polyfills.js')],
3532
setupTestFrameworkScriptFile: setupTestsFile,
3633
testPathIgnorePatterns: [
@@ -42,7 +39,7 @@ module.exports = (resolve, rootDir, isEjecting) => {
4239
'^.+\\.(js|jsx)$': isEjecting ?
4340
'<rootDir>/node_modules/babel-jest'
4441
: resolve('config/jest/babelTransform.js'),
45-
// '^.+\\.css$': resolve('config/jest/cssTransform.js'),
42+
'^.+\\.css$': resolve('config/jest/cssTransform.js'),
4643
'^(?!.*\\.(js|jsx|css|json)$)': resolve('config/jest/fileTransform.js'),
4744
},
4845
transformIgnorePatterns: [

0 commit comments

Comments
 (0)