🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

metro-resolver

Package Overview
Dependencies
Maintainers
2
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metro-resolver - npm Package Compare versions

Comparing version
0.84.4
to
0.85.0
+4
-4
package.json
{
"name": "metro-resolver",
"version": "0.84.4",
"version": "0.85.0",
"description": "🚇 Implementation of Metro's resolution logic.",

@@ -13,3 +13,3 @@ "main": "src/index.js",

"type": "git",
"url": "git+https://github.com/facebook/metro.git",
"url": "git+https://github.com/react/metro.git",
"directory": "packages/metro-resolver"

@@ -23,6 +23,6 @@ },

"engines": {
"node": "^20.19.4 || ^22.13.0 || ^24.3.0 || >= 25.0.0"
"node": "^22.13.0 || ^24.3.0 || >= 26.0.0"
},
"devDependencies": {
"metro": "0.84.4"
"metro": "0.85.0"
},

@@ -29,0 +29,0 @@ "dependencies": {

@@ -9,3 +9,3 @@ /**

* @oncall react_native
* @generated SignedSource<<7e880beb8b73f4a072dfd248ff41d7b0>>
* @generated SignedSource<<20b836efd67d20258d429521857d8eab>>
*

@@ -19,3 +19,3 @@ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js

import type {PackageInfo, ResolutionContext} from './types';
import type {PackageInfo, PackageJson, ResolutionContext} from './types';
/**

@@ -50,1 +50,16 @@ * Resolve the main entry point subpath for a package.

): string | false;
/**
* Get the mapped replacement for the given subpath defined by matching
* `mainFields` entries in the passed `package.json`
* (https://github.com/defunctzombie/package-browser-field-spec#replace-specific-files---advanced).
*
* Returns either:
* - A `string` with the matched replacement subpath.
* - `false`, indicating the module should be ignored.
* - `null` when there is no entry for the subpath.
*/
export declare function matchSubpathFromMainFields(
subpath: string | ReadonlyArray<string>,
pkg: PackageJson,
mainFields: ReadonlyArray<string>,
): string | false | null;

@@ -7,2 +7,3 @@ "use strict";

exports.getPackageEntryPoint = getPackageEntryPoint;
exports.matchSubpathFromMainFields = matchSubpathFromMainFields;
exports.redirectModulePath = redirectModulePath;

@@ -79,9 +80,18 @@ var _paths = require("./utils/paths");

function matchSubpathFromMainFields(subpath, pkg, mainFields) {
const fieldValues = mainFields
.map((name) => pkg[name])
.filter((value) => value != null && typeof value !== "string");
if (!fieldValues.length) {
let replacements = null;
for (let i = mainFields.length - 1; i >= 0; i--) {
const value = pkg[mainFields[i]];
if (value != null && typeof value !== "string") {
if (replacements == null) {
replacements = {};
}
replacements = {
...replacements,
...value,
};
}
}
if (replacements == null) {
return null;
}
const replacements = Object.assign({}, ...fieldValues.reverse());
const variants = Array.isArray(subpath)

@@ -88,0 +98,0 @@ ? subpath

@@ -99,7 +99,13 @@ "use strict";

}
const redirectedSpecifier = (0, _PackageResolve.redirectModulePath)(
context,
specifier,
);
if (redirectedSpecifier === false) {
const { originModulePath } = context;
const closestPackageToOrigin = context.getPackageForModule(originModulePath);
const maybeRedirectedSpecifier =
closestPackageToOrigin != null
? (0, _PackageResolve.matchSubpathFromMainFields)(
specifier,
closestPackageToOrigin.packageJson,
context.mainFields,
)
: null;
if (maybeRedirectedSpecifier === false) {
return {

@@ -109,14 +115,11 @@ type: "empty",

}
const { originModulePath } = context;
const isDirectImport =
isRelativeImport(redirectedSpecifier) ||
_path.default.isAbsolute(redirectedSpecifier);
if (isDirectImport) {
const fromModuleParentIdx =
originModulePath.lastIndexOf("node_modules" + _path.default.sep) + 13;
const originModuleDir = originModulePath.slice(
0,
originModulePath.indexOf(_path.default.sep, fromModuleParentIdx),
if (
maybeRedirectedSpecifier != null &&
closestPackageToOrigin != null &&
isRelativeImport(maybeRedirectedSpecifier)
) {
const absPath = _path.default.resolve(
closestPackageToOrigin.rootPath,
maybeRedirectedSpecifier,
);
const absPath = _path.default.join(originModuleDir, redirectedSpecifier);
const result = resolveModulePath(context, absPath, platform);

@@ -127,4 +130,21 @@ if (result.type === "failed") {

return result.resolution;
} else if (
maybeRedirectedSpecifier != null &&
closestPackageToOrigin != null &&
(_path.default.posix.isAbsolute(maybeRedirectedSpecifier) ||
_path.default.win32.isAbsolute(maybeRedirectedSpecifier))
) {
throw new _InvalidPackageConfigurationError.default({
packagePath: closestPackageToOrigin.rootPath,
reason:
"Attempted to redirect import to an absolute path. " +
'This is not allowed by the "browser" spec.' +
`\n From: ${originModulePath}` +
`\n Import: ${specifier}` +
`\n Attempted redirect: ${maybeRedirectedSpecifier}`,
});
}
const parsedSpecifier = parseBareSpecifier(redirectedSpecifier);
const parsedSpecifier = parseBareSpecifier(
maybeRedirectedSpecifier ?? specifier,
);
if (context.allowHaste) {

@@ -147,2 +167,43 @@ if (parsedSpecifier.isSinglePart) {

}
if (
context.unstable_enablePackageExports &&
closestPackageToOrigin != null &&
closestPackageToOrigin.packageJson.exports != null &&
closestPackageToOrigin.packageJson.name === parsedSpecifier.packageName
) {
try {
const exportsField = closestPackageToOrigin.packageJson.exports;
const packageExportsResult = (0,
_PackageExportsResolve.resolvePackageTargetFromExports)(
context,
closestPackageToOrigin.rootPath,
_path.default.join(
closestPackageToOrigin.rootPath,
parsedSpecifier.posixSubpath,
),
parsedSpecifier.posixSubpath === "."
? ""
: parsedSpecifier.posixSubpath.slice(2),
exportsField,
platform,
);
if (packageExportsResult != null) {
return packageExportsResult;
}
} catch (e) {
if (e instanceof _PackagePathNotExportedError.default) {
context.unstable_logWarning(
e.message +
" Falling back to hierarchical resolution for backwards compatibility.",
);
} else if (e instanceof _InvalidPackageConfigurationError.default) {
context.unstable_logWarning(
e.message +
" Falling back to hierarchical resolution for backwards compatibility.",
);
} else {
throw e;
}
}
}
const { disableHierarchicalLookup } = context;

@@ -149,0 +210,0 @@ if (!disableHierarchicalLookup) {

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