Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Absolute paths using REACT_APP_NODE_PATH instead of NODE_PATH #178

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-scripts/config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions packages/react-scripts/scripts/utils/createJestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@

const fs = require('fs');
const chalk = require('chalk');
const path = require('path');
const paths = require('../../config/paths');
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
Expand Down Expand Up @@ -41,6 +47,15 @@ module.exports = (resolve, rootDir) => {
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$',
],
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',
},
Expand Down