MCPcopy Create free account
hub / github.com/observablehq/framework / renderModule

Function renderModule

src/render.ts:292–312  ·  view source on GitHub ↗
(
  root: string,
  path: string,
  {resolveImport = getModuleResolver(root, path), ...options}: RenderModuleOptions = {}
)

Source from the content-addressed store, hash-verified

290export type RenderModuleOptions = Omit<TranspileModuleOptions, "root" | "path" | "servePath" | "params">;
291
292export async function renderModule(
293 root: string,
294 path: string,
295 {resolveImport = getModuleResolver(root, path), ...options}: RenderModuleOptions = {}
296): Promise<string> {
297 const module = findModule(root, path);
298 if (!module) throw enoent(path);
299 const imports = new Set<string>();
300 const resolutions = new Set<string>();
301 for (const i of await getModuleStaticImports(root, path)) {
302 const r = await resolveImport(i);
303 if (!resolutions.has(r)) {
304 resolutions.add(r);
305 imports.add(i);
306 }
307 }
308 const input = Array.from(imports, (i) => `import ${JSON.stringify(i)};\n`)
309 .concat(`export * from ${JSON.stringify(path)};\n`)
310 .join("");
311 return await transpileModule(input, {root, path, servePath: path, params: module.params, resolveImport, ...options});
312}

Callers 2

PreviewServerClass · 0.85
buildFunction · 0.85

Calls 7

getModuleResolverFunction · 0.85
findModuleFunction · 0.85
enoentFunction · 0.85
getModuleStaticImportsFunction · 0.85
transpileModuleFunction · 0.85
fromMethod · 0.80
resolveImportFunction · 0.70

Tested by

no test coverage detected