Skip to content

Commit 285f9cb

Browse files
authored
feat: remove typescript flag and NODE_PATH support (#8934)
1 parent 26a1c7f commit 285f9cb

File tree

17 files changed

+16
-93
lines changed

17 files changed

+16
-93
lines changed

docusaurus/docs/advanced-configuration.md

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ You can adjust various development and production settings by setting environmen
2222
| REACT_EDITOR | ✅ Used | 🚫 Ignored | When an app crashes in development, you will see an error overlay with clickable stack trace. When you click on it, Create React App will try to determine the editor you are using based on currently running processes, and open the relevant source file. You can [send a pull request to detect your editor of choice](https://github.com/facebook/create-react-app/issues/2636). Setting this environment variable overrides the automatic detection. If you do it, make sure your systems [PATH](<https://en.wikipedia.org/wiki/PATH_(variable)>) environment variable points to your editor’s bin folder. You can also set it to `none` to disable it completely. |
2323
| CHOKIDAR_USEPOLLING | ✅ Used | 🚫 Ignored | When set to `true`, the watcher runs in polling mode, as necessary inside a VM. Use this option if `npm start` isn't detecting changes. |
2424
| GENERATE_SOURCEMAP | 🚫 Ignored | ✅ Used | When set to `false`, source maps are not generated for a production build. This solves out of memory (OOM) issues on some smaller machines. |
25-
| NODE_PATH | ✅ Used | ✅ Used | Same as [`NODE_PATH` in Node.js](https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders), but only relative folders are allowed. Can be handy for emulating a monorepo setup by setting `NODE_PATH=src`. |
2625
| INLINE_RUNTIME_CHUNK | 🚫 Ignored | ✅ Used | By default, Create React App will embed the runtime script into `index.html` during the production build. When set to `false`, the script will not be embedded and will be imported as usual. This is normally required when dealing with CSP. |
2726
| IMAGE_INLINE_SIZE_LIMIT | 🚫 Ignored | ✅ Used | By default, images smaller than 10,000 bytes are encoded as a data URI in base64 and inlined in the CSS or JS build artifact. Set this to control the size limit in bytes. Setting it to 0 will disable the inlining of images. |
2827
| EXTEND_ESLINT | ✅ Used | ✅ Used | When set to `true`, user provided ESLint configs will be used by `eslint-loader`. Note that any rules set to `"error"` will stop the application from building. |

packages/create-react-app/createReactApp.js

+3-45
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ const program = new commander.Command(packageJson.name)
7474
)
7575
.option('--use-npm')
7676
.option('--use-pnp')
77-
// TODO: Remove this in next major release.
78-
.option(
79-
'--typescript',
80-
'(this option will be removed in favour of templates in the next major release of create-react-app)'
81-
)
8277
.allowUnknownOption()
8378
.on('--help', () => {
8479
console.log(` Only ${chalk.green('<project-directory>')} is required.`);
@@ -114,7 +109,7 @@ const program = new commander.Command(packageJson.name)
114109
console.log();
115110
console.log(` A custom ${chalk.cyan('--template')} can be one of:`);
116111
console.log(
117-
` - a custom fork published on npm: ${chalk.green(
112+
` - a custom template published on npm: ${chalk.green(
118113
'cra-template-typescript'
119114
)}`
120115
);
@@ -190,19 +185,10 @@ createApp(
190185
program.scriptsVersion,
191186
program.template,
192187
program.useNpm,
193-
program.usePnp,
194-
program.typescript
188+
program.usePnp
195189
);
196190

197-
function createApp(
198-
name,
199-
verbose,
200-
version,
201-
template,
202-
useNpm,
203-
usePnp,
204-
useTypeScript
205-
) {
191+
function createApp(name, verbose, version, template, useNpm, usePnp) {
206192
const unsupportedNodeVersion = !semver.satisfies(process.version, '>=10');
207193
if (unsupportedNodeVersion) {
208194
console.log(
@@ -284,23 +270,6 @@ function createApp(
284270
}
285271
}
286272

287-
if (useTypeScript) {
288-
console.log(
289-
chalk.yellow(
290-
'The --typescript option has been deprecated and will be removed in a future release.'
291-
)
292-
);
293-
console.log(
294-
chalk.yellow(
295-
`In future, please use ${chalk.cyan('--template typescript')}.`
296-
)
297-
);
298-
console.log();
299-
if (!template) {
300-
template = 'typescript';
301-
}
302-
}
303-
304273
if (useYarn) {
305274
let yarnUsesDefaultRegistry = true;
306275
try {
@@ -457,17 +426,6 @@ function run(
457426
console.log('');
458427
}
459428

460-
// TODO: Remove with next major release.
461-
if (!supportsTemplates && (template || '').includes('typescript')) {
462-
allDependencies.push(
463-
'@types/node',
464-
'@types/react',
465-
'@types/react-dom',
466-
'@types/jest',
467-
'typescript'
468-
);
469-
}
470-
471429
console.log(
472430
`Installing ${chalk.cyan('react')}, ${chalk.cyan(
473431
'react-dom'

packages/react-scripts/config/modules.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,8 @@ const resolve = require('resolve');
2222
function getAdditionalModulePaths(options = {}) {
2323
const baseUrl = options.baseUrl;
2424

25-
// We need to explicitly check for null and undefined (and not a falsy value) because
26-
// TypeScript treats an empty string as `.`.
27-
if (baseUrl == null) {
28-
// If there's no baseUrl set we respect NODE_PATH
29-
// Note that NODE_PATH is deprecated and will be removed
30-
// in the next major release of create-react-app.
31-
32-
const nodePath = process.env.NODE_PATH || '';
33-
return nodePath.split(path.delimiter).filter(Boolean);
25+
if (!baseUrl) {
26+
return '';
3427
}
3528

3629
const baseUrlResolved = path.resolve(paths.appPath, baseUrl);

packages/react-scripts/scripts/build.js

-12
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,6 @@ checkBrowsers(paths.appPath, isInteractive)
150150

151151
// Create the production build and print the deployment instructions.
152152
function build(previousFileSizes) {
153-
// We used to support resolving modules according to `NODE_PATH`.
154-
// This now has been deprecated in favor of jsconfig/tsconfig.json
155-
// This lets you use absolute paths in imports inside large monorepos:
156-
if (process.env.NODE_PATH) {
157-
console.log(
158-
chalk.yellow(
159-
'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.'
160-
)
161-
);
162-
console.log();
163-
}
164-
165153
console.log('Creating an optimized production build...');
166154

167155
const compiler = webpack(config);

packages/react-scripts/scripts/init.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,7 @@ module.exports = function (
110110
require.resolve(`${templateName}/package.json`, { paths: [appPath] })
111111
);
112112

113-
let templateJsonPath;
114-
if (templateName) {
115-
templateJsonPath = path.join(templatePath, 'template.json');
116-
} else {
117-
// TODO: Remove support for this in v4.
118-
templateJsonPath = path.join(appPath, '.template.dependencies.json');
119-
}
113+
const templateJsonPath = path.join(templatePath, 'template.json');
120114

121115
let templateJson = {};
122116
if (fs.existsSync(templateJsonPath)) {
@@ -125,7 +119,7 @@ module.exports = function (
125119

126120
const templatePackage = templateJson.package || {};
127121

128-
// TODO: Deprecate support for root-level `dependencies` and `scripts` in v4.
122+
// TODO: Deprecate support for root-level `dependencies` and `scripts` in v5.
129123
// These should now be set under the `package` key.
130124
if (templateJson.dependencies || templateJson.scripts) {
131125
console.log();

packages/react-scripts/scripts/start.js

-12
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,6 @@ checkBrowsers(paths.appPath, isInteractive)
142142
clearConsole();
143143
}
144144

145-
// We used to support resolving modules according to `NODE_PATH`.
146-
// This now has been deprecated in favor of jsconfig/tsconfig.json
147-
// This lets you use absolute paths in imports inside large monorepos:
148-
if (process.env.NODE_PATH) {
149-
console.log(
150-
chalk.yellow(
151-
'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.'
152-
)
153-
);
154-
console.log();
155-
}
156-
157145
console.log(chalk.cyan('Starting the development server...\n'));
158146
openBrowser(urls.localUrlForBrowser);
159147
});

packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ function verifyTypeScriptSetup() {
106106
allowSyntheticDefaultImports: { suggested: true },
107107
strict: { suggested: true },
108108
forceConsistentCasingInFileNames: { suggested: true },
109-
// TODO: Enable for v4.0 (#6936)
110-
// noFallthroughCasesInSwitch: { suggested: true },
109+
noFallthroughCasesInSwitch: { suggested: true },
111110

112111
// These values are required and cannot be changed by the user
113112
// Keep this in sync with the webpack config

tasks/e2e-installs.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ grep '"version": "1.0.17"' node_modules/react-scripts/package.json
147147
checkDependencies
148148

149149
# ******************************************************************************
150-
# Test --typescript flag
150+
# Test typescript setup
151151
# ******************************************************************************
152152

153153
cd "$temp_app_path"
154-
npx create-react-app test-app-typescript --typescript
154+
npx create-react-app test-app-typescript --template typescript
155155
cd test-app-typescript
156156

157157
# Check corresponding template is installed.
File renamed without changes.
File renamed without changes.

test/fixtures/jsconfig/jsconfig.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "src"
4+
}
5+
}
File renamed without changes.
File renamed without changes.

test/fixtures/node_path/src/App.test.js test/fixtures/jsconfig/src/App.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React from 'react';
99
import ReactDOM from 'react-dom';
1010
import App from './App';
1111

12-
test('loads modules absolutely with NODE_PATH', () => {
12+
test('loads modules absolutely with baseUrl', () => {
1313
const div = document.createElement('div');
1414
return new Promise(resolve => {
1515
ReactDOM.render(<App onReady={resolve} />, div);
File renamed without changes.

test/fixtures/node_path/.env

-1
This file was deleted.

0 commit comments

Comments
 (0)