Skip to content

Commit b2cf28b

Browse files
authored
Revert "Speed up TypeScript v2 (facebook#6406)" (facebook#6585)
This reverts commit 6a5b3cd.
1 parent b5887dc commit b2cf28b

14 files changed

+47
-220
lines changed

packages/react-dev-utils/ForkTsCheckerWebpackPlugin.js

-12
This file was deleted.

packages/react-dev-utils/README.md

+2-12
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,9 @@ printHostingInstructions(appPackage, publicUrl, publicPath, 'build', true);
325325

326326
Returns a Promise resolving to either `defaultPort` or next available port if the user confirms it is okay to do. If the port is taken and the user has refused to use another port, or if the terminal is not interactive and can’t present user with the choice, resolves to `null`.
327327

328-
##### `createCompiler(args: Object): WebpackCompiler`
328+
##### `createCompiler(webpack: Function, config: Object, appName: string, urls: Object, useYarn: boolean): WebpackCompiler`
329329

330-
Creates a Webpack compiler instance for WebpackDevServer with built-in helpful messages.
331-
332-
The `args` object accepts a number of properties:
333-
334-
- **appName** `string`: The name that will be printed to the terminal.
335-
- **config** `Object`: The webpack configuration options to be provided to the webpack constructor.
336-
- **devSocket** `Object`: Required if `useTypeScript` is `true`. This object should include `errors` and `warnings` which are functions accepting an array of errors or warnings emitted by the type checking. This is useful when running `fork-ts-checker-webpack-plugin` with `async: true` to report errors that are emitted after the webpack build is complete.
337-
- **urls** `Object`: To provide the `urls` argument, use `prepareUrls()` described below.
338-
- **useYarn** `boolean`: If `true`, yarn instructions will be emitted in the terminal instead of npm.
339-
- **useTypeScript** `boolean`: If `true`, TypeScript type checking will be enabled. Be sure to provide the `devSocket` argument above if this is set to `true`.
340-
- **webpack** `function`: A reference to the webpack constructor.
330+
Creates a Webpack compiler instance for WebpackDevServer with built-in helpful messages. Takes the `require('webpack')` entry point as the first argument. To provide the `urls` argument, use `prepareUrls()` described below.
341331

342332
##### `prepareProxy(proxySetting: string, appPublicFolder: string): Object`
343333

packages/react-dev-utils/WebpackDevServerUtils.js

+20-96
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,22 @@ const inquirer = require('inquirer');
1717
const clearConsole = require('./clearConsole');
1818
const formatWebpackMessages = require('./formatWebpackMessages');
1919
const getProcessForPort = require('./getProcessForPort');
20-
const typescriptFormatter = require('./typescriptFormatter');
21-
const forkTsCheckerWebpackPlugin = require('./ForkTsCheckerWebpackPlugin');
2220

2321
const isInteractive = process.stdout.isTTY;
22+
let handleCompile;
23+
24+
// You can safely remove this after ejecting.
25+
// We only use this block for testing of Create React App itself:
26+
const isSmokeTest = process.argv.some(arg => arg.indexOf('--smoke-test') > -1);
27+
if (isSmokeTest) {
28+
handleCompile = (err, stats) => {
29+
if (err || stats.hasErrors() || stats.hasWarnings()) {
30+
process.exit(1);
31+
} else {
32+
process.exit(0);
33+
}
34+
};
35+
}
2436

2537
function prepareUrls(protocol, host, port) {
2638
const formatUrl = hostname =>
@@ -101,20 +113,12 @@ function printInstructions(appName, urls, useYarn) {
101113
console.log();
102114
}
103115

104-
function createCompiler({
105-
appName,
106-
config,
107-
devSocket,
108-
urls,
109-
useYarn,
110-
useTypeScript,
111-
webpack,
112-
}) {
116+
function createCompiler(webpack, config, appName, urls, useYarn) {
113117
// "Compiler" is a low-level interface to Webpack.
114118
// It lets us listen to some events and provide our own custom messages.
115119
let compiler;
116120
try {
117-
compiler = webpack(config);
121+
compiler = webpack(config, handleCompile);
118122
} catch (err) {
119123
console.log(chalk.red('Failed to compile.'));
120124
console.log();
@@ -135,35 +139,10 @@ function createCompiler({
135139
});
136140

137141
let isFirstCompile = true;
138-
let tsMessagesPromise;
139-
let tsMessagesResolver;
140-
141-
if (useTypeScript) {
142-
compiler.hooks.beforeCompile.tap('beforeCompile', () => {
143-
tsMessagesPromise = new Promise(resolve => {
144-
tsMessagesResolver = msgs => resolve(msgs);
145-
});
146-
});
147-
148-
forkTsCheckerWebpackPlugin
149-
.getCompilerHooks(compiler)
150-
.receive.tap('afterTypeScriptCheck', (diagnostics, lints) => {
151-
const allMsgs = [...diagnostics, ...lints];
152-
const format = message =>
153-
`${message.file}\n${typescriptFormatter(message, true)}`;
154-
155-
tsMessagesResolver({
156-
errors: allMsgs.filter(msg => msg.severity === 'error').map(format),
157-
warnings: allMsgs
158-
.filter(msg => msg.severity === 'warning')
159-
.map(format),
160-
});
161-
});
162-
}
163142

164143
// "done" event fires when Webpack has finished recompiling the bundle.
165144
// Whether or not you have warnings or errors, you will get this event.
166-
compiler.hooks.done.tap('done', async stats => {
145+
compiler.hooks.done.tap('done', stats => {
167146
if (isInteractive) {
168147
clearConsole();
169148
}
@@ -173,43 +152,9 @@ function createCompiler({
173152
// them in a readable focused way.
174153
// We only construct the warnings and errors for speed:
175154
// https://github.com/facebook/create-react-app/issues/4492#issuecomment-421959548
176-
const statsData = stats.toJson({
177-
all: false,
178-
warnings: true,
179-
errors: true,
180-
});
181-
182-
if (useTypeScript && statsData.errors.length === 0) {
183-
const delayedMsg = setTimeout(() => {
184-
console.log(
185-
chalk.yellow(
186-
'Files successfully emitted, waiting for typecheck results...'
187-
)
188-
);
189-
}, 100);
190-
191-
const messages = await tsMessagesPromise;
192-
clearTimeout(delayedMsg);
193-
statsData.errors.push(...messages.errors);
194-
statsData.warnings.push(...messages.warnings);
195-
196-
// Push errors and warnings into compilation result
197-
// to show them after page refresh triggered by user.
198-
stats.compilation.errors.push(...messages.errors);
199-
stats.compilation.warnings.push(...messages.warnings);
200-
201-
if (messages.errors.length > 0) {
202-
devSocket.errors(messages.errors);
203-
} else if (messages.warnings.length > 0) {
204-
devSocket.warnings(messages.warnings);
205-
}
206-
207-
if (isInteractive) {
208-
clearConsole();
209-
}
210-
}
211-
212-
const messages = formatWebpackMessages(statsData);
155+
const messages = formatWebpackMessages(
156+
stats.toJson({ all: false, warnings: true, errors: true })
157+
);
213158
const isSuccessful = !messages.errors.length && !messages.warnings.length;
214159
if (isSuccessful) {
215160
console.log(chalk.green('Compiled successfully!'));
@@ -249,27 +194,6 @@ function createCompiler({
249194
);
250195
}
251196
});
252-
253-
// You can safely remove this after ejecting.
254-
// We only use this block for testing of Create React App itself:
255-
const isSmokeTest = process.argv.some(
256-
arg => arg.indexOf('--smoke-test') > -1
257-
);
258-
if (isSmokeTest) {
259-
compiler.hooks.failed.tap('smokeTest', async () => {
260-
await tsMessagesPromise;
261-
process.exit(1);
262-
});
263-
compiler.hooks.done.tap('smokeTest', async stats => {
264-
await tsMessagesPromise;
265-
if (stats.hasErrors() || stats.hasWarnings()) {
266-
process.exit(1);
267-
} else {
268-
process.exit(0);
269-
}
270-
});
271-
}
272-
273197
return compiler;
274198
}
275199

packages/react-dev-utils/package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "https://github.com/facebook/create-react-app/issues"
99
},
1010
"engines": {
11-
"node": ">=8.10"
11+
"node": ">=6"
1212
},
1313
"files": [
1414
"browsersHelper.js",
@@ -20,7 +20,6 @@
2020
"eslintFormatter.js",
2121
"evalSourceMapMiddleware.js",
2222
"FileSizeReporter.js",
23-
"ForkTsCheckerWebpackPlugin.js",
2423
"formatWebpackMessages.js",
2524
"getCacheIdentifier.js",
2625
"getCSSModuleLocalIdent.js",
@@ -55,7 +54,6 @@
5554
"escape-string-regexp": "1.0.5",
5655
"filesize": "3.6.1",
5756
"find-up": "3.0.0",
58-
"fork-ts-checker-webpack-plugin": "1.0.0-alpha.6",
5957
"global-modules": "2.0.0",
6058
"globby": "8.0.2",
6159
"gzip-size": "5.0.0",

packages/react-dev-utils/typescriptFormatter.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,12 @@ function formatter(message, useColors) {
4545
}
4646

4747
const severity = hasGetters ? message.getSeverity() : message.severity;
48-
const types = { diagnostic: 'TypeScript', lint: 'TSLint' };
4948

5049
return [
51-
messageColor.bold(`${types[message.type]} ${severity.toLowerCase()}: `) +
50+
messageColor.bold(`Type ${severity.toLowerCase()}: `) +
5251
(hasGetters ? message.getContent() : message.content) +
5352
' ' +
54-
messageColor.underline(
55-
(message.type === 'lint' ? 'Rule: ' : 'TS') + message.code
56-
),
53+
messageColor.underline(`TS${message.code}`),
5754
'',
5855
frame,
5956
].join(os.EOL);

packages/react-dev-utils/webpackHotDevClient.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function handleSuccess() {
106106
tryApplyUpdates(function onHotUpdateSuccess() {
107107
// Only dismiss it when we're sure it's a hot update.
108108
// Otherwise it would flicker right before the reload.
109-
tryDismissErrorOverlay();
109+
ErrorOverlay.dismissBuildError();
110110
});
111111
}
112112
}
@@ -140,15 +140,19 @@ function handleWarnings(warnings) {
140140
}
141141
}
142142

143-
printWarnings();
144-
145143
// Attempt to apply hot updates or reload.
146144
if (isHotUpdate) {
147145
tryApplyUpdates(function onSuccessfulHotUpdate() {
146+
// Only print warnings if we aren't refreshing the page.
147+
// Otherwise they'll disappear right away anyway.
148+
printWarnings();
148149
// Only dismiss it when we're sure it's a hot update.
149150
// Otherwise it would flicker right before the reload.
150-
tryDismissErrorOverlay();
151+
ErrorOverlay.dismissBuildError();
151152
});
153+
} else {
154+
// Print initial warnings immediately.
155+
printWarnings();
152156
}
153157
}
154158

@@ -179,12 +183,6 @@ function handleErrors(errors) {
179183
// We will reload on next success instead.
180184
}
181185

182-
function tryDismissErrorOverlay() {
183-
if (!hasCompileErrors) {
184-
ErrorOverlay.dismissBuildError();
185-
}
186-
}
187-
188186
// There is a newer version of the code available.
189187
function handleAvailableHash(hash) {
190188
// Update last known compilation hash.

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent')
2929
const paths = require('./paths');
3030
const getClientEnvironment = require('./env');
3131
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
32-
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
32+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin-alt');
3333
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
3434
// @remove-on-eject-begin
3535
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
@@ -617,10 +617,17 @@ module.exports = function(webpackEnv) {
617617
typescript: resolve.sync('typescript', {
618618
basedir: paths.appNodeModules,
619619
}),
620-
async: isEnvDevelopment,
621-
useTypescriptIncrementalApi: true,
620+
async: false,
622621
checkSyntacticErrors: true,
623622
tsconfig: paths.appTsConfig,
623+
compilerOptions: {
624+
module: 'esnext',
625+
moduleResolution: 'node',
626+
resolveJsonModule: true,
627+
isolatedModules: true,
628+
noEmit: true,
629+
jsx: 'preserve',
630+
},
624631
reportFiles: [
625632
'**',
626633
'!**/*.json',
@@ -631,8 +638,7 @@ module.exports = function(webpackEnv) {
631638
],
632639
watch: paths.appSrc,
633640
silent: true,
634-
// The formatter is invoked directly in WebpackDevServerUtils during development
635-
formatter: isEnvProduction ? typescriptFormatter : undefined,
641+
formatter: typescriptFormatter,
636642
}),
637643
].filter(Boolean),
638644
// Some libraries import Node modules but don't use them in the browser.

packages/react-scripts/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"repository": "facebook/create-react-app",
66
"license": "MIT",
77
"engines": {
8-
"node": ">=8.10"
8+
"node": ">=6"
99
},
1010
"bugs": {
1111
"url": "https://github.com/facebook/create-react-app/issues"
@@ -45,6 +45,7 @@
4545
"eslint-plugin-jsx-a11y": "6.1.2",
4646
"eslint-plugin-react": "7.12.4",
4747
"file-loader": "2.0.0",
48+
"fork-ts-checker-webpack-plugin-alt": "0.4.14",
4849
"fs-extra": "7.0.1",
4950
"html-webpack-plugin": "4.0.0-alpha.2",
5051
"identity-obj-proxy": "3.0.0",

packages/react-scripts/scripts/start.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,9 @@ checkBrowsers(paths.appPath, isInteractive)
9494
const config = configFactory('development');
9595
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
9696
const appName = require(paths.appPackageJson).name;
97-
const useTypeScript = fs.existsSync(paths.appTsConfig);
9897
const urls = prepareUrls(protocol, HOST, port);
99-
const devSocket = {
100-
warnings: warnings =>
101-
devServer.sockWrite(devServer.sockets, 'warnings', warnings),
102-
errors: errors =>
103-
devServer.sockWrite(devServer.sockets, 'errors', errors),
104-
};
10598
// Create a webpack compiler that is configured with custom messages.
106-
const compiler = createCompiler({
107-
appName,
108-
config,
109-
devSocket,
110-
urls,
111-
useYarn,
112-
useTypeScript,
113-
webpack,
114-
});
99+
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
115100
// Load proxy config
116101
const proxySetting = require(paths.appPackageJson).proxy;
117102
const proxyConfig = prepareProxy(proxySetting, paths.appPublic);

test/fixtures/typescript-typecheck/.disable-pnp

Whitespace-only changes.

test/fixtures/typescript-typecheck/index.test.js

-33
This file was deleted.

0 commit comments

Comments
 (0)