@qwik.dev/router 2.0.0-beta.13 → 2.0.0-beta.15
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 +7 -7
- package/lib/adapters/bun-server/vite/index.mjs +7 -7
- package/lib/adapters/cloud-run/vite/index.mjs +7 -7
- package/lib/adapters/cloudflare-pages/vite/index.mjs +8 -8
- package/lib/adapters/deno-server/vite/index.mjs +7 -7
- package/lib/adapters/netlify-edge/vite/index.mjs +7 -7
- package/lib/adapters/node-server/vite/index.mjs +7 -7
- package/lib/adapters/shared/vite/index.mjs +8 -8
- package/lib/adapters/ssg/vite/index.mjs +7 -8
- package/lib/adapters/vercel-edge/vite/index.mjs +7 -7
- package/lib/chunks/error-handler.mjs +2 -4
- package/lib/chunks/format-error.mjs +6 -6
- package/lib/chunks/fs.mjs +6 -27
- package/lib/chunks/index.mjs +39 -31
- package/lib/chunks/mime-types.mjs +2 -3
- package/lib/chunks/routing.qwik.mjs +23 -47
- package/lib/chunks/types.qwik.mjs +2 -5
- package/lib/index.d.ts +2 -1
- package/lib/index.qwik.mjs +48 -68
- package/lib/middleware/aws-lambda/index.mjs +4 -5
- package/lib/middleware/azure-swa/index.mjs +6 -7
- package/lib/middleware/bun/index.mjs +8 -9
- package/lib/middleware/cloudflare-pages/index.mjs +5 -6
- package/lib/middleware/deno/index.mjs +7 -8
- package/lib/middleware/firebase/index.mjs +4 -5
- package/lib/middleware/netlify-edge/index.mjs +5 -6
- package/lib/middleware/node/index.mjs +15 -11
- package/lib/middleware/request-handler/index.d.ts +2 -2
- package/lib/middleware/request-handler/index.mjs +64 -79
- package/lib/middleware/vercel-edge/index.mjs +5 -6
- package/lib/service-worker/index.mjs +2 -3
- package/lib/ssg/index.mjs +3 -4
- package/lib/vite/index.d.ts +7 -1
- package/lib/vite/index.mjs +91 -68
- package/package.json +21 -39
- package/lib/adapters/azure-swa/vite/index.cjs +0 -61
- package/lib/adapters/bun-server/vite/index.cjs +0 -27
- package/lib/adapters/cloud-run/vite/index.cjs +0 -24
- package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -65
- package/lib/adapters/deno-server/vite/index.cjs +0 -39
- package/lib/adapters/netlify-edge/vite/index.cjs +0 -88
- package/lib/adapters/node-server/vite/index.cjs +0 -27
- package/lib/adapters/shared/vite/index.cjs +0 -306
- package/lib/adapters/ssg/vite/index.cjs +0 -19
- package/lib/adapters/vercel-edge/vite/index.cjs +0 -81
- package/lib/chunks/error-handler.cjs +0 -58
- package/lib/chunks/format-error.cjs +0 -136
- package/lib/chunks/fs.cjs +0 -274
- package/lib/chunks/index.cjs +0 -877
- package/lib/chunks/mime-types.cjs +0 -52
- package/lib/chunks/routing.qwik.cjs +0 -452
- package/lib/chunks/types.qwik.cjs +0 -24
- package/lib/index.qwik.cjs +0 -1662
- package/lib/middleware/aws-lambda/index.cjs +0 -52
- package/lib/middleware/azure-swa/index.cjs +0 -92
- package/lib/middleware/bun/index.cjs +0 -143
- package/lib/middleware/cloudflare-pages/index.cjs +0 -96
- package/lib/middleware/deno/index.cjs +0 -130
- package/lib/middleware/firebase/index.cjs +0 -33
- package/lib/middleware/netlify-edge/index.cjs +0 -71
- package/lib/middleware/node/index.cjs +0 -219
- package/lib/middleware/request-handler/index.cjs +0 -1488
- package/lib/middleware/vercel-edge/index.cjs +0 -98
- package/lib/service-worker/index.cjs +0 -5
- package/lib/ssg/index.cjs +0 -15
- package/lib/vite/index.cjs +0 -2021
package/lib/chunks/index.cjs
DELETED
|
@@ -1,877 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const fs$1 = require("node:fs");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const node_os = require("node:os");
|
|
6
|
-
const node_worker_threads = require("node:worker_threads");
|
|
7
|
-
const fs = require("./fs.cjs");
|
|
8
|
-
const colors = require("kleur/colors");
|
|
9
|
-
const node_url = require("node:url");
|
|
10
|
-
const vite = require("vite");
|
|
11
|
-
const formatError = require("./format-error.cjs");
|
|
12
|
-
const requestHandler = require("@qwik.dev/router/middleware/request-handler");
|
|
13
|
-
const types = require("./types.qwik.cjs");
|
|
14
|
-
const internal = require("@qwik.dev/core/internal");
|
|
15
|
-
const web = require("node:stream/web");
|
|
16
|
-
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
17
|
-
async function createNodeMainProcess(sys, opts) {
|
|
18
|
-
const ssgWorkers = [];
|
|
19
|
-
const sitemapBuffer = [];
|
|
20
|
-
let sitemapPromise = null;
|
|
21
|
-
opts = { ...opts };
|
|
22
|
-
let outDir = opts.outDir;
|
|
23
|
-
if (typeof outDir !== "string") {
|
|
24
|
-
throw new Error(`Missing "outDir" option`);
|
|
25
|
-
}
|
|
26
|
-
if (!path.isAbsolute(outDir)) {
|
|
27
|
-
throw new Error(`"outDir" must be an absolute file path, received: ${outDir}`);
|
|
28
|
-
}
|
|
29
|
-
outDir = fs.normalizePath(outDir);
|
|
30
|
-
let maxWorkers = node_os.cpus().length;
|
|
31
|
-
if (typeof opts.maxWorkers === "number") {
|
|
32
|
-
maxWorkers = Math.max(1, Math.min(opts.maxWorkers, maxWorkers));
|
|
33
|
-
}
|
|
34
|
-
let maxTasksPerWorker = 20;
|
|
35
|
-
if (typeof opts.maxTasksPerWorker === "number") {
|
|
36
|
-
maxTasksPerWorker = Math.max(1, Math.min(opts.maxTasksPerWorker, 50));
|
|
37
|
-
}
|
|
38
|
-
let sitemapOutFile = opts.sitemapOutFile;
|
|
39
|
-
if (sitemapOutFile !== null) {
|
|
40
|
-
if (typeof sitemapOutFile !== "string") {
|
|
41
|
-
sitemapOutFile = "sitemap.xml";
|
|
42
|
-
}
|
|
43
|
-
if (!path.isAbsolute(sitemapOutFile)) {
|
|
44
|
-
sitemapOutFile = path.resolve(outDir, sitemapOutFile);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const createWorker = () => {
|
|
48
|
-
let terminateResolve = null;
|
|
49
|
-
const mainTasks = /* @__PURE__ */ new Map();
|
|
50
|
-
let workerFilePath;
|
|
51
|
-
let terminateTimeout = null;
|
|
52
|
-
if (typeof __filename === "string") {
|
|
53
|
-
const ext = path.extname(__filename) || ".js";
|
|
54
|
-
workerFilePath = path.join(path.dirname(__filename), `index${ext}`);
|
|
55
|
-
} else {
|
|
56
|
-
const thisUrl = new URL(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("chunks/index.cjs", document.baseURI).href);
|
|
57
|
-
const pathname = thisUrl.pathname || "";
|
|
58
|
-
let ext = ".js";
|
|
59
|
-
if (pathname.endsWith(".ts")) {
|
|
60
|
-
ext = ".ts";
|
|
61
|
-
} else if (pathname.endsWith(".mjs")) {
|
|
62
|
-
ext = ".mjs";
|
|
63
|
-
}
|
|
64
|
-
workerFilePath = new URL(`./index${ext}`, thisUrl);
|
|
65
|
-
}
|
|
66
|
-
const nodeWorker = new node_worker_threads.Worker(workerFilePath, { workerData: opts });
|
|
67
|
-
nodeWorker.unref();
|
|
68
|
-
const ssgWorker = {
|
|
69
|
-
activeTasks: 0,
|
|
70
|
-
totalTasks: 0,
|
|
71
|
-
render: (staticRoute) => {
|
|
72
|
-
return new Promise((resolve2, reject) => {
|
|
73
|
-
try {
|
|
74
|
-
ssgWorker.activeTasks++;
|
|
75
|
-
ssgWorker.totalTasks++;
|
|
76
|
-
mainTasks.set(staticRoute.pathname, resolve2);
|
|
77
|
-
nodeWorker.postMessage(staticRoute);
|
|
78
|
-
} catch (e) {
|
|
79
|
-
ssgWorker.activeTasks--;
|
|
80
|
-
mainTasks.delete(staticRoute.pathname);
|
|
81
|
-
reject(e);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
terminate: async () => {
|
|
86
|
-
mainTasks.clear();
|
|
87
|
-
const msg = { type: "close" };
|
|
88
|
-
await new Promise((resolve2) => {
|
|
89
|
-
terminateResolve = resolve2;
|
|
90
|
-
nodeWorker.postMessage(msg);
|
|
91
|
-
});
|
|
92
|
-
terminateTimeout = setTimeout(async () => {
|
|
93
|
-
await nodeWorker.terminate();
|
|
94
|
-
}, 1e3);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
nodeWorker.on("message", (msg) => {
|
|
98
|
-
switch (msg.type) {
|
|
99
|
-
case "render": {
|
|
100
|
-
const mainTask = mainTasks.get(msg.pathname);
|
|
101
|
-
if (mainTask) {
|
|
102
|
-
mainTasks.delete(msg.pathname);
|
|
103
|
-
ssgWorker.activeTasks--;
|
|
104
|
-
mainTask(msg);
|
|
105
|
-
}
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
case "close": {
|
|
109
|
-
if (terminateResolve) {
|
|
110
|
-
terminateResolve();
|
|
111
|
-
terminateResolve = null;
|
|
112
|
-
}
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
nodeWorker.on("error", (e) => {
|
|
118
|
-
console.error(`worker error`, e);
|
|
119
|
-
});
|
|
120
|
-
nodeWorker.on("exit", (code) => {
|
|
121
|
-
if (terminateTimeout) {
|
|
122
|
-
clearTimeout(terminateTimeout);
|
|
123
|
-
terminateTimeout = null;
|
|
124
|
-
}
|
|
125
|
-
if (code !== 0) {
|
|
126
|
-
console.error(`worker exit ${code}`);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
return ssgWorker;
|
|
130
|
-
};
|
|
131
|
-
const getNextWorker = () => ssgWorkers.sort(ssgWorkerCompare)[0];
|
|
132
|
-
const hasAvailableWorker = () => {
|
|
133
|
-
const ssgWorker = getNextWorker();
|
|
134
|
-
return ssgWorker.activeTasks < maxTasksPerWorker;
|
|
135
|
-
};
|
|
136
|
-
const render = async (ssgRoute) => {
|
|
137
|
-
const ssgWorker = getNextWorker();
|
|
138
|
-
const result = await ssgWorker.render(ssgRoute);
|
|
139
|
-
if (sitemapOutFile && result.ok && result.resourceType === "page") {
|
|
140
|
-
sitemapBuffer.push(`<url><loc>${result.url}</loc></url>`);
|
|
141
|
-
if (sitemapBuffer.length > 50) {
|
|
142
|
-
if (sitemapPromise) {
|
|
143
|
-
await sitemapPromise;
|
|
144
|
-
}
|
|
145
|
-
const siteMapUrls = sitemapBuffer.join("\n") + "\n";
|
|
146
|
-
sitemapBuffer.length = 0;
|
|
147
|
-
sitemapPromise = fs$1.promises.appendFile(sitemapOutFile, siteMapUrls);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return result;
|
|
151
|
-
};
|
|
152
|
-
const close = async () => {
|
|
153
|
-
const promises = [];
|
|
154
|
-
if (sitemapOutFile) {
|
|
155
|
-
if (sitemapPromise) {
|
|
156
|
-
await sitemapPromise;
|
|
157
|
-
}
|
|
158
|
-
sitemapBuffer.push(`</urlset>`);
|
|
159
|
-
promises.push(fs$1.promises.appendFile(sitemapOutFile, sitemapBuffer.join("\n")));
|
|
160
|
-
sitemapBuffer.length = 0;
|
|
161
|
-
}
|
|
162
|
-
for (const ssgWorker of ssgWorkers) {
|
|
163
|
-
try {
|
|
164
|
-
promises.push(ssgWorker.terminate());
|
|
165
|
-
} catch (e) {
|
|
166
|
-
console.error(e);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
await Promise.all(promises);
|
|
170
|
-
ssgWorkers.length = 0;
|
|
171
|
-
if (process.platform === "win32") {
|
|
172
|
-
await new Promise((resolve2) => setTimeout(resolve2, 300));
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
if (sitemapOutFile) {
|
|
176
|
-
await ensureDir(sitemapOutFile);
|
|
177
|
-
await fs$1.promises.writeFile(
|
|
178
|
-
sitemapOutFile,
|
|
179
|
-
`<?xml version="1.0" encoding="UTF-8"?>
|
|
180
|
-
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
181
|
-
`
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
for (let i = 0; i < maxWorkers; i++) {
|
|
185
|
-
ssgWorkers.push(createWorker());
|
|
186
|
-
if (process.platform === "win32" && i < maxWorkers - 1) {
|
|
187
|
-
await new Promise((resolve2) => setTimeout(resolve2, 100));
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
const mainCtx = {
|
|
191
|
-
hasAvailableWorker,
|
|
192
|
-
render,
|
|
193
|
-
close
|
|
194
|
-
};
|
|
195
|
-
return mainCtx;
|
|
196
|
-
}
|
|
197
|
-
function ssgWorkerCompare(a, b) {
|
|
198
|
-
if (a.activeTasks < b.activeTasks) {
|
|
199
|
-
return -1;
|
|
200
|
-
}
|
|
201
|
-
if (a.activeTasks > b.activeTasks) {
|
|
202
|
-
return 1;
|
|
203
|
-
}
|
|
204
|
-
return a.totalTasks < b.totalTasks ? -1 : 1;
|
|
205
|
-
}
|
|
206
|
-
async function createNodeWorkerProcess(onMessage) {
|
|
207
|
-
node_worker_threads.parentPort?.on("message", async (msg) => {
|
|
208
|
-
node_worker_threads.parentPort?.postMessage(await onMessage(msg));
|
|
209
|
-
if (msg.type === "close") {
|
|
210
|
-
node_worker_threads.parentPort?.close();
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
async function createSystem(opts, threadId) {
|
|
215
|
-
const createWriteStream = (filePath) => {
|
|
216
|
-
return fs$1.createWriteStream(filePath, {
|
|
217
|
-
flags: "w"
|
|
218
|
-
});
|
|
219
|
-
};
|
|
220
|
-
const NS_PER_SEC = 1e9;
|
|
221
|
-
const MS_PER_NS = 1e-6;
|
|
222
|
-
const createTimer = () => {
|
|
223
|
-
const start = process.hrtime();
|
|
224
|
-
return () => {
|
|
225
|
-
const diff = process.hrtime(start);
|
|
226
|
-
return (diff[0] * NS_PER_SEC + diff[1]) * MS_PER_NS;
|
|
227
|
-
};
|
|
228
|
-
};
|
|
229
|
-
const createLogger = async () => {
|
|
230
|
-
if (threadId !== void 0) {
|
|
231
|
-
return {
|
|
232
|
-
debug: opts.log === "debug" ? console.debug.bind(console, `[${threadId}]`) : () => {
|
|
233
|
-
},
|
|
234
|
-
error: console.error.bind(console, `[${threadId}]`),
|
|
235
|
-
info: console.info.bind(console, `[${threadId}]`)
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
return {
|
|
239
|
-
debug: opts.log === "debug" ? console.debug.bind(console) : () => {
|
|
240
|
-
},
|
|
241
|
-
error: console.error.bind(console),
|
|
242
|
-
info: console.info.bind(console)
|
|
243
|
-
};
|
|
244
|
-
};
|
|
245
|
-
const outDir = fs.normalizePath(opts.outDir);
|
|
246
|
-
const basePathname = opts.basePathname || "/";
|
|
247
|
-
const basenameLen = basePathname.length;
|
|
248
|
-
const getRouteFilePath = (pathname, isHtml) => {
|
|
249
|
-
pathname = pathname.slice(basenameLen);
|
|
250
|
-
if (isHtml) {
|
|
251
|
-
if (!pathname.endsWith(".html")) {
|
|
252
|
-
if (pathname.endsWith("/")) {
|
|
253
|
-
pathname += "index.html";
|
|
254
|
-
} else {
|
|
255
|
-
pathname += "/index.html";
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
} else {
|
|
259
|
-
if (pathname.endsWith("/")) {
|
|
260
|
-
pathname = pathname.slice(0, -1);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return path.join(outDir, pathname);
|
|
264
|
-
};
|
|
265
|
-
const getDataFilePath = (pathname) => {
|
|
266
|
-
pathname = pathname.slice(basenameLen);
|
|
267
|
-
if (pathname.endsWith("/")) {
|
|
268
|
-
pathname += "q-data.json";
|
|
269
|
-
} else {
|
|
270
|
-
pathname += "/q-data.json";
|
|
271
|
-
}
|
|
272
|
-
return path.join(outDir, pathname);
|
|
273
|
-
};
|
|
274
|
-
const sys = {
|
|
275
|
-
createMainProcess: null,
|
|
276
|
-
createWorkerProcess: createNodeWorkerProcess,
|
|
277
|
-
createLogger,
|
|
278
|
-
getOptions: () => opts,
|
|
279
|
-
ensureDir,
|
|
280
|
-
createWriteStream,
|
|
281
|
-
createTimer,
|
|
282
|
-
access,
|
|
283
|
-
getRouteFilePath,
|
|
284
|
-
getDataFilePath,
|
|
285
|
-
getEnv: (key) => process.env[key],
|
|
286
|
-
platform: {
|
|
287
|
-
static: true,
|
|
288
|
-
node: process.versions.node
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
sys.createMainProcess = () => createNodeMainProcess(sys, opts);
|
|
292
|
-
return sys;
|
|
293
|
-
}
|
|
294
|
-
const ensureDir = async (filePath) => {
|
|
295
|
-
await fs$1.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
296
|
-
};
|
|
297
|
-
const access = async (path2) => {
|
|
298
|
-
try {
|
|
299
|
-
await fs$1.promises.access(path2);
|
|
300
|
-
return true;
|
|
301
|
-
} catch {
|
|
302
|
-
return false;
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
function extractParamNames(routeName) {
|
|
306
|
-
const params = [];
|
|
307
|
-
let idx = 0;
|
|
308
|
-
while (idx < routeName.length) {
|
|
309
|
-
const start = routeName.indexOf("[", idx);
|
|
310
|
-
if (start !== -1) {
|
|
311
|
-
const end = routeName.indexOf("]", start);
|
|
312
|
-
const param = routeName.slice(start + 1, end);
|
|
313
|
-
params.push(param.startsWith("...") ? param.substring(3) : param);
|
|
314
|
-
idx = end + 1;
|
|
315
|
-
} else {
|
|
316
|
-
idx = routeName.length;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return params;
|
|
320
|
-
}
|
|
321
|
-
async function generateNotFoundPages(sys, opts, routes) {
|
|
322
|
-
if (opts.emit404Pages !== false) {
|
|
323
|
-
const basePathname = opts.basePathname || "/";
|
|
324
|
-
const rootNotFoundPathname = basePathname + "404.html";
|
|
325
|
-
const hasRootNotFound = routes.some(
|
|
326
|
-
(r) => r[types.RouteDataProp.OriginalPathname] === rootNotFoundPathname
|
|
327
|
-
);
|
|
328
|
-
if (!hasRootNotFound) {
|
|
329
|
-
const filePath = sys.getRouteFilePath(rootNotFoundPathname, true);
|
|
330
|
-
const html = requestHandler.getErrorHtml(404, "Resource Not Found");
|
|
331
|
-
await sys.ensureDir(filePath);
|
|
332
|
-
return new Promise((resolve) => {
|
|
333
|
-
const writer = sys.createWriteStream(filePath);
|
|
334
|
-
writer.write(html);
|
|
335
|
-
writer.end(resolve);
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
function createRouteTester(basePathname, includeRoutes, excludeRoutes) {
|
|
341
|
-
const includes = routesToRegExps(includeRoutes);
|
|
342
|
-
const excludes = routesToRegExps(excludeRoutes);
|
|
343
|
-
return (pathname) => {
|
|
344
|
-
if (pathname.endsWith("404.html")) {
|
|
345
|
-
return true;
|
|
346
|
-
}
|
|
347
|
-
if (basePathname !== "/") {
|
|
348
|
-
pathname = pathname.slice(basePathname.length - 1);
|
|
349
|
-
}
|
|
350
|
-
for (const exclude of excludes) {
|
|
351
|
-
if (exclude.test(pathname)) {
|
|
352
|
-
return false;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
for (const include of includes) {
|
|
356
|
-
if (include.test(pathname)) {
|
|
357
|
-
return true;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return false;
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
function routesToRegExps(routes) {
|
|
364
|
-
if (!Array.isArray(routes)) {
|
|
365
|
-
return [];
|
|
366
|
-
}
|
|
367
|
-
return routes.filter((r) => typeof r === "string").map(routeToRegExp);
|
|
368
|
-
}
|
|
369
|
-
function routeToRegExp(rule) {
|
|
370
|
-
let transformedRule;
|
|
371
|
-
if (rule === "/" || rule === "/*") {
|
|
372
|
-
transformedRule = rule;
|
|
373
|
-
} else if (rule.endsWith("/*")) {
|
|
374
|
-
transformedRule = `${rule.substring(0, rule.length - 2)}(/*)?`;
|
|
375
|
-
} else if (rule.endsWith("/")) {
|
|
376
|
-
transformedRule = `${rule.substring(0, rule.length - 1)}(/)?`;
|
|
377
|
-
} else if (rule.endsWith("*")) {
|
|
378
|
-
transformedRule = rule;
|
|
379
|
-
} else {
|
|
380
|
-
transformedRule = `${rule}(/)?`;
|
|
381
|
-
}
|
|
382
|
-
transformedRule = `^${transformedRule.replace(/\*/g, ".*")}$`;
|
|
383
|
-
return new RegExp(transformedRule);
|
|
384
|
-
}
|
|
385
|
-
async function mainThread(sys) {
|
|
386
|
-
const opts = sys.getOptions();
|
|
387
|
-
validateOptions(opts);
|
|
388
|
-
const main = await sys.createMainProcess();
|
|
389
|
-
const log = await sys.createLogger();
|
|
390
|
-
log.info("\n" + colors.bold(colors.green("Starting Qwik Router SSG...")));
|
|
391
|
-
const qwikRouterConfig = (await import(node_url.pathToFileURL(opts.qwikRouterConfigModulePath).href)).default;
|
|
392
|
-
const queue = [];
|
|
393
|
-
const active = /* @__PURE__ */ new Set();
|
|
394
|
-
const routes = qwikRouterConfig.routes || [];
|
|
395
|
-
const trailingSlash = !!qwikRouterConfig.trailingSlash;
|
|
396
|
-
const includeRoute = createRouteTester(opts.basePathname || "/", opts.include, opts.exclude);
|
|
397
|
-
return new Promise((resolve, reject) => {
|
|
398
|
-
try {
|
|
399
|
-
const timer = sys.createTimer();
|
|
400
|
-
const generatorResult = {
|
|
401
|
-
duration: 0,
|
|
402
|
-
rendered: 0,
|
|
403
|
-
errors: 0,
|
|
404
|
-
staticPaths: []
|
|
405
|
-
};
|
|
406
|
-
let isCompleted = false;
|
|
407
|
-
let isRoutesLoaded = false;
|
|
408
|
-
const completed = async () => {
|
|
409
|
-
const closePromise = main.close();
|
|
410
|
-
await generateNotFoundPages(sys, opts, routes);
|
|
411
|
-
generatorResult.duration = timer();
|
|
412
|
-
if (generatorResult.errors === 0) {
|
|
413
|
-
log.info(`
|
|
414
|
-
${colors.green("SSG results")}`);
|
|
415
|
-
if (generatorResult.rendered > 0) {
|
|
416
|
-
log.info(
|
|
417
|
-
`- Generated: ${colors.dim(
|
|
418
|
-
`${generatorResult.rendered} page${generatorResult.rendered === 1 ? "" : "s"}`
|
|
419
|
-
)}`
|
|
420
|
-
);
|
|
421
|
-
}
|
|
422
|
-
log.info(`- Duration: ${colors.dim(fs.msToString(generatorResult.duration))}`);
|
|
423
|
-
const total = generatorResult.rendered + generatorResult.errors;
|
|
424
|
-
if (total > 0) {
|
|
425
|
-
log.info(
|
|
426
|
-
`- Average: ${colors.dim(fs.msToString(generatorResult.duration / total) + " per page")}`
|
|
427
|
-
);
|
|
428
|
-
}
|
|
429
|
-
log.info(``);
|
|
430
|
-
}
|
|
431
|
-
closePromise.then(() => {
|
|
432
|
-
setTimeout(() => resolve(generatorResult));
|
|
433
|
-
}).catch(reject);
|
|
434
|
-
};
|
|
435
|
-
const next = () => {
|
|
436
|
-
while (!isCompleted && main.hasAvailableWorker() && queue.length > 0) {
|
|
437
|
-
const staticRoute = queue.shift();
|
|
438
|
-
if (staticRoute) {
|
|
439
|
-
render(staticRoute).catch((e) => {
|
|
440
|
-
console.error(`render failed for ${staticRoute.pathname}`, e);
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
if (!isCompleted && isRoutesLoaded && queue.length === 0 && active.size === 0) {
|
|
445
|
-
isCompleted = true;
|
|
446
|
-
completed().catch((e) => {
|
|
447
|
-
console.error("SSG completion failed", e);
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
let isPendingDrain = false;
|
|
452
|
-
const flushQueue = () => {
|
|
453
|
-
if (!isPendingDrain) {
|
|
454
|
-
isPendingDrain = true;
|
|
455
|
-
setTimeout(() => {
|
|
456
|
-
isPendingDrain = false;
|
|
457
|
-
next();
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
const render = async (staticRoute) => {
|
|
462
|
-
try {
|
|
463
|
-
active.add(staticRoute.pathname);
|
|
464
|
-
const result = await main.render({ type: "render", ...staticRoute });
|
|
465
|
-
active.delete(staticRoute.pathname);
|
|
466
|
-
if (result.error) {
|
|
467
|
-
const err = new Error(result.error.message);
|
|
468
|
-
err.stack = result.error.stack;
|
|
469
|
-
log.error(`
|
|
470
|
-
${colors.bold(colors.red(`!!! ${result.pathname}: Error during SSG`))}`);
|
|
471
|
-
log.error(colors.red(err.message));
|
|
472
|
-
log.error(` Pathname: ${colors.magenta(staticRoute.pathname)}`);
|
|
473
|
-
Object.assign(formatError.formatError(err), {
|
|
474
|
-
plugin: "qwik-ssg"
|
|
475
|
-
});
|
|
476
|
-
log.error(vite.buildErrorMessage(err));
|
|
477
|
-
generatorResult.errors++;
|
|
478
|
-
}
|
|
479
|
-
if (result.filePath != null) {
|
|
480
|
-
generatorResult.rendered++;
|
|
481
|
-
generatorResult.staticPaths.push(result.pathname);
|
|
482
|
-
const base = opts.rootDir ?? opts.outDir;
|
|
483
|
-
const path$1 = path.relative(base, result.filePath);
|
|
484
|
-
const lastSlash = path$1.lastIndexOf("/");
|
|
485
|
-
log.info(`${colors.dim(path$1.slice(0, lastSlash + 1))}${path$1.slice(lastSlash + 1)}`);
|
|
486
|
-
}
|
|
487
|
-
flushQueue();
|
|
488
|
-
} catch (e) {
|
|
489
|
-
console.error(`render failed for ${staticRoute.pathname}`, e);
|
|
490
|
-
isCompleted = true;
|
|
491
|
-
reject(e);
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
const addToQueue = (pathname, params) => {
|
|
495
|
-
if (pathname) {
|
|
496
|
-
pathname = new URL(pathname, `https://qwik.dev`).pathname;
|
|
497
|
-
if (pathname !== opts.basePathname) {
|
|
498
|
-
if (trailingSlash) {
|
|
499
|
-
if (!pathname.endsWith("/")) {
|
|
500
|
-
const segments = pathname.split("/");
|
|
501
|
-
const lastSegment = segments[segments.length - 1];
|
|
502
|
-
if (!lastSegment.includes(".")) {
|
|
503
|
-
pathname += "/";
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
} else {
|
|
507
|
-
if (pathname.endsWith("/")) {
|
|
508
|
-
pathname = pathname.slice(0, pathname.length - 1);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
if (includeRoute(pathname) && !queue.some((s) => s.pathname === pathname)) {
|
|
513
|
-
queue.push({
|
|
514
|
-
pathname,
|
|
515
|
-
params
|
|
516
|
-
});
|
|
517
|
-
flushQueue();
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
};
|
|
521
|
-
const loadStaticRoute = async (route) => {
|
|
522
|
-
const [routeName, loaders, originalPathname] = route;
|
|
523
|
-
const modules = await Promise.all(loaders.map((loader) => loader()));
|
|
524
|
-
const pageModule = modules[modules.length - 1];
|
|
525
|
-
const paramNames = extractParamNames(routeName);
|
|
526
|
-
const isValidStaticModule = pageModule && (pageModule.default || pageModule.onRequest || pageModule.onGet);
|
|
527
|
-
if (isValidStaticModule) {
|
|
528
|
-
if (Array.isArray(paramNames) && paramNames.length > 0) {
|
|
529
|
-
if (typeof pageModule.onStaticGenerate === "function" && paramNames.length > 0) {
|
|
530
|
-
const staticGenerate = await pageModule.onStaticGenerate({
|
|
531
|
-
env: {
|
|
532
|
-
get(key) {
|
|
533
|
-
return sys.getEnv(key);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
if (Array.isArray(staticGenerate.params)) {
|
|
538
|
-
for (const params of staticGenerate.params) {
|
|
539
|
-
const pathname = fs.getPathnameForDynamicRoute(
|
|
540
|
-
originalPathname,
|
|
541
|
-
paramNames,
|
|
542
|
-
params
|
|
543
|
-
);
|
|
544
|
-
addToQueue(pathname, params);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
} else {
|
|
549
|
-
addToQueue(originalPathname, void 0);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
};
|
|
553
|
-
const loadStaticRoutes = async () => {
|
|
554
|
-
await Promise.all(routes.map(loadStaticRoute));
|
|
555
|
-
isRoutesLoaded = true;
|
|
556
|
-
flushQueue();
|
|
557
|
-
};
|
|
558
|
-
loadStaticRoutes().catch((e) => {
|
|
559
|
-
console.error("SSG route loading failed", e);
|
|
560
|
-
reject(e);
|
|
561
|
-
});
|
|
562
|
-
} catch (e) {
|
|
563
|
-
console.error("SSG main thread failed", e);
|
|
564
|
-
reject(e);
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
function validateOptions(opts) {
|
|
569
|
-
if (!opts.qwikRouterConfigModulePath) {
|
|
570
|
-
if (!opts.qwikCityPlanModulePath) {
|
|
571
|
-
throw new Error(`Missing "qwikRouterConfigModulePath" option`);
|
|
572
|
-
} else {
|
|
573
|
-
console.warn(
|
|
574
|
-
"`qwikCityPlanModulePath` is deprecated. Use `qwikRouterConfigModulePath` instead."
|
|
575
|
-
);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
if (!opts.renderModulePath) {
|
|
579
|
-
throw new Error(`Missing "renderModulePath" option`);
|
|
580
|
-
}
|
|
581
|
-
let siteOrigin = opts.origin;
|
|
582
|
-
if (typeof siteOrigin !== "string" || siteOrigin.trim().length === 0) {
|
|
583
|
-
throw new Error(`Missing "origin" option`);
|
|
584
|
-
}
|
|
585
|
-
siteOrigin = siteOrigin.trim();
|
|
586
|
-
if (!/:\/\//.test(siteOrigin) || siteOrigin.startsWith("://")) {
|
|
587
|
-
throw new Error(
|
|
588
|
-
`"origin" must start with a valid protocol, such as "https://" or "http://", received "${siteOrigin}"`
|
|
589
|
-
);
|
|
590
|
-
}
|
|
591
|
-
try {
|
|
592
|
-
new URL(siteOrigin);
|
|
593
|
-
} catch (e) {
|
|
594
|
-
throw new Error(`Invalid "origin"`, { cause: e });
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
async function workerThread(sys) {
|
|
598
|
-
delete globalThis.__qwik;
|
|
599
|
-
const ssgOpts = sys.getOptions();
|
|
600
|
-
const pendingPromises = /* @__PURE__ */ new Set();
|
|
601
|
-
const log = await sys.createLogger();
|
|
602
|
-
const opts = {
|
|
603
|
-
...ssgOpts,
|
|
604
|
-
// TODO export this from server
|
|
605
|
-
render: (await import(node_url.pathToFileURL(ssgOpts.renderModulePath).href)).default,
|
|
606
|
-
// TODO this should be built-in
|
|
607
|
-
qwikRouterConfig: (await import(node_url.pathToFileURL(ssgOpts.qwikRouterConfigModulePath).href)).default
|
|
608
|
-
};
|
|
609
|
-
sys.createWorkerProcess(async (msg) => {
|
|
610
|
-
switch (msg.type) {
|
|
611
|
-
case "render": {
|
|
612
|
-
log.debug(`Worker thread rendering: ${msg.pathname}`);
|
|
613
|
-
return new Promise((resolve) => {
|
|
614
|
-
workerRender(sys, opts, msg, pendingPromises, resolve).catch((e) => {
|
|
615
|
-
console.error("Error during render", msg.pathname, e);
|
|
616
|
-
});
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
|
-
case "close": {
|
|
620
|
-
if (pendingPromises.size) {
|
|
621
|
-
log.debug(`Worker thread closing, waiting for ${pendingPromises.size} pending renders`);
|
|
622
|
-
const promises = Array.from(pendingPromises);
|
|
623
|
-
pendingPromises.clear();
|
|
624
|
-
await Promise.all(promises);
|
|
625
|
-
}
|
|
626
|
-
log.debug(`Worker thread closed`);
|
|
627
|
-
return { type: "close" };
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
})?.catch((e) => {
|
|
631
|
-
console.error("Worker process creation failed", e);
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
async function workerRender(sys, opts, staticRoute, pendingPromises, callback) {
|
|
635
|
-
const url = new URL(staticRoute.pathname, opts.origin);
|
|
636
|
-
const result = {
|
|
637
|
-
type: "render",
|
|
638
|
-
pathname: staticRoute.pathname,
|
|
639
|
-
url: url.href,
|
|
640
|
-
ok: false,
|
|
641
|
-
error: null,
|
|
642
|
-
filePath: null,
|
|
643
|
-
contentType: null,
|
|
644
|
-
resourceType: null
|
|
645
|
-
};
|
|
646
|
-
try {
|
|
647
|
-
let routeWriter = null;
|
|
648
|
-
let closeResolved;
|
|
649
|
-
const closePromise = new Promise((closePromiseResolve) => {
|
|
650
|
-
closeResolved = closePromiseResolve;
|
|
651
|
-
});
|
|
652
|
-
const request = new Request(url);
|
|
653
|
-
const requestCtx = {
|
|
654
|
-
mode: "static",
|
|
655
|
-
locale: void 0,
|
|
656
|
-
url,
|
|
657
|
-
request,
|
|
658
|
-
env: {
|
|
659
|
-
get(key) {
|
|
660
|
-
return sys.getEnv(key);
|
|
661
|
-
}
|
|
662
|
-
},
|
|
663
|
-
platform: sys.platform,
|
|
664
|
-
getClientConn: () => {
|
|
665
|
-
return {};
|
|
666
|
-
},
|
|
667
|
-
getWritableStream: (status, headers, _, _r, requestEv) => {
|
|
668
|
-
result.ok = status >= 200 && status < 300;
|
|
669
|
-
if (!result.ok) {
|
|
670
|
-
return noopWritableStream;
|
|
671
|
-
}
|
|
672
|
-
result.contentType = (headers.get("Content-Type") || "").toLowerCase();
|
|
673
|
-
const isHtml = result.contentType.includes("text/html");
|
|
674
|
-
const is404ErrorPage = url.pathname.endsWith("/404.html");
|
|
675
|
-
const routeFilePath = sys.getRouteFilePath(url.pathname, isHtml);
|
|
676
|
-
if (is404ErrorPage) {
|
|
677
|
-
result.resourceType = "404";
|
|
678
|
-
} else if (isHtml) {
|
|
679
|
-
result.resourceType = "page";
|
|
680
|
-
}
|
|
681
|
-
const hasRouteWriter = isHtml ? opts.emitHtml !== false : true;
|
|
682
|
-
const writeQDataEnabled = isHtml && opts.emitData !== false;
|
|
683
|
-
const stream = new web.WritableStream({
|
|
684
|
-
async start() {
|
|
685
|
-
try {
|
|
686
|
-
if (hasRouteWriter || writeQDataEnabled) {
|
|
687
|
-
await sys.ensureDir(routeFilePath);
|
|
688
|
-
}
|
|
689
|
-
if (hasRouteWriter) {
|
|
690
|
-
routeWriter = sys.createWriteStream(routeFilePath);
|
|
691
|
-
routeWriter.on("error", (e) => {
|
|
692
|
-
console.error(e);
|
|
693
|
-
routeWriter = null;
|
|
694
|
-
result.error = {
|
|
695
|
-
message: e.message,
|
|
696
|
-
stack: e.stack
|
|
697
|
-
};
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
} catch (e) {
|
|
701
|
-
console.error("Error during stream start", staticRoute.pathname, e);
|
|
702
|
-
routeWriter = null;
|
|
703
|
-
result.error = {
|
|
704
|
-
message: String(e),
|
|
705
|
-
stack: e.stack || ""
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
},
|
|
709
|
-
write(chunk) {
|
|
710
|
-
try {
|
|
711
|
-
if (routeWriter) {
|
|
712
|
-
routeWriter.write(Buffer.from(chunk.buffer));
|
|
713
|
-
}
|
|
714
|
-
} catch (e) {
|
|
715
|
-
console.error("Error during stream write", staticRoute.pathname, e);
|
|
716
|
-
routeWriter = null;
|
|
717
|
-
result.error = {
|
|
718
|
-
message: String(e),
|
|
719
|
-
stack: e.stack || ""
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
},
|
|
723
|
-
async close() {
|
|
724
|
-
const writePromises = [];
|
|
725
|
-
try {
|
|
726
|
-
if (writeQDataEnabled) {
|
|
727
|
-
const qData = requestEv.sharedMap.get(requestHandler.RequestEvShareQData);
|
|
728
|
-
if (qData && !is404ErrorPage) {
|
|
729
|
-
const qDataFilePath = sys.getDataFilePath(url.pathname);
|
|
730
|
-
const dataWriter = sys.createWriteStream(qDataFilePath);
|
|
731
|
-
dataWriter.on("error", (e) => {
|
|
732
|
-
console.error(e);
|
|
733
|
-
result.error = {
|
|
734
|
-
message: e.message,
|
|
735
|
-
stack: e.stack
|
|
736
|
-
};
|
|
737
|
-
});
|
|
738
|
-
const serialized = await internal._serialize([qData]);
|
|
739
|
-
dataWriter.write(serialized);
|
|
740
|
-
writePromises.push(
|
|
741
|
-
new Promise((resolve) => {
|
|
742
|
-
result.filePath = routeFilePath;
|
|
743
|
-
dataWriter.end(resolve);
|
|
744
|
-
})
|
|
745
|
-
);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
if (routeWriter) {
|
|
749
|
-
writePromises.push(
|
|
750
|
-
new Promise((resolve) => {
|
|
751
|
-
result.filePath = routeFilePath;
|
|
752
|
-
routeWriter.end(resolve);
|
|
753
|
-
}).finally(closeResolved)
|
|
754
|
-
);
|
|
755
|
-
}
|
|
756
|
-
if (writePromises.length > 0) {
|
|
757
|
-
await Promise.all(writePromises);
|
|
758
|
-
}
|
|
759
|
-
} catch (e) {
|
|
760
|
-
console.error("Error during stream close", staticRoute.pathname, e);
|
|
761
|
-
routeWriter = null;
|
|
762
|
-
result.error = {
|
|
763
|
-
message: String(e),
|
|
764
|
-
stack: e.stack || ""
|
|
765
|
-
};
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
});
|
|
769
|
-
return stream;
|
|
770
|
-
}
|
|
771
|
-
};
|
|
772
|
-
const promise = requestHandler.requestHandler(requestCtx, opts).then((rsp) => {
|
|
773
|
-
if (rsp != null) {
|
|
774
|
-
return rsp.completion.then((r) => {
|
|
775
|
-
if (routeWriter) {
|
|
776
|
-
return closePromise.then(() => r);
|
|
777
|
-
}
|
|
778
|
-
return r;
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
}).then((e) => {
|
|
782
|
-
if (e !== void 0) {
|
|
783
|
-
if (e instanceof requestHandler.RedirectMessage) {
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
if (e instanceof Error) {
|
|
787
|
-
result.error = {
|
|
788
|
-
message: e.message,
|
|
789
|
-
stack: e.stack
|
|
790
|
-
};
|
|
791
|
-
} else {
|
|
792
|
-
result.error = {
|
|
793
|
-
message: String(e),
|
|
794
|
-
stack: void 0
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
|
-
console.error("Error during request handling", staticRoute.pathname, e);
|
|
798
|
-
}
|
|
799
|
-
}).catch((e) => {
|
|
800
|
-
console.error("Unhandled error during request handling", staticRoute.pathname, e);
|
|
801
|
-
result.error = {
|
|
802
|
-
message: String(e),
|
|
803
|
-
stack: e.stack || ""
|
|
804
|
-
};
|
|
805
|
-
}).finally(() => {
|
|
806
|
-
pendingPromises.delete(promise);
|
|
807
|
-
callback(result);
|
|
808
|
-
});
|
|
809
|
-
pendingPromises.add(promise);
|
|
810
|
-
} catch (e) {
|
|
811
|
-
console.error("Error during render", staticRoute.pathname, e);
|
|
812
|
-
if (e instanceof Error) {
|
|
813
|
-
result.error = {
|
|
814
|
-
message: e.message,
|
|
815
|
-
stack: e.stack
|
|
816
|
-
};
|
|
817
|
-
} else {
|
|
818
|
-
result.error = {
|
|
819
|
-
message: String(e),
|
|
820
|
-
stack: void 0
|
|
821
|
-
};
|
|
822
|
-
}
|
|
823
|
-
callback(result);
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
const noopWriter = {
|
|
827
|
-
closed: Promise.resolve(void 0),
|
|
828
|
-
ready: Promise.resolve(void 0),
|
|
829
|
-
desiredSize: 0,
|
|
830
|
-
async close() {
|
|
831
|
-
},
|
|
832
|
-
async abort() {
|
|
833
|
-
},
|
|
834
|
-
async write() {
|
|
835
|
-
},
|
|
836
|
-
releaseLock() {
|
|
837
|
-
}
|
|
838
|
-
};
|
|
839
|
-
const noopWritableStream = {
|
|
840
|
-
get locked() {
|
|
841
|
-
return false;
|
|
842
|
-
},
|
|
843
|
-
set locked(_) {
|
|
844
|
-
},
|
|
845
|
-
async abort() {
|
|
846
|
-
},
|
|
847
|
-
async close() {
|
|
848
|
-
},
|
|
849
|
-
getWriter() {
|
|
850
|
-
return noopWriter;
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
async function generate(opts) {
|
|
854
|
-
if (node_worker_threads.isMainThread) {
|
|
855
|
-
const sys = await createSystem(opts);
|
|
856
|
-
const result = await mainThread(sys);
|
|
857
|
-
return result;
|
|
858
|
-
}
|
|
859
|
-
throw new Error(`generate() cannot be called from a worker thread`);
|
|
860
|
-
}
|
|
861
|
-
if (!node_worker_threads.isMainThread && node_worker_threads.workerData) {
|
|
862
|
-
const opts = node_worker_threads.workerData;
|
|
863
|
-
(async () => {
|
|
864
|
-
try {
|
|
865
|
-
if (opts.log === "debug") {
|
|
866
|
-
console.debug(`Worker thread starting (ID: ${node_worker_threads.threadId})`);
|
|
867
|
-
}
|
|
868
|
-
const sys = await createSystem(opts, node_worker_threads.threadId);
|
|
869
|
-
await workerThread(sys);
|
|
870
|
-
} catch (error) {
|
|
871
|
-
console.error(`Error occurred in worker thread (ID: ${node_worker_threads.threadId}): ${error}`);
|
|
872
|
-
}
|
|
873
|
-
})().catch((e) => {
|
|
874
|
-
console.error(e);
|
|
875
|
-
});
|
|
876
|
-
}
|
|
877
|
-
exports.generate = generate;
|