UNPKG

polen

Version:

A framework for delightful GraphQL developer portals

41 lines 1.5 kB
import { StackProcessor } from '../stack-processor/index.js'; import { debug } from './debug.js'; export const toHookLoad = (identifiedLoader) => { return async (...args) => { // debug(`load candidate`, { virtualIdentifier, args }) if (args[0] === identifiedLoader.identifier.resolved) { debug(`will load`, { identifier: identifiedLoader.identifier }); const result = await identifiedLoader.loader(...args); debug(`did load`, { identifier: identifiedLoader.identifier, result }); // Add moduleType for Rolldown compatibility if (result && typeof result === `string`) { return { code: result, moduleType: `js` }; } return result; } return undefined; }; }; export const toHookResolveId = (identifiedLoader) => { return id => { if (id === identifiedLoader.identifier.id) { return identifiedLoader.identifier.resolved; } return undefined; }; }; export const toHooks = (...identifiedloaders) => { const resolveId = StackProcessor.untilDefined(identifiedloaders.map(toHookResolveId)); const load = StackProcessor.untilDefined(identifiedloaders.map(toHookLoad)); return { resolveId, load, }; }; export const toPlugin = (...identifiedLoaders) => { return { name: `vite-virtual`, ...toHooks(...identifiedLoaders), }; }; //# sourceMappingURL=identified-loader.js.map