@qwik.dev/router 2.0.0-beta.29 → 2.0.0-beta.30
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/shared/vite/index.d.ts +1 -1
- package/lib/adapters/shared/vite/index.mjs +32 -3
- package/lib/chunks/deepFreeze.qwik.mjs +18 -0
- package/lib/chunks/http-error.qwik.mjs +14 -6
- package/lib/chunks/redirect-handler.mjs +6 -0
- package/lib/chunks/routing.qwik.mjs +52 -41
- package/lib/chunks/system.mjs +13 -8
- package/lib/chunks/worker-thread.qwik.mjs +2572 -0
- package/lib/index.qwik.mjs +70 -32
- package/lib/middleware/bun/index.mjs +3 -3
- package/lib/middleware/cloudflare-pages/index.mjs +3 -3
- package/lib/middleware/deno/index.mjs +3 -3
- package/lib/middleware/netlify-edge/index.mjs +3 -3
- package/lib/middleware/request-handler/index.d.ts +4 -15
- package/lib/middleware/request-handler/index.mjs +1190 -1049
- package/lib/middleware/vercel-edge/index.mjs +3 -3
- package/lib/ssg/index.d.ts +2 -2
- package/lib/ssg/index.mjs +32 -23
- package/lib/vite/index.mjs +162 -2
- package/package.json +4 -4
- package/lib/chunks/worker-thread.mjs +0 -271
|
@@ -75,7 +75,7 @@ export declare interface ServerAdapterOptions {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/** @public */
|
|
78
|
-
export declare function viteAdapter(opts: ViteAdapterPluginOptions): Plugin_2<
|
|
78
|
+
export declare function viteAdapter(opts: ViteAdapterPluginOptions): Plugin_2<any>[];
|
|
79
79
|
|
|
80
80
|
/** @public */
|
|
81
81
|
declare interface ViteAdapterPluginOptions {
|
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
import { join, resolve, dirname, basename } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
2
3
|
import fs from 'node:fs';
|
|
3
4
|
import { g as getErrorHtml } from '../../../chunks/error-handler.mjs';
|
|
4
5
|
|
|
6
|
+
const SSG_WORKER_IMPORT_PREFIX = "@qwik-router-ssg-worker/";
|
|
7
|
+
function ssgWorkerImportPlugin() {
|
|
8
|
+
return {
|
|
9
|
+
name: "qwik-router-ssg-worker-imports",
|
|
10
|
+
enforce: "pre",
|
|
11
|
+
async resolveId(id, importer) {
|
|
12
|
+
if (!id.startsWith(SSG_WORKER_IMPORT_PREFIX)) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const subpath = id.slice(SSG_WORKER_IMPORT_PREFIX.length);
|
|
16
|
+
const sourceId = fileURLToPath(new URL(`../../${subpath}`, import.meta.url));
|
|
17
|
+
const resolved = await this.resolve(sourceId, importer, {
|
|
18
|
+
skipSelf: true
|
|
19
|
+
});
|
|
20
|
+
return `${(resolved ?? {
|
|
21
|
+
id: sourceId
|
|
22
|
+
}).id}?ssg-worker`;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
5
27
|
function normalizeTrailingSlash(pathname) {
|
|
6
28
|
if (!pathname.endsWith("/")) {
|
|
7
29
|
return pathname + "/";
|
|
@@ -196,11 +218,16 @@ function viteAdapter(opts) {
|
|
|
196
218
|
`import { isMainThread } from 'node:worker_threads';`,
|
|
197
219
|
`import render from '${srcDir}/entry.ssr';`,
|
|
198
220
|
`import qwikRouterConfig from '@qwik-router-config';`,
|
|
221
|
+
`import { runSsg, startWorker } from '@qwik.dev/router/ssg';`,
|
|
199
222
|
``,
|
|
200
223
|
`const ssgOpts = ${JSON.stringify(ssgOpts)};`,
|
|
201
224
|
``,
|
|
225
|
+
`// Parse --quiet / --debug CLI flags`,
|
|
226
|
+
`const args = isMainThread ? process.argv.slice(2) : [];`,
|
|
227
|
+
`if (args.includes('--quiet')) ssgOpts.log = 'quiet';`,
|
|
228
|
+
`if (args.includes('--debug')) ssgOpts.log = 'debug';`,
|
|
229
|
+
``,
|
|
202
230
|
`if (isMainThread) {`,
|
|
203
|
-
` const { runSsg } = await import('@qwik.dev/router/ssg');`,
|
|
204
231
|
` await runSsg({`,
|
|
205
232
|
` render,`,
|
|
206
233
|
` qwikRouterConfig,`,
|
|
@@ -208,7 +235,6 @@ function viteAdapter(opts) {
|
|
|
208
235
|
` ...ssgOpts,`,
|
|
209
236
|
` });`,
|
|
210
237
|
`} else {`,
|
|
211
|
-
` const { startWorker } = await import('@qwik.dev/router/ssg');`,
|
|
212
238
|
` await startWorker({ render, qwikRouterConfig });`,
|
|
213
239
|
`}`
|
|
214
240
|
].join("\n");
|
|
@@ -300,7 +326,10 @@ See https://qwik.dev/docs/deployments/#cache-headers for more information.
|
|
|
300
326
|
}
|
|
301
327
|
}
|
|
302
328
|
};
|
|
303
|
-
return
|
|
329
|
+
return [
|
|
330
|
+
ssgWorkerImportPlugin(),
|
|
331
|
+
plugin
|
|
332
|
+
];
|
|
304
333
|
}
|
|
305
334
|
function getParentDir(startDir, dirName) {
|
|
306
335
|
const root = resolve("/");
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const deepFreeze = (obj) => {
|
|
2
|
+
if (obj == null) {
|
|
3
|
+
return obj;
|
|
4
|
+
}
|
|
5
|
+
Object.getOwnPropertyNames(obj).forEach((prop) => {
|
|
6
|
+
const value = obj[prop];
|
|
7
|
+
if (value && typeof value === "object" && !Object.isFrozen(value)) {
|
|
8
|
+
try {
|
|
9
|
+
deepFreeze(value);
|
|
10
|
+
} catch {
|
|
11
|
+
return obj;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return Object.freeze(obj);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { deepFreeze as d };
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { componentQrl, inlinedQrl, _jsxSorted } from '@qwik.dev/core';
|
|
1
|
+
import { componentQrl, inlinedQrl, _jsxSorted, _fnSignal } from '@qwik.dev/core';
|
|
2
2
|
import { k as useHttpStatus } from './use-functions.qwik.mjs';
|
|
3
3
|
|
|
4
|
+
const _hf0 = (p0) => p0.status || 500;
|
|
5
|
+
const _hf0_str = "p0.status||500";
|
|
6
|
+
const _hf1 = (p0) => p0.message || "";
|
|
7
|
+
const _hf1_str = 'p0.message||""';
|
|
4
8
|
const cacheKey = (status) => String(status);
|
|
5
9
|
const COLOR_400 = "#006ce9";
|
|
6
10
|
const COLOR_500 = "#713fc2";
|
|
7
11
|
const DisplayHttpStatus = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl(() => {
|
|
8
|
-
const
|
|
9
|
-
const width = message ? "600px" : "300px";
|
|
10
|
-
const color = status < 500 ? COLOR_400 : COLOR_500;
|
|
12
|
+
const httpstatus = useHttpStatus();
|
|
13
|
+
const width = httpstatus.message ? "600px" : "300px";
|
|
14
|
+
const color = httpstatus.status < 500 ? COLOR_400 : COLOR_500;
|
|
11
15
|
const style = `
|
|
12
16
|
body { color: ${color}; background-color: #fafafa; padding: 30px; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif; }
|
|
13
17
|
p { max-width: ${width}; margin: 60px auto 30px auto; background: white; border-radius: 4px; box-shadow: 0px 0px 50px -20px ${color}; overflow: hidden; }
|
|
@@ -18,9 +22,13 @@ const DisplayHttpStatus = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQr
|
|
|
18
22
|
/* @__PURE__ */ _jsxSorted("style", {
|
|
19
23
|
dangerouslySetInnerHTML: style
|
|
20
24
|
}, null, null, 3, null),
|
|
21
|
-
/* @__PURE__ */ _jsxSorted("strong", null, null,
|
|
25
|
+
/* @__PURE__ */ _jsxSorted("strong", null, null, _fnSignal(_hf0, [
|
|
26
|
+
httpstatus
|
|
27
|
+
], _hf0_str), 3, null),
|
|
22
28
|
" ",
|
|
23
|
-
/* @__PURE__ */ _jsxSorted("span", null, null,
|
|
29
|
+
/* @__PURE__ */ _jsxSorted("span", null, null, _fnSignal(_hf1, [
|
|
30
|
+
httpstatus
|
|
31
|
+
], _hf1_str), 3, null)
|
|
24
32
|
], 1, "vY_0");
|
|
25
33
|
}, "DisplayHttpStatus_component_PJf4K4PL7Oc"));
|
|
26
34
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createAsyncQrl, inlinedQrl, _captures, isBrowser, withLocale } from '@qwik.dev/core';
|
|
2
2
|
import { _deserialize, _UNINITIALIZED } from '@qwik.dev/core/internal';
|
|
3
3
|
import { p } from '@qwik.dev/core/preloader';
|
|
4
|
+
import { d as deepFreeze } from './deepFreeze.qwik.mjs';
|
|
4
5
|
|
|
5
|
-
const MODULE_CACHE = /* @__PURE__ */ new WeakMap();
|
|
6
6
|
const CLIENT_DATA_CACHE = /* @__PURE__ */ new Map();
|
|
7
7
|
const QACTION_KEY = "qaction";
|
|
8
8
|
const QLOADER_KEY = "qloaders";
|
|
@@ -376,23 +376,7 @@ const resolveHead = (endpoint, routeLocation, contentModules, locale, defaults)
|
|
|
376
376
|
return resolveRouteConfig(getData, routeLocation, contentModules, locale, endpoint.status, defaults).head;
|
|
377
377
|
};
|
|
378
378
|
|
|
379
|
-
const
|
|
380
|
-
if (obj == null) {
|
|
381
|
-
return obj;
|
|
382
|
-
}
|
|
383
|
-
Object.getOwnPropertyNames(obj).forEach((prop) => {
|
|
384
|
-
const value = obj[prop];
|
|
385
|
-
if (value && typeof value === "object" && !Object.isFrozen(value)) {
|
|
386
|
-
try {
|
|
387
|
-
deepFreeze(value);
|
|
388
|
-
} catch {
|
|
389
|
-
return obj;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
return Object.freeze(obj);
|
|
394
|
-
};
|
|
395
|
-
|
|
379
|
+
const MODULE_CACHE = /* @__PURE__ */ new WeakMap();
|
|
396
380
|
const httpErrorLoader = () => import('./http-error.qwik.mjs');
|
|
397
381
|
function walkTrieKeys(root, keys) {
|
|
398
382
|
let node = root;
|
|
@@ -401,7 +385,18 @@ function walkTrieKeys(root, keys) {
|
|
|
401
385
|
layouts.push(node._L);
|
|
402
386
|
}
|
|
403
387
|
for (const key of keys) {
|
|
404
|
-
|
|
388
|
+
let next = node[key];
|
|
389
|
+
if (!next && node._M) {
|
|
390
|
+
for (const group of node._M) {
|
|
391
|
+
next = group[key];
|
|
392
|
+
if (next) {
|
|
393
|
+
if (group._L) {
|
|
394
|
+
layouts.push(group._L);
|
|
395
|
+
}
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
405
400
|
if (!next) {
|
|
406
401
|
return void 0;
|
|
407
402
|
}
|
|
@@ -415,27 +410,6 @@ function walkTrieKeys(root, keys) {
|
|
|
415
410
|
layouts
|
|
416
411
|
};
|
|
417
412
|
}
|
|
418
|
-
function resolveLoaders(root, node, gatheredLayouts) {
|
|
419
|
-
if (node._G) {
|
|
420
|
-
const keys = node._G.split("/").filter((p) => p.length > 0);
|
|
421
|
-
const target = walkTrieKeys(root, keys);
|
|
422
|
-
if (!target) {
|
|
423
|
-
return void 0;
|
|
424
|
-
}
|
|
425
|
-
return resolveLoaders(root, target.node, target.layouts);
|
|
426
|
-
}
|
|
427
|
-
const index = node._I;
|
|
428
|
-
if (!index) {
|
|
429
|
-
return void 0;
|
|
430
|
-
}
|
|
431
|
-
if (Array.isArray(index)) {
|
|
432
|
-
return index;
|
|
433
|
-
}
|
|
434
|
-
return [
|
|
435
|
-
...gatheredLayouts,
|
|
436
|
-
index
|
|
437
|
-
];
|
|
438
|
-
}
|
|
439
413
|
function collectNodeMeta(node, groups, layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef) {
|
|
440
414
|
for (const g of groups) {
|
|
441
415
|
if (g._L) {
|
|
@@ -553,6 +527,43 @@ function findIndexNode(node) {
|
|
|
553
527
|
}
|
|
554
528
|
return void 0;
|
|
555
529
|
}
|
|
530
|
+
function resolveLoaders(root, node, gatheredLayouts) {
|
|
531
|
+
if (node._G) {
|
|
532
|
+
const keys = node._G.split("/").filter((p) => p.length > 0);
|
|
533
|
+
const target = walkTrieKeys(root, keys);
|
|
534
|
+
if (!target) {
|
|
535
|
+
return void 0;
|
|
536
|
+
}
|
|
537
|
+
let targetNode = target.node;
|
|
538
|
+
const targetLayouts = target.layouts;
|
|
539
|
+
if (!targetNode._I && !targetNode._G) {
|
|
540
|
+
const indexResult = findIndexNode(targetNode);
|
|
541
|
+
if (indexResult) {
|
|
542
|
+
for (const g of indexResult.groups) {
|
|
543
|
+
if (g._L) {
|
|
544
|
+
targetLayouts.push(g._L);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
targetNode = indexResult.target;
|
|
548
|
+
if (targetNode._L) {
|
|
549
|
+
targetLayouts.push(targetNode._L);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return resolveLoaders(root, targetNode, targetLayouts);
|
|
554
|
+
}
|
|
555
|
+
const index = node._I;
|
|
556
|
+
if (!index) {
|
|
557
|
+
return void 0;
|
|
558
|
+
}
|
|
559
|
+
if (Array.isArray(index)) {
|
|
560
|
+
return index;
|
|
561
|
+
}
|
|
562
|
+
return [
|
|
563
|
+
...gatheredLayouts,
|
|
564
|
+
index
|
|
565
|
+
];
|
|
566
|
+
}
|
|
556
567
|
function findRestNode(node) {
|
|
557
568
|
if (node._A) {
|
|
558
569
|
return {
|
|
@@ -806,4 +817,4 @@ const loadRoute = async (routes, cacheModules, pathname, isInternal) => {
|
|
|
806
817
|
};
|
|
807
818
|
};
|
|
808
819
|
|
|
809
|
-
export { CLIENT_DATA_CACHE as C, DEFAULT_LOADERS_SERIALIZATION_STRATEGY as D, Q_ROUTE as Q, createDocumentHead as a, isSameOrigin as b, createLoaderSignal as c,
|
|
820
|
+
export { CLIENT_DATA_CACHE as C, DEFAULT_LOADERS_SERIALIZATION_STRATEGY as D, Q_ROUTE as Q, createDocumentHead as a, isSameOrigin as b, createLoaderSignal as c, clientNavigate as d, loadRoute as e, toPath as f, getClientNavPath as g, QFN_KEY as h, isSamePath as i, QACTION_KEY as j, QDATA_KEY as k, loadClientData as l, resolveRouteConfig as m, QLOADER_KEY as n, isPromise as o, preloadRouteBundles as p, resolveHead as r, shouldPreload as s, toUrl as t };
|
package/lib/chunks/system.mjs
CHANGED
|
@@ -14,6 +14,7 @@ function ssgWorkerCompare(a, b) {
|
|
|
14
14
|
return a.totalTasks < b.totalTasks ? -1 : 1;
|
|
15
15
|
}
|
|
16
16
|
async function createWorkerPool(sys, opts) {
|
|
17
|
+
const log = await sys.createLogger();
|
|
17
18
|
const ssgWorkers = [];
|
|
18
19
|
const sitemapBuffer = [];
|
|
19
20
|
let sitemapStream = null;
|
|
@@ -119,9 +120,10 @@ async function createWorkerPool(sys, opts) {
|
|
|
119
120
|
}
|
|
120
121
|
});
|
|
121
122
|
nodeWorker.on("error", (e) => {
|
|
122
|
-
|
|
123
|
+
log.error(`worker error`, e);
|
|
123
124
|
});
|
|
124
125
|
nodeWorker.on("exit", (code) => {
|
|
126
|
+
log.debug(`worker exit code=${code}`);
|
|
125
127
|
if (terminateTimeout) {
|
|
126
128
|
clearTimeout(terminateTimeout);
|
|
127
129
|
terminateTimeout = null;
|
|
@@ -210,7 +212,7 @@ async function createWorkerPool(sys, opts) {
|
|
|
210
212
|
}
|
|
211
213
|
};
|
|
212
214
|
if (sitemapOutFile) {
|
|
213
|
-
await ensureDir(sitemapOutFile);
|
|
215
|
+
await sys.ensureDir(sitemapOutFile);
|
|
214
216
|
sitemapStream = fs.createWriteStream(sitemapOutFile, {
|
|
215
217
|
flags: "w"
|
|
216
218
|
});
|
|
@@ -218,6 +220,7 @@ async function createWorkerPool(sys, opts) {
|
|
|
218
220
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
219
221
|
`);
|
|
220
222
|
}
|
|
223
|
+
log.debug(`creating ${maxWorkers} workers, ${maxTasksPerWorker} tasks each`);
|
|
221
224
|
for (let i = 0; i < maxWorkers; i++) {
|
|
222
225
|
ssgWorkers.push(createWorker());
|
|
223
226
|
if (process.platform === "win32" && i < maxWorkers - 1) {
|
|
@@ -260,20 +263,22 @@ async function createSystem(opts, threadId) {
|
|
|
260
263
|
return (diff[0] * NS_PER_SEC + diff[1]) * MS_PER_NS;
|
|
261
264
|
};
|
|
262
265
|
};
|
|
266
|
+
const noop = () => {
|
|
267
|
+
};
|
|
263
268
|
const createLogger = async () => {
|
|
269
|
+
const isQuiet = opts.log === "quiet";
|
|
270
|
+
const isDebug = opts.log === "debug";
|
|
264
271
|
if (threadId !== void 0) {
|
|
265
272
|
return {
|
|
266
|
-
debug:
|
|
267
|
-
},
|
|
273
|
+
debug: isDebug ? console.debug.bind(console, `[${threadId}]`) : noop,
|
|
268
274
|
error: console.error.bind(console, `[${threadId}]`),
|
|
269
|
-
info: console.info.bind(console, `[${threadId}]`)
|
|
275
|
+
info: isQuiet ? noop : console.info.bind(console, `[${threadId}]`)
|
|
270
276
|
};
|
|
271
277
|
}
|
|
272
278
|
return {
|
|
273
|
-
debug:
|
|
274
|
-
},
|
|
279
|
+
debug: isDebug ? console.debug.bind(console) : noop,
|
|
275
280
|
error: console.error.bind(console),
|
|
276
|
-
info: console.info.bind(console)
|
|
281
|
+
info: isQuiet ? noop : console.info.bind(console)
|
|
277
282
|
};
|
|
278
283
|
};
|
|
279
284
|
const outDir = normalizePath(opts.outDir);
|