Skip to content

Commit

Permalink
Always type check TypeScript when being used (facebook#5515)
Browse files Browse the repository at this point in the history
* Always type check TypeScript when being used

* Use alternate version
  • Loading branch information
Timer committed Oct 21, 2018
1 parent 881f038 commit 81d205f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 42 deletions.
31 changes: 10 additions & 21 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const getClientEnvironment = require('./env');
const paths = require('./paths');
const ManifestPlugin = require('webpack-manifest-plugin');
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin-alt');
// @remove-on-eject-begin
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
// @remove-on-eject-end
Expand Down Expand Up @@ -410,27 +411,15 @@ module.exports = {
}),
// TypeScript type checking
fs.existsSync(paths.appTsConfig) &&
(() => {
let ForkTsCheckerWebpackPlugin;
try {
ForkTsCheckerWebpackPlugin = require(resolve.sync(
'fork-ts-checker-webpack-plugin',
{ basedir: paths.appNodeModules }
));
} catch (e) {
// Fail silently.
// Type checking using this plugin is optional.
// The user may decide to install `fork-ts-checker-webpack-plugin` or use `tsc -w`.
return null;
}

return new ForkTsCheckerWebpackPlugin({
async: false,
checkSyntacticErrors: true,
tsconfig: paths.appTsConfig,
watch: paths.appSrc,
});
})(),
new ForkTsCheckerWebpackPlugin({
typescript: resolve.sync('typescript', {
basedir: paths.appNodeModules,
}),
async: false,
checkSyntacticErrors: true,
tsconfig: paths.appTsConfig,
watch: paths.appSrc,
}),
].filter(Boolean),

// Some libraries import Node modules but don't use them in the browser.
Expand Down
31 changes: 10 additions & 21 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent')
const paths = require('./paths');
const getClientEnvironment = require('./env');
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin-alt');
// @remove-on-eject-begin
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
// @remove-on-eject-end
Expand Down Expand Up @@ -530,27 +531,15 @@ module.exports = {
}),
// TypeScript type checking
fs.existsSync(paths.appTsConfig) &&
(() => {
let ForkTsCheckerWebpackPlugin;
try {
ForkTsCheckerWebpackPlugin = require(resolve.sync(
'fork-ts-checker-webpack-plugin',
{ basedir: paths.appNodeModules }
));
} catch (e) {
// Fail silently.
// Type checking using this plugin is optional.
// The user may decide to install `fork-ts-checker-webpack-plugin` or use `tsc -w`.
return null;
}

return new ForkTsCheckerWebpackPlugin({
async: false,
checkSyntacticErrors: true,
tsconfig: paths.appTsConfig,
watch: paths.appSrc,
});
})(),
new ForkTsCheckerWebpackPlugin({
typescript: resolve.sync('typescript', {
basedir: paths.appNodeModules,
}),
async: false,
checkSyntacticErrors: true,
tsconfig: paths.appTsConfig,
watch: paths.appSrc,
}),
].filter(Boolean),
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"eslint-plugin-jsx-a11y": "6.1.2",
"eslint-plugin-react": "7.11.1",
"file-loader": "2.0.0",
"fork-ts-checker-webpack-plugin-alt": "0.4.10",
"fs-extra": "7.0.0",
"html-webpack-plugin": "4.0.0-alpha.2",
"identity-obj-proxy": "3.0.0",
Expand Down

0 comments on commit 81d205f

Please sign in to comment.