Allow resolution without a parent.

Reviewed By: jeanlauliac

Differential Revision: D4862926

fbshipit-source-id: 18f98b6db98e9f937632bd5d00e0b0acfcff9de5
This commit is contained in:
David Aurelio 2017-04-11 07:49:11 -07:00 committed by Facebook Github Bot
parent 2c0a79383b
commit 67aea411bd
1 changed files with 12 additions and 2 deletions

View File

@ -57,6 +57,14 @@ function getFakeModuleMap(hasteMap: HasteMap) {
};
}
const nullModule = {
path: '/',
getPackage() {},
hash() {
throw new Error('not implemented');
},
};
exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
const {
assetExts,
@ -94,7 +102,7 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
const hasteMapBuilt = hasteMap.build();
const resolutionRequests = {};
const filesByDirNameIndex = new FilesByDirNameIndex(hasteMap.getAllFiles());
return (id, source, platform, _, callback) => {
return (id, source: ?string, platform, _, callback) => {
let resolutionRequest = resolutionRequests[platform];
if (!resolutionRequest) {
resolutionRequest = resolutionRequests[platform] = new ResolutionRequest({
@ -113,7 +121,9 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
});
}
const from = new Module(source, moduleCache, getTransformedFile(source));
const from = source != null
? new Module(source, moduleCache, getTransformedFile(source))
: nullModule;
hasteMapBuilt
.then(() => resolutionRequest.resolveDependency(from, id))
.then(