mirror of https://github.com/status-im/metro.git
Make "browser" field work with the destination too
Reviewed By: rafeca Differential Revision: D7974989 fbshipit-source-id: f1a14dbd44a82c1929525416b56f455a6a685bcd
This commit is contained in:
parent
2b9a8fdc30
commit
4a1e4f7646
|
@ -113,7 +113,8 @@ function resolve(
|
||||||
|
|
||||||
const allDirPaths = dirPaths.concat(extraPaths);
|
const allDirPaths = dirPaths.concat(extraPaths);
|
||||||
for (let i = 0; i < allDirPaths.length; ++i) {
|
for (let i = 0; i < allDirPaths.length; ++i) {
|
||||||
const result = resolveFileOrDir(context, allDirPaths[i], platform);
|
const realModuleName = context.redirectModulePath(allDirPaths[i]);
|
||||||
|
const result = resolveFileOrDir(context, realModuleName, platform);
|
||||||
if (result.type === 'resolved') {
|
if (result.type === 'resolved') {
|
||||||
return result.resolution;
|
return result.resolution;
|
||||||
}
|
}
|
||||||
|
@ -127,11 +128,6 @@ type ModulePathContext = FileOrDirContext & {
|
||||||
* resolved.
|
* resolved.
|
||||||
*/
|
*/
|
||||||
+originModulePath: string,
|
+originModulePath: string,
|
||||||
/**
|
|
||||||
* Lookup the module's closest `package.json` and process the redirects
|
|
||||||
* metadata. Return an absolute path to the resolved path.
|
|
||||||
*/
|
|
||||||
+redirectModulePath: (modulePath: string) => string | false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -347,6 +343,7 @@ type FileContext = {
|
||||||
+doesFileExist: DoesFileExist,
|
+doesFileExist: DoesFileExist,
|
||||||
+isAssetFile: IsAssetFile,
|
+isAssetFile: IsAssetFile,
|
||||||
+preferNativePlatform: boolean,
|
+preferNativePlatform: boolean,
|
||||||
|
+redirectModulePath: (modulePath: string) => string | false,
|
||||||
+resolveAsset: ResolveAsset,
|
+resolveAsset: ResolveAsset,
|
||||||
+sourceExts: $ReadOnlyArray<string>,
|
+sourceExts: $ReadOnlyArray<string>,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1526,7 +1526,7 @@ Array [
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"dependencies": Array [],
|
"dependencies": Array [],
|
||||||
"path": "/root/node_modules/foo/node_modules/bar/lol.js",
|
"path": "/root/node_modules/foo/node_modules/bar/wow.js",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"dependencies": Array [],
|
"dependencies": Array [],
|
||||||
|
@ -1878,7 +1878,7 @@ Array [
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"dependencies": Array [],
|
"dependencies": Array [],
|
||||||
"path": "C:\\\\root\\\\node_modules\\\\foo\\\\node_modules\\\\bar\\\\lol.js",
|
"path": "C:\\\\root\\\\node_modules\\\\foo\\\\node_modules\\\\bar\\\\wow.js",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"dependencies": Array [],
|
"dependencies": Array [],
|
||||||
|
|
|
@ -75,10 +75,22 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
||||||
}
|
}
|
||||||
|
|
||||||
_redirectRequire(fromModule: TModule, modulePath: string): string | false {
|
_redirectRequire(fromModule: TModule, modulePath: string): string | false {
|
||||||
const pck = fromModule.getPackage();
|
const moduleCache = this._options.moduleCache;
|
||||||
if (pck) {
|
|
||||||
return pck.redirectRequire(modulePath);
|
try {
|
||||||
|
const pck =
|
||||||
|
modulePath.startsWith('.') || path.isAbsolute(modulePath)
|
||||||
|
? moduleCache.getModule(modulePath).getPackage()
|
||||||
|
: fromModule.getPackage();
|
||||||
|
|
||||||
|
if (pck) {
|
||||||
|
return pck.redirectRequire(modulePath);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// Do nothing. The standard module cache does not trigger any error, but
|
||||||
|
// the ModuleGraph one does, if the module does not exist.
|
||||||
}
|
}
|
||||||
|
|
||||||
return modulePath;
|
return modulePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue