From 67aea411bd00c02eeb4786ccddef06719e1851da 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 --- .../src/ModuleGraph/node-haste/node-haste.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/metro-bundler/src/ModuleGraph/node-haste/node-haste.js b/packages/metro-bundler/src/ModuleGraph/node-haste/node-haste.js index 0d643e3e..3481185b 100644 --- a/packages/metro-bundler/src/ModuleGraph/node-haste/node-haste.js +++ b/packages/metro-bundler/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(