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

Function loadModuleFromFile

test/fixtures/snapshot/typescript.js:43517–43532  ·  view source on GitHub ↗

* @param {boolean} onlyRecordFailures - if true then function won't try to actually load files but instead record all attempts as failures. This flag is necessary * in cases when we know upfront that all load attempts will fail (because containing folder does not exists) however we still need t

(extensions, candidate, onlyRecordFailures, state)

Source from the content-addressed store, hash-verified

43515 * in cases when we know upfront that all load attempts will fail (because containing folder does not exists) however we still need to record all failed lookup locations.
43516 */
43517 function loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) {
43518 if (extensions === Extensions.Json || extensions === Extensions.TSConfig) {
43519 var extensionLess = ts.tryRemoveExtension(candidate, ".json" /* Extension.Json */);
43520 var extension = extensionLess ? candidate.substring(extensionLess.length) : "";
43521 return (extensionLess === undefined && extensions === Extensions.Json) ? undefined : tryAddingExtensions(extensionLess || candidate, extensions, extension, onlyRecordFailures, state);
43522 }
43523 // esm mode resolutions don't include automatic extension lookup (without additional flags, at least)
43524 if (!(state.features & NodeResolutionFeatures.EsmMode)) {
43525 // First, try adding an extension. An import of "foo" could be matched by a file "foo.ts", or "foo.js" by "foo.js.ts"
43526 var resolvedByAddingExtension = tryAddingExtensions(candidate, extensions, "", onlyRecordFailures, state);
43527 if (resolvedByAddingExtension) {
43528 return resolvedByAddingExtension;
43529 }
43530 }
43531 return loadModuleFromFileNoImplicitExtensions(extensions, candidate, onlyRecordFailures, state);
43532 }
43533 function loadModuleFromFileNoImplicitExtensions(extensions, candidate, onlyRecordFailures, state) {
43534 // If that didn't work, try stripping a ".js" or ".jsx" extension and replacing it with a TypeScript one;
43535 // e.g. "./foo.js" can be matched by "./foo.ts" or "./foo.d.ts"

Calls 2

tryAddingExtensionsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…