MCPcopy Index your code
hub / github.com/QwikDev/qwik / resolveId

Function resolveId

packages/qwik/src/optimizer/src/plugins/plugin.ts:439–601  ·  view source on GitHub ↗
(
    ctx: Rollup.PluginContext,
    id: string,
    importerId: string | undefined,
    resolveOpts?: Parameters<Extract<Plugin['resolveId'], Function>>[2]
  )

Source from the content-addressed store, hash-verified

437 * `load()` phase ensure it is built first.
438 */
439 const resolveId = async (
440 ctx: Rollup.PluginContext,
441 id: string,
442 importerId: string | undefined,
443 resolveOpts?: Parameters<Extract<Plugin['resolveId'], Function>>[2]
444 ) => {
445 if (id.startsWith('\0')) {
446 return;
447 }
448
449 // Intercept requests to open in editor
450 const editMatch = devServer && /^(.*)\?editor(:(\d+)(:\d+)?)?$/.exec(id);
451 if (editMatch) {
452 // Throttle so we don't open multiple times on re-resolve
453 if (!doNotEdit) {
454 doNotEdit = true;
455 setTimeout(() => (doNotEdit = false), 500);
456
457 const [, origId, location] = editMatch;
458 // Find the actual file on disk by asking vite to resolve it
459 const resolved = await ctx.resolve(origId, importerId);
460 if (resolved) {
461 const file = devServer!.moduleGraph.getModuleById(resolved.id)?.file;
462 if (file) {
463 const path = `${file}${location}`;
464 try {
465 console.warn(`Opening in editor: ${path}`);
466 const launchEditor = (await import('launch-editor')).default;
467 launchEditor(path);
468 } catch (e: any) {
469 console.error(`Failed to open editor: ${e.message}`);
470 }
471 }
472 }
473 }
474 return { id: `\0editor` };
475 }
476
477 const count = resolveIdCount++;
478 const isServer = getIsServer(resolveOpts);
479 debug(`resolveId(${count})`, `begin ${id} | ${isServer ? 'server' : 'client'} | ${importerId}`);
480
481 const parsedImporterId = importerId && parseId(importerId);
482 importerId = parsedImporterId && normalizePath(parsedImporterId.pathId);
483
484 // Relative paths must be resolved vs the importer
485 if (id.startsWith('.') && parsedImporterId) {
486 const path = getPath();
487 const importerDir = path.dirname(parsedImporterId.pathId);
488 if (importerDir) {
489 id = path.resolve(importerDir, id);
490 }
491 }
492
493 // Split query, remove windows path encoding etc
494 const parsedId = parseId(id);
495 const pathId = normalizePath(parsedId.pathId);
496

Callers

nothing calls this directly

Calls 9

parseIdFunction · 0.90
getIsServerFunction · 0.85
debugFunction · 0.85
getPathFunction · 0.85
normalizePathFunction · 0.70
resolveMethod · 0.65
dirnameMethod · 0.65
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…