Skip to content
Closed
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
52 changes: 52 additions & 0 deletions packages/metro-config/src/defaults/__tests__/exclusionList-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ describe('exclusionList', () => {
path.sep = originalSeparator;
});

const asPlatformPath = (filepath: string) =>
filepath.replaceAll('/', path.sep);

const nativeBuildOutputPaths = [
'.cxx',
'android/.gradle',
'android/build',
'android/app/build',
'ios/build',
'ios/DerivedData',
];

test('proves we can write to path.sep for setting up the tests', () => {
setPathSeperator('/');
expect(require('node:path').sep).toBe('/');
Expand Down Expand Up @@ -71,6 +83,25 @@ describe('exclusionList', () => {
);
expect('/foo/bar').toMatch(exclusionList([/.*[\/\\]foo[\/\\]bar/]));
});

test.each(nativeBuildOutputPaths)(
'excludes React Native native build output %s',
buildOutputPath => {
const exclusion = exclusionList();

expect(asPlatformPath(buildOutputPath)).toMatch(exclusion);
expect(asPlatformPath(`${buildOutputPath}/generated/file.o`)).toMatch(
exclusion,
);
},
);

test('does not exclude adjacent source paths', () => {
const exclusion = exclusionList();

expect('src/android/app.js').not.toMatch(exclusion);
expect('src/ios/DerivedDataExample.js').not.toMatch(exclusion);
});
});

describe('simulate windows enviornment', () => {
Expand Down Expand Up @@ -107,5 +138,26 @@ describe('exclusionList', () => {
);
expect('\\foo\\bar').toMatch(exclusionList([/.*[\/\\]foo[\/\\]bar/]));
});

test.each(nativeBuildOutputPaths)(
'excludes React Native native build output %s',
buildOutputPath => {
const exclusion = exclusionList();

expect(asPlatformPath(buildOutputPath)).toMatch(exclusion);
expect(asPlatformPath(`${buildOutputPath}/generated/file.o`)).toMatch(
exclusion,
);
},
);

test('does not exclude adjacent source paths', () => {
const exclusion = exclusionList();

expect(asPlatformPath('src/android/app.js')).not.toMatch(exclusion);
expect(asPlatformPath('src/ios/DerivedDataExample.js')).not.toMatch(
exclusion,
);
});
});
});
10 changes: 9 additions & 1 deletion packages/metro-config/src/defaults/exclusionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@

import path from 'node:path';

const list = [/\/__tests__\/.*/];
const list = [
/\/__tests__\/.*/,
/(^|\/)\.cxx($|\/.*)/,
/(^|\/)android\/\.gradle($|\/.*)/,
/(^|\/)android\/build($|\/.*)/,
/(^|\/)android\/app\/build($|\/.*)/,
/(^|\/)ios\/build($|\/.*)/,
/(^|\/)ios\/DerivedData($|\/.*)/,
];

function escapeRegExp(pattern: RegExp | string) {
if (pattern instanceof RegExp) {
Expand Down