Skip to content

Commit

Permalink
Fix support for haste packages
Browse files Browse the repository at this point in the history
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
  • Loading branch information
davidaurelio authored and facebook-github-bot committed Apr 29, 2017
1 parent 8fe24da commit a26e042
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packager/src/ModuleGraph/node-haste/node-haste.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function getFakeModuleMap(hasteMap: HasteMap) {
return module && module.type === 'Module' ? module.path : null;
},
getPackage(name: string, platform: ?string): ?string {
const module = hasteMap.getModule(name, platform);
return module && module.type === 'Package' ? module.path : null;
const pkg = hasteMap.getPackage(name);
return pkg && pkg.path;
},
};
}
Expand Down
26 changes: 18 additions & 8 deletions packager/src/node-haste/DependencyGraph/HasteMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class HasteMap extends EventEmitter {

build() {
this._map = Object.create(null);
this._packages = Object.create(null);
const promises = [];
this._files.forEach(filePath => {
if (!this._helpers.isNodeModulesDir(filePath)) {
Expand Down Expand Up @@ -116,6 +117,10 @@ class HasteMap extends EventEmitter {
return module;
}

getPackage(name): Package {
return this._packages[name];
}

_processHasteModule(file, previousName) {
const module = this._moduleCache.getModule(file);
return module.isHaste().then(
Expand Down Expand Up @@ -151,14 +156,21 @@ class HasteMap extends EventEmitter {
}

_updateHasteMap(name, mod) {
if (this._map[name] == null) {
this._map[name] = Object.create(null);
let existingModule;

if (mod.type === 'Package') {
existingModule = this._packages[name];
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;
}

const moduleMap = this._map[name];
const modulePlatform = getPlatformExtension(mod.path, this._platforms) || GENERIC_PLATFORM;
const existingModule = moduleMap[modulePlatform];

if (existingModule && existingModule.path !== mod.path) {
throw new Error(
`@providesModule naming collision:\n` +
Expand All @@ -168,8 +180,6 @@ class HasteMap extends EventEmitter {
'with the same name across two different files.'
);
}

moduleMap[modulePlatform] = mod;
}
}

Expand Down

0 comments on commit a26e042

Please sign in to comment.