Skip to content

Commit 81d205f

Browse files
authored
Always type check TypeScript when being used (facebook#5515)
* Always type check TypeScript when being used * Use alternate version
1 parent 881f038 commit 81d205f

File tree

3 files changed

+21
-42
lines changed

3 files changed

+21
-42
lines changed

config/webpack.config.dev.js

+10-21
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const getClientEnvironment = require('./env');
2323
const paths = require('./paths');
2424
const ManifestPlugin = require('webpack-manifest-plugin');
2525
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
26+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin-alt');
2627
// @remove-on-eject-begin
2728
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
2829
// @remove-on-eject-end
@@ -410,27 +411,15 @@ module.exports = {
410411
}),
411412
// TypeScript type checking
412413
fs.existsSync(paths.appTsConfig) &&
413-
(() => {
414-
let ForkTsCheckerWebpackPlugin;
415-
try {
416-
ForkTsCheckerWebpackPlugin = require(resolve.sync(
417-
'fork-ts-checker-webpack-plugin',
418-
{ basedir: paths.appNodeModules }
419-
));
420-
} catch (e) {
421-
// Fail silently.
422-
// Type checking using this plugin is optional.
423-
// The user may decide to install `fork-ts-checker-webpack-plugin` or use `tsc -w`.
424-
return null;
425-
}
426-
427-
return new ForkTsCheckerWebpackPlugin({
428-
async: false,
429-
checkSyntacticErrors: true,
430-
tsconfig: paths.appTsConfig,
431-
watch: paths.appSrc,
432-
});
433-
})(),
414+
new ForkTsCheckerWebpackPlugin({
415+
typescript: resolve.sync('typescript', {
416+
basedir: paths.appNodeModules,
417+
}),
418+
async: false,
419+
checkSyntacticErrors: true,
420+
tsconfig: paths.appTsConfig,
421+
watch: paths.appSrc,
422+
}),
434423
].filter(Boolean),
435424

436425
// Some libraries import Node modules but don't use them in the browser.

config/webpack.config.prod.js

+10-21
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent')
2727
const paths = require('./paths');
2828
const getClientEnvironment = require('./env');
2929
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
30+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin-alt');
3031
// @remove-on-eject-begin
3132
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
3233
// @remove-on-eject-end
@@ -530,27 +531,15 @@ module.exports = {
530531
}),
531532
// TypeScript type checking
532533
fs.existsSync(paths.appTsConfig) &&
533-
(() => {
534-
let ForkTsCheckerWebpackPlugin;
535-
try {
536-
ForkTsCheckerWebpackPlugin = require(resolve.sync(
537-
'fork-ts-checker-webpack-plugin',
538-
{ basedir: paths.appNodeModules }
539-
));
540-
} catch (e) {
541-
// Fail silently.
542-
// Type checking using this plugin is optional.
543-
// The user may decide to install `fork-ts-checker-webpack-plugin` or use `tsc -w`.
544-
return null;
545-
}
546-
547-
return new ForkTsCheckerWebpackPlugin({
548-
async: false,
549-
checkSyntacticErrors: true,
550-
tsconfig: paths.appTsConfig,
551-
watch: paths.appSrc,
552-
});
553-
})(),
534+
new ForkTsCheckerWebpackPlugin({
535+
typescript: resolve.sync('typescript', {
536+
basedir: paths.appNodeModules,
537+
}),
538+
async: false,
539+
checkSyntacticErrors: true,
540+
tsconfig: paths.appTsConfig,
541+
watch: paths.appSrc,
542+
}),
554543
].filter(Boolean),
555544
// Some libraries import Node modules but don't use them in the browser.
556545
// Tell Webpack to provide empty mocks for them so importing them works.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"eslint-plugin-jsx-a11y": "6.1.2",
4444
"eslint-plugin-react": "7.11.1",
4545
"file-loader": "2.0.0",
46+
"fork-ts-checker-webpack-plugin-alt": "0.4.10",
4647
"fs-extra": "7.0.0",
4748
"html-webpack-plugin": "4.0.0-alpha.2",
4849
"identity-obj-proxy": "3.0.0",

0 commit comments

Comments
 (0)