mirror of https://github.com/status-im/metro.git
Fix support for haste packages
Summary: Fixes support for haste packages in `ModuleGraph`. As `HasteMap` is no longer used for anything else, we can probably strip it down completely. Reviewed By: cpojer Differential Revision: D4967367 fbshipit-source-id: d40cbe46c1e8b05690c0a2c71955479c28607c01
This commit is contained in:
parent
054b5aa4ce
commit
ee0fc30814
|
@ -51,8 +51,8 @@ function getFakeModuleMap(hasteMap: HasteMap) {
|
||||||
return module && module.type === 'Module' ? module.path : null;
|
return module && module.type === 'Module' ? module.path : null;
|
||||||
},
|
},
|
||||||
getPackage(name: string, platform: ?string): ?string {
|
getPackage(name: string, platform: ?string): ?string {
|
||||||
const module = hasteMap.getModule(name, platform);
|
const pkg = hasteMap.getPackage(name);
|
||||||
return module && module.type === 'Package' ? module.path : null;
|
return pkg && pkg.path;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ class HasteMap extends EventEmitter {
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
this._map = Object.create(null);
|
this._map = Object.create(null);
|
||||||
|
this._packages = Object.create(null);
|
||||||
const promises = [];
|
const promises = [];
|
||||||
this._files.forEach(filePath => {
|
this._files.forEach(filePath => {
|
||||||
if (!this._helpers.isNodeModulesDir(filePath)) {
|
if (!this._helpers.isNodeModulesDir(filePath)) {
|
||||||
|
@ -116,6 +117,10 @@ class HasteMap extends EventEmitter {
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPackage(name): Package {
|
||||||
|
return this._packages[name];
|
||||||
|
}
|
||||||
|
|
||||||
_processHasteModule(file, previousName) {
|
_processHasteModule(file, previousName) {
|
||||||
const module = this._moduleCache.getModule(file);
|
const module = this._moduleCache.getModule(file);
|
||||||
return module.isHaste().then(
|
return module.isHaste().then(
|
||||||
|
@ -151,13 +156,20 @@ class HasteMap extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateHasteMap(name, mod) {
|
_updateHasteMap(name, mod) {
|
||||||
if (this._map[name] == null) {
|
let existingModule;
|
||||||
this._map[name] = Object.create(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
const moduleMap = this._map[name];
|
if (mod.type === 'Package') {
|
||||||
const modulePlatform = getPlatformExtension(mod.path, this._platforms) || GENERIC_PLATFORM;
|
existingModule = this._packages[name];
|
||||||
const existingModule = moduleMap[modulePlatform];
|
this._packages[name] = mod;
|
||||||
|
} else {
|
||||||
|
if (this._map[name] == null) {
|
||||||
|
this._map[name] = Object.create(null);
|
||||||
|
}
|
||||||
|
const moduleMap = this._map[name];
|
||||||
|
const modulePlatform = getPlatformExtension(mod.path, this._platforms) || GENERIC_PLATFORM;
|
||||||
|
existingModule = moduleMap[modulePlatform];
|
||||||
|
moduleMap[modulePlatform] = mod;
|
||||||
|
}
|
||||||
|
|
||||||
if (existingModule && existingModule.path !== mod.path) {
|
if (existingModule && existingModule.path !== mod.path) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
@ -168,8 +180,6 @@ class HasteMap extends EventEmitter {
|
||||||
'with the same name across two different files.'
|
'with the same name across two different files.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleMap[modulePlatform] = mod;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue