MCPcopy
hub / github.com/jestjs/jest / resolvePaths

Method resolvePaths

packages/jest-runtime/src/internals/cjsRequire.ts:172–197  ·  view source on GitHub ↗
(
    from: string,
    moduleName: string | undefined,
  )

Source from the content-addressed store, hash-verified

170 }
171
172 private resolvePaths(
173 from: string,
174 moduleName: string | undefined,
175 ): Array<string> | null {
176 const fromDir = path.resolve(from, '..');
177 if (moduleName == null) {
178 throw new Error(
179 'The first argument to require.resolve.paths must be a string. Received null or undefined.',
180 );
181 }
182 if (moduleName.length === 0) {
183 throw new Error(
184 'The first argument to require.resolve.paths must not be the empty string.',
185 );
186 }
187
188 if (moduleName[0] === '.') {
189 return [fromDir];
190 }
191 if (this.resolution.isCoreModule(moduleName)) {
192 return null;
193 }
194 const modulePaths = this.resolution.getModulePaths(fromDir);
195 const globalPaths = this.resolution.getGlobalPaths(moduleName);
196 return [...modulePaths, ...globalPaths];
197 }
198}
199
200export interface CoreModuleProviderOptions {

Callers 1

forMethod · 0.95

Calls 4

resolveMethod · 0.45
isCoreModuleMethod · 0.45
getModulePathsMethod · 0.45
getGlobalPathsMethod · 0.45

Tested by

no test coverage detected