From 95b85db396391e94e8a2b81e4790a2d595617e81 Mon Sep 17 00:00:00 2001 From: Joe Lim Date: Mon, 30 Oct 2017 16:21:07 -0700 Subject: [PATCH 1/8] extra watch options regex to react-dev-utils --- packages/react-dev-utils/watchOptionsRegex.js | 18 ++++++++++++++++++ .../config/webpack.config.prod.js | 2 +- .../config/webpackDevServer.config.js | 9 ++------- 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 packages/react-dev-utils/watchOptionsRegex.js diff --git a/packages/react-dev-utils/watchOptionsRegex.js b/packages/react-dev-utils/watchOptionsRegex.js new file mode 100644 index 00000000000..619cc475adf --- /dev/null +++ b/packages/react-dev-utils/watchOptionsRegex.js @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +'use strict'; + +const path = require('path'); +const escapeStringRegexp = require('escape-string-regexp'); + +module.exports = function watchOptionsRegex(paths) { + return new RegExp( + `^(?!${escapeStringRegexp(path.join(paths.appSrc, '/'))}).+node_modules`, + 'g' + ); +}; diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index c32eb0f08a7..457a9672892 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -301,7 +301,7 @@ module.exports = { }, mangle: { safari10: true, - }, + }, output: { comments: false, // Turned on because emoji and regex is not minified properly using default diff --git a/packages/react-scripts/config/webpackDevServer.config.js b/packages/react-scripts/config/webpackDevServer.config.js index f401f2cce0d..5045eefa5cf 100644 --- a/packages/react-scripts/config/webpackDevServer.config.js +++ b/packages/react-scripts/config/webpackDevServer.config.js @@ -10,7 +10,7 @@ const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware'); const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware'); -const path = require('path'); +const watchOptionsRegex = require('react-dev-utils/watchOptionsRegex'); const config = require('./webpack.config.dev'); const paths = require('./paths'); @@ -76,12 +76,7 @@ module.exports = function(proxy, allowedHost) { // src/node_modules is not ignored to support absolute imports // https://github.com/facebookincubator/create-react-app/issues/1065 watchOptions: { - ignored: new RegExp( - `^(?!${path - .normalize(paths.appSrc + '/') - .replace(/[\\]+/g, '\\\\')}).+[\\\\/]node_modules[\\\\/]`, - 'g' - ), + ignored: watchOptionsRegex(paths), }, // Enable HTTPS if the HTTPS environment variable is set to 'true' https: protocol === 'https', From 440d4a6dc630ea74814310ced01f818cd5b4717b Mon Sep 17 00:00:00 2001 From: Joe Lim Date: Mon, 30 Oct 2017 21:12:47 -0700 Subject: [PATCH 2/8] fix regex --- .../{watchOptionsRegex.js => ignoredFiles.js} | 7 ++++--- packages/react-scripts/config/webpackDevServer.config.js | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) rename packages/react-dev-utils/{watchOptionsRegex.js => ignoredFiles.js} (58%) diff --git a/packages/react-dev-utils/watchOptionsRegex.js b/packages/react-dev-utils/ignoredFiles.js similarity index 58% rename from packages/react-dev-utils/watchOptionsRegex.js rename to packages/react-dev-utils/ignoredFiles.js index 619cc475adf..50348ea6bdd 100644 --- a/packages/react-dev-utils/watchOptionsRegex.js +++ b/packages/react-dev-utils/ignoredFiles.js @@ -8,11 +8,12 @@ 'use strict'; const path = require('path'); -const escapeStringRegexp = require('escape-string-regexp'); -module.exports = function watchOptionsRegex(paths) { +module.exports = function ignoredFiles(appSrc) { return new RegExp( - `^(?!${escapeStringRegexp(path.join(paths.appSrc, '/'))}).+node_modules`, + `^(?!${path + .normalize(appSrc + '/') + .replace(/[\\]+/g, '/')}).+/node_modules/`, 'g' ); }; diff --git a/packages/react-scripts/config/webpackDevServer.config.js b/packages/react-scripts/config/webpackDevServer.config.js index 5045eefa5cf..80684538f9a 100644 --- a/packages/react-scripts/config/webpackDevServer.config.js +++ b/packages/react-scripts/config/webpackDevServer.config.js @@ -10,7 +10,7 @@ const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware'); const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware'); -const watchOptionsRegex = require('react-dev-utils/watchOptionsRegex'); +const ignoredFiles = require('react-dev-utils/ignoredFiles'); const config = require('./webpack.config.dev'); const paths = require('./paths'); @@ -76,7 +76,7 @@ module.exports = function(proxy, allowedHost) { // src/node_modules is not ignored to support absolute imports // https://github.com/facebookincubator/create-react-app/issues/1065 watchOptions: { - ignored: watchOptionsRegex(paths), + ignored: ignoredFiles(paths.appSrc), }, // Enable HTTPS if the HTTPS environment variable is set to 'true' https: protocol === 'https', From 2806cd724f76c4bb62d3bb236a24e616dd9b4ddd Mon Sep 17 00:00:00 2001 From: Joe Lim Date: Mon, 30 Oct 2017 21:50:57 -0700 Subject: [PATCH 3/8] add test --- packages/react-dev-utils/package.json | 6 ++ .../src/__tests__/ignoredFiles.test.js | 55 +++++++++++++++++++ .../react-dev-utils/{ => src}/ignoredFiles.js | 0 .../config/webpackDevServer.config.js | 2 +- 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 packages/react-dev-utils/src/__tests__/ignoredFiles.test.js rename packages/react-dev-utils/{ => src}/ignoredFiles.js (100%) diff --git a/packages/react-dev-utils/package.json b/packages/react-dev-utils/package.json index db7114a261a..59cf72bc98b 100644 --- a/packages/react-dev-utils/package.json +++ b/packages/react-dev-utils/package.json @@ -53,5 +53,11 @@ "sockjs-client": "1.1.4", "strip-ansi": "3.0.1", "text-table": "0.2.0" + }, + "devDependencies": { + "jest": "20.0.4" + }, + "scripts": { + "test": "jest" } } diff --git a/packages/react-dev-utils/src/__tests__/ignoredFiles.test.js b/packages/react-dev-utils/src/__tests__/ignoredFiles.test.js new file mode 100644 index 00000000000..6feed979797 --- /dev/null +++ b/packages/react-dev-utils/src/__tests__/ignoredFiles.test.js @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +'use strict'; + +const ignoredFiles = require('../ignoredFiles'); + +describe('ignore watch files regex', () => { + it('normal file', () => { + const appSrc = '/root/src/'; + const isIgnored = ignoredFiles(appSrc).test('/foo'); + const isIgnoredInSrc = ignoredFiles(appSrc).test('/root/src/foo'); + + expect(isIgnored).toBe(false); + expect(isIgnoredInSrc).toBe(false); + }); + + it('node modules', () => { + const appSrc = '/root/src/'; + const isIgnored = ignoredFiles(appSrc).test('/root/node_modules/foo'); + + expect(isIgnored).toBe(true); + }); + + it('node modules inside source directory', () => { + const appSrc = '/root/src/'; + const isIgnored = ignoredFiles(appSrc).test('/root/src/node_modules/foo'); + const isIgnoredMoreThanOneLevel = ignoredFiles(appSrc).test( + '/root/src/bar/node_modules/foo' + ); + + expect(isIgnored).toBe(false); + expect(isIgnoredMoreThanOneLevel).toBe(false); + }); + + it('path contains source directory', () => { + const appSrc = '/root/src/'; + const isIgnored = ignoredFiles(appSrc).test( + '/bar/root/src/node_modules/foo' + ); + + expect(isIgnored).toBe(true); + }); + + it('path starts with source directory', () => { + const appSrc = '/root/src/'; + const isIgnored = ignoredFiles(appSrc).test('/root/src2/node_modules/foo'); + + expect(isIgnored).toBe(true); + }); +}); diff --git a/packages/react-dev-utils/ignoredFiles.js b/packages/react-dev-utils/src/ignoredFiles.js similarity index 100% rename from packages/react-dev-utils/ignoredFiles.js rename to packages/react-dev-utils/src/ignoredFiles.js diff --git a/packages/react-scripts/config/webpackDevServer.config.js b/packages/react-scripts/config/webpackDevServer.config.js index 80684538f9a..6e929a84f6f 100644 --- a/packages/react-scripts/config/webpackDevServer.config.js +++ b/packages/react-scripts/config/webpackDevServer.config.js @@ -10,7 +10,7 @@ const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware'); const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware'); -const ignoredFiles = require('react-dev-utils/ignoredFiles'); +const ignoredFiles = require('react-dev-utils/src/ignoredFiles'); const config = require('./webpack.config.dev'); const paths = require('./paths'); From 3f6e4a9725d78da698bc502c61d143722f4b7abc Mon Sep 17 00:00:00 2001 From: Joe Lim Date: Mon, 30 Oct 2017 22:19:53 -0700 Subject: [PATCH 4/8] fix eslint error --- packages/react-dev-utils/src/__tests__/.eslintrc | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/react-dev-utils/src/__tests__/.eslintrc diff --git a/packages/react-dev-utils/src/__tests__/.eslintrc b/packages/react-dev-utils/src/__tests__/.eslintrc new file mode 100644 index 00000000000..7bc296da26e --- /dev/null +++ b/packages/react-dev-utils/src/__tests__/.eslintrc @@ -0,0 +1,5 @@ +{ + "env": { + "jest": true + } +} \ No newline at end of file From d252e9a44b20b5bceb2c9eff13c565b21c3089e4 Mon Sep 17 00:00:00 2001 From: Joe Lim Date: Mon, 30 Oct 2017 22:38:12 -0700 Subject: [PATCH 5/8] include react-dev-utils test in CI script --- tasks/e2e-simple.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh index 867b6dc9503..9e51b00805d 100755 --- a/tasks/e2e-simple.sh +++ b/tasks/e2e-simple.sh @@ -159,6 +159,9 @@ cd packages/react-error-overlay/ npm test npm run build:prod cd ../.. +cd packages/react-dev-utils/ +npm test +cd ../.. # ****************************************************************************** # First, test the create-react-app development environment. From ad16d1a31cfa42db3c12ff4dd61802b0bda3ba5c Mon Sep 17 00:00:00 2001 From: Joe Lim Date: Wed, 1 Nov 2017 18:58:01 -0700 Subject: [PATCH 6/8] attempt to fix import error --- packages/react-dev-utils/{src => }/__tests__/.eslintrc | 0 .../react-dev-utils/{src => }/__tests__/ignoredFiles.test.js | 0 packages/react-dev-utils/{src => }/ignoredFiles.js | 0 packages/react-scripts/config/webpackDevServer.config.js | 2 +- 4 files changed, 1 insertion(+), 1 deletion(-) rename packages/react-dev-utils/{src => }/__tests__/.eslintrc (100%) rename packages/react-dev-utils/{src => }/__tests__/ignoredFiles.test.js (100%) rename packages/react-dev-utils/{src => }/ignoredFiles.js (100%) diff --git a/packages/react-dev-utils/src/__tests__/.eslintrc b/packages/react-dev-utils/__tests__/.eslintrc similarity index 100% rename from packages/react-dev-utils/src/__tests__/.eslintrc rename to packages/react-dev-utils/__tests__/.eslintrc diff --git a/packages/react-dev-utils/src/__tests__/ignoredFiles.test.js b/packages/react-dev-utils/__tests__/ignoredFiles.test.js similarity index 100% rename from packages/react-dev-utils/src/__tests__/ignoredFiles.test.js rename to packages/react-dev-utils/__tests__/ignoredFiles.test.js diff --git a/packages/react-dev-utils/src/ignoredFiles.js b/packages/react-dev-utils/ignoredFiles.js similarity index 100% rename from packages/react-dev-utils/src/ignoredFiles.js rename to packages/react-dev-utils/ignoredFiles.js diff --git a/packages/react-scripts/config/webpackDevServer.config.js b/packages/react-scripts/config/webpackDevServer.config.js index 6e929a84f6f..80684538f9a 100644 --- a/packages/react-scripts/config/webpackDevServer.config.js +++ b/packages/react-scripts/config/webpackDevServer.config.js @@ -10,7 +10,7 @@ const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware'); const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware'); -const ignoredFiles = require('react-dev-utils/src/ignoredFiles'); +const ignoredFiles = require('react-dev-utils/ignoredFiles'); const config = require('./webpack.config.dev'); const paths = require('./paths'); From 723a1d63490badd60b931bdc25dd511d686c64a3 Mon Sep 17 00:00:00 2001 From: Joe Lim Date: Wed, 1 Nov 2017 19:17:09 -0700 Subject: [PATCH 7/8] attempt to fix error on CI --- packages/react-dev-utils/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-dev-utils/package.json b/packages/react-dev-utils/package.json index 59cf72bc98b..54606f33fe8 100644 --- a/packages/react-dev-utils/package.json +++ b/packages/react-dev-utils/package.json @@ -21,6 +21,7 @@ "printBuildError.js", "formatWebpackMessages.js", "getProcessForPort.js", + "ignoredFiles.js", "inquirer.js", "InterpolateHtmlPlugin.js", "launchEditor.js", From 086ecdd75fd60e8f0e6785270e90996c2df6f024 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Fri, 3 Nov 2017 22:10:44 -0400 Subject: [PATCH 8/8] Update .eslintrc --- packages/react-dev-utils/__tests__/.eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-dev-utils/__tests__/.eslintrc b/packages/react-dev-utils/__tests__/.eslintrc index 7bc296da26e..55f121d152d 100644 --- a/packages/react-dev-utils/__tests__/.eslintrc +++ b/packages/react-dev-utils/__tests__/.eslintrc @@ -2,4 +2,4 @@ "env": { "jest": true } -} \ No newline at end of file +}