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

Function defaultResolve

lib/internal/modules/cjs/loader.js:1186–1214  ·  view source on GitHub ↗
(specifier, context)

Source from the content-addressed store, hash-verified

1184
1185 // This is used as the last nextResolve for the resolve hooks.
1186 function defaultResolve(specifier, context) {
1187 // TODO(joyeecheung): parent and isMain should be part of context, then we
1188 // no longer need to use a different defaultResolve for every resolution.
1189 // In the hooks, context.conditions is passed around as an array, but internally
1190 // the resolution helpers expect a SafeSet. Do the conversion here.
1191 let conditionSet;
1192 const conditions = context.conditions;
1193 if (conditions !== undefined && conditions !== getCjsConditionsArray()) {
1194 if (!ArrayIsArray(conditions)) {
1195 throw new ERR_INVALID_ARG_VALUE('context.conditions', conditions,
1196 'expected an array');
1197 }
1198 conditionSet = new SafeSet(conditions);
1199 } else {
1200 conditionSet = getCjsConditions();
1201 }
1202
1203 const result = defaultResolveImpl(specifier, parent, isMain, {
1204 __proto__: null,
1205 paths: requireResolveOptions?.paths,
1206 conditions: conditionSet,
1207 });
1208 // If the default resolver does not return a URL, convert it for the public API.
1209 result.url ??= convertCJSFilenameToURL(result.filename);
1210
1211 // Remove filename because it's not part of the public API.
1212 // TODO(joyeecheung): maybe expose it in the public API to avoid re-conversion for users too.
1213 return { __proto__: null, url: result.url, format: result.format };
1214 }
1215
1216 const resolveResult = resolveWithHooks(specifier, parentURL, /* importAttributes */ undefined,
1217 getCjsConditionsArray(), defaultResolve);

Callers 9

findPackageJSONFunction · 0.50
resolveWithHooksFunction · 0.50
checkSyntaxFunction · 0.50
mainFunction · 0.50
resolveFunction · 0.50
resolveFunction · 0.50
resolveFunction · 0.50
resolveFunction · 0.50

Calls 3

getCjsConditionsArrayFunction · 0.85
getCjsConditionsFunction · 0.85
convertCJSFilenameToURLFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…