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

Function legacyMainResolve

lib/internal/modules/esm/resolve.js:196–212  ·  view source on GitHub ↗

* Legacy CommonJS main resolution: * 1. let M = pkg_url + (json main field) * 2. TRY(M, M.js, M.json, M.node) * 3. TRY(M/index.js, M/index.json, M/index.node) * 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node) * 5. NOT_FOUND * @param {URL} packageJSONUrl * @param {import('typi

(packageJSONUrl, packageConfig, base)

Source from the content-addressed store, hash-verified

194 * @returns {URL}
195 */
196function legacyMainResolve(packageJSONUrl, packageConfig, base) {
197 assert(isURL(packageJSONUrl));
198 const pkgPath = fileURLToPath(new URL('.', packageJSONUrl));
199
200 const baseStringified = isURL(base) ? base.href : base;
201
202 const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);
203
204 const maybeMain = resolvedOption <= legacyMainResolveExtensionsIndexes.kResolvedByMainIndexNode ?
205 packageConfig.main || './' : '';
206 const resolvedPath = resolve(pkgPath, maybeMain + legacyMainResolveExtensions[resolvedOption]);
207 const resolvedUrl = pathToFileURL(resolvedPath);
208
209 emitLegacyIndexDeprecation(resolvedUrl, resolvedPath, pkgPath, base, packageConfig.main);
210
211 return resolvedUrl;
212}
213
214const encodedSepRegEx = /%2F|%5C/i;
215/**

Callers 4

packageResolveFunction · 0.85
mainFunction · 0.85

Calls 6

fileURLToPathFunction · 0.85
assertFunction · 0.50
isURLFunction · 0.50
resolveFunction · 0.50
pathToFileURLFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…