mirror of https://github.com/status-im/metro.git
metro: ModuleResolution: get rid of Packageish#root
Reviewed By: davidaurelio Differential Revision: D6610822 fbshipit-source-id: 116d3b066fefae035f26f2b7a4021816a3d39549
This commit is contained in:
parent
494422aa43
commit
78802d7a42
|
@ -40,7 +40,6 @@ export type ModuleMap = {
|
||||||
export type Packageish = {
|
export type Packageish = {
|
||||||
redirectRequire(toModuleName: string): string | false,
|
redirectRequire(toModuleName: string): string | false,
|
||||||
getMain(): string,
|
getMain(): string,
|
||||||
+root: string,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Moduleish = {
|
export type Moduleish = {
|
||||||
|
@ -177,26 +176,30 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let packageName = realModuleName;
|
let packageName = realModuleName;
|
||||||
let packagePath;
|
let packageJsonPath;
|
||||||
while (packageName && packageName !== '.') {
|
while (packageName && packageName !== '.') {
|
||||||
packagePath = this._options.moduleMap.getPackage(
|
packageJsonPath = this._options.moduleMap.getPackage(
|
||||||
packageName,
|
packageName,
|
||||||
platform,
|
platform,
|
||||||
/* supportsNativePlatform */ true,
|
/* supportsNativePlatform */ true,
|
||||||
);
|
);
|
||||||
if (packagePath != null) {
|
if (packageJsonPath != null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
packageName = path.dirname(packageName);
|
packageName = path.dirname(packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packagePath != null) {
|
if (packageJsonPath != null) {
|
||||||
const package_ = this._options.moduleCache.getPackage(packagePath);
|
// FIXME: `moduleCache.getModule` should return the directory path, not
|
||||||
/* temporary until we strengthen the typing */
|
// the `package.json` file path, because the directory is what's really
|
||||||
invariant(package_.type === 'Package', 'expected Package type');
|
// representing the package.
|
||||||
|
const packageDirPath = path.dirname(packageJsonPath);
|
||||||
|
// FIXME: if we're trying to require the package main module (ie.
|
||||||
|
// packageName === realModuleName), don't do as if it could be a
|
||||||
|
// "FileOrDir", call directly the `resolvePackage` function! Otherwise we
|
||||||
|
// might actually be grabbing a completely unrelated file.
|
||||||
const potentialModulePath = path.join(
|
const potentialModulePath = path.join(
|
||||||
package_.root,
|
packageDirPath,
|
||||||
path.relative(packageName, realModuleName),
|
path.relative(packageName, realModuleName),
|
||||||
);
|
);
|
||||||
return this._loadAsFileOrDirOrThrow(
|
return this._loadAsFileOrDirOrThrow(
|
||||||
|
|
Loading…
Reference in New Issue