From 3bcf4acfc74a082f07de85f99d4886b3a9fcc7e1 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Tue, 11 Apr 2017 07:49:11 -0700 Subject: [PATCH] Allow resolution without a parent. Reviewed By: jeanlauliac Differential Revision: D4862926 fbshipit-source-id: 18f98b6db98e9f937632bd5d00e0b0acfcff9de5 --- packager/src/ModuleGraph/node-haste/node-haste.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packager/src/ModuleGraph/node-haste/node-haste.js b/packager/src/ModuleGraph/node-haste/node-haste.js index 0d643e3e0..3481185b0 100644 --- a/packager/src/ModuleGraph/node-haste/node-haste.js +++ b/packager/src/ModuleGraph/node-haste/node-haste.js @@ -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(