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

Function load

packages/qwik/src/optimizer/src/plugins/plugin.ts:604–670  ·  view source on GitHub ↗
(
    ctx: Rollup.PluginContext,
    id: string,
    loadOpts?: Parameters<Extract<Plugin['load'], Function>>[1]
  )

Source from the content-addressed store, hash-verified

602
603 let loadCount = 0;
604 const load = async (
605 ctx: Rollup.PluginContext,
606 id: string,
607 loadOpts?: Parameters<Extract<Plugin['load'], Function>>[1]
608 ): Promise<Rollup.LoadResult> => {
609 if (id === '\0editor') {
610 // This doesn't get used, but we need to return something
611 return '"opening in editor"';
612 }
613 if (id.startsWith('\0') || id.startsWith('/@fs/')) {
614 return;
615 }
616 const count = loadCount++;
617 const isServer = getIsServer(loadOpts);
618
619 // Virtual modules
620 if (opts.resolveQwikBuild && id === QWIK_BUILD_ID) {
621 debug(`load(${count})`, QWIK_BUILD_ID, opts.buildMode);
622 return {
623 moduleSideEffects: false,
624 code: getQwikBuildModule(isServer, opts.target),
625 };
626 }
627 if (id === QWIK_CLIENT_MANIFEST_ID) {
628 debug(`load(${count})`, QWIK_CLIENT_MANIFEST_ID, opts.buildMode);
629 return {
630 moduleSideEffects: false,
631 code: await getQwikServerManifestModule(isServer),
632 };
633 }
634
635 // QRL segments
636 const parsedId = parseId(id);
637 id = normalizePath(parsedId.pathId);
638 const outputs = isServer ? serverTransformedOutputs : clientTransformedOutputs;
639 if (devServer && !outputs.has(id)) {
640 // in dev mode, it could be that the id is a QRL segment that wasn't transformed yet
641 const parentId = parentIds.get(id);
642 if (parentId) {
643 const parentModule = devServer.moduleGraph.getModuleById(parentId);
644 if (parentModule) {
645 // building here via ctx.load doesn't seem to work (no transform), instead we use the devserver directly
646 debug(`load(${count})`, 'transforming QRL parent', parentId);
647 // We need to encode it as an absolute path
648 await devServer.transformRequest(parentModule.url);
649 // The QRL segment should exist now
650 if (!outputs.has(id)) {
651 debug(`load(${count})`, `QRL segment ${id} not found in ${parentId}`);
652 return null;
653 }
654 } else {
655 console.error(`load(${count})`, `${parentModule} does not exist!`);
656 }
657 }
658 }
659
660 const transformedModule = outputs.get(id);
661

Callers

nothing calls this directly

Calls 8

parseIdFunction · 0.90
getIsServerFunction · 0.85
debugFunction · 0.85
getQwikBuildModuleFunction · 0.85
normalizePathFunction · 0.70
hasMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…