MCPcopy
hub / github.com/freshframework/fresh / generateSnapshotServer

Function generateSnapshotServer

packages/fresh/src/dev/dev_build_cache.ts:456–553  ·  view source on GitHub ↗
(
  options: {
    outDir: string;
    buildId: string;
    clientEntry: string;
    islands: IslandModChunk[];
    // deno-lint-ignore no-explicit-any
    fsRoutesFiles: FsRouteFileNoMod<any>[];
    staticFiles: PendingStaticFile[];
    entryAssets: string[];
    writeSpecifier: (filePath: string) => string;
  },
)

Source from the content-addressed store, hash-verified

454}
455
456export async function generateSnapshotServer(
457 options: {
458 outDir: string;
459 buildId: string;
460 clientEntry: string;
461 islands: IslandModChunk[];
462 // deno-lint-ignore no-explicit-any
463 fsRoutesFiles: FsRouteFileNoMod<any>[];
464 staticFiles: PendingStaticFile[];
465 entryAssets: string[];
466 writeSpecifier: (filePath: string) => string;
467 },
468): Promise<string> {
469 const {
470 islands,
471 writeSpecifier,
472 fsRoutesFiles,
473 outDir,
474 } = options;
475
476 const islandImports = islands
477 .map((item) => {
478 const spec = writeSpecifier(item.server);
479 return `import * as ${item.name} from "${spec}";`;
480 })
481 .join("\n");
482
483 const fsRouteImports = fsRoutesFiles
484 .map((item, i) => {
485 if (item.lazy) return null;
486 const spec = writeSpecifier(item.filePath);
487 return `import * as fsRoute_${i} from "${spec}"`;
488 })
489 .filter(Boolean)
490 .join("\n");
491
492 const islandMarkers = islands.map((item) => {
493 const browser = JSON.stringify(item.browser);
494 const name = JSON.stringify(item.name);
495 const css = JSON.stringify(item.css);
496 return `islandPreparer.prepare(islands, ${item.name}, ${browser}, ${name}, ${css});`;
497 }).join("\n");
498
499 const serializedFsRoutes = fsRoutesFiles
500 .map((item, i) => {
501 const id = JSON.stringify(item.id);
502 const pattern = JSON.stringify(item.pattern);
503 const type = JSON.stringify(item.type);
504 const routePattern = JSON.stringify(item.routePattern);
505
506 let mod = "";
507 if (item.lazy) {
508 const spec = writeSpecifier(item.filePath);
509 mod = `() => import(${JSON.stringify(spec)})`;
510 } else {
511 mod = `fsRoute_${i}`;
512 }
513

Callers 2

flushMethod · 0.85
handlerFunction · 0.85

Calls 2

prepareStaticFileFunction · 0.85
allMethod · 0.80

Tested by

no test coverage detected