From 4b7c4fb5b65bfbf22ab0c3f396b7e97577538b9f Mon Sep 17 00:00:00 2001 From: Pablo Date: Mon, 15 Jul 2019 18:34:13 -0300 Subject: [PATCH 1/6] Remove unused functions --- packages/react-scripts/config/yarn-workspaces.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packages/react-scripts/config/yarn-workspaces.js b/packages/react-scripts/config/yarn-workspaces.js index 93d86be6..6fc20980 100644 --- a/packages/react-scripts/config/yarn-workspaces.js +++ b/packages/react-scripts/config/yarn-workspaces.js @@ -161,17 +161,6 @@ const getDeps = pkg => { const depsTable = {}; -const filterDeps = deps => - Reflect.ownKeys(deps).filter(dep => Reflect.has(depsTable, dep)); - -const filterDepsTable = () => { - Reflect.ownKeys(depsTable).forEach(depName => { - const depsList = depsTable[depName].deps; - const workspacesOnlyDeps = filterDeps(depsList); - depsTable[depName].deps = workspacesOnlyDeps; - }); -}; - const buildDepsTable = srcPaths => { srcPaths.forEach(path => { const pkg = getPkg(path); From c8c9853f8d83c63d0f7aebd946aa0a5df7cca5ad Mon Sep 17 00:00:00 2001 From: Pablo Date: Mon, 15 Jul 2019 18:27:34 -0300 Subject: [PATCH 2/6] Don't consider a subpackage as the workspace root A leaf package may have a workspaces property (e.g. for nohoist). Prevent from considering that package to be a workspace root. --- packages/react-scripts/config/yarn-workspaces.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/config/yarn-workspaces.js b/packages/react-scripts/config/yarn-workspaces.js index 6fc20980..97500984 100644 --- a/packages/react-scripts/config/yarn-workspaces.js +++ b/packages/react-scripts/config/yarn-workspaces.js @@ -23,7 +23,13 @@ const getWorkspacesRootConfig = dir => { const packageObj = loadPackageJson(packageJsonUp); - if (Reflect.has(packageObj, 'workspaces')) { + if ( + packageObj.workspaces && + ( + Array.isArray(packageObj.workspaces) || + Reflect.has(packageObj.workspaces, 'packages') + ) + ) { const workspacesRootConfig = { root: path.dirname(packageJsonUp), workspaces: packageObj.workspaces From 2dec99196bf1d1c74a6020f02556ba01df7c1927 Mon Sep 17 00:00:00 2001 From: Pablo Date: Mon, 15 Jul 2019 18:47:34 -0300 Subject: [PATCH 3/6] Add 'browser' and 'module' package main fields This is required for some 3rd party dependencies to work. --- packages/react-scripts/config/webpack.config.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index b5faf0cc..98d9223c 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -62,7 +62,12 @@ module.exports = function(webpackEnv) { const isEnvDevelopment = webpackEnv === 'development'; const isEnvProduction = webpackEnv === 'production'; - const workspacesMainFields = [workspacesConfig.packageEntry, 'main']; + const workspacesMainFields = [ + workspacesConfig.packageEntry, + 'browser', + 'module', + 'main', + ]; const mainFields = isEnvDevelopment && workspacesConfig.development ? workspacesMainFields From 19e24904c48b5b9db35702f62779ced3152f47d5 Mon Sep 17 00:00:00 2001 From: Pablo Date: Tue, 16 Jul 2019 14:41:37 -0300 Subject: [PATCH 4/6] Find react-scripts even when hoisted --- packages/react-scripts/config/paths.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index e5a3e0b5..75c1d4ee 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -11,6 +11,7 @@ const path = require('path'); const fs = require('fs'); const url = require('url'); +const findUp = require('find-up'); // Make sure any symlinks in the project folder are resolved: // https://github.com/facebook/create-react-app/issues/637 @@ -122,7 +123,9 @@ module.exports = { }; const ownPackageJson = require('../package.json'); -const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`); +const reactScriptsPath = findUp.sync(`node_modules/${ownPackageJson.name}`, { + cwd: resolveApp('.'), +}); const reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink(); From a754bcff0b589336698728708ee2d4693cc65dcd Mon Sep 17 00:00:00 2001 From: Pablo Date: Tue, 16 Jul 2019 14:42:40 -0300 Subject: [PATCH 5/6] Set up ForkTsCheckerWebpackPlugin for workspaces --- .../react-scripts/config/webpack.config.js | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 98d9223c..2d03e946 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -75,6 +75,13 @@ module.exports = function(webpackEnv) { ? workspacesMainFields : undefined; + const includePaths = + isEnvDevelopment && workspacesConfig.development + ? [paths.appSrc, ...workspacesConfig.paths] + : isEnvProduction && workspacesConfig.production + ? [paths.appSrc, ...workspacesConfig.paths] + : paths.appSrc; + // Webpack uses `publicPath` to determine where the app is being served from. // It requires a trailing slash, or the file assets will get an incorrect path. // In development, we always serve from the root. This makes config easier. @@ -347,11 +354,7 @@ module.exports = function(webpackEnv) { loader: require.resolve('eslint-loader'), }, ], - include: isEnvDevelopment && workspacesConfig.development - ? [paths.appSrc, workspacesConfig.paths] - : isEnvProduction && workspacesConfig.production - ? [paths.appSrc, workspacesConfig.paths] - : paths.appSrc, + include: includePaths, }, { // "oneOf" will traverse all following loaders until one will @@ -373,12 +376,7 @@ module.exports = function(webpackEnv) { // The preset includes JSX, Flow, TypeScript, and some ESnext features. { test: /\.(js|mjs|jsx|ts|tsx)$/, - include: - isEnvDevelopment && workspacesConfig.development - ? [paths.appSrc, workspacesConfig.paths] - : isEnvProduction && workspacesConfig.production - ? [paths.appSrc, workspacesConfig.paths] - : paths.appSrc, + include: includePaths, loader: require.resolve('babel-loader'), options: { customize: require.resolve( @@ -661,6 +659,10 @@ module.exports = function(webpackEnv) { typescript: resolve.sync('typescript', { basedir: paths.appNodeModules, }), + compilerOptions: { + skipLibCheck: true, + suppressOutputPathCheck: true, + }, async: isEnvDevelopment, useTypescriptIncrementalApi: true, checkSyntacticErrors: true, @@ -672,7 +674,7 @@ module.exports = function(webpackEnv) { '!**/src/setupProxy.*', '!**/src/setupTests.*', ], - watch: paths.appSrc, + watch: includePaths, silent: true, // The formatter is invoked directly in WebpackDevServerUtils during development formatter: isEnvProduction ? typescriptFormatter : undefined, From e78111bf160b1d81b69cfd44e6993add093907dc Mon Sep 17 00:00:00 2001 From: Pablo Date: Wed, 17 Jul 2019 16:06:48 -0300 Subject: [PATCH 6/6] Disable typescript linting outside main project --- packages/react-scripts/config/webpack.config.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 2d03e946..61aeb9dc 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -355,6 +355,12 @@ module.exports = function(webpackEnv) { }, ], include: includePaths, + // Don't lint typescript files outside the main package because it has problems with some syntax rules, e.g. abstract + exclude: useTypeScript + ? file => + /\.tsx?/.test(path.extname(file)) && + !file.startsWith(paths.appSrc) + : undefined, }, { // "oneOf" will traverse all following loaders until one will