mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
Change endpoint from persons to people
This commit is contained in:
108
backend/apis/nodejs/node_modules/jest-resolve/build/ModuleNotFoundError.js
generated
vendored
Normal file
108
backend/apis/nodejs/node_modules/jest-resolve/build/ModuleNotFoundError.js
generated
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
'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;
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
class ModuleNotFoundError extends Error {
|
||||
code = 'MODULE_NOT_FOUND';
|
||||
hint;
|
||||
requireStack;
|
||||
siblingWithSimilarExtensionFound;
|
||||
moduleName;
|
||||
_originalMessage;
|
||||
constructor(message, moduleName) {
|
||||
super(message);
|
||||
this._originalMessage = message;
|
||||
this.moduleName = moduleName;
|
||||
}
|
||||
buildMessage(rootDir) {
|
||||
if (!this._originalMessage) {
|
||||
this._originalMessage = this.message || '';
|
||||
}
|
||||
let message = this._originalMessage;
|
||||
if (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;
|
240
backend/apis/nodejs/node_modules/jest-resolve/build/defaultResolver.js
generated
vendored
Normal file
240
backend/apis/nodejs/node_modules/jest-resolve/build/defaultResolver.js
generated
vendored
Normal file
@ -0,0 +1,240 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
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 resolve = _interopRequireWildcard(require('resolve.exports'));
|
||||
var _fileWalkers = require('./fileWalkers');
|
||||
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 _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows transforming parsed `package.json` contents.
|
||||
*
|
||||
* @param pkg - Parsed `package.json` contents.
|
||||
* @param file - Path to `package.json` file.
|
||||
* @param dir - Directory that contains the `package.json`.
|
||||
*
|
||||
* @returns Transformed `package.json` contents.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows transforming a path within a package.
|
||||
*
|
||||
* @param pkg - Parsed `package.json` contents.
|
||||
* @param path - Path being resolved.
|
||||
* @param relativePath - Path relative from the `package.json` location.
|
||||
*
|
||||
* @returns Relative path that will be joined from the `package.json` location.
|
||||
*/
|
||||
|
||||
const 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 resolveOptions = {
|
||||
...options,
|
||||
isDirectory: _fileWalkers.isDirectory,
|
||||
isFile: _fileWalkers.isFile,
|
||||
preserveSymlinks: false,
|
||||
readPackageSync,
|
||||
realpathSync: _fileWalkers.realpathSync
|
||||
};
|
||||
const pathToResolve = getPathInModule(path, resolveOptions);
|
||||
|
||||
// resolveSync dereferences symlinks to ensure we don't create a separate
|
||||
// module instance depending on how it was referenced.
|
||||
const result = (0, _resolve().sync)(pathToResolve, resolveOptions);
|
||||
return result;
|
||||
};
|
||||
var _default = defaultResolver;
|
||||
/*
|
||||
* helper functions
|
||||
*/
|
||||
exports.default = _default;
|
||||
function readPackageSync(_, file) {
|
||||
return (0, _fileWalkers.readPackageCached)(file);
|
||||
}
|
||||
function getPathInModule(path, options) {
|
||||
if (shouldIgnoreRequestForExports(path)) {
|
||||
return path;
|
||||
}
|
||||
if (path.startsWith('#')) {
|
||||
const closestPackageJson = (0, _fileWalkers.findClosestPackageJson)(
|
||||
options.basedir
|
||||
);
|
||||
if (!closestPackageJson) {
|
||||
throw new Error(
|
||||
`Jest: unable to locate closest package.json from ${options.basedir} when resolving import "${path}"`
|
||||
);
|
||||
}
|
||||
const pkg = (0, _fileWalkers.readPackageCached)(closestPackageJson);
|
||||
const resolved = resolve.imports(
|
||||
pkg,
|
||||
path,
|
||||
createResolveOptions(options.conditions)
|
||||
);
|
||||
if (resolved) {
|
||||
const target = resolved[0];
|
||||
return target.startsWith('.')
|
||||
? // internal relative filepath
|
||||
(0, _path().resolve)((0, _path().dirname)(closestPackageJson), target)
|
||||
: // this is an external module, re-resolve it
|
||||
defaultResolver(target, options);
|
||||
}
|
||||
if (pkg.imports) {
|
||||
throw new Error(
|
||||
'`imports` exists, but no results - this is a bug in Jest. Please report an issue'
|
||||
);
|
||||
}
|
||||
}
|
||||
const segments = path.split('/');
|
||||
let moduleName = segments.shift();
|
||||
if (moduleName) {
|
||||
if (moduleName.startsWith('@')) {
|
||||
moduleName = `${moduleName}/${segments.shift()}`;
|
||||
}
|
||||
|
||||
// self-reference
|
||||
const closestPackageJson = (0, _fileWalkers.findClosestPackageJson)(
|
||||
options.basedir
|
||||
);
|
||||
if (closestPackageJson) {
|
||||
const pkg = (0, _fileWalkers.readPackageCached)(closestPackageJson);
|
||||
if (pkg.name === moduleName) {
|
||||
const resolved = resolve.exports(
|
||||
pkg,
|
||||
segments.join('/') || '.',
|
||||
createResolveOptions(options.conditions)
|
||||
);
|
||||
if (resolved) {
|
||||
return (0, _path().resolve)(
|
||||
(0, _path().dirname)(closestPackageJson),
|
||||
resolved[0]
|
||||
);
|
||||
}
|
||||
if (pkg.exports) {
|
||||
throw new Error(
|
||||
'`exports` exists, but no results - this is a bug in Jest. Please report an issue'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
let packageJsonPath = '';
|
||||
try {
|
||||
packageJsonPath = (0, _resolve().sync)(
|
||||
`${moduleName}/package.json`,
|
||||
options
|
||||
);
|
||||
} catch {
|
||||
// ignore if package.json cannot be found
|
||||
}
|
||||
if (packageJsonPath && (0, _fileWalkers.isFile)(packageJsonPath)) {
|
||||
const pkg = (0, _fileWalkers.readPackageCached)(packageJsonPath);
|
||||
const resolved = resolve.exports(
|
||||
pkg,
|
||||
segments.join('/') || '.',
|
||||
createResolveOptions(options.conditions)
|
||||
);
|
||||
if (resolved) {
|
||||
return (0, _path().resolve)(
|
||||
(0, _path().dirname)(packageJsonPath),
|
||||
resolved[0]
|
||||
);
|
||||
}
|
||||
if (pkg.exports) {
|
||||
throw new Error(
|
||||
'`exports` exists, but no results - this is a bug in Jest. Please report an issue'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
function createResolveOptions(conditions) {
|
||||
return conditions
|
||||
? {
|
||||
conditions,
|
||||
unsafe: true
|
||||
}
|
||||
: // 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, imports/exports are ignored
|
||||
const shouldIgnoreRequestForExports = path =>
|
||||
path.startsWith('.') || (0, _path().isAbsolute)(path);
|
178
backend/apis/nodejs/node_modules/jest-resolve/build/fileWalkers.js
generated
vendored
Normal file
178
backend/apis/nodejs/node_modules/jest-resolve/build/fileWalkers.js
generated
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
'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) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
function clearFsCache() {
|
||||
checkedPaths.clear();
|
||||
checkedRealpathPaths.clear();
|
||||
packageContents.clear();
|
||||
}
|
||||
var IPathType = /*#__PURE__*/ (function (IPathType) {
|
||||
IPathType[(IPathType['FILE'] = 1)] = 'FILE';
|
||||
IPathType[(IPathType['DIRECTORY'] = 2)] = 'DIRECTORY';
|
||||
IPathType[(IPathType['OTHER'] = 3)] = 'OTHER';
|
||||
return 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);
|
||||
}
|
320
backend/apis/nodejs/node_modules/jest-resolve/build/index.d.ts
generated
vendored
Normal file
320
backend/apis/nodejs/node_modules/jest-resolve/build/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,320 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
import type {IModuleMap} from 'jest-haste-map';
|
||||
|
||||
export declare type AsyncResolver = (
|
||||
path: string,
|
||||
options: ResolverOptions,
|
||||
) => Promise<string>;
|
||||
|
||||
declare function cachedShouldLoadAsEsm(
|
||||
path: string,
|
||||
extensionsToTreatAsEsm: Array<string>,
|
||||
): boolean;
|
||||
|
||||
declare const defaultResolver: SyncResolver;
|
||||
|
||||
export declare type FindNodeModuleConfig = {
|
||||
basedir: string;
|
||||
conditions?: Array<string>;
|
||||
extensions?: Array<string>;
|
||||
moduleDirectory?: Array<string>;
|
||||
paths?: Array<string>;
|
||||
resolver?: string | null;
|
||||
rootDir?: string;
|
||||
throwIfNotFound?: boolean;
|
||||
};
|
||||
|
||||
export declare type JestResolver = ResolverSyncObject | ResolverAsyncObject;
|
||||
|
||||
declare interface JSONObject {
|
||||
[key: string]: JSONValue;
|
||||
}
|
||||
|
||||
declare type JSONValue =
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| JSONObject
|
||||
| Array<JSONValue>;
|
||||
|
||||
declare type ModuleNameMapperConfig = {
|
||||
regex: RegExp;
|
||||
moduleName: string | Array<string>;
|
||||
};
|
||||
|
||||
declare class ModuleNotFoundError extends Error {
|
||||
code: string;
|
||||
hint?: string;
|
||||
requireStack?: Array<string>;
|
||||
siblingWithSimilarExtensionFound?: boolean;
|
||||
moduleName?: string;
|
||||
private _originalMessage?;
|
||||
constructor(message: string, moduleName?: string);
|
||||
buildMessage(rootDir: string): void;
|
||||
static duckType(error: ModuleNotFoundError): ModuleNotFoundError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows transforming parsed `package.json` contents.
|
||||
*
|
||||
* @param pkg - Parsed `package.json` contents.
|
||||
* @param file - Path to `package.json` file.
|
||||
* @param dir - Directory that contains the `package.json`.
|
||||
*
|
||||
* @returns Transformed `package.json` contents.
|
||||
*/
|
||||
export declare type PackageFilter = (
|
||||
pkg: PackageJSON,
|
||||
file: string,
|
||||
dir: string,
|
||||
) => PackageJSON;
|
||||
|
||||
export declare type PackageJSON = JSONObject;
|
||||
|
||||
/**
|
||||
* Allows transforming a path within a package.
|
||||
*
|
||||
* @param pkg - Parsed `package.json` contents.
|
||||
* @param path - Path being resolved.
|
||||
* @param relativePath - Path relative from the `package.json` location.
|
||||
*
|
||||
* @returns Relative path that will be joined from the `package.json` location.
|
||||
*/
|
||||
export declare type PathFilter = (
|
||||
pkg: PackageJSON,
|
||||
path: string,
|
||||
relativePath: string,
|
||||
) => string;
|
||||
|
||||
export declare type ResolveModuleConfig = {
|
||||
conditions?: Array<string>;
|
||||
skipNodeResolution?: boolean;
|
||||
paths?: Array<string>;
|
||||
};
|
||||
|
||||
declare 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: string,
|
||||
options: FindNodeModuleConfig,
|
||||
): string | null;
|
||||
static findNodeModuleAsync(
|
||||
path: string,
|
||||
options: FindNodeModuleConfig,
|
||||
): Promise<string | null>;
|
||||
static unstable_shouldLoadAsEsm: typeof cachedShouldLoadAsEsm;
|
||||
resolveModuleFromDirIfExists(
|
||||
dirname: string,
|
||||
moduleName: string,
|
||||
options?: ResolveModuleConfig,
|
||||
): string | null;
|
||||
resolveModuleFromDirIfExistsAsync(
|
||||
dirname: string,
|
||||
moduleName: string,
|
||||
options?: ResolveModuleConfig,
|
||||
): Promise<string | null>;
|
||||
resolveModule(
|
||||
from: string,
|
||||
moduleName: string,
|
||||
options?: ResolveModuleConfig,
|
||||
): string;
|
||||
resolveModuleAsync(
|
||||
from: string,
|
||||
moduleName: string,
|
||||
options?: ResolveModuleConfig,
|
||||
): Promise<string>;
|
||||
/**
|
||||
* _prepareForResolution is shared between the sync and async module resolution
|
||||
* methods, to try to keep them as DRY as possible.
|
||||
*/
|
||||
private _prepareForResolution;
|
||||
/**
|
||||
* _getHasteModulePath attempts to return the path to a haste module.
|
||||
*/
|
||||
private _getHasteModulePath;
|
||||
private _throwModNotFoundError;
|
||||
private _getMapModuleName;
|
||||
private _isAliasModule;
|
||||
isCoreModule(moduleName: string): boolean;
|
||||
getModule(name: string): string | null;
|
||||
getModulePath(from: string, moduleName: string): string;
|
||||
getPackage(name: string): string | null;
|
||||
getMockModule(from: string, name: string): string | null;
|
||||
getMockModuleAsync(from: string, name: string): Promise<string | null>;
|
||||
getModulePaths(from: string): Array<string>;
|
||||
getGlobalPaths(moduleName?: string): Array<string>;
|
||||
getModuleID(
|
||||
virtualMocks: Map<string, boolean>,
|
||||
from: string,
|
||||
moduleName?: string,
|
||||
options?: ResolveModuleConfig,
|
||||
): string;
|
||||
getModuleIDAsync(
|
||||
virtualMocks: Map<string, boolean>,
|
||||
from: string,
|
||||
moduleName?: string,
|
||||
options?: ResolveModuleConfig,
|
||||
): Promise<string>;
|
||||
private _getModuleType;
|
||||
private _getAbsolutePath;
|
||||
private _getAbsolutePathAsync;
|
||||
private _getMockPath;
|
||||
private _getMockPathAsync;
|
||||
private _getVirtualMockPath;
|
||||
private _getVirtualMockPathAsync;
|
||||
private _isModuleResolved;
|
||||
private _isModuleResolvedAsync;
|
||||
resolveStubModuleName(from: string, moduleName: string): string | null;
|
||||
resolveStubModuleNameAsync(
|
||||
from: string,
|
||||
moduleName: string,
|
||||
): Promise<string | null>;
|
||||
}
|
||||
export default Resolver;
|
||||
|
||||
declare type ResolverAsyncObject = {
|
||||
sync?: SyncResolver;
|
||||
async: AsyncResolver;
|
||||
};
|
||||
|
||||
declare type ResolverConfig = {
|
||||
defaultPlatform?: string | null;
|
||||
extensions: Array<string>;
|
||||
hasCoreModules: boolean;
|
||||
moduleDirectories: Array<string>;
|
||||
moduleNameMapper?: Array<ModuleNameMapperConfig> | null;
|
||||
modulePaths?: Array<string>;
|
||||
platforms?: Array<string>;
|
||||
resolver?: string | null;
|
||||
rootDir: string;
|
||||
};
|
||||
|
||||
export declare type ResolverOptions = {
|
||||
/** Directory to begin resolving from. */
|
||||
basedir: string;
|
||||
/** List of export conditions. */
|
||||
conditions?: Array<string>;
|
||||
/** Instance of default resolver. */
|
||||
defaultResolver: typeof defaultResolver;
|
||||
/** List of file extensions to search in order. */
|
||||
extensions?: Array<string>;
|
||||
/**
|
||||
* List of directory names to be looked up for modules recursively.
|
||||
*
|
||||
* @defaultValue
|
||||
* The default is `['node_modules']`.
|
||||
*/
|
||||
moduleDirectory?: Array<string>;
|
||||
/**
|
||||
* List of `require.paths` to use if nothing is found in `node_modules`.
|
||||
*
|
||||
* @defaultValue
|
||||
* The default is `undefined`.
|
||||
*/
|
||||
paths?: Array<string>;
|
||||
/** Allows transforming parsed `package.json` contents. */
|
||||
packageFilter?: PackageFilter;
|
||||
/** Allows transforms a path within a package. */
|
||||
pathFilter?: PathFilter;
|
||||
/** Current root directory. */
|
||||
rootDir?: string;
|
||||
};
|
||||
|
||||
declare type ResolverSyncObject = {
|
||||
sync: SyncResolver;
|
||||
async?: AsyncResolver;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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: string;
|
||||
requireResolveFunction: (moduleName: string) => string;
|
||||
},
|
||||
) => string;
|
||||
|
||||
export declare const resolveSequencer: (
|
||||
resolver: string | undefined | null,
|
||||
{
|
||||
filePath,
|
||||
rootDir,
|
||||
requireResolveFunction,
|
||||
}: {
|
||||
filePath: string;
|
||||
rootDir: string;
|
||||
requireResolveFunction: (moduleName: string) => string;
|
||||
},
|
||||
) => string;
|
||||
|
||||
/**
|
||||
* 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: string;
|
||||
testEnvironment: string;
|
||||
requireResolveFunction: (moduleName: string) => string;
|
||||
}) => 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: string;
|
||||
requireResolveFunction: (moduleName: string) => string;
|
||||
},
|
||||
) => string;
|
||||
|
||||
export declare type SyncResolver = (
|
||||
path: string,
|
||||
options: ResolverOptions,
|
||||
) => string;
|
||||
|
||||
export {};
|
31
backend/apis/nodejs/node_modules/jest-resolve/build/index.js
generated
vendored
Normal file
31
backend/apis/nodejs/node_modules/jest-resolve/build/index.js
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
'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) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
var _default = _resolver.default;
|
||||
exports.default = _default;
|
27
backend/apis/nodejs/node_modules/jest-resolve/build/isBuiltinModule.js
generated
vendored
Normal file
27
backend/apis/nodejs/node_modules/jest-resolve/build/isBuiltinModule.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
'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) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const BUILTIN_MODULES = new Set(_module().default.builtinModules);
|
||||
function isBuiltinModule(module) {
|
||||
return BUILTIN_MODULES.has(module);
|
||||
}
|
131
backend/apis/nodejs/node_modules/jest-resolve/build/nodeModulesPaths.js
generated
vendored
Normal file
131
backend/apis/nodejs/node_modules/jest-resolve/build/nodeModulesPaths.js
generated
vendored
Normal file
@ -0,0 +1,131 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.GlobalPaths = void 0;
|
||||
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) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* 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) => {
|
||||
for (const moduleDir of modules) {
|
||||
if (path().isAbsolute(moduleDir)) {
|
||||
if (aPath === basedirAbs && moduleDir) {
|
||||
dirs.push(moduleDir);
|
||||
}
|
||||
} else {
|
||||
dirs.push(path().join(prefix, aPath, moduleDir));
|
||||
}
|
||||
}
|
||||
return dirs;
|
||||
}, []);
|
||||
if (options.paths) {
|
||||
dirs.push(...options.paths);
|
||||
}
|
||||
return dirs;
|
||||
}
|
||||
function findGlobalPaths() {
|
||||
const {root} = path().parse(process.cwd());
|
||||
const globalPath = path().join(root, 'node_modules');
|
||||
const resolvePaths = require.resolve.paths('/');
|
||||
if (resolvePaths) {
|
||||
// the global paths start one after the root node_modules
|
||||
const rootIndex = resolvePaths.indexOf(globalPath);
|
||||
return rootIndex > -1 ? resolvePaths.slice(rootIndex + 1) : [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
const GlobalPaths = findGlobalPaths();
|
||||
exports.GlobalPaths = GlobalPaths;
|
796
backend/apis/nodejs/node_modules/jest-resolve/build/resolver.js
generated
vendored
Normal file
796
backend/apis/nodejs/node_modules/jest-resolve/build/resolver.js
generated
vendored
Normal file
@ -0,0 +1,796 @@
|
||||
'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 = _interopRequireWildcard(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;
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/* eslint-disable local/prefer-spread-eventually */
|
||||
|
||||
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 {
|
||||
_options;
|
||||
_moduleMap;
|
||||
_moduleIDCache;
|
||||
_moduleNameCache;
|
||||
_modulePathCache;
|
||||
_supportsNativePlatform;
|
||||
constructor(moduleMap, options) {
|
||||
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 ModuleNotFoundError = _ModuleNotFoundError.default;
|
||||
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 resolverModule = loadResolver(options.resolver);
|
||||
let resolver = _defaultResolver.default;
|
||||
if (typeof resolverModule === 'function') {
|
||||
resolver = resolverModule;
|
||||
} else if (typeof resolverModule.sync === 'function') {
|
||||
resolver = resolverModule.sync;
|
||||
}
|
||||
const paths = options.paths;
|
||||
try {
|
||||
return resolver(path, {
|
||||
basedir: options.basedir,
|
||||
conditions: options.conditions,
|
||||
defaultResolver: _defaultResolver.default,
|
||||
extensions: options.extensions,
|
||||
moduleDirectory: options.moduleDirectory,
|
||||
paths: paths ? (nodePaths || []).concat(paths) : nodePaths,
|
||||
rootDir: options.rootDir
|
||||
});
|
||||
} catch (e) {
|
||||
// we always wanna throw if it's an internal import
|
||||
if (options.throwIfNotFound || path.startsWith('#')) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
static async findNodeModuleAsync(path, options) {
|
||||
const resolverModule = loadResolver(options.resolver);
|
||||
let resolver = _defaultResolver.default;
|
||||
if (typeof resolverModule === 'function') {
|
||||
resolver = resolverModule;
|
||||
} else if (
|
||||
typeof resolverModule.async === 'function' ||
|
||||
typeof resolverModule.sync === 'function'
|
||||
) {
|
||||
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 {
|
||||
const result = await resolver(path, {
|
||||
basedir: options.basedir,
|
||||
conditions: options.conditions,
|
||||
defaultResolver: _defaultResolver.default,
|
||||
extensions: options.extensions,
|
||||
moduleDirectory: options.moduleDirectory,
|
||||
paths: paths ? (nodePaths || []).concat(paths) : nodePaths,
|
||||
rootDir: options.rootDir
|
||||
});
|
||||
return result;
|
||||
} catch (e) {
|
||||
// we always wanna throw if it's an internal import
|
||||
if (options.throwIfNotFound || path.startsWith('#')) {
|
||||
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
|
||||
static unstable_shouldLoadAsEsm = _shouldLoadAsEsm.default;
|
||||
resolveModuleFromDirIfExists(dirname, moduleName, options) {
|
||||
const {extensions, key, moduleDirectory, paths, skipResolution} =
|
||||
this._prepareForResolution(dirname, moduleName, options);
|
||||
let module;
|
||||
|
||||
// 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 resolveNodeModule = (name, throwIfNotFound = false) => {
|
||||
// Only skip default resolver
|
||||
if (this.isCoreModule(name) && !this._options.resolver) {
|
||||
return name;
|
||||
}
|
||||
return Resolver.findNodeModule(name, {
|
||||
basedir: dirname,
|
||||
conditions: 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.
|
||||
try {
|
||||
const hasteModulePath = this._getHasteModulePath(moduleName);
|
||||
if (hasteModulePath) {
|
||||
// try resolving with custom resolver first to support extensions,
|
||||
// then fallback to require.resolve
|
||||
const resolvedModule =
|
||||
resolveNodeModule(hasteModulePath) ||
|
||||
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;
|
||||
|
||||
// 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 resolveNodeModule = async (name, throwIfNotFound = false) => {
|
||||
// Only skip default resolver
|
||||
if (this.isCoreModule(name) && !this._options.resolver) {
|
||||
return name;
|
||||
}
|
||||
return Resolver.findNodeModuleAsync(name, {
|
||||
basedir: dirname,
|
||||
conditions: options?.conditions,
|
||||
extensions,
|
||||
moduleDirectory,
|
||||
paths,
|
||||
resolver: this._options.resolver,
|
||||
rootDir: this._options.rootDir,
|
||||
throwIfNotFound
|
||||
});
|
||||
};
|
||||
if (!skipResolution) {
|
||||
module = await 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.
|
||||
try {
|
||||
const hasteModulePath = this._getHasteModulePath(moduleName);
|
||||
if (hasteModulePath) {
|
||||
// try resolving with custom resolver first to support extensions,
|
||||
// then fallback to require.resolve
|
||||
const resolvedModule =
|
||||
(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) {
|
||||
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.
|
||||
this._throwModNotFoundError(from, moduleName);
|
||||
}
|
||||
async resolveModuleAsync(from, moduleName, options) {
|
||||
const dirname = path().dirname(from);
|
||||
const module =
|
||||
(await this.resolveStubModuleNameAsync(from, moduleName)) ||
|
||||
(await this.resolveModuleFromDirIfExistsAsync(
|
||||
dirname,
|
||||
moduleName,
|
||||
options
|
||||
));
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* _prepareForResolution is shared between the sync and async module resolution
|
||||
* methods, to try to keep them as DRY as possible.
|
||||
*/
|
||||
_prepareForResolution(dirname, moduleName, options) {
|
||||
const paths = 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();
|
||||
if (this._supportsNativePlatform) {
|
||||
extensions.unshift(
|
||||
...this._options.extensions.map(ext => `.${NATIVE_PLATFORM}${ext}`)
|
||||
);
|
||||
}
|
||||
if (defaultPlatform) {
|
||||
extensions.unshift(
|
||||
...this._options.extensions.map(ext => `.${defaultPlatform}${ext}`)
|
||||
);
|
||||
}
|
||||
const skipResolution =
|
||||
options && options.skipNodeResolution && !moduleName.includes(path().sep);
|
||||
return {
|
||||
extensions,
|
||||
key,
|
||||
moduleDirectory,
|
||||
paths,
|
||||
skipResolution
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* _getHasteModulePath attempts to return the path to a haste module.
|
||||
*/
|
||||
_getHasteModulePath(moduleName) {
|
||||
const parts = moduleName.split('/');
|
||||
const hastePackage = this.getPackage(parts.shift());
|
||||
if (hastePackage) {
|
||||
return path().join.apply(
|
||||
path(),
|
||||
[path().dirname(hastePackage)].concat(parts)
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
_throwModNotFoundError(from, moduleName) {
|
||||
const relativePath =
|
||||
(0, _slash().default)(path().relative(this._options.rootDir, from)) ||
|
||||
'.';
|
||||
throw new _ModuleNotFoundError.default(
|
||||
`Cannot find module '${moduleName}' from '${relativePath}'`,
|
||||
moduleName
|
||||
);
|
||||
}
|
||||
_getMapModuleName(matches) {
|
||||
return matches
|
||||
? moduleName =>
|
||||
moduleName.replace(
|
||||
/\$([0-9]+)/g,
|
||||
(_, index) => matches[parseInt(index, 10)] || ''
|
||||
)
|
||||
: moduleName => 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:')) &&
|
||||
!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;
|
||||
}
|
||||
async getMockModuleAsync(from, name) {
|
||||
const mock = this._moduleMap.getMockModule(name);
|
||||
if (mock) {
|
||||
return mock;
|
||||
} else {
|
||||
const moduleName = await this.resolveStubModuleNameAsync(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;
|
||||
}
|
||||
getGlobalPaths(moduleName) {
|
||||
if (!moduleName || moduleName[0] === '.' || this.isCoreModule(moduleName)) {
|
||||
return [];
|
||||
}
|
||||
return _nodeModulesPaths.GlobalPaths;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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(
|
||||
virtualMocks,
|
||||
from,
|
||||
moduleName,
|
||||
options
|
||||
);
|
||||
const mockPath = await this._getMockPathAsync(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;
|
||||
}
|
||||
if (moduleName.startsWith('data:')) {
|
||||
return moduleName;
|
||||
}
|
||||
return this._isModuleResolved(from, moduleName)
|
||||
? this.getModule(moduleName)
|
||||
: this._getVirtualMockPath(virtualMocks, from, moduleName, options);
|
||||
}
|
||||
async _getAbsolutePathAsync(virtualMocks, from, moduleName, options) {
|
||||
if (this.isCoreModule(moduleName)) {
|
||||
return moduleName;
|
||||
}
|
||||
if (moduleName.startsWith('data:')) {
|
||||
return moduleName;
|
||||
}
|
||||
const isModuleResolved = await this._isModuleResolvedAsync(
|
||||
from,
|
||||
moduleName
|
||||
);
|
||||
return isModuleResolved
|
||||
? this.getModule(moduleName)
|
||||
: this._getVirtualMockPathAsync(virtualMocks, from, moduleName, options);
|
||||
}
|
||||
_getMockPath(from, moduleName) {
|
||||
return !this.isCoreModule(moduleName)
|
||||
? this.getMockModule(from, moduleName)
|
||||
: null;
|
||||
}
|
||||
async _getMockPathAsync(from, moduleName) {
|
||||
return !this.isCoreModule(moduleName)
|
||||
? this.getMockModuleAsync(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;
|
||||
}
|
||||
async _getVirtualMockPathAsync(virtualMocks, from, moduleName, options) {
|
||||
const virtualMockPath = this.getModulePath(from, moduleName);
|
||||
return virtualMocks.get(virtualMockPath)
|
||||
? virtualMockPath
|
||||
: moduleName
|
||||
? this.resolveModuleAsync(from, moduleName, options)
|
||||
: from;
|
||||
}
|
||||
_isModuleResolved(from, moduleName) {
|
||||
return !!(
|
||||
this.getModule(moduleName) || this.getMockModule(from, moduleName)
|
||||
);
|
||||
}
|
||||
async _isModuleResolvedAsync(from, moduleName) {
|
||||
return !!(
|
||||
this.getModule(moduleName) ||
|
||||
(await this.getMockModuleAsync(from, moduleName))
|
||||
);
|
||||
}
|
||||
resolveStubModuleName(from, moduleName) {
|
||||
const dirname = path().dirname(from);
|
||||
const {extensions, moduleDirectory, paths} = this._prepareForResolution(
|
||||
dirname,
|
||||
moduleName
|
||||
);
|
||||
const moduleNameMapper = this._options.moduleNameMapper;
|
||||
const resolver = this._options.resolver;
|
||||
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 = this._getMapModuleName(matches);
|
||||
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;
|
||||
}
|
||||
async resolveStubModuleNameAsync(from, moduleName) {
|
||||
const dirname = path().dirname(from);
|
||||
const {extensions, moduleDirectory, paths} = this._prepareForResolution(
|
||||
dirname,
|
||||
moduleName
|
||||
);
|
||||
const moduleNameMapper = this._options.moduleNameMapper;
|
||||
const resolver = this._options.resolver;
|
||||
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 = this._getMapModuleName(matches);
|
||||
const possibleModuleNames = Array.isArray(mappedModuleName)
|
||||
? mappedModuleName
|
||||
: [mappedModuleName];
|
||||
let module = null;
|
||||
for (const possibleModuleName of possibleModuleNames) {
|
||||
const updatedName = mapModuleName(possibleModuleName);
|
||||
module =
|
||||
this.getModule(updatedName) ||
|
||||
(await Resolver.findNodeModuleAsync(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;
|
||||
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) + ' '.repeat(4)
|
||||
}]` /// 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;
|
||||
};
|
||||
function loadResolver(resolver) {
|
||||
if (resolver == null) {
|
||||
return _defaultResolver.default;
|
||||
}
|
||||
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 (
|
||||
typeof loadedResolver === 'object' &&
|
||||
(loadedResolver.sync != null || loadedResolver.async != null)
|
||||
) {
|
||||
return loadedResolver;
|
||||
}
|
||||
throw new Error(
|
||||
`Resolver located at ${resolver} does not export a function or an object with "sync" and "async" props`
|
||||
);
|
||||
}
|
90
backend/apis/nodejs/node_modules/jest-resolve/build/shouldLoadAsEsm.js
generated
vendored
Normal file
90
backend/apis/nodejs/node_modules/jest-resolve/build/shouldLoadAsEsm.js
generated
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
'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) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// @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;
|
||||
}
|
1
backend/apis/nodejs/node_modules/jest-resolve/build/types.js
generated
vendored
Normal file
1
backend/apis/nodejs/node_modules/jest-resolve/build/types.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
'use strict';
|
233
backend/apis/nodejs/node_modules/jest-resolve/build/utils.js
generated
vendored
Normal file
233
backend/apis/nodejs/node_modules/jest-resolve/build/utils.js
generated
vendored
Normal file
@ -0,0 +1,233 @@
|
||||
'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) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
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,
|
||||
requireResolveFunction
|
||||
}) => {
|
||||
// we don't want to resolve the actual `jsdom` module if `jest-environment-jsdom` is not installed, but `jsdom` package is
|
||||
if (filePath === 'jsdom') {
|
||||
filePath = 'jest-environment-jsdom';
|
||||
}
|
||||
try {
|
||||
return resolveWithPrefix(undefined, {
|
||||
filePath,
|
||||
humanOptionName: 'Test environment',
|
||||
optionName: 'testEnvironment',
|
||||
prefix: 'jest-environment-',
|
||||
requireResolveFunction,
|
||||
rootDir
|
||||
});
|
||||
} catch (error) {
|
||||
if (filePath === 'jest-environment-jsdom') {
|
||||
error.message +=
|
||||
'\n\nAs of Jest 28 "jest-environment-jsdom" is no longer shipped by default, make sure to install it separately.';
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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, requireResolveFunction}
|
||||
) =>
|
||||
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, requireResolveFunction}) =>
|
||||
resolveWithPrefix(resolver, {
|
||||
filePath,
|
||||
humanOptionName: 'Jest Runner',
|
||||
optionName: 'runner',
|
||||
prefix: 'jest-runner-',
|
||||
requireResolveFunction,
|
||||
rootDir
|
||||
});
|
||||
exports.resolveRunner = resolveRunner;
|
||||
const resolveSequencer = (
|
||||
resolver,
|
||||
{filePath, rootDir, requireResolveFunction}
|
||||
) =>
|
||||
resolveWithPrefix(resolver, {
|
||||
filePath,
|
||||
humanOptionName: 'Jest Sequencer',
|
||||
optionName: 'testSequencer',
|
||||
prefix: 'jest-sequencer-',
|
||||
requireResolveFunction,
|
||||
rootDir
|
||||
});
|
||||
exports.resolveSequencer = resolveSequencer;
|
Reference in New Issue
Block a user