Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

metro-resolver

Package Overview
Dependencies
Maintainers
2
Versions
145
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.75.1 to 0.76.0

src/utils/isAssetFile.js

8

package.json
{
"name": "metro-resolver",
"version": "0.75.1",
"version": "0.76.0",
"description": "🚇 Implementation of Metro's resolution logic.",

@@ -14,10 +14,6 @@ "main": "src",

},
"dependencies": {
"absolute-path": "^0.0.0",
"invariant": "^2.2.4"
},
"license": "MIT",
"engines": {
"node": ">=14.17.0"
"node": ">=16"
}
}

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

var _resolveAsset = _interopRequireDefault(require("./resolveAsset"));
var _isAssetFile = _interopRequireDefault(require("./utils/isAssetFile"));
var _toPosixPath = _interopRequireDefault(require("./utils/toPosixPath"));

@@ -108,3 +109,3 @@ function _interopRequireDefault(obj) {

);
if (context.isAssetFile(filePath)) {
if ((0, _isAssetFile.default)(filePath, context.assetExts)) {
const assetResult = (0, _resolveAsset.default)(context, filePath);

@@ -129,5 +130,3 @@ if (assetResult != null) {

`"exports" of "${packagePath}, however no match was resolved for this` +
`request (platform = ${
platform !== null && platform !== void 0 ? platform : "null"
}).`
`request (platform = ${platform ?? "null"}).`
);

@@ -216,3 +215,2 @@ }

) {
var _context$unstable_con;
const conditionNames = new Set([

@@ -222,7 +220,3 @@ "default",

...(platform != null
? (_context$unstable_con =
context.unstable_conditionsByPlatform[platform]) !== null &&
_context$unstable_con !== void 0
? _context$unstable_con
: []
? context.unstable_conditionsByPlatform[platform] ?? []
: []),

@@ -229,0 +223,0 @@ ]);

@@ -14,3 +14,2 @@ /**

var _absolutePath = _interopRequireDefault(require("absolute-path"));
var _path = _interopRequireDefault(require("path"));

@@ -41,3 +40,3 @@ var _FailedToResolveNameError = _interopRequireDefault(

var _resolveAsset = _interopRequireDefault(require("./resolveAsset"));
var _invariant = _interopRequireDefault(require("invariant"));
var _isAssetFile = _interopRequireDefault(require("./utils/isAssetFile"));
function _interopRequireDefault(obj) {

@@ -62,4 +61,8 @@ return obj && obj.__esModule ? obj : { default: obj };

}
if (isRelativeImport(moduleName) || (0, _absolutePath.default)(moduleName)) {
return resolveModulePath(context, moduleName, platform);
if (isRelativeImport(moduleName) || _path.default.isAbsolute(moduleName)) {
const result = resolveModulePath(context, moduleName, platform);
if (result.type === "failed") {
throw new _FailedToResolvePathError.default(result.candidates);
}
return result.resolution;
}

@@ -77,3 +80,3 @@ const realModuleName = context.redirectModulePath(moduleName);

isRelativeImport(realModuleName) ||
(0, _absolutePath.default)(realModuleName);
_path.default.isAbsolute(realModuleName);
if (isDirectImport) {

@@ -88,3 +91,7 @@ // derive absolute path /.../node_modules/originModuleDir/realModuleName

const absPath = _path.default.join(originModuleDir, realModuleName);
return resolveModulePath(context, absPath, platform);
const result = resolveModulePath(context, absPath, platform);
if (result.type === "failed") {
throw new _FailedToResolvePathError.default(result.candidates);
}
return result.resolution;
}

@@ -134,3 +141,7 @@ if (context.allowHaste && !isDirectImport) {

const candidate = context.redirectModulePath(allDirPaths[i]);
// $FlowFixMe[incompatible-call]
if (candidate === false) {
return {
type: "empty",
};
}
const result = resolvePackage(context, candidate, platform);

@@ -152,3 +163,3 @@ if (result.type === "resolved") {

function resolveModulePath(context, toModuleName, platform) {
const modulePath = (0, _absolutePath.default)(toModuleName)
const modulePath = _path.default.isAbsolute(toModuleName)
? resolveWindowsPath(toModuleName)

@@ -161,11 +172,20 @@ : _path.default.join(

if (redirectedPath === false) {
return {
return resolvedAs({
type: "empty",
};
});
}
const result = resolvePackage(context, redirectedPath, platform);
if (result.type === "resolved") {
return result.resolution;
const dirPath = _path.default.dirname(redirectedPath);
const fileName = _path.default.basename(redirectedPath);
const fileResult = resolveFile(context, dirPath, fileName, platform);
if (fileResult.type === "resolved") {
return fileResult;
}
throw new _FailedToResolvePathError.default(result.candidates);
const dirResult = resolvePackageEntryPoint(context, redirectedPath, platform);
if (dirResult.type === "resolved") {
return dirResult;
}
return failedFor({
file: fileResult.candidates,
dir: dirResult.candidates,
});
}

@@ -198,3 +218,3 @@

const potentialModulePath = _path.default.join(packageDirPath, pathInModule);
const result = resolvePackage(context, potentialModulePath, platform);
const result = resolveModulePath(context, potentialModulePath, platform);
if (result.type === "resolved") {

@@ -229,6 +249,7 @@ return result;

/**
* In the NodeJS-style module resolution scheme we want to check potential
* paths both as directories and as files. For example, `/foo/bar` may resolve
* to `/foo/bar.js` (preferred), but it might also be `/foo/bar/index.js`, or
* even a package directory.
* Resolve a package entry point or subpath target.
*
* This should be used when resolving a bare import specifier prefixed with the
* package name. Use `resolveModulePath` instead to scope to legacy "browser"
* spec behaviour, which is also applicable to relative and absolute imports.
*/

@@ -244,10 +265,5 @@ function resolvePackage(

) {
(0, _invariant.default)(
_path.default.isAbsolute(modulePath),
"resolvePackage expects an absolute module path"
);
if (context.unstable_enablePackageExports) {
const pkg = context.getPackageForModule(modulePath);
const exportsField =
pkg === null || pkg === void 0 ? void 0 : pkg.packageJson.exports;
const exportsField = pkg?.packageJson.exports;
if (pkg != null && exportsField != null) {

@@ -286,16 +302,3 @@ try {

}
const dirPath = _path.default.dirname(modulePath);
const fileName = _path.default.basename(modulePath);
const fileResult = resolveFile(context, dirPath, fileName, platform);
if (fileResult.type === "resolved") {
return fileResult;
}
const dirResult = resolvePackageEntryPoint(context, modulePath, platform);
if (dirResult.type === "resolved") {
return dirResult;
}
return failedFor({
file: fileResult.candidates,
dir: dirResult.candidates,
});
return resolveModulePath(context, modulePath, platform);
}

@@ -315,3 +318,2 @@

function resolvePackageEntryPoint(context, packagePath, platform) {
var _context$getPackage;
const packageJsonPath = _path.default.join(packagePath, "package.json");

@@ -323,7 +325,3 @@ if (!context.doesFileExist(packageJsonPath)) {

rootPath: _path.default.dirname(packageJsonPath),
packageJson:
(_context$getPackage = context.getPackage(packageJsonPath)) !== null &&
_context$getPackage !== void 0
? _context$getPackage
: {},
packageJson: context.getPackage(packageJsonPath) ?? {},
};

@@ -367,3 +365,3 @@ const mainModulePath = _path.default.join(

function resolveFile(context, dirPath, fileName, platform) {
if (context.isAssetFile(fileName)) {
if ((0, _isAssetFile.default)(fileName, context.assetExts)) {
const assetResolutions = (0, _resolveAsset.default)(

@@ -370,0 +368,0 @@ context,

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc