MCPcopy Index your code
hub / github.com/nodejs/node / tryLoadModuleUsingPaths

Function tryLoadModuleUsingPaths

test/fixtures/snapshot/typescript.js:44385–44413  ·  view source on GitHub ↗
(extensions, moduleName, baseDirectory, paths, pathPatterns, loader, onlyRecordFailures, state)

Source from the content-addressed store, hash-verified

44383 return loader(extensions, candidate, !nodeModulesDirectoryExists, state);
44384 }
44385 function tryLoadModuleUsingPaths(extensions, moduleName, baseDirectory, paths, pathPatterns, loader, onlyRecordFailures, state) {
44386 pathPatterns || (pathPatterns = ts.tryParsePatterns(paths));
44387 var matchedPattern = ts.matchPatternOrExact(pathPatterns, moduleName);
44388 if (matchedPattern) {
44389 var matchedStar_1 = ts.isString(matchedPattern) ? undefined : ts.matchedText(matchedPattern, moduleName);
44390 var matchedPatternText = ts.isString(matchedPattern) ? matchedPattern : ts.patternText(matchedPattern);
44391 if (state.traceEnabled) {
44392 trace(state.host, ts.Diagnostics.Module_name_0_matched_pattern_1, moduleName, matchedPatternText);
44393 }
44394 var resolved = ts.forEach(paths[matchedPatternText], function (subst) {
44395 var path = matchedStar_1 ? subst.replace("*", matchedStar_1) : subst;
44396 // When baseUrl is not specified, the command line parser resolves relative paths to the config file location.
44397 var candidate = ts.normalizePath(ts.combinePaths(baseDirectory, path));
44398 if (state.traceEnabled) {
44399 trace(state.host, ts.Diagnostics.Trying_substitution_0_candidate_module_location_Colon_1, subst, path);
44400 }
44401 // A path mapping may have an extension, in contrast to an import, which should omit it.
44402 var extension = ts.tryGetExtensionFromPath(subst);
44403 if (extension !== undefined) {
44404 var path_1 = tryFile(candidate, onlyRecordFailures, state);
44405 if (path_1 !== undefined) {
44406 return noPackageId({ path: path_1, ext: extension });
44407 }
44408 }
44409 return loader(extensions, candidate, onlyRecordFailures || !ts.directoryProbablyExists(ts.getDirectoryPath(candidate), state.host), state);
44410 });
44411 return { value: resolved };
44412 }
44413 }
44414 /** Double underscores are used in DefinitelyTyped to delimit scoped packages. */
44415 var mangledScopedPackageSeparator = "__";
44416 /** For a scoped package, we must look in `@types/foo__bar` instead of `@types/@foo/bar`. */

Calls 5

traceFunction · 0.85
noPackageIdFunction · 0.85
tryFileFunction · 0.70
loaderFunction · 0.70
forEachMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…