metro-resolver
Advanced tools
| /** | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| * | ||
| * @noformat | ||
| * @oncall react_native | ||
| * @generated SignedSource<<5fff5c32149db3606cb58437bfe37a8b>> | ||
| * | ||
| * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js | ||
| * Original file: packages/metro-resolver/src/utils/paths.js | ||
| * To regenerate, run: | ||
| * js1 build metro-ts-defs (internal) OR | ||
| * yarn run build-ts-defs (OSS) | ||
| */ | ||
| export declare const systemToPosixPath: (relativeSystemPath: string) => string; | ||
| export declare type systemToPosixPath = typeof systemToPosixPath; | ||
| export declare const posixToSystemPath: (relativePosixPath: string) => string; | ||
| export declare type posixToSystemPath = typeof posixToSystemPath; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true, | ||
| }); | ||
| exports.systemToPosixPath = exports.posixToSystemPath = void 0; | ||
| var _path = _interopRequireDefault(require("path")); | ||
| function _interopRequireDefault(e) { | ||
| return e && e.__esModule ? e : { default: e }; | ||
| } | ||
| const systemToPosixPath = (exports.systemToPosixPath = | ||
| _path.default.sep === "/" | ||
| ? (inputPath) => inputPath | ||
| : (inputPath) => inputPath.replaceAll("\\", "/")); | ||
| const posixToSystemPath = (exports.posixToSystemPath = | ||
| _path.default.sep === "/" | ||
| ? (inputPath) => inputPath | ||
| : (inputPath) => inputPath.replaceAll("/", "\\")); |
Sorry, the diff of this file is not supported yet
+2
-2
| { | ||
| "name": "metro-resolver", | ||
| "version": "0.83.6", | ||
| "version": "0.83.7", | ||
| "description": "🚇 Implementation of Metro's resolution logic.", | ||
@@ -25,3 +25,3 @@ "main": "src/index.js", | ||
| "devDependencies": { | ||
| "metro": "0.83.6" | ||
| "metro": "0.83.7" | ||
| }, | ||
@@ -28,0 +28,0 @@ "dependencies": { |
@@ -17,3 +17,3 @@ "use strict"; | ||
| var _matchSubpathFromExportsLike = require("./utils/matchSubpathFromExportsLike"); | ||
| var _toPosixPath = _interopRequireDefault(require("./utils/toPosixPath")); | ||
| var _paths = require("./utils/paths"); | ||
| var _path = _interopRequireDefault(require("path")); | ||
@@ -99,3 +99,3 @@ function _interopRequireDefault(e) { | ||
| ? "." | ||
| : "./" + (0, _toPosixPath.default)(packageSubpath); | ||
| : "./" + (0, _paths.systemToPosixPath)(packageSubpath); | ||
| } | ||
@@ -102,0 +102,0 @@ const _normalizedExportsFields = new WeakMap(); |
@@ -8,3 +8,3 @@ "use strict"; | ||
| exports.redirectModulePath = redirectModulePath; | ||
| var _toPosixPath = _interopRequireDefault(require("./utils/toPosixPath")); | ||
| var _paths = require("./utils/paths"); | ||
| var _path = _interopRequireDefault(require("path")); | ||
@@ -57,3 +57,3 @@ function _interopRequireDefault(e) { | ||
| redirectedPath = matchSubpathFromMainFields( | ||
| "./" + (0, _toPosixPath.default)(packageRelativeModulePath), | ||
| "./" + (0, _paths.systemToPosixPath)(packageRelativeModulePath), | ||
| containingPackage.packageJson, | ||
@@ -60,0 +60,0 @@ mainFields, |
+2
-2
@@ -9,3 +9,3 @@ /** | ||
| * @oncall react_native | ||
| * @generated SignedSource<<56f6e00225ee5ece6142bb2b9e4c608d>> | ||
| * @generated SignedSource<<c1a6123a3994fc6aa9ebc04c528af213>> | ||
| * | ||
@@ -23,5 +23,5 @@ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js | ||
| context: ResolutionContext, | ||
| moduleName: string, | ||
| specifier: string, | ||
| platform: string | null, | ||
| ): Resolution; | ||
| export default resolve; |
+123
-51
@@ -33,2 +33,3 @@ "use strict"; | ||
| var _isAssetFile = _interopRequireDefault(require("./utils/isAssetFile")); | ||
| var _paths = require("./utils/paths"); | ||
| var _path = _interopRequireDefault(require("path")); | ||
@@ -38,3 +39,3 @@ function _interopRequireDefault(e) { | ||
| } | ||
| function resolve(context, moduleName, platform) { | ||
| function resolve(context, specifier, platform) { | ||
| const resolveRequest = context.resolveRequest; | ||
@@ -47,8 +48,8 @@ if (resolveRequest && resolveRequest !== resolve) { | ||
| }), | ||
| moduleName, | ||
| specifier, | ||
| platform, | ||
| ); | ||
| } | ||
| if (isRelativeImport(moduleName) || _path.default.isAbsolute(moduleName)) { | ||
| const result = resolveModulePath(context, moduleName, platform); | ||
| if (isRelativeImport(specifier) || _path.default.isAbsolute(specifier)) { | ||
| const result = resolveModulePath(context, specifier, platform); | ||
| if (result.type === "failed") { | ||
@@ -58,3 +59,3 @@ throw new _FailedToResolvePathError.default(result.candidates); | ||
| return result.resolution; | ||
| } else if (isSubpathImport(moduleName)) { | ||
| } else if (isSubpathImport(specifier)) { | ||
| const pkg = context.getPackageForModule(context.originModulePath); | ||
@@ -64,3 +65,3 @@ const importsField = pkg?.packageJson.imports; | ||
| throw new _PackageImportNotResolvedError.default({ | ||
| importSpecifier: moduleName, | ||
| importSpecifier: specifier, | ||
| reason: `Could not find a package.json file relative to module ${context.originModulePath}`, | ||
@@ -70,3 +71,3 @@ }); | ||
| throw new _PackageImportNotResolvedError.default({ | ||
| importSpecifier: moduleName, | ||
| importSpecifier: specifier, | ||
| reason: `Missing field "imports" in package.json. Check package.json at: ${pkg.rootPath}`, | ||
@@ -80,3 +81,3 @@ }); | ||
| pkg.rootPath, | ||
| moduleName, | ||
| specifier, | ||
| importsField, | ||
@@ -105,7 +106,7 @@ platform, | ||
| } | ||
| const realModuleName = (0, _PackageResolve.redirectModulePath)( | ||
| const redirectedSpecifier = (0, _PackageResolve.redirectModulePath)( | ||
| context, | ||
| moduleName, | ||
| specifier, | ||
| ); | ||
| if (realModuleName === false) { | ||
| if (redirectedSpecifier === false) { | ||
| return { | ||
@@ -117,4 +118,4 @@ type: "empty", | ||
| const isDirectImport = | ||
| isRelativeImport(realModuleName) || | ||
| _path.default.isAbsolute(realModuleName); | ||
| isRelativeImport(redirectedSpecifier) || | ||
| _path.default.isAbsolute(redirectedSpecifier); | ||
| if (isDirectImport) { | ||
@@ -127,3 +128,3 @@ const fromModuleParentIdx = | ||
| ); | ||
| const absPath = _path.default.join(originModuleDir, realModuleName); | ||
| const absPath = _path.default.join(originModuleDir, redirectedSpecifier); | ||
| const result = resolveModulePath(context, absPath, platform); | ||
@@ -135,3 +136,3 @@ if (result.type === "failed") { | ||
| } | ||
| const parsedSpecifier = parseBareSpecifier(realModuleName); | ||
| const parsedSpecifier = parseBareSpecifier(redirectedSpecifier); | ||
| if (context.allowHaste) { | ||
@@ -155,5 +156,5 @@ if (parsedSpecifier.isSinglePart) { | ||
| const { disableHierarchicalLookup } = context; | ||
| const nodeModulesPaths = []; | ||
| let next = _path.default.dirname(originModulePath); | ||
| if (!disableHierarchicalLookup) { | ||
| const visited = Object.create(null); | ||
| let next = _path.default.dirname(originModulePath); | ||
| let candidate; | ||
@@ -165,48 +166,119 @@ do { | ||
| : candidate + _path.default.sep + "node_modules"; | ||
| nodeModulesPaths.push(nodeModulesPath); | ||
| const resolution = resolveFromNodeModulesPath( | ||
| context, | ||
| parsedSpecifier, | ||
| platform, | ||
| nodeModulesPath, | ||
| ); | ||
| if (resolution != null) { | ||
| return resolution; | ||
| } | ||
| visited[nodeModulesPath] = true; | ||
| next = _path.default.dirname(candidate); | ||
| } while (candidate !== next); | ||
| for (let i = 0; i < context.nodeModulesPaths.length; i++) { | ||
| if (visited[context.nodeModulesPaths[i]]) { | ||
| continue; | ||
| } | ||
| const resolution = resolveFromNodeModulesPath( | ||
| context, | ||
| parsedSpecifier, | ||
| platform, | ||
| context.nodeModulesPaths[i], | ||
| ); | ||
| if (resolution != null) { | ||
| return resolution; | ||
| } | ||
| } | ||
| } else { | ||
| for (let i = 0; i < context.nodeModulesPaths.length; i++) { | ||
| const resolution = resolveFromNodeModulesPath( | ||
| context, | ||
| parsedSpecifier, | ||
| platform, | ||
| context.nodeModulesPaths[i], | ||
| ); | ||
| if (resolution != null) { | ||
| return resolution; | ||
| } | ||
| } | ||
| } | ||
| nodeModulesPaths.push(...context.nodeModulesPaths); | ||
| const extraPaths = []; | ||
| const { extraNodeModules } = context; | ||
| let extraNodeModulePath; | ||
| if (extraNodeModules && extraNodeModules[parsedSpecifier.packageName]) { | ||
| const newPackageName = extraNodeModules[parsedSpecifier.packageName]; | ||
| extraPaths.push( | ||
| _path.default.join(newPackageName, parsedSpecifier.posixSubpath), | ||
| extraNodeModulePath = _path.default.join( | ||
| newPackageName, | ||
| parsedSpecifier.posixSubpath, | ||
| ); | ||
| } | ||
| const allDirPaths = nodeModulesPaths | ||
| .map((nodeModulePath) => { | ||
| let lookupResult = 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; | ||
| } | ||
| return _path.default.join(nodeModulePath, realModuleName); | ||
| }) | ||
| .filter(Boolean) | ||
| .concat(extraPaths); | ||
| for (let i = 0; i < allDirPaths.length; ++i) { | ||
| const candidate = (0, _PackageResolve.redirectModulePath)( | ||
| const resolution = resolveModuleFromTargetPath( | ||
| context, | ||
| allDirPaths[i], | ||
| platform, | ||
| extraNodeModulePath, | ||
| ); | ||
| if (candidate === false) { | ||
| return { | ||
| type: "empty", | ||
| }; | ||
| if (resolution != null) { | ||
| return resolution; | ||
| } | ||
| const result = resolvePackage(context, candidate, platform); | ||
| if (result.type === "resolved") { | ||
| return result.resolution; | ||
| } | ||
| } | ||
| throw new _FailedToResolveNameError.default(nodeModulesPaths, extraPaths); | ||
| throw buildFailedToResolveNameError( | ||
| context, | ||
| extraNodeModulePath != null ? [extraNodeModulePath] : [], | ||
| ); | ||
| } | ||
| function resolveFromNodeModulesPath( | ||
| context, | ||
| parsedSpecifier, | ||
| platform, | ||
| nodeModulesPath, | ||
| ) { | ||
| const mustBeDirectory = | ||
| parsedSpecifier.posixSubpath !== "." || | ||
| parsedSpecifier.packageName.length > parsedSpecifier.firstPart.length | ||
| ? nodeModulesPath + _path.default.sep + parsedSpecifier.firstPart | ||
| : nodeModulesPath; | ||
| const lookupResult = context.fileSystemLookup(mustBeDirectory); | ||
| if (!lookupResult.exists || lookupResult.type !== "d") { | ||
| return null; | ||
| } | ||
| return resolveModuleFromTargetPath( | ||
| context, | ||
| platform, | ||
| nodeModulesPath + | ||
| _path.default.sep + | ||
| (0, _paths.posixToSystemPath)(parsedSpecifier.normalizedSpecifier), | ||
| ); | ||
| } | ||
| function resolveModuleFromTargetPath(context, platform, targetPath) { | ||
| const candidate = (0, _PackageResolve.redirectModulePath)( | ||
| context, | ||
| targetPath, | ||
| ); | ||
| if (candidate === false) { | ||
| return { | ||
| type: "empty", | ||
| }; | ||
| } | ||
| const result = resolvePackage(context, candidate, platform); | ||
| if (result.type === "resolved") { | ||
| return result.resolution; | ||
| } | ||
| return null; | ||
| } | ||
| function buildFailedToResolveNameError(context, extraPaths) { | ||
| const nodeModulesPaths = []; | ||
| if (!context.disableHierarchicalLookup) { | ||
| let next = _path.default.dirname(context.originModulePath); | ||
| let candidate; | ||
| do { | ||
| candidate = next; | ||
| const nodeModulesPath = candidate.endsWith(_path.default.sep) | ||
| ? candidate + "node_modules" | ||
| : candidate + _path.default.sep + "node_modules"; | ||
| nodeModulesPaths.push(nodeModulesPath); | ||
| next = _path.default.dirname(candidate); | ||
| } while (candidate !== next); | ||
| } | ||
| nodeModulesPaths.push(...context.nodeModulesPaths); | ||
| return new _FailedToResolveNameError.default(nodeModulesPaths, extraPaths); | ||
| } | ||
| function parseBareSpecifier(specifier) { | ||
@@ -213,0 +285,0 @@ const normalized = |
| /** | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| * | ||
| * @noformat | ||
| * @oncall react_native | ||
| * @generated SignedSource<<091df9100cc8f841af449036a548f6aa>> | ||
| * | ||
| * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js | ||
| * Original file: packages/metro-resolver/src/utils/toPosixPath.js | ||
| * To regenerate, run: | ||
| * js1 build metro-ts-defs (internal) OR | ||
| * yarn run build-ts-defs (OSS) | ||
| */ | ||
| /** | ||
| * Replace path separators in the passed string to coerce to a POSIX path. This | ||
| * is a no-op on POSIX systems. | ||
| */ | ||
| declare function toPosixPath(relativePathOrSpecifier: string): string; | ||
| export default toPosixPath; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true, | ||
| }); | ||
| exports.default = toPosixPath; | ||
| var _path = _interopRequireDefault(require("path")); | ||
| function _interopRequireDefault(e) { | ||
| return e && e.__esModule ? e : { default: e }; | ||
| } | ||
| const MATCH_NON_POSIX_PATH_SEPS = new RegExp( | ||
| "\\" + _path.default.win32.sep, | ||
| "g", | ||
| ); | ||
| function toPosixPath(relativePathOrSpecifier) { | ||
| if (_path.default.sep === _path.default.posix.sep) { | ||
| return relativePathOrSpecifier; | ||
| } | ||
| return relativePathOrSpecifier.replace( | ||
| MATCH_NON_POSIX_PATH_SEPS, | ||
| _path.default.posix.sep, | ||
| ); | ||
| } |
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
143629
3.03%2221
3.01%