mirror of https://github.com/status-im/metro.git
metro-bundler: ModuleGraph: nit: reduce code nesting
Reviewed By: davidaurelio Differential Revision: D6324409 fbshipit-source-id: da7626772cb24b4f3749962e72e5952982b917d6
This commit is contained in:
parent
c04393b397
commit
f0a4418b5b
|
@ -68,40 +68,41 @@ const NULL_MODULE: Moduleish = {
|
||||||
const createModuleMap = ({files, helpers, moduleCache, sourceExts}) => {
|
const createModuleMap = ({files, helpers, moduleCache, sourceExts}) => {
|
||||||
const map = Object.create(null);
|
const map = Object.create(null);
|
||||||
files.forEach(filePath => {
|
files.forEach(filePath => {
|
||||||
if (!helpers.isNodeModulesDir(filePath)) {
|
if (helpers.isNodeModulesDir(filePath)) {
|
||||||
let id;
|
return;
|
||||||
let module;
|
}
|
||||||
if (filePath.endsWith(PACKAGE_JSON)) {
|
let id;
|
||||||
module = moduleCache.getPackage(filePath);
|
let module;
|
||||||
id = module.data.name;
|
if (filePath.endsWith(PACKAGE_JSON)) {
|
||||||
} else if (sourceExts.indexOf(path.extname(filePath).substr(1)) !== -1) {
|
module = moduleCache.getPackage(filePath);
|
||||||
module = moduleCache.getModule(filePath);
|
id = module.data.name;
|
||||||
id = module.name;
|
} else if (sourceExts.indexOf(path.extname(filePath).substr(1)) !== -1) {
|
||||||
}
|
module = moduleCache.getModule(filePath);
|
||||||
|
id = module.name;
|
||||||
|
}
|
||||||
|
|
||||||
if (id && module && module.isHaste()) {
|
if (!(id && module && module.isHaste())) {
|
||||||
if (!map[id]) {
|
return;
|
||||||
map[id] = Object.create(null);
|
}
|
||||||
}
|
if (!map[id]) {
|
||||||
const platform =
|
map[id] = Object.create(null);
|
||||||
parsePlatformFilePath(filePath, platforms).platform ||
|
}
|
||||||
GENERIC_PLATFORM;
|
const platform =
|
||||||
|
parsePlatformFilePath(filePath, platforms).platform || GENERIC_PLATFORM;
|
||||||
|
|
||||||
const existingModule = map[id][platform];
|
const existingModule = map[id][platform];
|
||||||
// 0 = Module, 1 = Package in jest-haste-map
|
// 0 = Module, 1 = Package in jest-haste-map
|
||||||
map[id][platform] = [filePath, module.type === 'Package' ? 1 : 0];
|
map[id][platform] = [filePath, module.type === 'Package' ? 1 : 0];
|
||||||
|
|
||||||
if (existingModule && existingModule[0] !== filePath) {
|
if (existingModule && existingModule[0] !== filePath) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`@providesModule naming collision:\n` +
|
`@providesModule naming collision:\n` +
|
||||||
` Duplicate module name: \`${id}\`\n` +
|
` Duplicate module name: \`${id}\`\n` +
|
||||||
` Paths: \`${filePath}\` collides with ` +
|
` Paths: \`${filePath}\` collides with ` +
|
||||||
`\`${existingModule[0]}\`\n\n` +
|
`\`${existingModule[0]}\`\n\n` +
|
||||||
'This error is caused by a @providesModule declaration ' +
|
'This error is caused by a @providesModule declaration ' +
|
||||||
'with the same name across two different files.',
|
'with the same name across two different files.',
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return map;
|
return map;
|
||||||
|
|
Loading…
Reference in New Issue