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 abd148fa21
commit 3bcf4acfc7
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 { exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
const { const {
assetExts, assetExts,
@ -94,7 +102,7 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
const hasteMapBuilt = hasteMap.build(); const hasteMapBuilt = hasteMap.build();
const resolutionRequests = {}; const resolutionRequests = {};
const filesByDirNameIndex = new FilesByDirNameIndex(hasteMap.getAllFiles()); const filesByDirNameIndex = new FilesByDirNameIndex(hasteMap.getAllFiles());
return (id, source, platform, _, callback) => { return (id, source: ?string, platform, _, callback) => {
let resolutionRequest = resolutionRequests[platform]; let resolutionRequest = resolutionRequests[platform];
if (!resolutionRequest) { if (!resolutionRequest) {
resolutionRequest = resolutionRequests[platform] = new 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 hasteMapBuilt
.then(() => resolutionRequest.resolveDependency(from, id)) .then(() => resolutionRequest.resolveDependency(from, id))
.then( .then(