metro-resolver
Advanced tools
Comparing version 0.81.0-alpha.2 to 0.81.0
{ | ||
"name": "metro-resolver", | ||
"version": "0.81.0-alpha.2", | ||
"version": "0.81.0", | ||
"description": "🚇 Implementation of Metro's resolution logic.", | ||
@@ -19,3 +19,3 @@ "main": "src", | ||
"devDependencies": { | ||
"metro": "0.81.0-alpha.2" | ||
"metro": "0.81.0" | ||
}, | ||
@@ -22,0 +22,0 @@ "dependencies": { |
@@ -6,2 +6,3 @@ "use strict"; | ||
FailedToResolvePathError: require("./errors/FailedToResolvePathError"), | ||
FailedToResolveUnsupportedError: require("./errors/FailedToResolveUnsupportedError"), | ||
formatFileCandidates: require("./errors/formatFileCandidates"), | ||
@@ -8,0 +9,0 @@ InvalidPackageError: require("./errors/InvalidPackageError"), |
@@ -18,8 +18,4 @@ "use strict"; | ||
var _path = _interopRequireDefault(require("path")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule | ||
? obj | ||
: { | ||
default: obj, | ||
}; | ||
function _interopRequireDefault(e) { | ||
return e && e.__esModule ? e : { default: e }; | ||
} | ||
@@ -75,14 +71,7 @@ function resolvePackageTargetFromExports( | ||
} | ||
if (context.unstable_fileSystemLookup != null) { | ||
const lookupResult = context.unstable_fileSystemLookup(filePath); | ||
if (lookupResult.exists && lookupResult.type === "f") { | ||
return { | ||
type: "sourceFile", | ||
filePath: lookupResult.realPath, | ||
}; | ||
} | ||
} else if (context.doesFileExist(filePath)) { | ||
const lookupResult = context.fileSystemLookup(filePath); | ||
if (lookupResult.exists && lookupResult.type === "f") { | ||
return { | ||
type: "sourceFile", | ||
filePath, | ||
filePath: lookupResult.realPath, | ||
}; | ||
@@ -89,0 +78,0 @@ } |
@@ -10,8 +10,4 @@ "use strict"; | ||
var _path = _interopRequireDefault(require("path")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule | ||
? obj | ||
: { | ||
default: obj, | ||
}; | ||
function _interopRequireDefault(e) { | ||
return e && e.__esModule ? e : { default: e }; | ||
} | ||
@@ -18,0 +14,0 @@ function getPackageEntryPoint(context, packageInfo, platform) { |
@@ -9,2 +9,5 @@ "use strict"; | ||
); | ||
var _FailedToResolveUnsupportedError = _interopRequireDefault( | ||
require("./errors/FailedToResolveUnsupportedError") | ||
); | ||
var _formatFileCandidates = _interopRequireDefault( | ||
@@ -27,8 +30,4 @@ require("./errors/formatFileCandidates") | ||
var _path = _interopRequireDefault(require("path")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule | ||
? obj | ||
: { | ||
default: obj, | ||
}; | ||
function _interopRequireDefault(e) { | ||
return e && e.__esModule ? e : { default: e }; | ||
} | ||
@@ -54,3 +53,11 @@ function resolve(context, moduleName, platform) { | ||
} | ||
const realModuleName = context.redirectModulePath(moduleName); | ||
if (moduleName.startsWith("#")) { | ||
throw new _FailedToResolveUnsupportedError.default( | ||
'Specifier starts with "#" but subpath imports are not currently supported.' | ||
); | ||
} | ||
const realModuleName = (0, _PackageResolve.redirectModulePath)( | ||
context, | ||
moduleName | ||
); | ||
if (realModuleName === false) { | ||
@@ -79,8 +86,19 @@ return { | ||
} | ||
const parsedSpecifier = parseBareSpecifier(realModuleName); | ||
if (context.allowHaste) { | ||
const normalizedName = normalizePath(realModuleName); | ||
const result = resolveHasteName(context, normalizedName, platform); | ||
if (result.type === "resolved") { | ||
return result.resolution; | ||
if (parsedSpecifier.isSinglePart) { | ||
const result = context.resolveHasteModule(parsedSpecifier.firstPart); | ||
if (result != null) { | ||
return { | ||
type: "sourceFile", | ||
filePath: result, | ||
}; | ||
} | ||
} | ||
if (parsedSpecifier.isValidPackageName) { | ||
const result = resolveHastePackage(context, parsedSpecifier, platform); | ||
if (result.type === "resolved") { | ||
return result.resolution; | ||
} | ||
} | ||
} | ||
@@ -103,3 +121,2 @@ const { disableHierarchicalLookup } = context; | ||
const extraPaths = []; | ||
const parsedSpecifier = parsePackageSpecifier(realModuleName); | ||
const { extraNodeModules } = context; | ||
@@ -115,12 +132,10 @@ if (extraNodeModules && extraNodeModules[parsedSpecifier.packageName]) { | ||
let lookupResult = null; | ||
if (context.unstable_fileSystemLookup) { | ||
const mustBeDirectory = | ||
parsedSpecifier.posixSubpath !== "." || | ||
parsedSpecifier.packageName.length > parsedSpecifier.firstPart.length | ||
? nodeModulePath + _path.default.sep + parsedSpecifier.firstPart | ||
: nodeModulePath; | ||
lookupResult = context.unstable_fileSystemLookup(mustBeDirectory); | ||
if (!lookupResult.exists || lookupResult.type !== "d") { | ||
return null; | ||
} | ||
const mustBeDirectory = | ||
parsedSpecifier.posixSubpath !== "." || | ||
parsedSpecifier.packageName.length > parsedSpecifier.firstPart.length | ||
? nodeModulePath + _path.default.sep + parsedSpecifier.firstPart | ||
: nodeModulePath; | ||
lookupResult = context.fileSystemLookup(mustBeDirectory); | ||
if (!lookupResult.exists || lookupResult.type !== "d") { | ||
return null; | ||
} | ||
@@ -132,3 +147,6 @@ return _path.default.join(nodeModulePath, realModuleName); | ||
for (let i = 0; i < allDirPaths.length; ++i) { | ||
const candidate = context.redirectModulePath(allDirPaths[i]); | ||
const candidate = (0, _PackageResolve.redirectModulePath)( | ||
context, | ||
allDirPaths[i] | ||
); | ||
if (candidate === false) { | ||
@@ -146,3 +164,3 @@ return { | ||
} | ||
function parsePackageSpecifier(specifier) { | ||
function parseBareSpecifier(specifier) { | ||
const normalized = | ||
@@ -155,3 +173,6 @@ _path.default.sep === "/" ? specifier : specifier.replaceAll("\\", "/"); | ||
return { | ||
isSinglePart: false, | ||
isValidPackageName: true, | ||
firstPart: normalized.slice(0, firstSepIdx), | ||
normalizedSpecifier: normalized, | ||
packageName: normalized, | ||
@@ -162,3 +183,6 @@ posixSubpath: ".", | ||
return { | ||
isSinglePart: false, | ||
isValidPackageName: true, | ||
firstPart: normalized.slice(0, firstSepIdx), | ||
normalizedSpecifier: normalized, | ||
packageName: normalized.slice(0, secondSepIdx), | ||
@@ -170,3 +194,6 @@ posixSubpath: "." + normalized.slice(secondSepIdx), | ||
return { | ||
isSinglePart: true, | ||
isValidPackageName: !normalized.startsWith("@"), | ||
firstPart: normalized, | ||
normalizedSpecifier: normalized, | ||
packageName: normalized, | ||
@@ -178,3 +205,6 @@ posixSubpath: ".", | ||
return { | ||
isSinglePart: false, | ||
isValidPackageName: true, | ||
firstPart: packageName, | ||
normalizedSpecifier: normalized, | ||
packageName, | ||
@@ -193,3 +223,6 @@ posixSubpath: "." + normalized.slice(firstSepIdx), | ||
); | ||
const redirectedPath = context.redirectModulePath(modulePath); | ||
const redirectedPath = (0, _PackageResolve.redirectModulePath)( | ||
context, | ||
modulePath | ||
); | ||
if (redirectedPath === false) { | ||
@@ -217,22 +250,16 @@ return resolvedAs({ | ||
} | ||
function resolveHasteName(context, moduleName, platform) { | ||
const modulePath = context.resolveHasteModule(moduleName); | ||
if (modulePath != null) { | ||
return resolvedAs({ | ||
type: "sourceFile", | ||
filePath: modulePath, | ||
}); | ||
} | ||
let packageName = moduleName; | ||
let packageJsonPath = context.resolveHastePackage(packageName); | ||
while (packageJsonPath == null && packageName && packageName !== ".") { | ||
packageName = _path.default.dirname(packageName); | ||
packageJsonPath = context.resolveHastePackage(packageName); | ||
} | ||
function resolveHastePackage( | ||
context, | ||
{ normalizedSpecifier: moduleName, packageName, posixSubpath: pathInModule }, | ||
platform | ||
) { | ||
const packageJsonPath = context.resolveHastePackage(packageName); | ||
if (packageJsonPath == null) { | ||
return failedFor(); | ||
} | ||
const packageDirPath = _path.default.dirname(packageJsonPath); | ||
const pathInModule = moduleName.substring(packageName.length + 1); | ||
const potentialModulePath = _path.default.join(packageDirPath, pathInModule); | ||
const potentialModulePath = _path.default.join( | ||
packageJsonPath, | ||
"..", | ||
pathInModule | ||
); | ||
const result = resolvePackage(context, potentialModulePath, platform); | ||
@@ -256,3 +283,3 @@ if (result.type === "resolved") { | ||
`the Haste package \`${opts.packageName}\` was found. However the ` + | ||
`module \`${opts.pathInModule}\` could not be found within ` + | ||
`subpath \`${opts.pathInModule}\` could not be found within ` + | ||
"the package. Indeed, none of these files exist:\n\n" + | ||
@@ -317,7 +344,4 @@ [opts.candidates.file, opts.candidates.dir] | ||
function resolvePackageEntryPoint(context, packagePath, platform) { | ||
const dirLookup = context.unstable_fileSystemLookup?.(packagePath); | ||
if ( | ||
dirLookup != null && | ||
(dirLookup.exists === false || dirLookup.type !== "d") | ||
) { | ||
const dirLookup = context.fileSystemLookup(packagePath); | ||
if (dirLookup.exists == false || dirLookup.type !== "d") { | ||
return failedFor({ | ||
@@ -433,3 +457,5 @@ type: "sourceFile", | ||
const redirectedPath = | ||
extension !== "" ? context.redirectModulePath(filePath) : filePath; | ||
extension !== "" | ||
? (0, _PackageResolve.redirectModulePath)(context, filePath) | ||
: filePath; | ||
if (redirectedPath === false) { | ||
@@ -440,9 +466,5 @@ return { | ||
} | ||
if (context.unstable_fileSystemLookup) { | ||
const lookupResult = context.unstable_fileSystemLookup(redirectedPath); | ||
if (lookupResult.exists && lookupResult.type === "f") { | ||
return lookupResult.realPath; | ||
} | ||
} else if (context.doesFileExist(redirectedPath)) { | ||
return redirectedPath; | ||
const lookupResult = context.fileSystemLookup(redirectedPath); | ||
if (lookupResult.exists && lookupResult.type === "f") { | ||
return lookupResult.realPath; | ||
} | ||
@@ -455,10 +477,2 @@ context.candidateExts.push(extension); | ||
} | ||
function normalizePath(modulePath) { | ||
if (_path.default.sep === "/") { | ||
modulePath = _path.default.normalize(modulePath); | ||
} else if (_path.default.posix) { | ||
modulePath = _path.default.posix.normalize(modulePath); | ||
} | ||
return modulePath.replace(/\/$/, ""); | ||
} | ||
function resolvedAs(resolution) { | ||
@@ -465,0 +479,0 @@ return { |
@@ -8,8 +8,4 @@ "use strict"; | ||
var _path = _interopRequireDefault(require("path")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule | ||
? obj | ||
: { | ||
default: obj, | ||
}; | ||
function _interopRequireDefault(e) { | ||
return e && e.__esModule ? e : { default: e }; | ||
} | ||
@@ -16,0 +12,0 @@ function resolveAsset(context, filePath) { |
@@ -104,2 +104,8 @@ /** | ||
readonly disableHierarchicalLookup: boolean; | ||
/** | ||
* Determine whether a regular file exists at the given path. | ||
* | ||
* @deprecated, prefer `fileSystemLookup` | ||
*/ | ||
readonly doesFileExist: DoesFileExist; | ||
@@ -132,2 +138,9 @@ readonly extraNodeModules?: {[key: string]: string}; | ||
/** | ||
* Synchonously returns information about a given absolute path, including | ||
* whether it exists, whether it is a file or directory, and its absolute | ||
* real path. | ||
*/ | ||
readonly fileSystemLookup: FileSystemLookup; | ||
/** | ||
* The ordered list of fields to read in `package.json` to resolve a main | ||
@@ -170,3 +183,2 @@ * entry point based on the "browser" field spec. | ||
unstable_enablePackageExports: boolean; | ||
unstable_fileSystemLookup?: FileSystemLookup | null; | ||
unstable_logWarning: (message: string) => void; | ||
@@ -173,0 +185,0 @@ } |
@@ -8,8 +8,4 @@ "use strict"; | ||
var _path = _interopRequireDefault(require("path")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule | ||
? obj | ||
: { | ||
default: obj, | ||
}; | ||
function _interopRequireDefault(e) { | ||
return e && e.__esModule ? e : { default: e }; | ||
} | ||
@@ -16,0 +12,0 @@ function isAssetFile(filePath, assetExts) { |
@@ -8,8 +8,4 @@ "use strict"; | ||
var _path = _interopRequireDefault(require("path")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule | ||
? obj | ||
: { | ||
default: obj, | ||
}; | ||
function _interopRequireDefault(e) { | ||
return e && e.__esModule ? e : { default: e }; | ||
} | ||
@@ -16,0 +12,0 @@ const MATCH_NON_POSIX_PATH_SEPS = new RegExp( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98432
36
1206