Skip to content

Commit

Permalink
feat: remove typescript flag and NODE_PATH support (#8934)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmckeb authored May 29, 2020
1 parent 26a1c7f commit 285f9cb
Show file tree
Hide file tree
Showing 17 changed files with 16 additions and 93 deletions.
1 change: 0 additions & 1 deletion docusaurus/docs/advanced-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ You can adjust various development and production settings by setting environmen
| 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. |
| 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. |
| 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. |
| 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`. |
| 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. |
| 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. |
| 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. |
Expand Down
48 changes: 3 additions & 45 deletions packages/create-react-app/createReactApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ const program = new commander.Command(packageJson.name)
)
.option('--use-npm')
.option('--use-pnp')
// TODO: Remove this in next major release.
.option(
'--typescript',
'(this option will be removed in favour of templates in the next major release of create-react-app)'
)
.allowUnknownOption()
.on('--help', () => {
console.log(` Only ${chalk.green('<project-directory>')} is required.`);
Expand Down Expand Up @@ -114,7 +109,7 @@ const program = new commander.Command(packageJson.name)
console.log();
console.log(` A custom ${chalk.cyan('--template')} can be one of:`);
console.log(
` - a custom fork published on npm: ${chalk.green(
` - a custom template published on npm: ${chalk.green(
'cra-template-typescript'
)}`
);
Expand Down Expand Up @@ -190,19 +185,10 @@ createApp(
program.scriptsVersion,
program.template,
program.useNpm,
program.usePnp,
program.typescript
program.usePnp
);

function createApp(
name,
verbose,
version,
template,
useNpm,
usePnp,
useTypeScript
) {
function createApp(name, verbose, version, template, useNpm, usePnp) {
const unsupportedNodeVersion = !semver.satisfies(process.version, '>=10');
if (unsupportedNodeVersion) {
console.log(
Expand Down Expand Up @@ -284,23 +270,6 @@ function createApp(
}
}

if (useTypeScript) {
console.log(
chalk.yellow(
'The --typescript option has been deprecated and will be removed in a future release.'
)
);
console.log(
chalk.yellow(
`In future, please use ${chalk.cyan('--template typescript')}.`
)
);
console.log();
if (!template) {
template = 'typescript';
}
}

if (useYarn) {
let yarnUsesDefaultRegistry = true;
try {
Expand Down Expand Up @@ -457,17 +426,6 @@ function run(
console.log('');
}

// TODO: Remove with next major release.
if (!supportsTemplates && (template || '').includes('typescript')) {
allDependencies.push(
'@types/node',
'@types/react',
'@types/react-dom',
'@types/jest',
'typescript'
);
}

console.log(
`Installing ${chalk.cyan('react')}, ${chalk.cyan(
'react-dom'
Expand Down
11 changes: 2 additions & 9 deletions packages/react-scripts/config/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@ const resolve = require('resolve');
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) {
// 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.

const nodePath = process.env.NODE_PATH || '';
return nodePath.split(path.delimiter).filter(Boolean);
if (!baseUrl) {
return '';
}

const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
Expand Down
12 changes: 0 additions & 12 deletions packages/react-scripts/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,6 @@ 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);
Expand Down
10 changes: 2 additions & 8 deletions packages/react-scripts/scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,7 @@ module.exports = function (
require.resolve(`${templateName}/package.json`, { paths: [appPath] })
);

let templateJsonPath;
if (templateName) {
templateJsonPath = path.join(templatePath, 'template.json');
} else {
// TODO: Remove support for this in v4.
templateJsonPath = path.join(appPath, '.template.dependencies.json');
}
const templateJsonPath = path.join(templatePath, 'template.json');

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

const templatePackage = templateJson.package || {};

// TODO: Deprecate support for root-level `dependencies` and `scripts` in v4.
// TODO: Deprecate support for root-level `dependencies` and `scripts` in v5.
// These should now be set under the `package` key.
if (templateJson.dependencies || templateJson.scripts) {
console.log();
Expand Down
12 changes: 0 additions & 12 deletions packages/react-scripts/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,6 @@ checkBrowsers(paths.appPath, 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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ function verifyTypeScriptSetup() {
allowSyntheticDefaultImports: { suggested: true },
strict: { suggested: true },
forceConsistentCasingInFileNames: { suggested: true },
// TODO: Enable for v4.0 (#6936)
// noFallthroughCasesInSwitch: { suggested: true },
noFallthroughCasesInSwitch: { suggested: true },

// These values are required and cannot be changed by the user
// Keep this in sync with the webpack config
Expand Down
4 changes: 2 additions & 2 deletions tasks/e2e-installs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ grep '"version": "1.0.17"' node_modules/react-scripts/package.json
checkDependencies

# ******************************************************************************
# Test --typescript flag
# Test typescript setup
# ******************************************************************************

cd "$temp_app_path"
npx create-react-app test-app-typescript --typescript
npx create-react-app test-app-typescript --template typescript
cd test-app-typescript

# Check corresponding template is installed.
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions test/fixtures/jsconfig/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"baseUrl": "src"
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

test('loads modules absolutely with NODE_PATH', () => {
test('loads modules absolutely with baseUrl', () => {
const div = document.createElement('div');
return new Promise(resolve => {
ReactDOM.render(<App onReady={resolve} />, div);
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion test/fixtures/node_path/.env

This file was deleted.

0 comments on commit 285f9cb

Please sign in to comment.