Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions packages/react-dev-utils/__tests__/ignoredFiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,33 @@

const ignoredFiles = require('../ignoredFiles');

const anymatch = require('anymatch');

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');
const isIgnored = anymatch(ignoredFiles(appSrc), '/foo');
const isIgnoredInSrc = anymatch(ignoredFiles(appSrc), '/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');
const isIgnored = anymatch(ignoredFiles(appSrc), '/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(
const isIgnored = anymatch(
ignoredFiles(appSrc),
'/root/src/node_modules/foo'
);
const isIgnoredMoreThanOneLevel = anymatch(
ignoredFiles(appSrc),
'/root/src/bar/node_modules/foo'
);

Expand All @@ -39,7 +45,8 @@ describe('ignore watch files regex', () => {

it('path contains source directory', () => {
const appSrc = '/root/src/';
const isIgnored = ignoredFiles(appSrc).test(
const isIgnored = anymatch(
ignoredFiles(appSrc),
'/bar/root/src/node_modules/foo'
);

Expand All @@ -48,7 +55,31 @@ describe('ignore watch files regex', () => {

it('path starts with source directory', () => {
const appSrc = '/root/src/';
const isIgnored = ignoredFiles(appSrc).test('/root/src2/node_modules/foo');
const isIgnored = anymatch(
ignoredFiles(appSrc),
'/root/src2/node_modules/foo'
);

expect(isIgnored).toBe(true);
});

it('ignores emacs temporary files', () => {
const appSrc = '/root/src/';
const isIgnored = anymatch(ignoredFiles(appSrc), 'file.txt~');

expect(isIgnored).toBe(true);
});

it('ignores emacs lock files', () => {
const appSrc = '/root/src/';
const isIgnored = anymatch(ignoredFiles(appSrc), '.#file.txt');

expect(isIgnored).toBe(true);
});

it('ignores emacs backup files', () => {
const appSrc = '/root/src/';
const isIgnored = anymatch(ignoredFiles(appSrc), '.#file.txt#');

expect(isIgnored).toBe(true);
});
Expand Down
17 changes: 11 additions & 6 deletions packages/react-dev-utils/ignoredFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ const path = require('path');
const escape = require('escape-string-regexp');

module.exports = function ignoredFiles(appSrc) {
return new RegExp(
`^(?!${escape(
path.normalize(appSrc + '/').replace(/[\\]+/g, '/')
)}).+/node_modules/`,
'g'
);
return [
new RegExp(
`^(?!${escape(
path.normalize(appSrc + '/').replace(/[\\]+/g, '/'),
)}).+/node_modules/`,
'g',
),
'**/.#*',
'**/*~',
'**/#*#',
];
};