From 13f65e8a5fdecf459994dd7da6cca9bbb4681449 Mon Sep 17 00:00:00 2001 From: Robert van Steen Date: Fri, 15 Mar 2019 20:14:51 +0100 Subject: [PATCH 01/19] Set baseUrl from jsconfig.json/tsconfig.json --- packages/react-scripts/config/env.js | 17 -------- packages/react-scripts/config/paths.js | 3 ++ .../react-scripts/config/webpack.config.js | 4 +- .../kitchensink/integration/env.test.js | 7 ---- .../fixtures/kitchensink/src/App.js | 6 ++- .../kitchensink/src/features/env/NodePath.js | 40 ------------------- .../src/features/env/NodePath.test.js | 19 --------- packages/react-scripts/scripts/start.js | 9 +++++ .../scripts/utils/createJestConfig.js | 4 ++ .../scripts/utils/verifyTypeScriptSetup.js | 11 ++--- tasks/e2e-kitchensink.sh | 2 - test/fixtures/typescript/src/App.test.ts | 10 +++++ test/fixtures/typescript/src/App.ts | 3 ++ test/fixtures/typescript/tsconfig.json | 1 + 14 files changed, 40 insertions(+), 96 deletions(-) delete mode 100644 packages/react-scripts/fixtures/kitchensink/src/features/env/NodePath.js delete mode 100644 packages/react-scripts/fixtures/kitchensink/src/features/env/NodePath.test.js diff --git a/packages/react-scripts/config/env.js b/packages/react-scripts/config/env.js index 7565cecd001..08b748ffe8e 100644 --- a/packages/react-scripts/config/env.js +++ b/packages/react-scripts/config/env.js @@ -9,7 +9,6 @@ 'use strict'; const fs = require('fs'); -const path = require('path'); const paths = require('./paths'); // Make sure that including paths.js after env.js will read .env variables. @@ -48,22 +47,6 @@ dotenvFiles.forEach(dotenvFile => { } }); -// We support resolving modules according to `NODE_PATH`. -// This lets you use absolute paths in imports inside large monorepos: -// https://github.com/facebook/create-react-app/issues/253. -// It works similar to `NODE_PATH` in Node itself: -// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders -// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. -// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. -// https://github.com/facebook/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 || '') - .split(path.delimiter) - .filter(folder => folder && !path.isAbsolute(folder)) - .map(folder => path.resolve(appDirectory, folder)) - .join(path.delimiter); - // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be // injected into the application via DefinePlugin in Webpack configuration. const REACT_APP = /^REACT_APP_/i; diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index b719054583b..e5a3e0b5374 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -84,6 +84,7 @@ module.exports = { appPackageJson: resolveApp('package.json'), appSrc: resolveApp('src'), appTsConfig: resolveApp('tsconfig.json'), + appJsConfig: resolveApp('jsconfig.json'), yarnLockFile: resolveApp('yarn.lock'), testsSetup: resolveModule(resolveApp, 'src/setupTests'), proxySetup: resolveApp('src/setupProxy.js'), @@ -106,6 +107,7 @@ module.exports = { appPackageJson: resolveApp('package.json'), appSrc: resolveApp('src'), appTsConfig: resolveApp('tsconfig.json'), + appJsConfig: resolveApp('jsconfig.json'), yarnLockFile: resolveApp('yarn.lock'), testsSetup: resolveModule(resolveApp, 'src/setupTests'), proxySetup: resolveApp('src/setupProxy.js'), @@ -140,6 +142,7 @@ if ( appPackageJson: resolveOwn('package.json'), appSrc: resolveOwn('template/src'), appTsConfig: resolveOwn('template/tsconfig.json'), + appJsConfig: resolveOwn('template/jsconfig.json'), yarnLockFile: resolveOwn('template/yarn.lock'), testsSetup: resolveModule(resolveOwn, 'template/src/setupTests'), proxySetup: resolveOwn('template/src/setupProxy.js'), diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index c569868fdfa..db7696d180c 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -27,6 +27,7 @@ const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeM const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent'); const paths = require('./paths'); +const modules = require('./modules'); const getClientEnvironment = require('./env'); const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin'); const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin'); @@ -259,8 +260,7 @@ module.exports = function(webpackEnv) { // if there are any conflicts. This matches Node resolution mechanism. // https://github.com/facebook/create-react-app/issues/253 modules: ['node_modules'].concat( - // It is guaranteed to exist because we tweak it in `env.js` - process.env.NODE_PATH.split(path.delimiter).filter(Boolean) + modules.additionalModulePath ? [modules.additionalModulePath] : [] ), // These are the reasonable defaults supported by the Node ecosystem. // We also include JSX as a common component filename extension to support diff --git a/packages/react-scripts/fixtures/kitchensink/integration/env.test.js b/packages/react-scripts/fixtures/kitchensink/integration/env.test.js index 79de16706dc..90e0e631e88 100644 --- a/packages/react-scripts/fixtures/kitchensink/integration/env.test.js +++ b/packages/react-scripts/fixtures/kitchensink/integration/env.test.js @@ -37,13 +37,6 @@ describe('Integration', () => { doc.defaultView.close(); }); - it('NODE_PATH', async () => { - const doc = await initDOM('node-path'); - - expect(doc.getElementById('feature-node-path').childElementCount).toBe(4); - doc.defaultView.close(); - }); - it('PUBLIC_URL', async () => { const doc = await initDOM('public-url'); diff --git a/packages/react-scripts/fixtures/kitchensink/src/App.js b/packages/react-scripts/fixtures/kitchensink/src/App.js index 380a49fc639..76a4a79fe4b 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/App.js +++ b/packages/react-scripts/fixtures/kitchensink/src/App.js @@ -149,8 +149,10 @@ class App extends Component { this.setFeature(f.default) ); break; - case 'node-path': - import('./features/env/NodePath').then(f => this.setFeature(f.default)); + case 'base-url': + import('./features/config/BaseUrl').then(f => + this.setFeature(f.default) + ); break; case 'no-ext-inclusion': import('./features/webpack/NoExtInclusion').then(f => diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/env/NodePath.js b/packages/react-scripts/fixtures/kitchensink/src/features/env/NodePath.js deleted file mode 100644 index e89228e20b0..00000000000 --- a/packages/react-scripts/fixtures/kitchensink/src/features/env/NodePath.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import load from 'absoluteLoad'; - -export default class extends Component { - static propTypes = { - onReady: PropTypes.func.isRequired, - }; - - constructor(props) { - super(props); - this.state = { users: [] }; - } - - async componentDidMount() { - const users = load(); - this.setState({ users }); - } - - componentDidUpdate() { - this.props.onReady(); - } - - render() { - return ( -
- {this.state.users.map(user => ( -
{user.name}
- ))} -
- ); - } -} diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/env/NodePath.test.js b/packages/react-scripts/fixtures/kitchensink/src/features/env/NodePath.test.js deleted file mode 100644 index 1de025d2f2f..00000000000 --- a/packages/react-scripts/fixtures/kitchensink/src/features/env/NodePath.test.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -import React from 'react'; -import ReactDOM from 'react-dom'; -import NodePath from './NodePath'; - -describe('NODE_PATH', () => { - it('renders without crashing', () => { - const div = document.createElement('div'); - return new Promise(resolve => { - ReactDOM.render(, div); - }); - }); -}); diff --git a/packages/react-scripts/scripts/start.js b/packages/react-scripts/scripts/start.js index 35bce798ed3..a58d58f204a 100644 --- a/packages/react-scripts/scripts/start.js +++ b/packages/react-scripts/scripts/start.js @@ -77,6 +77,15 @@ if (process.env.HOST) { console.log(); } +// We used to support resolving modules according to `NODE_PATH`. +// This now has been deprecated in favor of jsconfig/tsconfig.json +// This lets you use absolute paths in imports inside large monorepos: +if (process.env.NODE_PATH) { + console.log( + 'Setting NODE_PATH to resolves modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using Typescript) to achieve the same behaviour.' + ); +} + // We require that you explictly set browsers and do not fall back to // browserslist defaults. const { checkBrowsers } = require('react-dev-utils/browsersHelper'); diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index 705f0f87ae3..ca823a0c336 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -10,6 +10,7 @@ const fs = require('fs'); const chalk = require('react-dev-utils/chalk'); const paths = require('../../config/paths'); +const modules = require('../../config/modules'); module.exports = (resolve, rootDir, isEjecting) => { // Use this instead of `paths.testsSetup` to avoid putting @@ -50,6 +51,9 @@ module.exports = (resolve, rootDir, isEjecting) => { '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$', '^.+\\.module\\.(css|sass|scss)$', ], + modulePaths: modules.additionalModulePath + ? [modules.additionalModulePath] + : [], moduleNameMapper: { '^react-native$': 'react-native-web', '^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy', diff --git a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js index 5fcc38f8ad2..9fbe6fc94c0 100644 --- a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js +++ b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js @@ -18,7 +18,10 @@ const immer = require('react-dev-utils/immer').produce; const globby = require('react-dev-utils/globby').sync; function writeJson(fileName, object) { - fs.writeFileSync(fileName, JSON.stringify(object, null, 2).replace(/\n/g, os.EOL) + os.EOL); + fs.writeFileSync( + fileName, + JSON.stringify(object, null, 2).replace(/\n/g, os.EOL) + os.EOL + ); } function verifyNoTypeScript() { @@ -124,12 +127,6 @@ function verifyTypeScriptSetup() { value: 'preserve', reason: 'JSX is compiled by Babel', }, - // We do not support absolute imports, though this may come as a future - // enhancement - baseUrl: { - value: undefined, - reason: 'absolute imports are not supported (yet)', - }, paths: { value: undefined, reason: 'aliased imports are not supported' }, }; diff --git a/tasks/e2e-kitchensink.sh b/tasks/e2e-kitchensink.sh index b57e4550c88..57fcee24be4 100755 --- a/tasks/e2e-kitchensink.sh +++ b/tasks/e2e-kitchensink.sh @@ -122,7 +122,6 @@ npm link "$temp_module_path/node_modules/test-integrity" # Test the build REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ - NODE_PATH=src \ PUBLIC_URL=http://www.example.org/spa/ \ yarn build @@ -134,7 +133,6 @@ exists build/static/js/main.*.js # https://facebook.github.io/jest/docs/en/troubleshooting.html#tests-are-extremely-slow-on-docker-and-or-continuous-integration-ci-server REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ CI=true \ - NODE_PATH=src \ NODE_ENV=test \ yarn test --no-cache --runInBand --testPathPattern=src diff --git a/test/fixtures/typescript/src/App.test.ts b/test/fixtures/typescript/src/App.test.ts index f02c462b553..636c014031b 100644 --- a/test/fixtures/typescript/src/App.test.ts +++ b/test/fixtures/typescript/src/App.test.ts @@ -13,3 +13,13 @@ it('supports decorators', () => { const app = new App(); expect(app.decorated).toBe(42); }); + +it('supports loading modules with baseUrl', () => { + const app = new App(); + expect(app.users).toEqual([ + { id: 1, name: '1' }, + { id: 2, name: '2' }, + { id: 3, name: '3' }, + { id: 4, name: '4' }, + ]); +}); diff --git a/test/fixtures/typescript/src/App.ts b/test/fixtures/typescript/src/App.ts index d803c92d199..665f8b49f1f 100644 --- a/test/fixtures/typescript/src/App.ts +++ b/test/fixtures/typescript/src/App.ts @@ -1,3 +1,5 @@ +import absoluteLoad from 'absoluteLoad'; + interface MyType { foo: number; bar: boolean; @@ -12,6 +14,7 @@ class App { n = App.foo.baz!.n; @propertyDecorator decorated = 5; + users = absoluteLoad(); } function annotation(target: any) { diff --git a/test/fixtures/typescript/tsconfig.json b/test/fixtures/typescript/tsconfig.json index 504cd646e14..7bda36e19bf 100644 --- a/test/fixtures/typescript/tsconfig.json +++ b/test/fixtures/typescript/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "baseUrl": "src", "experimentalDecorators": true } } From 3237f4c013b692a2eb3b6f08bb0ea45f27711fd6 Mon Sep 17 00:00:00 2001 From: Robert van Steen Date: Fri, 15 Mar 2019 21:09:21 +0100 Subject: [PATCH 02/19] Resolve the path for loading modules --- packages/react-scripts/config/modules.js | 87 ++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 packages/react-scripts/config/modules.js diff --git a/packages/react-scripts/config/modules.js b/packages/react-scripts/config/modules.js new file mode 100644 index 00000000000..83f089d1fa1 --- /dev/null +++ b/packages/react-scripts/config/modules.js @@ -0,0 +1,87 @@ +// @remove-on-eject-begin +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +// @remove-on-eject-end +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const chalk = require('chalk'); +const paths = require('./paths'); + +/** + * Get the baseUrl of a compilerOptions object. + * + * @param {Object} options + */ +function getAdditionalModulePath(options = {}) { + const baseUrl = options.baseUrl; + + // We need to explicitly check for null and undefined (and not a falsy value) because + // TypeScript treats an empty string as `.`. + if (baseUrl == null) { + return null; + } + + const baseUrlResolved = path.resolve(paths.appPath, baseUrl); + + // We don't need to do anything if `baseUrl` is set to `node_modules`. This is + // the default behavior. + if (path.relative(paths.appNodeModules, baseUrlResolved) === '') { + return null; + } + + // Allow the user set the `baseUrl` to `appSrc`. + if (path.relative(paths.appSrc, baseUrlResolved) === '') { + return paths.appSrc; + } + + // Otherwise, throw an error. + throw new Error( + chalk.red.bold( + "Your project's `baseUrl` can only be set to `src` or `node_modules`." + + ' Create React App does not support other values at this time.' + ) + ); +} + +function getModules() { + // Check if TypeScript is setup + const useTypeScript = fs.existsSync(paths.appTsConfig); + const hasJsConfig = fs.existsSync(paths.appJsConfig); + + if (useTypeScript && hasJsConfig) { + throw new Error( + 'You have both a tsconfig.json and a jsconfig.json. If you are using Typescript please remove your jsconfig.json file.' + ); + } + + let config; + + // If there's a tsconfig.json we assume it's a + // Typescript project and set up the config + // based on tsconfig.json + if (useTypeScript) { + config = require(paths.appTsConfig); + // Otherwise we'll check if there is jsconfig.json + // for non TS projects. + } else if (hasJsConfig) { + config = require(paths.appJsConfig); + } + + config = config || {}; + const options = config.compilerOptions || {}; + + const additionalModulePath = getAdditionalModulePath(options); + + return { + additionalModulePath: additionalModulePath, + useTypeScript, + }; +} + +module.exports = getModules(); From 8d35263fa07dee729fccc26e0c789d5cbf7c66ab Mon Sep 17 00:00:00 2001 From: Robert van Steen Date: Fri, 15 Mar 2019 21:09:35 +0100 Subject: [PATCH 03/19] Add tests for jsconfig.json --- .../kitchensink/integration/config.test.js | 26 ++++++++++++ .../kitchensink/src/features/env/BaseUrl.js | 40 +++++++++++++++++++ .../src/features/env/BaseUrl.test.js | 19 +++++++++ 3 files changed, 85 insertions(+) create mode 100644 packages/react-scripts/fixtures/kitchensink/integration/config.test.js create mode 100644 packages/react-scripts/fixtures/kitchensink/src/features/env/BaseUrl.js create mode 100644 packages/react-scripts/fixtures/kitchensink/src/features/env/BaseUrl.test.js diff --git a/packages/react-scripts/fixtures/kitchensink/integration/config.test.js b/packages/react-scripts/fixtures/kitchensink/integration/config.test.js new file mode 100644 index 00000000000..07831724aa4 --- /dev/null +++ b/packages/react-scripts/fixtures/kitchensink/integration/config.test.js @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import initDOM from './initDOM'; + +describe('Integration', () => { + describe('jsconfig.json/tsconfig.json', () => { + it('Supports setting baseUrl to src', async () => { + const doc = await initDOM('base-url'); + + expect(doc.getElementById('feature-base-url').childElementCount).toBe(4); + doc.defaultView.close(); + }); + + it('Supports setting @ as alias to src', async () => { + const doc = await initDOM('alias'); + + expect(doc.getElementById('feature-alias').childElementCount).toBe(4); + doc.defaultView.close(); + }); + }); +}); diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/env/BaseUrl.js b/packages/react-scripts/fixtures/kitchensink/src/features/env/BaseUrl.js new file mode 100644 index 00000000000..818d4db271b --- /dev/null +++ b/packages/react-scripts/fixtures/kitchensink/src/features/env/BaseUrl.js @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import load from 'absoluteLoad'; + +export default class extends Component { + static propTypes = { + onReady: PropTypes.func.isRequired, + }; + + constructor(props) { + super(props); + this.state = { users: [] }; + } + + async componentDidMount() { + const users = load(); + this.setState({ users }); + } + + componentDidUpdate() { + this.props.onReady(); + } + + render() { + return ( +
+ {this.state.users.map(user => ( +
{user.name}
+ ))} +
+ ); + } +} diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/env/BaseUrl.test.js b/packages/react-scripts/fixtures/kitchensink/src/features/env/BaseUrl.test.js new file mode 100644 index 00000000000..aa8ddc396f7 --- /dev/null +++ b/packages/react-scripts/fixtures/kitchensink/src/features/env/BaseUrl.test.js @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React from 'react'; +import ReactDOM from 'react-dom'; +import NodePath from './BaseUrl'; + +describe('BASE_URL', () => { + it('renders without crashing', () => { + const div = document.createElement('div'); + return new Promise(resolve => { + ReactDOM.render(, div); + }); + }); +}); From 7ab30a4536042d25129f8e63e3eabdd9b4e5f241 Mon Sep 17 00:00:00 2001 From: Robert van Steen Date: Fri, 15 Mar 2019 21:11:17 +0100 Subject: [PATCH 04/19] Add jsconfig.json --- packages/react-scripts/fixtures/kitchensink/jsconfig.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/react-scripts/fixtures/kitchensink/jsconfig.json diff --git a/packages/react-scripts/fixtures/kitchensink/jsconfig.json b/packages/react-scripts/fixtures/kitchensink/jsconfig.json new file mode 100644 index 00000000000..ec2332eb49c --- /dev/null +++ b/packages/react-scripts/fixtures/kitchensink/jsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "baseUrl": "src" + } +} From 503bd6378cce642d6eb068dccfc42809cc81ed11 Mon Sep 17 00:00:00 2001 From: Ian Sutherland Date: Fri, 15 Mar 2019 21:14:49 +0100 Subject: [PATCH 05/19] Update packages/react-scripts/scripts/start.js Co-Authored-By: rovansteen --- packages/react-scripts/scripts/start.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/start.js b/packages/react-scripts/scripts/start.js index a58d58f204a..dd4798a0348 100644 --- a/packages/react-scripts/scripts/start.js +++ b/packages/react-scripts/scripts/start.js @@ -82,7 +82,7 @@ if (process.env.HOST) { // This lets you use absolute paths in imports inside large monorepos: if (process.env.NODE_PATH) { console.log( - 'Setting NODE_PATH to resolves modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using Typescript) to achieve the same behaviour.' + 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript).' ); } From 4dd60058be70a0689fce26992928df17ef306e0b Mon Sep 17 00:00:00 2001 From: Robert van Steen Date: Fri, 15 Mar 2019 21:46:47 +0100 Subject: [PATCH 06/19] Move baseUrl test to config folder --- packages/react-scripts/fixtures/kitchensink/src/App.js | 10 +++++----- .../src/features/{env => config}/BaseUrl.js | 0 .../src/features/{env => config}/BaseUrl.test.js | 0 3 files changed, 5 insertions(+), 5 deletions(-) rename packages/react-scripts/fixtures/kitchensink/src/features/{env => config}/BaseUrl.js (100%) rename packages/react-scripts/fixtures/kitchensink/src/features/{env => config}/BaseUrl.test.js (100%) diff --git a/packages/react-scripts/fixtures/kitchensink/src/App.js b/packages/react-scripts/fixtures/kitchensink/src/App.js index 76a4a79fe4b..35098380f07 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/App.js +++ b/packages/react-scripts/fixtures/kitchensink/src/App.js @@ -149,11 +149,6 @@ class App extends Component { this.setFeature(f.default) ); break; - case 'base-url': - import('./features/config/BaseUrl').then(f => - this.setFeature(f.default) - ); - break; case 'no-ext-inclusion': import('./features/webpack/NoExtInclusion').then(f => this.setFeature(f.default) @@ -224,6 +219,11 @@ class App extends Component { this.setFeature(f.default) ); break; + case 'base-url': + import('./features/config/BaseUrl').then(f => + this.setFeature(f.default) + ); + break; default: throw new Error(`Missing feature "${feature}"`); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/env/BaseUrl.js b/packages/react-scripts/fixtures/kitchensink/src/features/config/BaseUrl.js similarity index 100% rename from packages/react-scripts/fixtures/kitchensink/src/features/env/BaseUrl.js rename to packages/react-scripts/fixtures/kitchensink/src/features/config/BaseUrl.js diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/env/BaseUrl.test.js b/packages/react-scripts/fixtures/kitchensink/src/features/config/BaseUrl.test.js similarity index 100% rename from packages/react-scripts/fixtures/kitchensink/src/features/env/BaseUrl.test.js rename to packages/react-scripts/fixtures/kitchensink/src/features/config/BaseUrl.test.js From d7f0816bb9d8fa416c5ee28dbfa4929a2c546eea Mon Sep 17 00:00:00 2001 From: Robert van Steen Date: Fri, 15 Mar 2019 22:20:42 +0100 Subject: [PATCH 07/19] Remove alias test --- .../fixtures/kitchensink/integration/config.test.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packages/react-scripts/fixtures/kitchensink/integration/config.test.js b/packages/react-scripts/fixtures/kitchensink/integration/config.test.js index 07831724aa4..6d09b56c481 100644 --- a/packages/react-scripts/fixtures/kitchensink/integration/config.test.js +++ b/packages/react-scripts/fixtures/kitchensink/integration/config.test.js @@ -15,12 +15,5 @@ describe('Integration', () => { expect(doc.getElementById('feature-base-url').childElementCount).toBe(4); doc.defaultView.close(); }); - - it('Supports setting @ as alias to src', async () => { - const doc = await initDOM('alias'); - - expect(doc.getElementById('feature-alias').childElementCount).toBe(4); - doc.defaultView.close(); - }); }); }); From b16bad2c36a82a82908748f594b0a5097369ba5f Mon Sep 17 00:00:00 2001 From: Robert van Steen Date: Sun, 17 Mar 2019 15:37:54 +0100 Subject: [PATCH 08/19] Use chalk from react-dev-utils --- packages/react-scripts/config/modules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/config/modules.js b/packages/react-scripts/config/modules.js index 83f089d1fa1..02551e1d667 100644 --- a/packages/react-scripts/config/modules.js +++ b/packages/react-scripts/config/modules.js @@ -10,8 +10,8 @@ const fs = require('fs'); const path = require('path'); -const chalk = require('chalk'); const paths = require('./paths'); +const chalk = require('react-dev-utils/chalk'); /** * Get the baseUrl of a compilerOptions object. From 9eca658d2451e073c5387bf180f2176f0b884419 Mon Sep 17 00:00:00 2001 From: Robert van Steen Date: Sun, 17 Mar 2019 16:52:28 +0100 Subject: [PATCH 09/19] Add lost absolute file for typescript baseUrl test --- test/fixtures/typescript/src/absoluteLoad.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/fixtures/typescript/src/absoluteLoad.ts diff --git a/test/fixtures/typescript/src/absoluteLoad.ts b/test/fixtures/typescript/src/absoluteLoad.ts new file mode 100644 index 00000000000..5c4f7842e28 --- /dev/null +++ b/test/fixtures/typescript/src/absoluteLoad.ts @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +export default () => [ + { id: 1, name: '1' }, + { id: 2, name: '2' }, + { id: 3, name: '3' }, + { id: 4, name: '4' }, +]; From a7b084f76eb20271b50e4a18fc1834eb8bd1bf6d Mon Sep 17 00:00:00 2001 From: Brody McKee Date: Mon, 1 Apr 2019 20:29:29 +0200 Subject: [PATCH 10/19] Update packages/react-scripts/config/modules.js Co-Authored-By: rovansteen --- packages/react-scripts/config/modules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/config/modules.js b/packages/react-scripts/config/modules.js index 02551e1d667..f2bfff1fcb2 100644 --- a/packages/react-scripts/config/modules.js +++ b/packages/react-scripts/config/modules.js @@ -51,7 +51,7 @@ function getAdditionalModulePath(options = {}) { function getModules() { // Check if TypeScript is setup - const useTypeScript = fs.existsSync(paths.appTsConfig); + const hasTsConfig = fs.existsSync(paths.appTsConfig); const hasJsConfig = fs.existsSync(paths.appJsConfig); if (useTypeScript && hasJsConfig) { From 8193cef9ace55fe39cb118df5776fed496596803 Mon Sep 17 00:00:00 2001 From: Robert van Steen Date: Mon, 1 Apr 2019 20:36:05 +0200 Subject: [PATCH 11/19] Update other references of useTypeScript to hasTsConfig --- packages/react-scripts/config/modules.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-scripts/config/modules.js b/packages/react-scripts/config/modules.js index f2bfff1fcb2..03f2aa58cb9 100644 --- a/packages/react-scripts/config/modules.js +++ b/packages/react-scripts/config/modules.js @@ -54,7 +54,7 @@ function getModules() { const hasTsConfig = fs.existsSync(paths.appTsConfig); const hasJsConfig = fs.existsSync(paths.appJsConfig); - if (useTypeScript && hasJsConfig) { + if (hasTsConfig && hasJsConfig) { throw new Error( 'You have both a tsconfig.json and a jsconfig.json. If you are using Typescript please remove your jsconfig.json file.' ); @@ -65,7 +65,7 @@ function getModules() { // If there's a tsconfig.json we assume it's a // Typescript project and set up the config // based on tsconfig.json - if (useTypeScript) { + if (hasTsConfig) { config = require(paths.appTsConfig); // Otherwise we'll check if there is jsconfig.json // for non TS projects. @@ -80,7 +80,7 @@ function getModules() { return { additionalModulePath: additionalModulePath, - useTypeScript, + hasTsConfig, }; } From 4f627e96b680c7276ae15472e4638fc8e640663d Mon Sep 17 00:00:00 2001 From: Ian Sutherland Date: Fri, 5 Apr 2019 09:58:02 -0600 Subject: [PATCH 12/19] Fix casing of TypeScript --- packages/react-scripts/config/modules.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/config/modules.js b/packages/react-scripts/config/modules.js index 03f2aa58cb9..311c6bf7091 100644 --- a/packages/react-scripts/config/modules.js +++ b/packages/react-scripts/config/modules.js @@ -56,14 +56,14 @@ function getModules() { if (hasTsConfig && hasJsConfig) { throw new Error( - 'You have both a tsconfig.json and a jsconfig.json. If you are using Typescript please remove your jsconfig.json file.' + 'You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.' ); } let config; // If there's a tsconfig.json we assume it's a - // Typescript project and set up the config + // TypeScript project and set up the config // based on tsconfig.json if (hasTsConfig) { config = require(paths.appTsConfig); From c629a9e81d4ddc4761d3a45d9f39e45834b02a04 Mon Sep 17 00:00:00 2001 From: Robert van Steen Date: Sun, 14 Apr 2019 08:55:15 +0200 Subject: [PATCH 13/19] Keep respecting NODE_PATH for now to support multiple module paths. --- packages/react-scripts/config/env.js | 17 +++++++++++++++++ packages/react-scripts/config/modules.js | 15 ++++++++++----- packages/react-scripts/config/webpack.config.js | 4 +--- packages/react-scripts/scripts/start.js | 2 +- .../scripts/utils/createJestConfig.js | 4 +--- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/packages/react-scripts/config/env.js b/packages/react-scripts/config/env.js index 08b748ffe8e..7565cecd001 100644 --- a/packages/react-scripts/config/env.js +++ b/packages/react-scripts/config/env.js @@ -9,6 +9,7 @@ 'use strict'; const fs = require('fs'); +const path = require('path'); const paths = require('./paths'); // Make sure that including paths.js after env.js will read .env variables. @@ -47,6 +48,22 @@ dotenvFiles.forEach(dotenvFile => { } }); +// We support resolving modules according to `NODE_PATH`. +// This lets you use absolute paths in imports inside large monorepos: +// https://github.com/facebook/create-react-app/issues/253. +// It works similar to `NODE_PATH` in Node itself: +// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders +// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. +// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. +// https://github.com/facebook/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 || '') + .split(path.delimiter) + .filter(folder => folder && !path.isAbsolute(folder)) + .map(folder => path.resolve(appDirectory, folder)) + .join(path.delimiter); + // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be // injected into the application via DefinePlugin in Webpack configuration. const REACT_APP = /^REACT_APP_/i; diff --git a/packages/react-scripts/config/modules.js b/packages/react-scripts/config/modules.js index 311c6bf7091..3967a6b5f07 100644 --- a/packages/react-scripts/config/modules.js +++ b/packages/react-scripts/config/modules.js @@ -18,13 +18,18 @@ const chalk = require('react-dev-utils/chalk'); * * @param {Object} options */ -function getAdditionalModulePath(options = {}) { +function getAdditionalModulePaths(options = {}) { const baseUrl = options.baseUrl; // We need to explicitly check for null and undefined (and not a falsy value) because // TypeScript treats an empty string as `.`. if (baseUrl == null) { - return null; + // If there's no baseUrl set we respect NODE_PATH + // Note that NODE_PATH is deprecated and will be removed + // in the next major release of create-react-app. + + // It is guaranteed to exist because we tweak it in `env.js` + return process.env.NODE_PATH.split(path.delimiter).filter(Boolean); } const baseUrlResolved = path.resolve(paths.appPath, baseUrl); @@ -37,7 +42,7 @@ function getAdditionalModulePath(options = {}) { // Allow the user set the `baseUrl` to `appSrc`. if (path.relative(paths.appSrc, baseUrlResolved) === '') { - return paths.appSrc; + return [paths.appSrc]; } // Otherwise, throw an error. @@ -76,10 +81,10 @@ function getModules() { config = config || {}; const options = config.compilerOptions || {}; - const additionalModulePath = getAdditionalModulePath(options); + const additionalModulePaths = getAdditionalModulePaths(options); return { - additionalModulePath: additionalModulePath, + additionalModulePaths: additionalModulePaths, hasTsConfig, }; } diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 669ea62e4e7..472b280deae 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -261,9 +261,7 @@ module.exports = function(webpackEnv) { // 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 - modules: ['node_modules'].concat( - modules.additionalModulePath ? [modules.additionalModulePath] : [] - ), + modules: ['node_modules'].concat(modules.additionalModulePaths || []), // These are the reasonable defaults supported by the Node ecosystem. // We also include JSX as a common component filename extension to support // some tools, although we do not recommend using it, see: diff --git a/packages/react-scripts/scripts/start.js b/packages/react-scripts/scripts/start.js index dd4798a0348..4a6551c81c1 100644 --- a/packages/react-scripts/scripts/start.js +++ b/packages/react-scripts/scripts/start.js @@ -82,7 +82,7 @@ if (process.env.HOST) { // This lets you use absolute paths in imports inside large monorepos: if (process.env.NODE_PATH) { console.log( - 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript).' + 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.' ); } diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index d463242c916..c4e811aae57 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -50,9 +50,7 @@ module.exports = (resolve, rootDir, isEjecting) => { '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$', '^.+\\.module\\.(css|sass|scss)$', ], - modulePaths: modules.additionalModulePath - ? [modules.additionalModulePath] - : [], + modulePaths: modules.additionalModulePaths || [], moduleNameMapper: { '^react-native$': 'react-native-web', '^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy', From e72d38c72591714a69f4c8fa28c656236dbc9d42 Mon Sep 17 00:00:00 2001 From: Robert van Steen Date: Sun, 14 Apr 2019 09:08:29 +0200 Subject: [PATCH 14/19] Add test for NODE_PATH --- test/fixtures/node_path/.disable-pnp | 0 test/fixtures/node_path/.env | 1 + test/fixtures/node_path/index.test.js | 16 ++++++++ test/fixtures/node_path/package.json | 3 ++ test/fixtures/node_path/src/App.js | 41 +++++++++++++++++++++ test/fixtures/node_path/src/App.test.js | 17 +++++++++ test/fixtures/node_path/src/absoluteLoad.js | 13 +++++++ 7 files changed, 91 insertions(+) create mode 100644 test/fixtures/node_path/.disable-pnp create mode 100644 test/fixtures/node_path/.env create mode 100644 test/fixtures/node_path/index.test.js create mode 100644 test/fixtures/node_path/package.json create mode 100644 test/fixtures/node_path/src/App.js create mode 100644 test/fixtures/node_path/src/App.test.js create mode 100644 test/fixtures/node_path/src/absoluteLoad.js diff --git a/test/fixtures/node_path/.disable-pnp b/test/fixtures/node_path/.disable-pnp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/fixtures/node_path/.env b/test/fixtures/node_path/.env new file mode 100644 index 00000000000..f85aab1a415 --- /dev/null +++ b/test/fixtures/node_path/.env @@ -0,0 +1 @@ +NODE_PATH=src \ No newline at end of file diff --git a/test/fixtures/node_path/index.test.js b/test/fixtures/node_path/index.test.js new file mode 100644 index 00000000000..fe7ff9c2bda --- /dev/null +++ b/test/fixtures/node_path/index.test.js @@ -0,0 +1,16 @@ +const testSetup = require('../__shared__/test-setup'); + +test('builds in development', async () => { + const { fulfilled } = await testSetup.scripts.start({ smoke: true }); + expect(fulfilled).toBe(true); +}); +test('builds in production', async () => { + const { fulfilled } = await testSetup.scripts.build(); + expect(fulfilled).toBe(true); +}); +test('passes tests', async () => { + const { fulfilled } = await testSetup.scripts.test({ + jestEnvironment: 'node', + }); + expect(fulfilled).toBe(true); +}); diff --git a/test/fixtures/node_path/package.json b/test/fixtures/node_path/package.json new file mode 100644 index 00000000000..18a1e415e56 --- /dev/null +++ b/test/fixtures/node_path/package.json @@ -0,0 +1,3 @@ +{ + "dependencies": {} +} diff --git a/test/fixtures/node_path/src/App.js b/test/fixtures/node_path/src/App.js new file mode 100644 index 00000000000..ba7136fc0aa --- /dev/null +++ b/test/fixtures/node_path/src/App.js @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React, { Component } from 'react'; + +import PropTypes from 'prop-types'; +import load from 'absoluteLoad'; + +export default class extends Component { + static propTypes = { + onReady: PropTypes.func.isRequired, + }; + + constructor(props) { + super(props); + this.state = { users: [] }; + } + + async componentDidMount() { + const users = load(); + this.setState({ users }); + } + + componentDidUpdate() { + this.props.onReady(); + } + + render() { + return ( +
+ {this.state.users.map(user => ( +
{user.name}
+ ))} +
+ ); + } +} diff --git a/test/fixtures/node_path/src/App.test.js b/test/fixtures/node_path/src/App.test.js new file mode 100644 index 00000000000..bacc39efcfe --- /dev/null +++ b/test/fixtures/node_path/src/App.test.js @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React from 'react'; +import ReactDOM from 'react-dom'; +import App from './App'; + +test('loads modules absolutely with NODE_PATH', () => { + const div = document.createElement('div'); + return new Promise(resolve => { + ReactDOM.render(, div); + }); +}); diff --git a/test/fixtures/node_path/src/absoluteLoad.js b/test/fixtures/node_path/src/absoluteLoad.js new file mode 100644 index 00000000000..5c4f7842e28 --- /dev/null +++ b/test/fixtures/node_path/src/absoluteLoad.js @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +export default () => [ + { id: 1, name: '1' }, + { id: 2, name: '2' }, + { id: 3, name: '3' }, + { id: 4, name: '4' }, +]; From 84a479252c86fe2cddd9972c8c0314870f924d68 Mon Sep 17 00:00:00 2001 From: Robert van Steen Date: Sun, 14 Apr 2019 09:19:54 +0200 Subject: [PATCH 15/19] Add fallback if NODE_PATH is not set. --- packages/react-scripts/config/modules.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/config/modules.js b/packages/react-scripts/config/modules.js index 3967a6b5f07..b232fe37150 100644 --- a/packages/react-scripts/config/modules.js +++ b/packages/react-scripts/config/modules.js @@ -28,8 +28,8 @@ function getAdditionalModulePaths(options = {}) { // Note that NODE_PATH is deprecated and will be removed // in the next major release of create-react-app. - // It is guaranteed to exist because we tweak it in `env.js` - return process.env.NODE_PATH.split(path.delimiter).filter(Boolean); + const nodePath = process.env.NODE_PATH || ''; + return nodePath.split(path.delimiter).filter(Boolean); } const baseUrlResolved = path.resolve(paths.appPath, baseUrl); From 06902313730486ca8803f21de39733da1d9467e2 Mon Sep 17 00:00:00 2001 From: Ian Sutherland Date: Mon, 15 Apr 2019 22:07:58 -0600 Subject: [PATCH 16/19] Fix node path behavior tests --- tasks/e2e-behavior.sh | 4 ++- tasks/local-test.sh | 3 +++ test/fixtures/__shared__/util/scripts.js | 31 +++++++++++++----------- test/fixtures/node_path/.env | 2 +- test/fixtures/node_path/index.test.js | 4 +-- test/fixtures/node_path/package.json | 6 ++++- test/fixtures/node_path/src/index.js | 5 ++++ 7 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 test/fixtures/node_path/src/index.js diff --git a/tasks/e2e-behavior.sh b/tasks/e2e-behavior.sh index 93a49e5b6b3..619883787b3 100755 --- a/tasks/e2e-behavior.sh +++ b/tasks/e2e-behavior.sh @@ -9,6 +9,8 @@ # You can also run it locally but it's slow. # ****************************************************************************** +echo 'Hello!' + # Start in tasks/ even if run from root directory cd "$(dirname "$0")" @@ -98,7 +100,7 @@ git clean -df # Run all tests cd test/ -CI=true ../node_modules/.bin/jest -w 2 +CI=true ../node_modules/.bin/jest -w 2 fixtures/node_path/index.test.js # Cleanup cleanup diff --git a/tasks/local-test.sh b/tasks/local-test.sh index d1c01946c2f..ed4fcbe50ff 100755 --- a/tasks/local-test.sh +++ b/tasks/local-test.sh @@ -65,6 +65,9 @@ case ${test_suite} in "installs") test_command="./tasks/e2e-installs.sh" ;; + "behavior") + test_command="./tasks/e2e-behavior.sh" + ;; *) ;; esac diff --git a/test/fixtures/__shared__/util/scripts.js b/test/fixtures/__shared__/util/scripts.js index b1ee60e7be8..5e1f14aa067 100644 --- a/test/fixtures/__shared__/util/scripts.js +++ b/test/fixtures/__shared__/util/scripts.js @@ -25,20 +25,23 @@ function execaSafe(...args) { stderr: stripYarn(stripAnsi(stderr)), ...rest, })) - .catch(err => ({ - fulfilled: false, - rejected: true, - reason: err, - stdout: '', - stderr: stripYarn( - stripAnsi( - err.message - .split(os.EOL) - .slice(2) - .join(os.EOL) - ) - ), - })); + .catch(err => { + console.error(err); + return { + fulfilled: false, + rejected: true, + reason: err, + stdout: '', + stderr: stripYarn( + stripAnsi( + err.message + .split(os.EOL) + .slice(2) + .join(os.EOL) + ) + ), + }; + }); } module.exports = class ReactScripts { diff --git a/test/fixtures/node_path/.env b/test/fixtures/node_path/.env index f85aab1a415..f5fe60280fd 100644 --- a/test/fixtures/node_path/.env +++ b/test/fixtures/node_path/.env @@ -1 +1 @@ -NODE_PATH=src \ No newline at end of file +NODE_PATH=src diff --git a/test/fixtures/node_path/index.test.js b/test/fixtures/node_path/index.test.js index fe7ff9c2bda..eeba70a7420 100644 --- a/test/fixtures/node_path/index.test.js +++ b/test/fixtures/node_path/index.test.js @@ -9,8 +9,6 @@ test('builds in production', async () => { expect(fulfilled).toBe(true); }); test('passes tests', async () => { - const { fulfilled } = await testSetup.scripts.test({ - jestEnvironment: 'node', - }); + const { fulfilled } = await testSetup.scripts.test(); expect(fulfilled).toBe(true); }); diff --git a/test/fixtures/node_path/package.json b/test/fixtures/node_path/package.json index 18a1e415e56..fb6d17fe77d 100644 --- a/test/fixtures/node_path/package.json +++ b/test/fixtures/node_path/package.json @@ -1,3 +1,7 @@ { - "dependencies": {} + "dependencies": { + "prop-types": "^15.7.2", + "react": "latest", + "react-dom": "latest" + } } diff --git a/test/fixtures/node_path/src/index.js b/test/fixtures/node_path/src/index.js new file mode 100644 index 00000000000..b597a44232c --- /dev/null +++ b/test/fixtures/node_path/src/index.js @@ -0,0 +1,5 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import App from './App'; + +ReactDOM.render(, document.getElementById('root')); From 255a6bdf46f67c774c3e7da11d7a7c897c279cc9 Mon Sep 17 00:00:00 2001 From: Ian Sutherland Date: Mon, 15 Apr 2019 22:42:25 -0600 Subject: [PATCH 17/19] Remove debugging code from behavior test suite --- tasks/e2e-behavior.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tasks/e2e-behavior.sh b/tasks/e2e-behavior.sh index 619883787b3..93a49e5b6b3 100755 --- a/tasks/e2e-behavior.sh +++ b/tasks/e2e-behavior.sh @@ -9,8 +9,6 @@ # You can also run it locally but it's slow. # ****************************************************************************** -echo 'Hello!' - # Start in tasks/ even if run from root directory cd "$(dirname "$0")" @@ -100,7 +98,7 @@ git clean -df # Run all tests cd test/ -CI=true ../node_modules/.bin/jest -w 2 fixtures/node_path/index.test.js +CI=true ../node_modules/.bin/jest -w 2 # Cleanup cleanup From 0e0b19ebd64971f15a5e972bcb62d73e683bbef2 Mon Sep 17 00:00:00 2001 From: Ian Sutherland Date: Mon, 15 Apr 2019 22:49:48 -0600 Subject: [PATCH 18/19] Remove more debugging code --- test/fixtures/__shared__/util/scripts.js | 31 +++++++++++------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/test/fixtures/__shared__/util/scripts.js b/test/fixtures/__shared__/util/scripts.js index 5e1f14aa067..b1ee60e7be8 100644 --- a/test/fixtures/__shared__/util/scripts.js +++ b/test/fixtures/__shared__/util/scripts.js @@ -25,23 +25,20 @@ function execaSafe(...args) { stderr: stripYarn(stripAnsi(stderr)), ...rest, })) - .catch(err => { - console.error(err); - return { - fulfilled: false, - rejected: true, - reason: err, - stdout: '', - stderr: stripYarn( - stripAnsi( - err.message - .split(os.EOL) - .slice(2) - .join(os.EOL) - ) - ), - }; - }); + .catch(err => ({ + fulfilled: false, + rejected: true, + reason: err, + stdout: '', + stderr: stripYarn( + stripAnsi( + err.message + .split(os.EOL) + .slice(2) + .join(os.EOL) + ) + ), + })); } module.exports = class ReactScripts { From f039bf544c95636e803d32c9327c2b2d5e1ea3eb Mon Sep 17 00:00:00 2001 From: Ian Sutherland Date: Tue, 16 Apr 2019 14:04:42 -0600 Subject: [PATCH 19/19] Show NODE_PATH deprecation warning during build --- packages/react-scripts/scripts/build.js | 12 ++++++++++++ packages/react-scripts/scripts/start.js | 22 +++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index ab9cdee8ba1..edbc6d11557 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -136,6 +136,18 @@ checkBrowsers(paths.appPath, isInteractive) // Create the production build and print the deployment instructions. function build(previousFileSizes) { + // We used to support resolving modules according to `NODE_PATH`. + // This now has been deprecated in favor of jsconfig/tsconfig.json + // This lets you use absolute paths in imports inside large monorepos: + if (process.env.NODE_PATH) { + console.log( + chalk.yellow( + 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.' + ) + ); + console.log(); + } + console.log('Creating an optimized production build...'); const compiler = webpack(config); diff --git a/packages/react-scripts/scripts/start.js b/packages/react-scripts/scripts/start.js index 3be4d8e5f03..d4726f5f67e 100644 --- a/packages/react-scripts/scripts/start.js +++ b/packages/react-scripts/scripts/start.js @@ -77,15 +77,6 @@ if (process.env.HOST) { console.log(); } -// We used to support resolving modules according to `NODE_PATH`. -// This now has been deprecated in favor of jsconfig/tsconfig.json -// This lets you use absolute paths in imports inside large monorepos: -if (process.env.NODE_PATH) { - console.log( - 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.' - ); -} - // We require that you explicitly set browsers and do not fall back to // browserslist defaults. const { checkBrowsers } = require('react-dev-utils/browsersHelper'); @@ -138,6 +129,19 @@ checkBrowsers(paths.appPath, isInteractive) if (isInteractive) { clearConsole(); } + + // We used to support resolving modules according to `NODE_PATH`. + // This now has been deprecated in favor of jsconfig/tsconfig.json + // This lets you use absolute paths in imports inside large monorepos: + if (process.env.NODE_PATH) { + console.log( + chalk.yellow( + 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.' + ) + ); + console.log(); + } + console.log(chalk.cyan('Starting the development server...\n')); openBrowser(urls.localUrlForBrowser); });