Skip to content

Commit 17c24bd

Browse files
xjlimPavel Zhytko
authored and
Pavel Zhytko
committed
Refactor extra watch options regex to react-dev-utils (facebook#3362)
* extra watch options regex to react-dev-utils * fix regex * add test * fix eslint error * include react-dev-utils test in CI script * attempt to fix import error * attempt to fix error on CI * Update .eslintrc
1 parent 3cc04f6 commit 17c24bd

File tree

6 files changed

+91
-7
lines changed

6 files changed

+91
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"env": {
3+
"jest": true
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
const ignoredFiles = require('../ignoredFiles');
11+
12+
describe('ignore watch files regex', () => {
13+
it('normal file', () => {
14+
const appSrc = '/root/src/';
15+
const isIgnored = ignoredFiles(appSrc).test('/foo');
16+
const isIgnoredInSrc = ignoredFiles(appSrc).test('/root/src/foo');
17+
18+
expect(isIgnored).toBe(false);
19+
expect(isIgnoredInSrc).toBe(false);
20+
});
21+
22+
it('node modules', () => {
23+
const appSrc = '/root/src/';
24+
const isIgnored = ignoredFiles(appSrc).test('/root/node_modules/foo');
25+
26+
expect(isIgnored).toBe(true);
27+
});
28+
29+
it('node modules inside source directory', () => {
30+
const appSrc = '/root/src/';
31+
const isIgnored = ignoredFiles(appSrc).test('/root/src/node_modules/foo');
32+
const isIgnoredMoreThanOneLevel = ignoredFiles(appSrc).test(
33+
'/root/src/bar/node_modules/foo'
34+
);
35+
36+
expect(isIgnored).toBe(false);
37+
expect(isIgnoredMoreThanOneLevel).toBe(false);
38+
});
39+
40+
it('path contains source directory', () => {
41+
const appSrc = '/root/src/';
42+
const isIgnored = ignoredFiles(appSrc).test(
43+
'/bar/root/src/node_modules/foo'
44+
);
45+
46+
expect(isIgnored).toBe(true);
47+
});
48+
49+
it('path starts with source directory', () => {
50+
const appSrc = '/root/src/';
51+
const isIgnored = ignoredFiles(appSrc).test('/root/src2/node_modules/foo');
52+
53+
expect(isIgnored).toBe(true);
54+
});
55+
});
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
const path = require('path');
11+
12+
module.exports = function ignoredFiles(appSrc) {
13+
return new RegExp(
14+
`^(?!${path
15+
.normalize(appSrc + '/')
16+
.replace(/[\\]+/g, '/')}).+/node_modules/`,
17+
'g'
18+
);
19+
};

packages/react-dev-utils/package.json

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"printBuildError.js",
2222
"formatWebpackMessages.js",
2323
"getProcessForPort.js",
24+
"ignoredFiles.js",
2425
"inquirer.js",
2526
"InterpolateHtmlPlugin.js",
2627
"launchEditor.js",
@@ -53,5 +54,11 @@
5354
"sockjs-client": "1.1.4",
5455
"strip-ansi": "3.0.1",
5556
"text-table": "0.2.0"
57+
},
58+
"devDependencies": {
59+
"jest": "20.0.4"
60+
},
61+
"scripts": {
62+
"test": "jest"
5663
}
5764
}

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
1212
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
13-
const path = require('path');
13+
const ignoredFiles = require('react-dev-utils/ignoredFiles');
1414
const config = require('./webpack.config.dev');
1515
const paths = require('./paths');
1616

@@ -76,12 +76,7 @@ module.exports = function(proxy, allowedHost) {
7676
// src/node_modules is not ignored to support absolute imports
7777
// https://github.com/facebookincubator/create-react-app/issues/1065
7878
watchOptions: {
79-
ignored: new RegExp(
80-
`^(?!${path
81-
.normalize(paths.appSrc + '/')
82-
.replace(/[\\]+/g, '\\\\')}).+[\\\\/]node_modules[\\\\/]`,
83-
'g'
84-
),
79+
ignored: ignoredFiles(paths.appSrc),
8580
},
8681
// Enable HTTPS if the HTTPS environment variable is set to 'true'
8782
https: protocol === 'https',

tasks/e2e-simple.sh

+3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ cd packages/react-error-overlay/
159159
npm test
160160
npm run build:prod
161161
cd ../..
162+
cd packages/react-dev-utils/
163+
npm test
164+
cd ../..
162165

163166
# ******************************************************************************
164167
# First, test the create-react-app development environment.

0 commit comments

Comments
 (0)