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
6 changes: 1 addition & 5 deletions packages/metro-config/src/loadConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,7 @@ async function loadConfig(
validate(configuration, {
exampleConfig: await validConfig(),
recursiveDenylist: ['reporter', 'resolver', 'transformer'],
deprecatedConfig: {
blacklistRE: () =>
`Warning: Metro config option \`blacklistRE\` is deprecated.
Please use \`blockList\` instead.`,
},
deprecatedConfig: {},
});

// Override the configuration with cli parameters
Expand Down
1 change: 0 additions & 1 deletion packages/metro-config/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export type PerfLoggerFactory = (
type ResolverConfigT = {
assetExts: ReadonlyArray<string>,
assetResolutions: ReadonlyArray<string>,
blacklistRE?: RegExp | Array<RegExp>,
blockList: RegExp | Array<RegExp>,
disableHierarchicalLookup: boolean,
dependencyExtractor: ?string,
Expand Down
3 changes: 1 addition & 2 deletions packages/metro-config/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @noformat
* @oncall react_native
* @generated SignedSource<<926fc453e7c2af496911a003ca20e556>>
* @generated SignedSource<<fcd4ec40719bf4050bc337bfa17ccc5a>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro-config/src/types.js
Expand Down Expand Up @@ -91,7 +91,6 @@ export type PerfLoggerFactory = (
type ResolverConfigT = {
assetExts: ReadonlyArray<string>;
assetResolutions: ReadonlyArray<string>;
blacklistRE?: RegExp | Array<RegExp>;
blockList: RegExp | Array<RegExp>;
disableHierarchicalLookup: boolean;
dependencyExtractor: null | undefined | string;
Expand Down
60 changes: 23 additions & 37 deletions packages/metro/src/node-haste/DependencyGraph/createFileMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,29 @@ import MetroFileMap, {
HastePlugin,
} from 'metro-file-map';

function getIgnorePattern(config: ConfigT): RegExp {
// For now we support both options
const {blockList, blacklistRE} = config.resolver;
const ignorePattern = blacklistRE || blockList;

// If neither option has been set, use default pattern
if (!ignorePattern) {
return / ^/;
}

const combine = (regexes: Array<RegExp>) =>
new RegExp(
regexes
.map((regex, index) => {
if (regex.flags !== regexes[0].flags) {
throw new Error(
'Cannot combine blockList patterns, because they have different flags:\n' +
' - Pattern 0: ' +
regexes[0].toString() +
'\n' +
` - Pattern ${index}: ` +
regexes[index].toString(),
);
}
return '(' + regex.source + ')';
})
.join('|'),
regexes[0]?.flags ?? '',
);

// If ignorePattern is an array, merge it into one
if (Array.isArray(ignorePattern)) {
return combine(ignorePattern);
const flattenBlockList = (regexes: ConfigT['resolver']['blockList']) => {
if (!Array.isArray(regexes)) {
return regexes;
}

return ignorePattern;
}
return new RegExp(
regexes
.map((regex, index) => {
if (regex.flags !== regexes[0].flags) {
throw new Error(
'Cannot combine blockList patterns, because they have different flags:\n' +
' - Pattern 0: ' +
regexes[0].toString() +
'\n' +
` - Pattern ${index}: ` +
regexes[index].toString(),
);
}
return '(' + regex.source + ')';
})
.join('|'),
regexes[0]?.flags ?? '',
);
};

export default function createFileMap(
config: ConfigT,
Expand Down Expand Up @@ -126,7 +112,7 @@ export default function createFileMap(
]),
),
healthCheck: config.watcher.healthCheck,
ignorePattern: getIgnorePattern(config),
ignorePattern: flattenBlockList(config.resolver.blockList),
maxWorkers: config.maxWorkers,
plugins,
retainAllFiles: true,
Expand Down
Loading