Socket
Socket
Sign inDemoInstall

jest-resolve

Package Overview
Dependencies
Maintainers
6
Versions
274
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-resolve - npm Package Compare versions

Comparing version 29.1.2 to 29.2.0

49

build/defaultResolver.js

@@ -7,41 +7,28 @@ 'use strict';

exports.default = void 0;
function _path() {
const data = require('path');
_path = function () {
return data;
};
return data;
}
function _jestPnpResolver() {
const data = _interopRequireDefault(require('jest-pnp-resolver'));
_jestPnpResolver = function () {
return data;
};
return data;
}
function _resolve() {
const data = require('resolve');
_resolve = function () {
return data;
};
return data;
}
var _resolve2 = require('resolve.exports');
var _fileWalkers = require('./fileWalkers');
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
/**

@@ -53,2 +40,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

*/
const defaultResolver = (path, options) => {

@@ -60,3 +48,2 @@ // Yarn 2 adds support to `resolve` automatically so the pnpResolver is only

}
const resolveOptions = {

@@ -71,8 +58,8 @@ ...options,

const pathToResolve = getPathInModule(path, resolveOptions);
const result = (0, _resolve().sync)(pathToResolve, resolveOptions); // Dereference symlinks to ensure we don't create a separate
const result = (0, _resolve().sync)(pathToResolve, resolveOptions);
// Dereference symlinks to ensure we don't create a separate
// module instance depending on how it was referenced.
return (0, _fileWalkers.realpathSync)(result);
};
var _default = defaultResolver;

@@ -82,9 +69,6 @@ /*

*/
exports.default = _default;
function readPackageSync(_, file) {
return (0, _fileWalkers.readPackageCached)(file);
}
function getPathInModule(path, options) {

@@ -94,6 +78,4 @@ if (shouldIgnoreRequestForExports(path)) {

}
const segments = path.split('/');
let moduleName = segments.shift();
if (moduleName) {

@@ -103,11 +85,10 @@ // TODO: handle `#` here: https://github.com/facebook/jest/issues/12270

moduleName = `${moduleName}/${segments.shift()}`;
} // self-reference
}
// self-reference
const closestPackageJson = (0, _fileWalkers.findClosestPackageJson)(
options.basedir
);
if (closestPackageJson) {
const pkg = (0, _fileWalkers.readPackageCached)(closestPackageJson);
if (pkg.name === moduleName && pkg.exports) {

@@ -120,3 +101,2 @@ const subpath = segments.join('/') || '.';

);
if (!resolved) {

@@ -127,3 +107,2 @@ throw new Error(

}
return (0, _path().resolve)(

@@ -135,5 +114,3 @@ (0, _path().dirname)(closestPackageJson),

}
let packageJsonPath = '';
try {

@@ -147,6 +124,4 @@ packageJsonPath = (0, _resolve().sync)(

}
if (packageJsonPath && (0, _fileWalkers.isFile)(packageJsonPath)) {
const pkg = (0, _fileWalkers.readPackageCached)(packageJsonPath);
if (pkg.exports) {

@@ -159,3 +134,2 @@ const subpath = segments.join('/') || '.';

);
if (!resolved) {

@@ -166,3 +140,2 @@ throw new Error(

}
return (0, _path().resolve)(

@@ -175,6 +148,4 @@ (0, _path().dirname)(packageJsonPath),

}
return path;
}
function createResolveOptions(conditions) {

@@ -185,10 +156,12 @@ return conditions

unsafe: true
} // no conditions were passed - let's assume this is Jest internal and it should be `require`
: {
}
: // no conditions were passed - let's assume this is Jest internal and it should be `require`
{
browser: false,
require: true
};
} // if it's a relative import or an absolute path, exports are ignored
}
// if it's a relative import or an absolute path, exports are ignored
const shouldIgnoreRequestForExports = path =>
path.startsWith('.') || (0, _path().isAbsolute)(path);

@@ -12,33 +12,23 @@ 'use strict';

exports.realpathSync = realpathSync;
function _path() {
const data = require('path');
_path = function () {
return data;
};
return data;
}
function fs() {
const data = _interopRequireWildcard(require('graceful-fs'));
fs = function () {
return data;
};
return data;
}
function _jestUtil() {
const data = require('jest-util');
_jestUtil = function () {
return data;
};
return data;
}
function _getRequireWildcardCache(nodeInterop) {

@@ -52,3 +42,2 @@ if (typeof WeakMap !== 'function') return null;

}
function _interopRequireWildcard(obj, nodeInterop) {

@@ -86,3 +75,2 @@ if (!nodeInterop && obj && obj.__esModule) {

}
/**

@@ -94,2 +82,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

*/
function clearFsCache() {

@@ -100,5 +89,3 @@ checkedPaths.clear();

}
var IPathType;
(function (IPathType) {

@@ -109,14 +96,9 @@ IPathType[(IPathType['FILE'] = 1)] = 'FILE';

})(IPathType || (IPathType = {}));
const checkedPaths = new Map();
function statSyncCached(path) {
const result = checkedPaths.get(path);
if (result != null) {
return result;
}
let stat;
try {

@@ -132,3 +114,2 @@ // @ts-expect-error TS2554 - throwIfNoEntry is only available in recent version of node, but inclusion of the option is a backward compatible no-op.

}
if (stat) {

@@ -143,19 +124,13 @@ if (stat.isFile() || stat.isFIFO()) {

}
checkedPaths.set(path, IPathType.OTHER);
return IPathType.OTHER;
}
const checkedRealpathPaths = new Map();
function realpathCached(path) {
let result = checkedRealpathPaths.get(path);
if (result != null) {
return result;
}
result = (0, _jestUtil().tryRealpath)(path);
checkedRealpathPaths.set(path, result);
if (path !== result) {

@@ -165,40 +140,31 @@ // also cache the result in case it's ever referenced directly - no reason to `realpath` that as well

}
return result;
}
const packageContents = new Map();
function readPackageCached(path) {
let result = packageContents.get(path);
if (result != null) {
return result;
}
result = JSON.parse(fs().readFileSync(path, 'utf8'));
packageContents.set(path, result);
return result;
} // adapted from
}
// adapted from
// https://github.com/lukeed/escalade/blob/2477005062cdbd8407afc90d3f48f4930354252b/src/sync.js
// to use cached `fs` calls
function findClosestPackageJson(start) {
let dir = (0, _path().resolve)('.', start);
if (!isDirectory(dir)) {
dir = (0, _path().dirname)(dir);
}
while (true) {
const pkgJsonFile = (0, _path().resolve)(dir, './package.json');
const hasPackageJson = isFile(pkgJsonFile);
if (hasPackageJson) {
return pkgJsonFile;
}
const prevDir = dir;
dir = (0, _path().dirname)(dir);
if (prevDir === dir) {

@@ -209,16 +175,14 @@ return undefined;

}
/*
* helper functions
*/
function isFile(file) {
return statSyncCached(file) === IPathType.FILE;
}
function isDirectory(dir) {
return statSyncCached(dir) === IPathType.DIRECTORY;
}
function realpathSync(file) {
return realpathCached(file);
}

@@ -285,3 +285,3 @@ /**

rootDir,
testEnvironment,
testEnvironment: filePath,
requireResolveFunction,

@@ -288,0 +288,0 @@ }: {

@@ -8,7 +8,4 @@ 'use strict';

exports.default = void 0;
var _resolver = _interopRequireDefault(require('./resolver'));
var _utils = require('./utils');
Object.keys(_utils).forEach(function (key) {

@@ -25,7 +22,5 @@ if (key === 'default' || key === '__esModule') return;

});
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
/**

@@ -36,4 +31,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

* LICENSE file in the root directory of this source tree.
*/
var _default = _resolver.default;
*/ var _default = _resolver.default;
exports.default = _default;

@@ -7,17 +7,12 @@ 'use strict';

exports.default = isBuiltinModule;
function _module() {
const data = _interopRequireDefault(require('module'));
_module = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
/**

@@ -29,6 +24,6 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

*/
const BUILTIN_MODULES = new Set(_module().default.builtinModules);
function isBuiltinModule(module) {
return BUILTIN_MODULES.has(module);
}

@@ -7,27 +7,19 @@ 'use strict';

exports.default = void 0;
function path() {
const data = _interopRequireWildcard(require('path'));
path = function () {
return data;
};
return data;
}
function _slash() {
const data = _interopRequireDefault(require('slash'));
_slash = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
function _getRequireWildcardCache(nodeInterop) {

@@ -41,3 +33,2 @@ if (typeof WeakMap !== 'function') return null;

}
function _interopRequireWildcard(obj, nodeInterop) {

@@ -75,3 +66,2 @@ if (!nodeInterop && obj && obj.__esModule) {

}
/**

@@ -83,2 +73,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

*/
class ModuleNotFoundError extends Error {

@@ -91,3 +82,2 @@ code = 'MODULE_NOT_FOUND';

_originalMessage;
constructor(message, moduleName) {

@@ -98,3 +88,2 @@ super(message);

}
buildMessage(rootDir) {

@@ -104,5 +93,3 @@ if (!this._originalMessage) {

}
let message = this._originalMessage;
if (this.requireStack?.length && this.requireStack.length > 1) {

@@ -118,10 +105,7 @@ message += `

}
if (this.hint) {
message += this.hint;
}
this.message = message;
}
static duckType(error) {

@@ -132,3 +116,2 @@ error.buildMessage = ModuleNotFoundError.prototype.buildMessage;

}
exports.default = ModuleNotFoundError;

@@ -7,23 +7,16 @@ 'use strict';

exports.default = nodeModulesPaths;
function path() {
const data = _interopRequireWildcard(require('path'));
path = function () {
return data;
};
return data;
}
function _jestUtil() {
const data = require('jest-util');
_jestUtil = function () {
return data;
};
return data;
}
function _getRequireWildcardCache(nodeInterop) {

@@ -37,3 +30,2 @@ if (typeof WeakMap !== 'function') return null;

}
function _interopRequireWildcard(obj, nodeInterop) {

@@ -71,3 +63,2 @@ if (!nodeInterop && obj && obj.__esModule) {

}
/**

@@ -81,2 +72,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

*/
function nodeModulesPaths(basedir, options) {

@@ -86,8 +78,8 @@ const modules =

? Array.from(options.moduleDirectory)
: ['node_modules']; // ensure that `basedir` is an absolute path at this point,
: ['node_modules'];
// ensure that `basedir` is an absolute path at this point,
// resolving against the process' current working directory
const basedirAbs = path().resolve(basedir);
let prefix = '/';
if (/^([A-Za-z]:)/.test(basedirAbs)) {

@@ -97,7 +89,7 @@ prefix = '';

prefix = '\\\\';
} // The node resolution algorithm (as implemented by NodeJS and TypeScript)
}
// The node resolution algorithm (as implemented by NodeJS and TypeScript)
// traverses parents of the physical path, not the symlinked path
let physicalBasedir;
try {

@@ -109,6 +101,4 @@ physicalBasedir = (0, _jestUtil().tryRealpath)(basedirAbs);

}
const paths = [physicalBasedir];
let parsed = path().parse(physicalBasedir);
while (parsed.dir !== paths[paths.length - 1]) {

@@ -118,3 +108,2 @@ paths.push(parsed.dir);

}
const dirs = paths

@@ -121,0 +110,0 @@ .reduce(

@@ -7,61 +7,41 @@ 'use strict';

exports.default = void 0;
function path() {
const data = _interopRequireWildcard(require('path'));
path = function () {
return data;
};
return data;
}
function _chalk() {
const data = _interopRequireDefault(require('chalk'));
_chalk = function () {
return data;
};
return data;
}
function _slash() {
const data = _interopRequireDefault(require('slash'));
_slash = function () {
return data;
};
return data;
}
function _jestUtil() {
const data = require('jest-util');
_jestUtil = function () {
return data;
};
return data;
}
var _ModuleNotFoundError = _interopRequireDefault(
require('./ModuleNotFoundError')
);
var _defaultResolver = _interopRequireDefault(require('./defaultResolver'));
var _fileWalkers = require('./fileWalkers');
var _isBuiltinModule = _interopRequireDefault(require('./isBuiltinModule'));
var _nodeModulesPaths = _interopRequireDefault(require('./nodeModulesPaths'));
var _shouldLoadAsEsm = _interopRequireWildcard(require('./shouldLoadAsEsm'));
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
function _getRequireWildcardCache(nodeInterop) {

@@ -75,3 +55,2 @@ if (typeof WeakMap !== 'function') return null;

}
function _interopRequireWildcard(obj, nodeInterop) {

@@ -109,3 +88,2 @@ if (!nodeInterop && obj && obj.__esModule) {

}
/**

@@ -119,4 +97,6 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

/* eslint-disable local/prefer-spread-eventually */
const NATIVE_PLATFORM = 'native'; // We might be inside a symlink.
const NATIVE_PLATFORM = 'native';
// We might be inside a symlink.
const resolvedCwd = (0, _jestUtil().tryRealpath)(process.cwd());

@@ -126,6 +106,6 @@ const {NODE_PATH} = process.env;

? NODE_PATH.split(path().delimiter)
.filter(Boolean) // The resolver expects absolute paths.
.filter(Boolean)
// The resolver expects absolute paths.
.map(p => path().resolve(resolvedCwd, p))
: undefined;
class Resolver {

@@ -138,3 +118,2 @@ _options;

_supportsNativePlatform;
constructor(moduleMap, options) {

@@ -161,5 +140,3 @@ this._options = {

}
static ModuleNotFoundError = _ModuleNotFoundError.default;
static tryCastModuleNotFoundError(error) {

@@ -169,12 +146,8 @@ if (error instanceof _ModuleNotFoundError.default) {

}
const casted = error;
if (casted.code === 'MODULE_NOT_FOUND') {
return _ModuleNotFoundError.default.duckType(casted);
}
return null;
}
static clearDefaultResolverCache() {

@@ -184,7 +157,5 @@ (0, _fileWalkers.clearFsCache)();

}
static findNodeModule(path, options) {
const resolverModule = loadResolver(options.resolver);
let resolver = _defaultResolver.default;
if (typeof resolverModule === 'function') {

@@ -195,5 +166,3 @@ resolver = resolverModule;

}
const paths = options.paths;
try {

@@ -214,10 +183,7 @@ return resolver(path, {

}
return null;
}
static async findNodeModuleAsync(path, options) {
const resolverModule = loadResolver(options.resolver);
let resolver = _defaultResolver.default;
if (typeof resolverModule === 'function') {

@@ -230,12 +196,8 @@ resolver = resolverModule;

const asyncOrSync = resolverModule.async || resolverModule.sync;
if (asyncOrSync == null) {
throw new Error(`Unable to load resolver at ${options.resolver}`);
}
resolver = asyncOrSync;
}
const paths = options.paths;
try {

@@ -257,28 +219,27 @@ const result = await resolver(path, {

}
return null;
} // unstable as it should be replaced by https://github.com/nodejs/modules/issues/393, and we don't want people to use it
}
// unstable as it should be replaced by https://github.com/nodejs/modules/issues/393, and we don't want people to use it
static unstable_shouldLoadAsEsm = _shouldLoadAsEsm.default;
resolveModuleFromDirIfExists(dirname, moduleName, options) {
const {extensions, key, moduleDirectory, paths, skipResolution} =
this._prepareForResolution(dirname, moduleName, options);
let module;
let module; // 1. If we have already resolved this module for this directory name,
// 1. If we have already resolved this module for this directory name,
// return a value from the cache.
const cacheResult = this._moduleNameCache.get(key);
if (cacheResult) {
return cacheResult;
} // 2. Check if the module is a haste module.
}
// 2. Check if the module is a haste module.
module = this.getModule(moduleName);
if (module) {
this._moduleNameCache.set(key, module);
return module;
}
return module;
} // 3. Check if the module is a node module and resolve it based on
// 3. Check if the module is a node module and resolve it based on
// the node module resolution algorithm. If skipNodeResolution is given we

@@ -289,3 +250,2 @@ // ignore all modules that look like node modules (ie. are not relative

// exist and aren't mocked.
const resolveNodeModule = (name, throwIfNotFound = false) => {

@@ -296,3 +256,2 @@ // Only skip default resolver

}
return Resolver.findNodeModule(name, {

@@ -309,17 +268,14 @@ basedir: dirname,

};
if (!skipResolution) {
module = resolveNodeModule(moduleName, Boolean(process.versions.pnp));
if (module) {
this._moduleNameCache.set(key, module);
return module;
}
} // 4. Resolve "haste packages" which are `package.json` files outside of
}
// 4. Resolve "haste packages" which are `package.json` files outside of
// `node_modules` folders anywhere in the file system.
try {
const hasteModulePath = this._getHasteModulePath(moduleName);
if (hasteModulePath) {

@@ -331,32 +287,28 @@ // try resolving with custom resolver first to support extensions,

require.resolve(hasteModulePath);
this._moduleNameCache.set(key, resolvedModule);
return resolvedModule;
}
} catch {}
return null;
}
async resolveModuleFromDirIfExistsAsync(dirname, moduleName, options) {
const {extensions, key, moduleDirectory, paths, skipResolution} =
this._prepareForResolution(dirname, moduleName, options);
let module;
let module; // 1. If we have already resolved this module for this directory name,
// 1. If we have already resolved this module for this directory name,
// return a value from the cache.
const cacheResult = this._moduleNameCache.get(key);
if (cacheResult) {
return cacheResult;
} // 2. Check if the module is a haste module.
}
// 2. Check if the module is a haste module.
module = this.getModule(moduleName);
if (module) {
this._moduleNameCache.set(key, module);
return module;
}
return module;
} // 3. Check if the module is a node module and resolve it based on
// 3. Check if the module is a node module and resolve it based on
// the node module resolution algorithm. If skipNodeResolution is given we

@@ -367,3 +319,2 @@ // ignore all modules that look like node modules (ie. are not relative

// exist and aren't mocked.
const resolveNodeModule = async (name, throwIfNotFound = false) => {

@@ -374,4 +325,3 @@ // Only skip default resolver

}
return await Resolver.findNodeModuleAsync(name, {
return Resolver.findNodeModuleAsync(name, {
basedir: dirname,

@@ -387,3 +337,2 @@ conditions: options?.conditions,

};
if (!skipResolution) {

@@ -394,14 +343,12 @@ module = await resolveNodeModule(

);
if (module) {
this._moduleNameCache.set(key, module);
return module;
}
} // 4. Resolve "haste packages" which are `package.json` files outside of
}
// 4. Resolve "haste packages" which are `package.json` files outside of
// `node_modules` folders anywhere in the file system.
try {
const hasteModulePath = this._getHasteModulePath(moduleName);
if (hasteModulePath) {

@@ -411,14 +358,11 @@ // try resolving with custom resolver first to support extensions,

const resolvedModule =
(await resolveNodeModule(hasteModulePath)) || // QUESTION: should this be async?
(await resolveNodeModule(hasteModulePath)) ||
// QUESTION: should this be async?
require.resolve(hasteModulePath);
this._moduleNameCache.set(key, resolvedModule);
return resolvedModule;
}
} catch {}
return null;
}
resolveModule(from, moduleName, options) {

@@ -429,9 +373,9 @@ const dirname = path().dirname(from);

this.resolveModuleFromDirIfExists(dirname, moduleName, options);
if (module) return module; // 5. Throw an error if the module could not be found. `resolve.sync` only
if (module) return module;
// 5. Throw an error if the module could not be found. `resolve.sync` only
// produces an error based on the dirname but we have the actual current
// module name available.
this._throwModNotFoundError(from, moduleName);
}
async resolveModuleAsync(from, moduleName, options) {

@@ -446,8 +390,10 @@ const dirname = path().dirname(from);

));
if (module) return module; // 5. Throw an error if the module could not be found. `resolve` only
if (module) return module;
// 5. Throw an error if the module could not be found. `resolve` only
// produces an error based on the dirname but we have the actual current
// module name available.
this._throwModNotFoundError(from, moduleName);
}
/**

@@ -457,3 +403,2 @@ * _prepareForResolution is shared between the sync and async module resolution

*/
_prepareForResolution(dirname, moduleName, options) {

@@ -465,5 +410,3 @@ const paths = options?.paths || this._options.modulePaths;

const defaultPlatform = this._options.defaultPlatform;
const extensions = this._options.extensions.slice();
if (this._supportsNativePlatform) {

@@ -474,3 +417,2 @@ extensions.unshift(

}
if (defaultPlatform) {

@@ -481,3 +423,2 @@ extensions.unshift(

}
const skipResolution =

@@ -493,10 +434,9 @@ options && options.skipNodeResolution && !moduleName.includes(path().sep);

}
/**
* _getHasteModulePath attempts to return the path to a haste module.
*/
_getHasteModulePath(moduleName) {
const parts = moduleName.split('/');
const hastePackage = this.getPackage(parts.shift());
if (hastePackage) {

@@ -508,6 +448,4 @@ return path().join.apply(

}
return null;
}
_throwModNotFoundError(from, moduleName) {

@@ -522,3 +460,2 @@ const relativePath =

}
_getMapModuleName(matches) {

@@ -533,13 +470,9 @@ return matches

}
_isAliasModule(moduleName) {
const moduleNameMapper = this._options.moduleNameMapper;
if (!moduleNameMapper) {
return false;
}
return moduleNameMapper.some(({regex}) => regex.test(moduleName));
}
isCoreModule(moduleName) {

@@ -554,3 +487,2 @@ return (

}
getModule(name) {

@@ -563,3 +495,2 @@ return this._moduleMap.getModule(

}
getModulePath(from, moduleName) {

@@ -569,6 +500,4 @@ if (moduleName[0] !== '.' || path().isAbsolute(moduleName)) {

}
return path().normalize(`${path().dirname(from)}/${moduleName}`);
}
getPackage(name) {

@@ -581,6 +510,4 @@ return this._moduleMap.getPackage(

}
getMockModule(from, name) {
const mock = this._moduleMap.getMockModule(name);
if (mock) {

@@ -590,3 +517,2 @@ return mock;

const moduleName = this.resolveStubModuleName(from, name);
if (moduleName) {

@@ -596,9 +522,6 @@ return this.getModule(moduleName) || moduleName;

}
return null;
}
async getMockModuleAsync(from, name) {
const mock = this._moduleMap.getMockModule(name);
if (mock) {

@@ -608,3 +531,2 @@ return mock;

const moduleName = await this.resolveStubModuleNameAsync(from, name);
if (moduleName) {

@@ -614,13 +536,9 @@ return this.getModule(moduleName) || moduleName;

}
return null;
}
getModulePaths(from) {
const cachedModule = this._modulePathCache.get(from);
if (cachedModule) {
return cachedModule;
}
const moduleDirectory = this._options.moduleDirectories;

@@ -630,3 +548,2 @@ const paths = (0, _nodeModulesPaths.default)(from, {

});
if (paths[paths.length - 1] === undefined) {

@@ -636,20 +553,13 @@ // circumvent node-resolve bug that adds `undefined` as last item.

}
this._modulePathCache.set(from, paths);
return paths;
}
getModuleID(virtualMocks, from, moduleName = '', options) {
const stringifiedOptions = options ? JSON.stringify(options) : '';
const key = from + path().delimiter + moduleName + stringifiedOptions;
const cachedModuleID = this._moduleIDCache.get(key);
if (cachedModuleID) {
return cachedModuleID;
}
const moduleType = this._getModuleType(moduleName);
const absolutePath = this._getAbsolutePath(

@@ -661,5 +571,3 @@ virtualMocks,

);
const mockPath = this._getMockPath(from, moduleName);
const sep = path().delimiter;

@@ -672,24 +580,16 @@ const id =

(stringifiedOptions ? stringifiedOptions + sep : '');
this._moduleIDCache.set(key, id);
return id;
}
async getModuleIDAsync(virtualMocks, from, moduleName = '', options) {
const stringifiedOptions = options ? JSON.stringify(options) : '';
const key = from + path().delimiter + moduleName + stringifiedOptions;
const cachedModuleID = this._moduleIDCache.get(key);
if (cachedModuleID) {
return cachedModuleID;
}
if (moduleName.startsWith('data:')) {
return moduleName;
}
const moduleType = this._getModuleType(moduleName);
const absolutePath = await this._getAbsolutePathAsync(

@@ -709,12 +609,8 @@ virtualMocks,

(stringifiedOptions ? stringifiedOptions + sep : '');
this._moduleIDCache.set(key, id);
return id;
}
_getModuleType(moduleName) {
return this.isCoreModule(moduleName) ? 'node' : 'user';
}
_getAbsolutePath(virtualMocks, from, moduleName, options) {

@@ -724,7 +620,5 @@ if (this.isCoreModule(moduleName)) {

}
if (moduleName.startsWith('data:')) {
return moduleName;
}
return this._isModuleResolved(from, moduleName)

@@ -734,3 +628,2 @@ ? this.getModule(moduleName)

}
async _getAbsolutePathAsync(virtualMocks, from, moduleName, options) {

@@ -740,7 +633,5 @@ if (this.isCoreModule(moduleName)) {

}
if (moduleName.startsWith('data:')) {
return moduleName;
}
const isModuleResolved = await this._isModuleResolvedAsync(

@@ -752,10 +643,4 @@ from,

? this.getModule(moduleName)
: await this._getVirtualMockPathAsync(
virtualMocks,
from,
moduleName,
options
);
: this._getVirtualMockPathAsync(virtualMocks, from, moduleName, options);
}
_getMockPath(from, moduleName) {

@@ -766,9 +651,7 @@ return !this.isCoreModule(moduleName)

}
async _getMockPathAsync(from, moduleName) {
return !this.isCoreModule(moduleName)
? await this.getMockModuleAsync(from, moduleName)
? this.getMockModuleAsync(from, moduleName)
: null;
}
_getVirtualMockPath(virtualMocks, from, moduleName, options) {

@@ -782,3 +665,2 @@ const virtualMockPath = this.getModulePath(from, moduleName);

}
async _getVirtualMockPathAsync(virtualMocks, from, moduleName, options) {

@@ -789,6 +671,5 @@ const virtualMockPath = this.getModulePath(from, moduleName);

: moduleName
? await this.resolveModuleAsync(from, moduleName, options)
? this.resolveModuleAsync(from, moduleName, options)
: from;
}
_isModuleResolved(from, moduleName) {

@@ -799,3 +680,2 @@ return !!(

}
async _isModuleResolvedAsync(from, moduleName) {

@@ -807,6 +687,4 @@ return !!(

}
resolveStubModuleName(from, moduleName) {
const dirname = path().dirname(from);
const {extensions, moduleDirectory, paths} = this._prepareForResolution(

@@ -816,6 +694,4 @@ dirname,

);
const moduleNameMapper = this._options.moduleNameMapper;
const resolver = this._options.resolver;
if (moduleNameMapper) {

@@ -827,5 +703,3 @@ for (const {moduleName: mappedModuleName, regex} of moduleNameMapper) {

const matches = moduleName.match(regex);
const mapModuleName = this._getMapModuleName(matches);
const possibleModuleNames = Array.isArray(mappedModuleName)

@@ -835,3 +709,2 @@ ? mappedModuleName

let module = null;
for (const possibleModuleName of possibleModuleNames) {

@@ -849,3 +722,2 @@ const updatedName = mapModuleName(possibleModuleName);

});
if (module) {

@@ -855,3 +727,2 @@ break;

}
if (!module) {

@@ -866,3 +737,2 @@ throw createNoMappedModuleFoundError(

}
return module;

@@ -872,9 +742,6 @@ }

}
return null;
}
async resolveStubModuleNameAsync(from, moduleName) {
const dirname = path().dirname(from);
const {extensions, moduleDirectory, paths} = this._prepareForResolution(

@@ -884,6 +751,4 @@ dirname,

);
const moduleNameMapper = this._options.moduleNameMapper;
const resolver = this._options.resolver;
if (moduleNameMapper) {

@@ -895,5 +760,3 @@ for (const {moduleName: mappedModuleName, regex} of moduleNameMapper) {

const matches = moduleName.match(regex);
const mapModuleName = this._getMapModuleName(matches);
const possibleModuleNames = Array.isArray(mappedModuleName)

@@ -903,3 +766,2 @@ ? mappedModuleName

let module = null;
for (const possibleModuleName of possibleModuleNames) {

@@ -917,3 +779,2 @@ const updatedName = mapModuleName(possibleModuleName);

}));
if (module) {

@@ -923,3 +784,2 @@ break;

}
if (!module) {

@@ -934,3 +794,2 @@ throw createNoMappedModuleFoundError(

}
return module;

@@ -940,9 +799,6 @@ }

}
return null;
}
}
exports.default = Resolver;
const createNoMappedModuleFoundError = (

@@ -981,3 +837,2 @@ moduleName,

};
function loadResolver(resolver) {

@@ -987,13 +842,9 @@ if (resolver == null) {

}
const loadedResolver = require(resolver);
if (loadedResolver == null) {
throw new Error(`Resolver located at ${resolver} does not export anything`);
}
if (typeof loadedResolver === 'function') {
return loadedResolver;
}
if (

@@ -1005,3 +856,2 @@ typeof loadedResolver === 'object' &&

}
throw new Error(

@@ -1008,0 +858,0 @@ `Resolver located at ${resolver} does not export a function or an object with "sync" and "async" props`

@@ -8,25 +8,17 @@ 'use strict';

exports.default = cachedShouldLoadAsEsm;
function _path() {
const data = require('path');
_path = function () {
return data;
};
return data;
}
function _vm() {
const data = require('vm');
_vm = function () {
return data;
};
return data;
}
var _fileWalkers = require('./fileWalkers');
/**

@@ -38,3 +30,5 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

*/
// @ts-expect-error: experimental, not added to the types
const runtimeSupportsVmModules = typeof _vm().SyntheticModule === 'function';

@@ -44,3 +38,2 @@ const cachedFileLookups = new Map();

const cachedChecks = new Map();
function clearCachedLookups() {

@@ -51,3 +44,2 @@ cachedFileLookups.clear();

}
function cachedShouldLoadAsEsm(path, extensionsToTreatAsEsm) {

@@ -57,5 +49,3 @@ if (!runtimeSupportsVmModules) {

}
let cachedLookup = cachedFileLookups.get(path);
if (cachedLookup === undefined) {

@@ -65,24 +55,19 @@ cachedLookup = shouldLoadAsEsm(path, extensionsToTreatAsEsm);

}
return cachedLookup;
} // this is a bad version of what https://github.com/nodejs/modules/issues/393 would provide
}
// this is a bad version of what https://github.com/nodejs/modules/issues/393 would provide
function shouldLoadAsEsm(path, extensionsToTreatAsEsm) {
const extension = (0, _path().extname)(path);
if (extension === '.mjs') {
return true;
}
if (extension === '.cjs') {
return false;
}
if (extension !== '.js') {
return extensionsToTreatAsEsm.includes(extension);
}
const cwd = (0, _path().dirname)(path);
let cachedLookup = cachedDirLookups.get(cwd);
if (cachedLookup === undefined) {

@@ -92,19 +77,13 @@ cachedLookup = cachedPkgCheck(cwd);

}
return cachedLookup;
}
function cachedPkgCheck(cwd) {
const pkgPath = (0, _fileWalkers.findClosestPackageJson)(cwd);
if (!pkgPath) {
return false;
}
let hasModuleField = cachedChecks.get(pkgPath);
if (hasModuleField != null) {
return hasModuleField;
}
try {

@@ -116,5 +95,4 @@ const pkg = (0, _fileWalkers.readPackageCached)(pkgPath);

}
cachedChecks.set(pkgPath, hasModuleField);
return hasModuleField;
}

@@ -11,39 +11,27 @@ 'use strict';

void 0;
function path() {
const data = _interopRequireWildcard(require('path'));
path = function () {
return data;
};
return data;
}
function _chalk() {
const data = _interopRequireDefault(require('chalk'));
_chalk = function () {
return data;
};
return data;
}
function _jestValidate() {
const data = require('jest-validate');
_jestValidate = function () {
return data;
};
return data;
}
var _resolver = _interopRequireDefault(require('./resolver'));
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
function _getRequireWildcardCache(nodeInterop) {

@@ -57,3 +45,2 @@ if (typeof WeakMap !== 'function') return null;

}
function _interopRequireWildcard(obj, nodeInterop) {

@@ -91,3 +78,2 @@ if (!nodeInterop && obj && obj.__esModule) {

}
/**

@@ -99,4 +85,4 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

*/
const BULLET = _chalk().default.bold('\u25cf ');
const DOCUMENTATION_NOTE = ` ${_chalk().default.bold(

@@ -107,3 +93,2 @@ 'Configuration Documentation:'

`;
const createValidationError = message =>

@@ -115,3 +100,2 @@ new (_jestValidate().ValidationError)(

);
const replaceRootDirInPath = (rootDir, filePath) => {

@@ -121,3 +105,2 @@ if (!/^<rootDir>/.test(filePath)) {

}
return path().resolve(

@@ -128,3 +111,2 @@ rootDir,

};
const resolveWithPrefix = (

@@ -142,3 +124,2 @@ resolver,

const fileName = replaceRootDirInPath(rootDir, filePath);
let module = _resolver.default.findNodeModule(`${prefix}${fileName}`, {

@@ -148,11 +129,8 @@ basedir: rootDir,

});
if (module) {
return module;
}
try {
return requireResolveFunction(`${prefix}${fileName}`);
} catch {}
module = _resolver.default.findNodeModule(fileName, {

@@ -162,11 +140,8 @@ basedir: rootDir,

});
if (module) {
return module;
}
try {
return requireResolveFunction(fileName);
} catch {}
throw createValidationError(

@@ -180,2 +155,3 @@ ` ${humanOptionName} ${_chalk().default.bold(

};
/**

@@ -189,3 +165,2 @@ * Finds the test environment to use:

*/
const resolveTestEnvironment = ({

@@ -200,3 +175,2 @@ rootDir,

}
try {

@@ -216,6 +190,6 @@ return resolveWithPrefix(undefined, {

}
throw error;
}
};
/**

@@ -229,5 +203,3 @@ * Finds the watch plugins to use:

*/
exports.resolveTestEnvironment = resolveTestEnvironment;
const resolveWatchPlugin = (

@@ -245,2 +217,3 @@ resolver,

});
/**

@@ -254,5 +227,3 @@ * Finds the runner to use:

*/
exports.resolveWatchPlugin = resolveWatchPlugin;
const resolveRunner = (resolver, {filePath, rootDir, requireResolveFunction}) =>

@@ -267,5 +238,3 @@ resolveWithPrefix(resolver, {

});
exports.resolveRunner = resolveRunner;
const resolveSequencer = (

@@ -283,3 +252,2 @@ resolver,

});
exports.resolveSequencer = resolveSequencer;
{
"name": "jest-resolve",
"version": "29.1.2",
"version": "29.2.0",
"repository": {

@@ -22,6 +22,6 @@ "type": "git",

"graceful-fs": "^4.2.9",
"jest-haste-map": "^29.1.2",
"jest-haste-map": "^29.2.0",
"jest-pnp-resolver": "^1.2.2",
"jest-util": "^29.1.2",
"jest-validate": "^29.1.2",
"jest-util": "^29.2.0",
"jest-validate": "^29.2.0",
"resolve": "^1.20.0",

@@ -44,3 +44,3 @@ "resolve.exports": "^1.1.0",

},
"gitHead": "3c31dd619e8c022cde53f40fa12ea2a67f4752ce"
"gitHead": "ee5b37a4f4433afcfffb0356cea47739d8092287"
}
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