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

Method resolve

lib/internal/modules/esm/hooks.js:224–345  ·  view source on GitHub ↗

* Resolve the location of the module. * * Internally, this behaves like a backwards iterator, wherein the stack of * hooks starts at the top and each call to `nextResolve()` moves down 1 step * until it reaches the bottom or short-circuits. * @param {string} originalSpecifier The spec

(
    originalSpecifier,
    parentURL,
    importAttributes = { __proto__: null },
  )

Source from the content-addressed store, hash-verified

222 * @returns {Promise<{ format: string, url: URL['href'] }>}
223 */
224 async resolve(
225 originalSpecifier,
226 parentURL,
227 importAttributes = { __proto__: null },
228 ) {
229 throwIfInvalidParentURL(parentURL);
230
231 const chain = this.#chains.resolve;
232 const context = {
233 conditions: getDefaultConditions(),
234 importAttributes,
235 parentURL,
236 };
237 const meta = {
238 chainFinished: null,
239 context,
240 hookErrIdentifier: '',
241 hookName: 'resolve',
242 shortCircuited: false,
243 };
244
245 const validateArgs = (hookErrIdentifier, suppliedSpecifier, ctx) => {
246 validateString(
247 suppliedSpecifier,
248 `${hookErrIdentifier} specifier`,
249 ); // non-strings can be coerced to a URL string
250
251 if (ctx) { validateObject(ctx, `${hookErrIdentifier} context`); }
252 };
253 const validateOutput = (hookErrIdentifier, output) => {
254 if (typeof output !== 'object' || output === null) { // [2]
255 throw new ERR_INVALID_RETURN_VALUE(
256 'an object',
257 hookErrIdentifier,
258 output,
259 );
260 }
261 };
262
263 const nextResolve = nextHookFactory(chain[chain.length - 1], meta, { validateArgs, validateOutput });
264
265 const resolution = await nextResolve(originalSpecifier, defineImportAssertionAlias(context));
266 const { hookErrIdentifier } = meta; // Retrieve the value after all settled
267
268 validateOutput(hookErrIdentifier, resolution);
269
270 if (resolution?.shortCircuit === true) { meta.shortCircuited = true; }
271
272 if (!meta.chainFinished && !meta.shortCircuited) {
273 throw new ERR_LOADER_CHAIN_INCOMPLETE(hookErrIdentifier);
274 }
275
276 let resolvedImportAttributes;
277 const {
278 format,
279 url,
280 } = resolution;
281

Callers 8

#resolveMethod · 0.45
_readPackageFunction · 0.45
tryPackageFunction · 0.45
tryFileFunction · 0.45
tryPackageMapResolveCJSFunction · 0.45
resolveExportsFunction · 0.45
loader.jsFile · 0.45

Calls 7

throwIfInvalidParentURLFunction · 0.85
getDefaultConditionsFunction · 0.85
nextHookFactoryFunction · 0.85
hasMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected