diff options
author | Joel Kronqvist <joel.h.kronqvist@gmail.com> | 2022-03-05 19:02:27 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.h.kronqvist@gmail.com> | 2022-03-05 19:02:27 +0200 |
commit | 5d309ff52cd399a6b71968a6b9a70c8ac0b98981 (patch) | |
tree | 360f7eb50f956e2367ef38fa1fc6ac7ac5258042 /node_modules/jest-resolve/build | |
parent | b500a50f1b97d93c98b36ed9a980f8188d648147 (diff) | |
download | LYLLRuoka-5d309ff52cd399a6b71968a6b9a70c8ac0b98981.tar.gz LYLLRuoka-5d309ff52cd399a6b71968a6b9a70c8ac0b98981.zip |
Added node_modules for the updating to work properly.
Diffstat (limited to 'node_modules/jest-resolve/build')
20 files changed, 1894 insertions, 0 deletions
diff --git a/node_modules/jest-resolve/build/ModuleNotFoundError.d.ts b/node_modules/jest-resolve/build/ModuleNotFoundError.d.ts new file mode 100644 index 0000000..711983a --- /dev/null +++ b/node_modules/jest-resolve/build/ModuleNotFoundError.d.ts @@ -0,0 +1,18 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +import type { Config } from '@jest/types'; +export default class ModuleNotFoundError extends Error { + code: string; + hint?: string; + requireStack?: Array<Config.Path>; + siblingWithSimilarExtensionFound?: boolean; + moduleName?: string; + private _originalMessage?; + constructor(message: string, moduleName?: string); + buildMessage(rootDir: Config.Path): void; + static duckType(error: ModuleNotFoundError): ModuleNotFoundError; +} diff --git a/node_modules/jest-resolve/build/ModuleNotFoundError.js b/node_modules/jest-resolve/build/ModuleNotFoundError.js new file mode 100644 index 0000000..25aafca --- /dev/null +++ b/node_modules/jest-resolve/build/ModuleNotFoundError.js @@ -0,0 +1,146 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +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) { + if (typeof WeakMap !== 'function') return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function (nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); +} + +function _interopRequireWildcard(obj, nodeInterop) { + if (!nodeInterop && obj && obj.__esModule) { + return obj; + } + if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) { + return {default: obj}; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = {}; + var hasPropertyDescriptor = + Object.defineProperty && Object.getOwnPropertyDescriptor; + for (var key in obj) { + if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor + ? Object.getOwnPropertyDescriptor(obj, key) + : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; +} + +class ModuleNotFoundError extends Error { + constructor(message, moduleName) { + super(message); + + _defineProperty(this, 'code', 'MODULE_NOT_FOUND'); + + _defineProperty(this, 'hint', void 0); + + _defineProperty(this, 'requireStack', void 0); + + _defineProperty(this, 'siblingWithSimilarExtensionFound', void 0); + + _defineProperty(this, 'moduleName', void 0); + + _defineProperty(this, '_originalMessage', void 0); + + this._originalMessage = message; + this.moduleName = moduleName; + } + + buildMessage(rootDir) { + var _this$requireStack; + + if (!this._originalMessage) { + this._originalMessage = this.message || ''; + } + + let message = this._originalMessage; + + if ( + (_this$requireStack = this.requireStack) !== null && + _this$requireStack !== void 0 && + _this$requireStack.length && + this.requireStack.length > 1 + ) { + message += ` + +Require stack: + ${this.requireStack + .map(p => p.replace(`${rootDir}${path().sep}`, '')) + .map(_slash().default) + .join('\n ')} +`; + } + + if (this.hint) { + message += this.hint; + } + + this.message = message; + } + + static duckType(error) { + error.buildMessage = ModuleNotFoundError.prototype.buildMessage; + return error; + } +} + +exports.default = ModuleNotFoundError; diff --git a/node_modules/jest-resolve/build/defaultResolver.d.ts b/node_modules/jest-resolve/build/defaultResolver.d.ts new file mode 100644 index 0000000..c50f748 --- /dev/null +++ b/node_modules/jest-resolve/build/defaultResolver.d.ts @@ -0,0 +1,29 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +import type { Config } from '@jest/types'; +import { PkgJson } from './fileWalkers'; +interface ResolverOptions { + basedir: Config.Path; + browser?: boolean; + conditions?: Array<string>; + defaultResolver: typeof defaultResolver; + extensions?: Array<string>; + moduleDirectory?: Array<string>; + paths?: Array<Config.Path>; + rootDir?: Config.Path; + packageFilter?: (pkg: PkgJson, dir: string) => PkgJson; + pathFilter?: (pkg: PkgJson, path: string, relativePath: string) => string; +} +declare global { + namespace NodeJS { + interface ProcessVersions { + pnp?: any; + } + } +} +export default function defaultResolver(path: Config.Path, options: ResolverOptions): Config.Path; +export {}; diff --git a/node_modules/jest-resolve/build/defaultResolver.js b/node_modules/jest-resolve/build/defaultResolver.js new file mode 100644 index 0000000..6b26f66 --- /dev/null +++ b/node_modules/jest-resolve/build/defaultResolver.js @@ -0,0 +1,123 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +exports.default = defaultResolver; + +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}; +} + +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +function defaultResolver(path, options) { + // Yarn 2 adds support to `resolve` automatically so the pnpResolver is only + // needed for Yarn 1 which implements version 1 of the pnp spec + if (process.versions.pnp === '1') { + return (0, _jestPnpResolver().default)(path, options); + } + + const result = (0, _resolve().sync)(path, { + ...options, + isDirectory: _fileWalkers.isDirectory, + isFile: _fileWalkers.isFile, + packageFilter: createPackageFilter( + options.conditions, + options.packageFilter + ), + preserveSymlinks: false, + readPackageSync, + realpathSync: _fileWalkers.realpathSync + }); // Dereference symlinks to ensure we don't create a separate + // module instance depending on how it was referenced. + + return (0, _fileWalkers.realpathSync)(result); +} +/* + * helper functions + */ + +function readPackageSync(_, file) { + return (0, _fileWalkers.readPackageCached)(file); +} + +function createPackageFilter(conditions, userFilter) { + function attemptExportsFallback(pkg) { + const options = conditions + ? { + conditions, + unsafe: true + } // no conditions were passed - let's assume this is Jest internal and it should be `require` + : { + browser: false, + require: true + }; + + try { + return (0, _resolve2.resolve)(pkg, '.', options); + } catch { + return undefined; + } + } + + return function packageFilter(pkg, packageDir) { + let filteredPkg = pkg; + + if (userFilter) { + filteredPkg = userFilter(filteredPkg, packageDir); + } + + if (filteredPkg.main != null) { + return filteredPkg; + } + + const indexInRoot = (0, _path().resolve)(packageDir, './index.js'); // if the module contains an `index.js` file in root, `resolve` will request + // that if there is no `main`. Since we don't wanna break that, add this + // check + + if ((0, _fileWalkers.isFile)(indexInRoot)) { + return filteredPkg; + } + + return {...filteredPkg, main: attemptExportsFallback(filteredPkg)}; + }; +} diff --git a/node_modules/jest-resolve/build/fileWalkers.d.ts b/node_modules/jest-resolve/build/fileWalkers.d.ts new file mode 100644 index 0000000..05cf7c7 --- /dev/null +++ b/node_modules/jest-resolve/build/fileWalkers.d.ts @@ -0,0 +1,14 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +import type { Config } from '@jest/types'; +export declare function clearFsCache(): void; +export declare type PkgJson = Record<string, unknown>; +export declare function readPackageCached(path: Config.Path): PkgJson; +export declare function findClosestPackageJson(start: Config.Path): Config.Path | undefined; +export declare function isFile(file: Config.Path): boolean; +export declare function isDirectory(dir: Config.Path): boolean; +export declare function realpathSync(file: Config.Path): Config.Path; diff --git a/node_modules/jest-resolve/build/fileWalkers.js b/node_modules/jest-resolve/build/fileWalkers.js new file mode 100644 index 0000000..d621fcf --- /dev/null +++ b/node_modules/jest-resolve/build/fileWalkers.js @@ -0,0 +1,214 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +exports.clearFsCache = clearFsCache; +exports.findClosestPackageJson = findClosestPackageJson; +exports.isDirectory = isDirectory; +exports.isFile = isFile; +exports.readPackageCached = readPackageCached; +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) { + if (typeof WeakMap !== 'function') return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function (nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); +} + +function _interopRequireWildcard(obj, nodeInterop) { + if (!nodeInterop && obj && obj.__esModule) { + return obj; + } + if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) { + return {default: obj}; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = {}; + var hasPropertyDescriptor = + Object.defineProperty && Object.getOwnPropertyDescriptor; + for (var key in obj) { + if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor + ? Object.getOwnPropertyDescriptor(obj, key) + : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; +} + +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +function clearFsCache() { + checkedPaths.clear(); + checkedRealpathPaths.clear(); + packageContents.clear(); +} + +var IPathType; + +(function (IPathType) { + IPathType[(IPathType['FILE'] = 1)] = 'FILE'; + IPathType[(IPathType['DIRECTORY'] = 2)] = 'DIRECTORY'; + IPathType[(IPathType['OTHER'] = 3)] = 'OTHER'; +})(IPathType || (IPathType = {})); + +const checkedPaths = new Map(); + +function statSyncCached(path) { + const result = checkedPaths.get(path); + + if (result != null) { + return result; + } + + let stat; + + try { + // @ts-expect-error TS2554 - throwIfNoEntry is only available in recent version of node, but inclusion of the option is a backward compatible no-op. + stat = fs().statSync(path, { + throwIfNoEntry: false + }); + } catch (e) { + if (!(e && (e.code === 'ENOENT' || e.code === 'ENOTDIR'))) { + throw e; + } + } + + if (stat) { + if (stat.isFile() || stat.isFIFO()) { + checkedPaths.set(path, IPathType.FILE); + return IPathType.FILE; + } else if (stat.isDirectory()) { + checkedPaths.set(path, IPathType.DIRECTORY); + return IPathType.DIRECTORY; + } + } + + 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) { + // also cache the result in case it's ever referenced directly - no reason to `realpath` that as well + checkedRealpathPaths.set(result, result); + } + + 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 +// 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) { + 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); +} diff --git a/node_modules/jest-resolve/build/index.d.ts b/node_modules/jest-resolve/build/index.d.ts new file mode 100644 index 0000000..ca23fec --- /dev/null +++ b/node_modules/jest-resolve/build/index.d.ts @@ -0,0 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +import Resolver from './resolver'; +export type { ResolveModuleConfig } from './resolver'; +export * from './utils'; +export default Resolver; diff --git a/node_modules/jest-resolve/build/index.js b/node_modules/jest-resolve/build/index.js new file mode 100644 index 0000000..837877b --- /dev/null +++ b/node_modules/jest-resolve/build/index.js @@ -0,0 +1,36 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +var _exportNames = {}; +exports.default = void 0; + +var _resolver = _interopRequireDefault(require('./resolver')); + +var _utils = require('./utils'); + +Object.keys(_utils).forEach(function (key) { + if (key === 'default' || key === '__esModule') return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _utils[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _utils[key]; + } + }); +}); + +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : {default: obj}; +} + +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +var _default = _resolver.default; +exports.default = _default; diff --git a/node_modules/jest-resolve/build/isBuiltinModule.d.ts b/node_modules/jest-resolve/build/isBuiltinModule.d.ts new file mode 100644 index 0000000..70ede3e --- /dev/null +++ b/node_modules/jest-resolve/build/isBuiltinModule.d.ts @@ -0,0 +1,7 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +export default function isBuiltinModule(module: string): boolean; diff --git a/node_modules/jest-resolve/build/isBuiltinModule.js b/node_modules/jest-resolve/build/isBuiltinModule.js new file mode 100644 index 0000000..798cfae --- /dev/null +++ b/node_modules/jest-resolve/build/isBuiltinModule.js @@ -0,0 +1,36 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +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}; +} + +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +// TODO: remove when we drop support for node v10 - it is included from node v12 +const EXPERIMENTAL_MODULES = ['worker_threads']; +const BUILTIN_MODULES = new Set( + _module().default.builtinModules.concat(EXPERIMENTAL_MODULES) +); + +function isBuiltinModule(module) { + return BUILTIN_MODULES.has(module); +} diff --git a/node_modules/jest-resolve/build/nodeModulesPaths.d.ts b/node_modules/jest-resolve/build/nodeModulesPaths.d.ts new file mode 100644 index 0000000..0c37731 --- /dev/null +++ b/node_modules/jest-resolve/build/nodeModulesPaths.d.ts @@ -0,0 +1,15 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * Adapted from: https://github.com/substack/node-resolve + */ +import type { Config } from '@jest/types'; +declare type NodeModulesPathsOptions = { + moduleDirectory?: Array<string>; + paths?: Array<Config.Path>; +}; +export default function nodeModulesPaths(basedir: Config.Path, options: NodeModulesPathsOptions): Array<Config.Path>; +export {}; diff --git a/node_modules/jest-resolve/build/nodeModulesPaths.js b/node_modules/jest-resolve/build/nodeModulesPaths.js new file mode 100644 index 0000000..15aae46 --- /dev/null +++ b/node_modules/jest-resolve/build/nodeModulesPaths.js @@ -0,0 +1,128 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +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) { + if (typeof WeakMap !== 'function') return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function (nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); +} + +function _interopRequireWildcard(obj, nodeInterop) { + if (!nodeInterop && obj && obj.__esModule) { + return obj; + } + if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) { + return {default: obj}; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = {}; + var hasPropertyDescriptor = + Object.defineProperty && Object.getOwnPropertyDescriptor; + for (var key in obj) { + if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor + ? Object.getOwnPropertyDescriptor(obj, key) + : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; +} + +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * Adapted from: https://github.com/substack/node-resolve + */ +function nodeModulesPaths(basedir, options) { + const modules = + options && options.moduleDirectory + ? Array.from(options.moduleDirectory) + : ['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)) { + prefix = ''; + } else if (/^\\\\/.test(basedirAbs)) { + prefix = '\\\\'; + } // The node resolution algorithm (as implemented by NodeJS and TypeScript) + // traverses parents of the physical path, not the symlinked path + + let physicalBasedir; + + try { + physicalBasedir = (0, _jestUtil().tryRealpath)(basedirAbs); + } catch { + // realpath can throw, e.g. on mapped drives + physicalBasedir = basedirAbs; + } + + const paths = [physicalBasedir]; + let parsed = path().parse(physicalBasedir); + + while (parsed.dir !== paths[paths.length - 1]) { + paths.push(parsed.dir); + parsed = path().parse(parsed.dir); + } + + const dirs = paths + .reduce( + (dirs, aPath) => + dirs.concat( + modules.map(moduleDir => + path().isAbsolute(moduleDir) + ? aPath === basedirAbs + ? moduleDir + : '' + : path().join(prefix, aPath, moduleDir) + ) + ), + [] + ) + .filter(dir => dir !== ''); + return options.paths ? dirs.concat(options.paths) : dirs; +} diff --git a/node_modules/jest-resolve/build/resolver.d.ts b/node_modules/jest-resolve/build/resolver.d.ts new file mode 100644 index 0000000..cfe184e --- /dev/null +++ b/node_modules/jest-resolve/build/resolver.d.ts @@ -0,0 +1,58 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +import type { Config } from '@jest/types'; +import type { IModuleMap } from 'jest-haste-map'; +import ModuleNotFoundError from './ModuleNotFoundError'; +import shouldLoadAsEsm from './shouldLoadAsEsm'; +import type { ResolverConfig } from './types'; +declare type FindNodeModuleConfig = { + basedir: Config.Path; + browser?: boolean; + conditions?: Array<string>; + extensions?: Array<string>; + moduleDirectory?: Array<string>; + paths?: Array<Config.Path>; + resolver?: Config.Path | null; + rootDir?: Config.Path; + throwIfNotFound?: boolean; +}; +export declare type ResolveModuleConfig = { + conditions?: Array<string>; + skipNodeResolution?: boolean; + paths?: Array<Config.Path>; +}; +export default class Resolver { + private readonly _options; + private readonly _moduleMap; + private readonly _moduleIDCache; + private readonly _moduleNameCache; + private readonly _modulePathCache; + private readonly _supportsNativePlatform; + constructor(moduleMap: IModuleMap, options: ResolverConfig); + static ModuleNotFoundError: typeof ModuleNotFoundError; + static tryCastModuleNotFoundError(error: unknown): ModuleNotFoundError | null; + static clearDefaultResolverCache(): void; + static findNodeModule(path: Config.Path, options: FindNodeModuleConfig): Config.Path | null; + static unstable_shouldLoadAsEsm: typeof shouldLoadAsEsm; + resolveModuleFromDirIfExists(dirname: Config.Path, moduleName: string, options?: ResolveModuleConfig): Config.Path | null; + resolveModule(from: Config.Path, moduleName: string, options?: ResolveModuleConfig): Config.Path; + private _isAliasModule; + isCoreModule(moduleName: string): boolean; + getModule(name: string): Config.Path | null; + getModulePath(from: Config.Path, moduleName: string): Config.Path; + getPackage(name: string): Config.Path | null; + getMockModule(from: Config.Path, name: string): Config.Path | null; + getModulePaths(from: Config.Path): Array<Config.Path>; + getModuleID(virtualMocks: Map<string, boolean>, from: Config.Path, moduleName?: string, options?: ResolveModuleConfig): string; + private _getModuleType; + private _getAbsolutePath; + private _getMockPath; + private _getVirtualMockPath; + private _isModuleResolved; + resolveStubModuleName(from: Config.Path, moduleName: string): Config.Path | null; +} +export {}; diff --git a/node_modules/jest-resolve/build/resolver.js b/node_modules/jest-resolve/build/resolver.js new file mode 100644 index 0000000..27414ef --- /dev/null +++ b/node_modules/jest-resolve/build/resolver.js @@ -0,0 +1,595 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +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) { + if (typeof WeakMap !== 'function') return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function (nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); +} + +function _interopRequireWildcard(obj, nodeInterop) { + if (!nodeInterop && obj && obj.__esModule) { + return obj; + } + if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) { + return {default: obj}; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = {}; + var hasPropertyDescriptor = + Object.defineProperty && Object.getOwnPropertyDescriptor; + for (var key in obj) { + if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor + ? Object.getOwnPropertyDescriptor(obj, key) + : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; +} + +const NATIVE_PLATFORM = 'native'; // We might be inside a symlink. + +const resolvedCwd = (0, _jestUtil().tryRealpath)(process.cwd()); +const {NODE_PATH} = process.env; +const nodePaths = NODE_PATH + ? NODE_PATH.split(path().delimiter) + .filter(Boolean) // The resolver expects absolute paths. + .map(p => path().resolve(resolvedCwd, p)) + : undefined; + +class Resolver { + constructor(moduleMap, options) { + _defineProperty(this, '_options', void 0); + + _defineProperty(this, '_moduleMap', void 0); + + _defineProperty(this, '_moduleIDCache', void 0); + + _defineProperty(this, '_moduleNameCache', void 0); + + _defineProperty(this, '_modulePathCache', void 0); + + _defineProperty(this, '_supportsNativePlatform', void 0); + + this._options = { + defaultPlatform: options.defaultPlatform, + extensions: options.extensions, + hasCoreModules: + options.hasCoreModules === undefined ? true : options.hasCoreModules, + moduleDirectories: options.moduleDirectories || ['node_modules'], + moduleNameMapper: options.moduleNameMapper, + modulePaths: options.modulePaths, + platforms: options.platforms, + resolver: options.resolver, + rootDir: options.rootDir + }; + this._supportsNativePlatform = options.platforms + ? options.platforms.includes(NATIVE_PLATFORM) + : false; + this._moduleMap = moduleMap; + this._moduleIDCache = new Map(); + this._moduleNameCache = new Map(); + this._modulePathCache = new Map(); + } + + static tryCastModuleNotFoundError(error) { + if (error instanceof _ModuleNotFoundError.default) { + return error; + } + + const casted = error; + + if (casted.code === 'MODULE_NOT_FOUND') { + return _ModuleNotFoundError.default.duckType(casted); + } + + return null; + } + + static clearDefaultResolverCache() { + (0, _fileWalkers.clearFsCache)(); + (0, _shouldLoadAsEsm.clearCachedLookups)(); + } + + static findNodeModule(path, options) { + const resolver = options.resolver + ? require(options.resolver) + : _defaultResolver.default; + const paths = options.paths; + + try { + return resolver(path, { + basedir: options.basedir, + browser: options.browser, + conditions: options.conditions, + defaultResolver: _defaultResolver.default, + extensions: options.extensions, + moduleDirectory: options.moduleDirectory, + paths: paths ? (nodePaths || []).concat(paths) : nodePaths, + rootDir: options.rootDir + }); + } catch (e) { + if (options.throwIfNotFound) { + throw e; + } + } + + 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 + + resolveModuleFromDirIfExists(dirname, moduleName, options) { + const paths = + (options === null || options === void 0 ? void 0 : options.paths) || + this._options.modulePaths; + const moduleDirectory = this._options.moduleDirectories; + const stringifiedOptions = options ? JSON.stringify(options) : ''; + const key = dirname + path().delimiter + moduleName + stringifiedOptions; + const defaultPlatform = this._options.defaultPlatform; + + const extensions = this._options.extensions.slice(); + + let module; + + if (this._supportsNativePlatform) { + extensions.unshift( + ...this._options.extensions.map(ext => '.' + NATIVE_PLATFORM + ext) + ); + } + + if (defaultPlatform) { + extensions.unshift( + ...this._options.extensions.map(ext => '.' + defaultPlatform + ext) + ); + } // 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. + + module = this.getModule(moduleName); + + if (module) { + this._moduleNameCache.set(key, module); + + return module; + } // 3. Check if the module is a node module and resolve it based on + // the node module resolution algorithm. If skipNodeResolution is given we + // ignore all modules that look like node modules (ie. are not relative + // requires). This enables us to speed up resolution when we build a + // dependency graph because we don't have to look at modules that may not + // exist and aren't mocked. + + const skipResolution = + options && options.skipNodeResolution && !moduleName.includes(path().sep); + + const resolveNodeModule = (name, throwIfNotFound = false) => { + if (this.isCoreModule(name)) { + return name; + } + + return Resolver.findNodeModule(name, { + basedir: dirname, + conditions: + options === null || options === void 0 ? void 0 : options.conditions, + extensions, + moduleDirectory, + paths, + resolver: this._options.resolver, + rootDir: this._options.rootDir, + throwIfNotFound + }); + }; + + 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 + // `node_modules` folders anywhere in the file system. + + const parts = moduleName.split('/'); + const hastePackage = this.getPackage(parts.shift()); + + if (hastePackage) { + try { + const module = path().join.apply( + path(), + [path().dirname(hastePackage)].concat(parts) + ); // try resolving with custom resolver first to support extensions, + // then fallback to require.resolve + + const resolvedModule = + resolveNodeModule(module) || require.resolve(module); + + this._moduleNameCache.set(key, resolvedModule); + + return resolvedModule; + } catch {} + } + + return null; + } + + resolveModule(from, moduleName, options) { + const dirname = path().dirname(from); + const module = + this.resolveStubModuleName(from, moduleName) || + this.resolveModuleFromDirIfExists(dirname, moduleName, options); + 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. + + const relativePath = + (0, _slash().default)(path().relative(this._options.rootDir, from)) || + '.'; + throw new _ModuleNotFoundError.default( + `Cannot find module '${moduleName}' from '${relativePath}'`, + moduleName + ); + } + + _isAliasModule(moduleName) { + const moduleNameMapper = this._options.moduleNameMapper; + + if (!moduleNameMapper) { + return false; + } + + return moduleNameMapper.some(({regex}) => regex.test(moduleName)); + } + + isCoreModule(moduleName) { + return ( + this._options.hasCoreModules && + ((0, _isBuiltinModule.default)(moduleName) || + (moduleName.startsWith('node:') && + (0, _isBuiltinModule.default)(moduleName.slice('node:'.length)))) && + !this._isAliasModule(moduleName) + ); + } + + getModule(name) { + return this._moduleMap.getModule( + name, + this._options.defaultPlatform, + this._supportsNativePlatform + ); + } + + getModulePath(from, moduleName) { + if (moduleName[0] !== '.' || path().isAbsolute(moduleName)) { + return moduleName; + } + + return path().normalize(path().dirname(from) + '/' + moduleName); + } + + getPackage(name) { + return this._moduleMap.getPackage( + name, + this._options.defaultPlatform, + this._supportsNativePlatform + ); + } + + getMockModule(from, name) { + const mock = this._moduleMap.getMockModule(name); + + if (mock) { + return mock; + } else { + const moduleName = this.resolveStubModuleName(from, name); + + if (moduleName) { + return this.getModule(moduleName) || moduleName; + } + } + + return null; + } + + getModulePaths(from) { + const cachedModule = this._modulePathCache.get(from); + + if (cachedModule) { + return cachedModule; + } + + const moduleDirectory = this._options.moduleDirectories; + const paths = (0, _nodeModulesPaths.default)(from, { + moduleDirectory + }); + + if (paths[paths.length - 1] === undefined) { + // circumvent node-resolve bug that adds `undefined` as last item. + paths.pop(); + } + + 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( + virtualMocks, + from, + moduleName, + options + ); + + const mockPath = this._getMockPath(from, moduleName); + + const sep = path().delimiter; + const id = + moduleType + + sep + + (absolutePath ? absolutePath + sep : '') + + (mockPath ? mockPath + sep : '') + + (stringifiedOptions ? stringifiedOptions + sep : ''); + + this._moduleIDCache.set(key, id); + + return id; + } + + _getModuleType(moduleName) { + return this.isCoreModule(moduleName) ? 'node' : 'user'; + } + + _getAbsolutePath(virtualMocks, from, moduleName, options) { + if (this.isCoreModule(moduleName)) { + return moduleName; + } + + return this._isModuleResolved(from, moduleName) + ? this.getModule(moduleName) + : this._getVirtualMockPath(virtualMocks, from, moduleName, options); + } + + _getMockPath(from, moduleName) { + return !this.isCoreModule(moduleName) + ? this.getMockModule(from, moduleName) + : null; + } + + _getVirtualMockPath(virtualMocks, from, moduleName, options) { + const virtualMockPath = this.getModulePath(from, moduleName); + return virtualMocks.get(virtualMockPath) + ? virtualMockPath + : moduleName + ? this.resolveModule(from, moduleName, options) + : from; + } + + _isModuleResolved(from, moduleName) { + return !!( + this.getModule(moduleName) || this.getMockModule(from, moduleName) + ); + } + + resolveStubModuleName(from, moduleName) { + const dirname = path().dirname(from); + const paths = this._options.modulePaths; + + const extensions = this._options.extensions.slice(); + + const moduleDirectory = this._options.moduleDirectories; + const moduleNameMapper = this._options.moduleNameMapper; + const resolver = this._options.resolver; + const defaultPlatform = this._options.defaultPlatform; + + if (this._supportsNativePlatform) { + extensions.unshift( + ...this._options.extensions.map(ext => '.' + NATIVE_PLATFORM + ext) + ); + } + + if (defaultPlatform) { + extensions.unshift( + ...this._options.extensions.map(ext => '.' + defaultPlatform + ext) + ); + } + + if (moduleNameMapper) { + for (const {moduleName: mappedModuleName, regex} of moduleNameMapper) { + if (regex.test(moduleName)) { + // Note: once a moduleNameMapper matches the name, it must result + // in a module, or else an error is thrown. + const matches = moduleName.match(regex); + const mapModuleName = matches + ? moduleName => + moduleName.replace( + /\$([0-9]+)/g, + (_, index) => matches[parseInt(index, 10)] + ) + : moduleName => moduleName; + const possibleModuleNames = Array.isArray(mappedModuleName) + ? mappedModuleName + : [mappedModuleName]; + let module = null; + + for (const possibleModuleName of possibleModuleNames) { + const updatedName = mapModuleName(possibleModuleName); + module = + this.getModule(updatedName) || + Resolver.findNodeModule(updatedName, { + basedir: dirname, + extensions, + moduleDirectory, + paths, + resolver, + rootDir: this._options.rootDir + }); + + if (module) { + break; + } + } + + if (!module) { + throw createNoMappedModuleFoundError( + moduleName, + mapModuleName, + mappedModuleName, + regex, + resolver + ); + } + + return module; + } + } + } + + return null; + } +} + +exports.default = Resolver; + +_defineProperty(Resolver, 'ModuleNotFoundError', _ModuleNotFoundError.default); + +_defineProperty(Resolver, 'unstable_shouldLoadAsEsm', _shouldLoadAsEsm.default); + +const createNoMappedModuleFoundError = ( + moduleName, + mapModuleName, + mappedModuleName, + regex, + resolver +) => { + const mappedAs = Array.isArray(mappedModuleName) + ? JSON.stringify(mappedModuleName.map(mapModuleName), null, 2) + : mappedModuleName; + const original = Array.isArray(mappedModuleName) + ? JSON.stringify(mappedModuleName, null, 6) // using 6 because of misalignment when nested below + .slice(0, -1) + ' ]' /// align last bracket correctly as well + : mappedModuleName; + const error = new Error( + _chalk().default.red(`${_chalk().default.bold('Configuration error')}: + +Could not locate module ${_chalk().default.bold(moduleName)} mapped as: +${_chalk().default.bold(mappedAs)}. + +Please check your configuration for these entries: +{ + "moduleNameMapper": { + "${regex.toString()}": "${_chalk().default.bold(original)}" + }, + "resolver": ${_chalk().default.bold(String(resolver))} +}`) + ); + error.name = ''; + return error; +}; diff --git a/node_modules/jest-resolve/build/shouldLoadAsEsm.d.ts b/node_modules/jest-resolve/build/shouldLoadAsEsm.d.ts new file mode 100644 index 0000000..dcb8919 --- /dev/null +++ b/node_modules/jest-resolve/build/shouldLoadAsEsm.d.ts @@ -0,0 +1,9 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +import type { Config } from '@jest/types'; +export declare function clearCachedLookups(): void; +export default function cachedShouldLoadAsEsm(path: Config.Path, extensionsToTreatAsEsm: Array<Config.Path>): boolean; diff --git a/node_modules/jest-resolve/build/shouldLoadAsEsm.js b/node_modules/jest-resolve/build/shouldLoadAsEsm.js new file mode 100644 index 0000000..b53a7d6 --- /dev/null +++ b/node_modules/jest-resolve/build/shouldLoadAsEsm.js @@ -0,0 +1,112 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +exports.clearCachedLookups = clearCachedLookups; +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'); + +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +// @ts-expect-error: experimental, not added to the types +const runtimeSupportsVmModules = typeof _vm().SyntheticModule === 'function'; +const cachedFileLookups = new Map(); +const cachedDirLookups = new Map(); +const cachedChecks = new Map(); + +function clearCachedLookups() { + cachedFileLookups.clear(); + cachedDirLookups.clear(); + cachedChecks.clear(); +} + +function cachedShouldLoadAsEsm(path, extensionsToTreatAsEsm) { + if (!runtimeSupportsVmModules) { + return false; + } + + let cachedLookup = cachedFileLookups.get(path); + + if (cachedLookup === undefined) { + cachedLookup = shouldLoadAsEsm(path, extensionsToTreatAsEsm); + cachedFileLookups.set(path, cachedLookup); + } + + return cachedLookup; +} // 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) { + cachedLookup = cachedPkgCheck(cwd); + cachedFileLookups.set(cwd, cachedLookup); + } + + 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 { + const pkg = (0, _fileWalkers.readPackageCached)(pkgPath); + hasModuleField = pkg.type === 'module'; + } catch { + hasModuleField = false; + } + + cachedChecks.set(pkgPath, hasModuleField); + return hasModuleField; +} diff --git a/node_modules/jest-resolve/build/types.d.ts b/node_modules/jest-resolve/build/types.d.ts new file mode 100644 index 0000000..cb5428c --- /dev/null +++ b/node_modules/jest-resolve/build/types.d.ts @@ -0,0 +1,23 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +import type { Config } from '@jest/types'; +export declare type ResolverConfig = { + defaultPlatform?: string | null; + extensions: Array<string>; + hasCoreModules: boolean; + moduleDirectories: Array<string>; + moduleNameMapper?: Array<ModuleNameMapperConfig> | null; + modulePaths?: Array<Config.Path>; + platforms?: Array<string>; + resolver?: Config.Path | null; + rootDir: Config.Path; +}; +declare type ModuleNameMapperConfig = { + regex: RegExp; + moduleName: string | Array<string>; +}; +export {}; diff --git a/node_modules/jest-resolve/build/types.js b/node_modules/jest-resolve/build/types.js new file mode 100644 index 0000000..ad9a93a --- /dev/null +++ b/node_modules/jest-resolve/build/types.js @@ -0,0 +1 @@ +'use strict'; diff --git a/node_modules/jest-resolve/build/utils.d.ts b/node_modules/jest-resolve/build/utils.d.ts new file mode 100644 index 0000000..81b3850 --- /dev/null +++ b/node_modules/jest-resolve/build/utils.d.ts @@ -0,0 +1,51 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +import type { Config } from '@jest/types'; +/** + * Finds the test environment to use: + * + * 1. looks for jest-environment-<name> relative to project. + * 1. looks for jest-environment-<name> relative to Jest. + * 1. looks for <name> relative to project. + * 1. looks for <name> relative to Jest. + */ +export declare const resolveTestEnvironment: ({ rootDir, testEnvironment: filePath, requireResolveFunction, }: { + rootDir: Config.Path; + testEnvironment: string; + requireResolveFunction?: ((moduleName: string) => string) | undefined; +}) => string; +/** + * Finds the watch plugins to use: + * + * 1. looks for jest-watch-<name> relative to project. + * 1. looks for jest-watch-<name> relative to Jest. + * 1. looks for <name> relative to project. + * 1. looks for <name> relative to Jest. + */ +export declare const resolveWatchPlugin: (resolver: string | undefined | null, { filePath, rootDir, requireResolveFunction, }: { + filePath: string; + rootDir: Config.Path; + requireResolveFunction?: ((moduleName: string) => string) | undefined; +}) => string; +/** + * Finds the runner to use: + * + * 1. looks for jest-runner-<name> relative to project. + * 1. looks for jest-runner-<name> relative to Jest. + * 1. looks for <name> relative to project. + * 1. looks for <name> relative to Jest. + */ +export declare const resolveRunner: (resolver: string | undefined | null, { filePath, rootDir, requireResolveFunction, }: { + filePath: string; + rootDir: Config.Path; + requireResolveFunction?: ((moduleName: string) => string) | undefined; +}) => string; +export declare const resolveSequencer: (resolver: string | undefined | null, { filePath, rootDir, requireResolveFunction, }: { + filePath: string; + rootDir: Config.Path; + requireResolveFunction?: ((moduleName: string) => string) | undefined; +}) => string; diff --git a/node_modules/jest-resolve/build/utils.js b/node_modules/jest-resolve/build/utils.js new file mode 100644 index 0000000..6bad7ff --- /dev/null +++ b/node_modules/jest-resolve/build/utils.js @@ -0,0 +1,269 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +exports.resolveWatchPlugin = + exports.resolveTestEnvironment = + exports.resolveSequencer = + exports.resolveRunner = + 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) { + if (typeof WeakMap !== 'function') return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function (nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); +} + +function _interopRequireWildcard(obj, nodeInterop) { + if (!nodeInterop && obj && obj.__esModule) { + return obj; + } + if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) { + return {default: obj}; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = {}; + var hasPropertyDescriptor = + Object.defineProperty && Object.getOwnPropertyDescriptor; + for (var key in obj) { + if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor + ? Object.getOwnPropertyDescriptor(obj, key) + : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; +} + +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +const BULLET = _chalk().default.bold('\u25cf '); + +const DOCUMENTATION_NOTE = ` ${_chalk().default.bold( + 'Configuration Documentation:' +)} + https://jestjs.io/docs/configuration +`; + +const createValidationError = message => + new (_jestValidate().ValidationError)( + `${BULLET}Validation Error`, + message, + DOCUMENTATION_NOTE + ); + +const replaceRootDirInPath = (rootDir, filePath) => { + if (!/^<rootDir>/.test(filePath)) { + return filePath; + } + + return path().resolve( + rootDir, + path().normalize('./' + filePath.substr('<rootDir>'.length)) + ); +}; + +const resolveWithPrefix = ( + resolver, + { + filePath, + humanOptionName, + optionName, + prefix, + requireResolveFunction, + rootDir + } +) => { + const fileName = replaceRootDirInPath(rootDir, filePath); + + let module = _resolver.default.findNodeModule(`${prefix}${fileName}`, { + basedir: rootDir, + resolver: resolver || undefined + }); + + if (module) { + return module; + } + + try { + return requireResolveFunction(`${prefix}${fileName}`); + } catch {} + + module = _resolver.default.findNodeModule(fileName, { + basedir: rootDir, + resolver: resolver || undefined + }); + + if (module) { + return module; + } + + try { + return requireResolveFunction(fileName); + } catch {} + + throw createValidationError( + ` ${humanOptionName} ${_chalk().default.bold( + fileName + )} cannot be found. Make sure the ${_chalk().default.bold( + optionName + )} configuration option points to an existing node module.` + ); +}; +/** + * Finds the test environment to use: + * + * 1. looks for jest-environment-<name> relative to project. + * 1. looks for jest-environment-<name> relative to Jest. + * 1. looks for <name> relative to project. + * 1. looks for <name> relative to Jest. + */ + +const resolveTestEnvironment = ({ + rootDir, + testEnvironment: filePath, + // TODO: remove default in Jest 28 + requireResolveFunction = require.resolve +}) => + resolveWithPrefix(undefined, { + filePath, + humanOptionName: 'Test environment', + optionName: 'testEnvironment', + prefix: 'jest-environment-', + requireResolveFunction, + rootDir + }); +/** + * Finds the watch plugins to use: + * + * 1. looks for jest-watch-<name> relative to project. + * 1. looks for jest-watch-<name> relative to Jest. + * 1. looks for <name> relative to project. + * 1. looks for <name> relative to Jest. + */ + +exports.resolveTestEnvironment = resolveTestEnvironment; + +const resolveWatchPlugin = ( + resolver, + { + filePath, + rootDir, + // TODO: remove default in Jest 28 + requireResolveFunction = require.resolve + } +) => + resolveWithPrefix(resolver, { + filePath, + humanOptionName: 'Watch plugin', + optionName: 'watchPlugins', + prefix: 'jest-watch-', + requireResolveFunction, + rootDir + }); +/** + * Finds the runner to use: + * + * 1. looks for jest-runner-<name> relative to project. + * 1. looks for jest-runner-<name> relative to Jest. + * 1. looks for <name> relative to project. + * 1. looks for <name> relative to Jest. + */ + +exports.resolveWatchPlugin = resolveWatchPlugin; + +const resolveRunner = ( + resolver, + { + filePath, + rootDir, + // TODO: remove default in Jest 28 + requireResolveFunction = require.resolve + } +) => + resolveWithPrefix(resolver, { + filePath, + humanOptionName: 'Jest Runner', + optionName: 'runner', + prefix: 'jest-runner-', + requireResolveFunction, + rootDir + }); + +exports.resolveRunner = resolveRunner; + +const resolveSequencer = ( + resolver, + { + filePath, + rootDir, + // TODO: remove default in Jest 28 + requireResolveFunction = require.resolve + } +) => + resolveWithPrefix(resolver, { + filePath, + humanOptionName: 'Jest Sequencer', + optionName: 'testSequencer', + prefix: 'jest-sequencer-', + requireResolveFunction, + rootDir + }); + +exports.resolveSequencer = resolveSequencer; |