@qwik.dev/router 2.0.0-beta.39 → 2.0.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapters/azure-swa/vite/index.mjs +45 -54
- package/lib/adapters/bun-server/vite/index.mjs +16 -22
- package/lib/adapters/cloud-run/vite/index.mjs +15 -19
- package/lib/adapters/cloudflare-pages/vite/index.mjs +46 -67
- package/lib/adapters/deno-server/vite/index.mjs +25 -39
- package/lib/adapters/netlify-edge/vite/index.mjs +50 -76
- package/lib/adapters/node-server/vite/index.mjs +16 -22
- package/lib/adapters/shared/vite/index.mjs +271 -360
- package/lib/adapters/ssg/vite/index.mjs +11 -15
- package/lib/adapters/vercel-edge/vite/index.mjs +74 -95
- package/lib/chunks/dev-preloaded-route-loader.mjs +2 -3
- package/lib/chunks/format.mjs +16 -23
- package/lib/chunks/fs.mjs +93 -106
- package/lib/chunks/head.qwik.mjs +1174 -1382
- package/lib/chunks/http-error.qwik.mjs +20 -28
- package/lib/chunks/pathname.mjs +50 -69
- package/lib/chunks/request-body-limit.mjs +25 -35
- package/lib/chunks/request-path.mjs +44 -55
- package/lib/chunks/routes.mjs +20 -41
- package/lib/chunks/server-error.mjs +15 -18
- package/lib/chunks/system.mjs +258 -326
- package/lib/chunks/url.mjs +56 -58
- package/lib/chunks/user-response.mjs +1616 -1804
- package/lib/chunks/worker-thread.mjs +254 -307
- package/lib/index.qwik.mjs +1637 -1918
- package/lib/middleware/aws-lambda/index.mjs +44 -52
- package/lib/middleware/azure-swa/index.mjs +85 -94
- package/lib/middleware/bun/index.mjs +118 -138
- package/lib/middleware/cloudflare-pages/index.mjs +83 -96
- package/lib/middleware/deno/index.mjs +104 -125
- package/lib/middleware/firebase/index.mjs +21 -25
- package/lib/middleware/netlify-edge/index.mjs +63 -71
- package/lib/middleware/node/index.mjs +297 -357
- package/lib/middleware/request-handler/index.mjs +110 -133
- package/lib/middleware/vercel-edge/index.mjs +82 -98
- package/lib/service-worker/index.mjs +12 -3
- package/lib/ssg/index.mjs +249 -289
- package/lib/vite/index.mjs +2344 -3030
- package/package.json +5 -5
- package/lib/chunks/use-functions.qwik.mjs +0 -23
package/lib/ssg/index.mjs
CHANGED
|
@@ -1,297 +1,257 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import { n as getPathnameForDynamicRoute, t as ensureSlash } from "../chunks/pathname.mjs";
|
|
2
|
+
import { r as msToString } from "../chunks/format.mjs";
|
|
3
|
+
import { t as createRouteTester } from "../chunks/routes.mjs";
|
|
4
|
+
import { relative } from "node:path";
|
|
5
|
+
import { bold, dim, green, magenta, red } from "kleur/colors";
|
|
7
6
|
function validateOptions(opts) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
new URL(siteOrigin);
|
|
21
|
-
} catch (e) {
|
|
22
|
-
throw new Error(`Invalid "origin"`, {
|
|
23
|
-
cause: e
|
|
24
|
-
});
|
|
25
|
-
}
|
|
7
|
+
if (!opts.qwikRouterConfig) throw new Error(`Missing "qwikRouterConfig" option`);
|
|
8
|
+
let siteOrigin = opts.origin;
|
|
9
|
+
if (typeof siteOrigin !== "string" || siteOrigin.trim().length === 0) throw new Error(`Missing "origin" option`);
|
|
10
|
+
siteOrigin = siteOrigin.trim();
|
|
11
|
+
if (!/:\/\//.test(siteOrigin) || siteOrigin.startsWith("://")) throw new Error(`"origin" must start with a valid protocol, such as "https://" or "http://", received "${siteOrigin}"`);
|
|
12
|
+
try {
|
|
13
|
+
new URL(siteOrigin);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
throw new Error(`Invalid "origin"`, { cause: e });
|
|
16
|
+
}
|
|
26
17
|
}
|
|
27
18
|
async function mainThread(sys) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
${
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
if (node._W && typeof node._W === "object") {
|
|
216
|
-
const childNode = node._W;
|
|
217
|
-
const paramName = childNode._P;
|
|
218
|
-
const pathPart = paramName ? `[${paramName}]` : "[param]";
|
|
219
|
-
await traverseRouteTree(childNode, [
|
|
220
|
-
...pathParts,
|
|
221
|
-
pathPart
|
|
222
|
-
], basePathname, currentLoaders);
|
|
223
|
-
}
|
|
224
|
-
if (node._A && typeof node._A === "object") {
|
|
225
|
-
const childNode = node._A;
|
|
226
|
-
const paramName = childNode._P;
|
|
227
|
-
const pathPart = paramName ? `[...${paramName}]` : "[...rest]";
|
|
228
|
-
await traverseRouteTree(childNode, [
|
|
229
|
-
...pathParts,
|
|
230
|
-
pathPart
|
|
231
|
-
], basePathname, currentLoaders);
|
|
232
|
-
}
|
|
233
|
-
for (const [key, child] of Object.entries(node)) {
|
|
234
|
-
if (key.charCodeAt(0) === 95) {
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
const childNode = child;
|
|
238
|
-
await traverseRouteTree(childNode, [
|
|
239
|
-
...pathParts,
|
|
240
|
-
key
|
|
241
|
-
], basePathname, currentLoaders);
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
const loadStaticRoutes = async () => {
|
|
245
|
-
log.debug("traversing route tree...");
|
|
246
|
-
await traverseRouteTree(routes, [], "/", []);
|
|
247
|
-
log.debug(`route tree traversed, ${queue.length} routes queued, ${active.size} active`);
|
|
248
|
-
isRoutesLoaded = true;
|
|
249
|
-
flushQueue();
|
|
250
|
-
};
|
|
251
|
-
loadStaticRoutes().catch((e) => {
|
|
252
|
-
console.error("SSG route loading failed", e);
|
|
253
|
-
reject(e);
|
|
254
|
-
});
|
|
255
|
-
} catch (e) {
|
|
256
|
-
console.error("SSG main thread failed", e);
|
|
257
|
-
reject(e);
|
|
258
|
-
}
|
|
259
|
-
});
|
|
19
|
+
const opts = sys.getOptions();
|
|
20
|
+
validateOptions(opts);
|
|
21
|
+
const main = await sys.createMainProcess();
|
|
22
|
+
const log = await sys.createLogger();
|
|
23
|
+
log.info("\n" + bold(green("Starting Qwik Router SSG...")));
|
|
24
|
+
const qwikRouterConfig = opts.qwikRouterConfig;
|
|
25
|
+
const renderTimeout = 3e4;
|
|
26
|
+
const queue = [];
|
|
27
|
+
const active = /* @__PURE__ */ new Set();
|
|
28
|
+
const routes = qwikRouterConfig.routes;
|
|
29
|
+
const trailingSlash = !!qwikRouterConfig.trailingSlash;
|
|
30
|
+
const includeRoute = createRouteTester(opts.basePathname || "/", opts.include, opts.exclude);
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
try {
|
|
33
|
+
const timer = sys.createTimer();
|
|
34
|
+
const generatorResult = {
|
|
35
|
+
duration: 0,
|
|
36
|
+
rendered: 0,
|
|
37
|
+
errors: 0,
|
|
38
|
+
staticPaths: []
|
|
39
|
+
};
|
|
40
|
+
let isCompleted = false;
|
|
41
|
+
let isRoutesLoaded = false;
|
|
42
|
+
const completed = async () => {
|
|
43
|
+
const closePromise = main.close();
|
|
44
|
+
generatorResult.duration = timer();
|
|
45
|
+
if (generatorResult.errors === 0) {
|
|
46
|
+
log.info(`\n${green("SSG results")}`);
|
|
47
|
+
if (generatorResult.rendered > 0) log.info(`- Generated: ${dim(`${generatorResult.rendered} page${generatorResult.rendered === 1 ? "" : "s"}`)}`);
|
|
48
|
+
log.info(`- Duration: ${dim(msToString(generatorResult.duration))}`);
|
|
49
|
+
const total = generatorResult.rendered + generatorResult.errors;
|
|
50
|
+
if (total > 0) log.info(`- Average: ${dim(msToString(generatorResult.duration / total) + " per page")}`);
|
|
51
|
+
log.info(``);
|
|
52
|
+
}
|
|
53
|
+
closePromise.then(() => {
|
|
54
|
+
setTimeout(() => resolve(generatorResult));
|
|
55
|
+
}).catch(reject);
|
|
56
|
+
};
|
|
57
|
+
const next = () => {
|
|
58
|
+
while (!isCompleted && main.hasAvailableWorker() && queue.length > 0) {
|
|
59
|
+
const staticRoute = queue.shift();
|
|
60
|
+
if (staticRoute) render(staticRoute).catch((e) => {
|
|
61
|
+
console.error(`render failed for ${staticRoute.pathname}`, e);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (!isCompleted && isRoutesLoaded && queue.length === 0 && active.size === 0) {
|
|
65
|
+
isCompleted = true;
|
|
66
|
+
completed().catch((e) => {
|
|
67
|
+
console.error("SSG completion failed", e);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
let isPendingDrain = false;
|
|
72
|
+
const flushQueue = () => {
|
|
73
|
+
if (!isPendingDrain) {
|
|
74
|
+
isPendingDrain = true;
|
|
75
|
+
setTimeout(() => {
|
|
76
|
+
isPendingDrain = false;
|
|
77
|
+
next();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const render = async (staticRoute) => {
|
|
82
|
+
try {
|
|
83
|
+
active.add(staticRoute.pathname);
|
|
84
|
+
log.debug(`render start: ${staticRoute.pathname}`);
|
|
85
|
+
const result = await Promise.race([main.render({
|
|
86
|
+
type: "render",
|
|
87
|
+
...staticRoute
|
|
88
|
+
}), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error(`SSG render timed out after ${renderTimeout}ms`)), renderTimeout))]);
|
|
89
|
+
active.delete(staticRoute.pathname);
|
|
90
|
+
log.debug(`render done: ${staticRoute.pathname}`);
|
|
91
|
+
if (result.error) {
|
|
92
|
+
const err = new Error(result.error.message);
|
|
93
|
+
err.stack = result.error.stack;
|
|
94
|
+
log.error(`\n${bold(red(`!!! ${result.pathname}: Error during SSG`))}`);
|
|
95
|
+
log.error(red(err.message));
|
|
96
|
+
log.error(` Pathname: ${magenta(staticRoute.pathname)}`);
|
|
97
|
+
if (err.stack) log.error(dim(err.stack));
|
|
98
|
+
generatorResult.errors++;
|
|
99
|
+
}
|
|
100
|
+
if (result.filePath != null) {
|
|
101
|
+
generatorResult.rendered++;
|
|
102
|
+
generatorResult.staticPaths.push(result.pathname);
|
|
103
|
+
const base = opts.rootDir ?? opts.outDir;
|
|
104
|
+
const path = relative(base, result.filePath);
|
|
105
|
+
const lastSlash = path.lastIndexOf("/");
|
|
106
|
+
log.info(`${dim(path.slice(0, lastSlash + 1))}${path.slice(lastSlash + 1)}`);
|
|
107
|
+
}
|
|
108
|
+
flushQueue();
|
|
109
|
+
} catch (e) {
|
|
110
|
+
console.error(`render failed for ${staticRoute.pathname}`, e);
|
|
111
|
+
isCompleted = true;
|
|
112
|
+
reject(e);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const addToQueue = (pathname, params) => {
|
|
116
|
+
if (pathname) {
|
|
117
|
+
pathname = new URL(pathname, `https://qwik.dev`).pathname;
|
|
118
|
+
if (pathname !== opts.basePathname) {
|
|
119
|
+
if (trailingSlash) {
|
|
120
|
+
if (!pathname.endsWith("/")) {
|
|
121
|
+
const segments = pathname.split("/");
|
|
122
|
+
if (!segments[segments.length - 1].includes(".")) pathname = ensureSlash(pathname);
|
|
123
|
+
}
|
|
124
|
+
} else if (pathname.endsWith("/")) pathname = pathname.slice(0, pathname.length - 1);
|
|
125
|
+
}
|
|
126
|
+
if (includeRoute(pathname) && !queue.some((s) => s.pathname === pathname)) {
|
|
127
|
+
queue.push({
|
|
128
|
+
pathname,
|
|
129
|
+
params
|
|
130
|
+
});
|
|
131
|
+
flushQueue();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Traverse the route tree and call the callback for each route that has module loaders.
|
|
137
|
+
* Reconstructs the original pathname and param names from the tree path. Accumulates _L
|
|
138
|
+
* layout loaders from ancestors during traversal.
|
|
139
|
+
*/ const traverseRouteTree = async (node, pathParts, basePathname, ancestorLoaders) => {
|
|
140
|
+
const currentLoaders = node._L ? [...ancestorLoaders, node._L] : ancestorLoaders;
|
|
141
|
+
const index = node._I;
|
|
142
|
+
if (index) {
|
|
143
|
+
const pageLoaders = Array.isArray(index) ? index : [...currentLoaders, index];
|
|
144
|
+
const joinedParts = pathParts.join("/");
|
|
145
|
+
const originalPathname = basePathname + (joinedParts ? ensureSlash(joinedParts) : "");
|
|
146
|
+
const paramNames = pathParts.filter((p) => p.startsWith("[") && p.endsWith("]")).map((p) => p.startsWith("[...") ? p.slice(4, -1) : p.slice(1, -1));
|
|
147
|
+
if (paramNames.length === 0) addToQueue(originalPathname, void 0);
|
|
148
|
+
else {
|
|
149
|
+
const pageLoader = pageLoaders[pageLoaders.length - 1];
|
|
150
|
+
if (typeof pageLoader === "function") {
|
|
151
|
+
const pageModule = await pageLoader();
|
|
152
|
+
if (typeof pageModule.onStaticGenerate === "function") {
|
|
153
|
+
const staticGenerate = await pageModule.onStaticGenerate({ env: { get(key) {
|
|
154
|
+
return sys.getEnv(key);
|
|
155
|
+
} } });
|
|
156
|
+
if (Array.isArray(staticGenerate.params)) for (const params of staticGenerate.params) {
|
|
157
|
+
const pathname = getPathnameForDynamicRoute(originalPathname, paramNames, params);
|
|
158
|
+
addToQueue(pathname, params);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (node._4 || node._E) {
|
|
165
|
+
if (!pathParts.some((p) => p.startsWith("["))) {
|
|
166
|
+
const joinedParts = pathParts.join("/");
|
|
167
|
+
const dirPathname = basePathname + (joinedParts ? ensureSlash(joinedParts) : "");
|
|
168
|
+
addToQueue(dirPathname + "404.html", void 0);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (node._M) for (const group of node._M) await traverseRouteTree(group, pathParts, basePathname, currentLoaders);
|
|
172
|
+
if (node._W && typeof node._W === "object") {
|
|
173
|
+
const childNode = node._W;
|
|
174
|
+
const paramName = childNode._P;
|
|
175
|
+
const pathPart = paramName ? `[${paramName}]` : "[param]";
|
|
176
|
+
await traverseRouteTree(childNode, [...pathParts, pathPart], basePathname, currentLoaders);
|
|
177
|
+
}
|
|
178
|
+
if (node._A && typeof node._A === "object") {
|
|
179
|
+
const childNode = node._A;
|
|
180
|
+
const paramName = childNode._P;
|
|
181
|
+
const pathPart = paramName ? `[...${paramName}]` : "[...rest]";
|
|
182
|
+
await traverseRouteTree(childNode, [...pathParts, pathPart], basePathname, currentLoaders);
|
|
183
|
+
}
|
|
184
|
+
for (const [key, child] of Object.entries(node)) {
|
|
185
|
+
if (key.charCodeAt(0) === 95) continue;
|
|
186
|
+
await traverseRouteTree(child, [...pathParts, key], basePathname, currentLoaders);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const loadStaticRoutes = async () => {
|
|
190
|
+
log.debug("traversing route tree...");
|
|
191
|
+
await traverseRouteTree(routes, [], "/", []);
|
|
192
|
+
log.debug(`route tree traversed, ${queue.length} routes queued, ${active.size} active`);
|
|
193
|
+
isRoutesLoaded = true;
|
|
194
|
+
flushQueue();
|
|
195
|
+
};
|
|
196
|
+
loadStaticRoutes().catch((e) => {
|
|
197
|
+
console.error("SSG route loading failed", e);
|
|
198
|
+
reject(e);
|
|
199
|
+
});
|
|
200
|
+
} catch (e) {
|
|
201
|
+
console.error("SSG main thread failed", e);
|
|
202
|
+
reject(e);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
260
205
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
206
|
+
/**
|
|
207
|
+
* Use this function when SSG should be generated from another module, such as a Vite plugin. This
|
|
208
|
+
* function's should be passed the paths of the entry module and Qwik Router Plan.
|
|
209
|
+
*
|
|
210
|
+
* @public
|
|
211
|
+
*/ async function generate(opts) {
|
|
212
|
+
const { createSystem } = await import("../chunks/system.mjs");
|
|
213
|
+
return mainThread(await createSystem(opts));
|
|
266
214
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Run SSG as a standalone process. Writes `_static-paths.json` to `outDir` and exits with code 0 on
|
|
217
|
+
* success, 1 on error.
|
|
218
|
+
*
|
|
219
|
+
* Intended to be called from a generated `run-ssg.js` wrapper that provides render/config.
|
|
220
|
+
*
|
|
221
|
+
* @public
|
|
222
|
+
*/ async function runSsg(opts) {
|
|
223
|
+
try {
|
|
224
|
+
const result = await generate(opts);
|
|
225
|
+
const fs = await import("node:fs");
|
|
226
|
+
const { join } = await import("node:path");
|
|
227
|
+
const staticPathsFile = join(opts.outDir, "_static-paths.json");
|
|
228
|
+
await fs.promises.writeFile(staticPathsFile, JSON.stringify(result.staticPaths));
|
|
229
|
+
if (result.errors > 0) {
|
|
230
|
+
console.error(`SSG completed with ${result.errors} error(s)`);
|
|
231
|
+
process.exit(1);
|
|
232
|
+
}
|
|
233
|
+
process.exit(0);
|
|
234
|
+
} catch (e) {
|
|
235
|
+
console.error("SSG failed:", e);
|
|
236
|
+
process.exit(1);
|
|
237
|
+
}
|
|
283
238
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
239
|
+
/**
|
|
240
|
+
* Bootstrap a worker thread for SSG rendering. Called from the generated `run-ssg.js` when it
|
|
241
|
+
* detects it's running as a worker thread.
|
|
242
|
+
*
|
|
243
|
+
* @param opts - Must include `render` and `qwikRouterConfig` (imported by the worker entry). The
|
|
244
|
+
* remaining serializable options come from `workerData`.
|
|
245
|
+
* @public
|
|
246
|
+
*/ async function startWorker(opts) {
|
|
247
|
+
const { workerData } = await import("node:worker_threads");
|
|
248
|
+
const mergedOpts = {
|
|
249
|
+
...workerData,
|
|
250
|
+
render: opts.render,
|
|
251
|
+
qwikRouterConfig: opts.qwikRouterConfig
|
|
252
|
+
};
|
|
253
|
+
const { createSystem } = await import("../chunks/system.mjs");
|
|
254
|
+
const { workerThread } = await import("../chunks/worker-thread.mjs");
|
|
255
|
+
await workerThread(await createSystem(mergedOpts, workerData?.threadId));
|
|
295
256
|
}
|
|
296
|
-
|
|
297
257
|
export { generate, runSsg, startWorker };
|