MCPcopy
hub / github.com/sveltejs/kit / prerender

Function prerender

packages/kit/src/core/postbuild/prerender.js:37–568  ·  view source on GitHub ↗

* @param {{ * hash: boolean; * out: string; * manifest_path: string; * metadata: import('types').ServerMetadata; * verbose: boolean; * env: Record * }} opts

({ hash, out, manifest_path, metadata, verbose, env })

Source from the content-addressed store, hash-verified

35 * }} opts
36 */
37async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
38 /** @type {import('@sveltejs/kit').SSRManifest} */
39 const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;
40
41 /** @type {import('types').ServerInternalModule} */
42 const internal = await import(pathToFileURL(`${out}/server/internal.js`).href);
43
44 /** @type {import('types').ServerModule} */
45 const { Server } = await import(pathToFileURL(`${out}/server/index.js`).href);
46
47 // configure `import { building } from '$app/environment'` —
48 // essential we do this before analysing the code
49 internal.set_building();
50 internal.set_prerendering();
51
52 /**
53 * @template {{message: string}} T
54 * @template {Omit<T, 'message'>} K
55 * @param {import('types').Logger} log
56 * @param {'fail' | 'warn' | 'ignore' | ((details: T) => void)} input
57 * @param {(details: K) => string} format
58 * @returns {(details: K) => void}
59 */
60 function normalise_error_handler(log, input, format) {
61 switch (input) {
62 case 'fail':
63 return (details) => {
64 throw new Error(format(details));
65 };
66 case 'warn':
67 return (details) => {
68 log.error(format(details));
69 };
70 case 'ignore':
71 return () => {};
72 default:
73 // @ts-expect-error TS thinks T might be of a different kind, but it's not
74 return (details) => input({ ...details, message: format(details) });
75 }
76 }
77
78 const OK = 2;
79 const REDIRECT = 3;
80
81 /** @type {import('types').Prerendered} */
82 const prerendered = {
83 pages: new Map(),
84 assets: new Map(),
85 redirects: new Map(),
86 paths: []
87 };
88
89 /** @type {import('types').PrerenderMap} */
90 const prerender_map = new Map();
91
92 for (const [id, { prerender }] of metadata.routes) {
93 if (prerender !== undefined) {
94 prerender_map.set(id, prerender);

Callers 1

handlerFunction · 0.50

Calls 15

initMethod · 0.95
load_configFunction · 0.90
mkdirpFunction · 0.90
loggerFunction · 0.90
installPolyfillsFunction · 0.90
queueFunction · 0.90
walkFunction · 0.90
posixifyFunction · 0.90
createReadableStreamFunction · 0.90
get_route_segmentsFunction · 0.90
stringify_remote_argFunction · 0.90
generate_fallbackFunction · 0.85

Tested by

no test coverage detected