@qwik.dev/router 2.0.0-rc.4 → 2.0.0-rc.6
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/cloudflare-pages/vite/index.mjs +1 -1
- package/lib/adapters/shared/vite/index.mjs +78 -61
- package/lib/chunks/fs.mjs +1 -1
- package/lib/chunks/head.qwik.mjs +221 -105
- package/lib/chunks/pathname.mjs +1 -0
- package/lib/chunks/request-path.mjs +9 -1
- package/lib/chunks/system.mjs +66 -11
- package/lib/chunks/user-response.mjs +315 -330
- package/lib/chunks/worker-thread.mjs +23 -12
- package/lib/index.d.ts +11 -7
- package/lib/index.qwik.mjs +341 -129
- package/lib/middleware/bun/index.mjs +1 -1
- package/lib/middleware/deno/index.mjs +1 -1
- package/lib/middleware/node/index.mjs +8 -2
- package/lib/middleware/request-handler/index.d.ts +2 -2
- package/lib/middleware/request-handler/index.mjs +5 -6
- package/lib/ssg/index.d.ts +7 -0
- package/lib/ssg/index.mjs +53 -7
- package/lib/vite/index.d.ts +1 -1
- package/lib/vite/index.mjs +127 -35
- package/package.json +5 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as limitRequestBody } from "../../chunks/request-body-limit.mjs";
|
|
2
1
|
import { n as normalizeRequestUrl, r as MIME_TYPES, t as getStaticFilePath } from "../../chunks/static-file.mjs";
|
|
2
|
+
import { r as limitRequestBody } from "../../chunks/request-body-limit.mjs";
|
|
3
3
|
import { isDev } from "@qwik.dev/core/build";
|
|
4
4
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
5
5
|
import { extname, join } from "node:path";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as limitRequestBody } from "../../chunks/request-body-limit.mjs";
|
|
2
1
|
import { n as normalizeRequestUrl, r as MIME_TYPES, t as getStaticFilePath } from "../../chunks/static-file.mjs";
|
|
2
|
+
import { r as limitRequestBody } from "../../chunks/request-body-limit.mjs";
|
|
3
3
|
import { isDev } from "@qwik.dev/core/build";
|
|
4
4
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
5
5
|
import { isStaticPath, mergeHeadersCookies, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as validateRequestBodyLimit, n as RequestBodyLimitError, t as DEFAULT_REQUEST_BODY_LIMIT } from "../../chunks/request-body-limit.mjs";
|
|
2
1
|
import { n as normalizeRequestUrl, r as MIME_TYPES, t as getStaticFilePath } from "../../chunks/static-file.mjs";
|
|
3
2
|
import { t as devPreloadedRouteLoaders } from "../../chunks/dev-preloaded-route-loader.mjs";
|
|
3
|
+
import { i as validateRequestBodyLimit, n as RequestBodyLimitError, t as DEFAULT_REQUEST_BODY_LIMIT } from "../../chunks/request-body-limit.mjs";
|
|
4
4
|
import { isDev } from "@qwik.dev/core";
|
|
5
5
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
6
6
|
import { createReadStream } from "node:fs";
|
|
@@ -269,8 +269,14 @@ function createQwikRouter(opts) {
|
|
|
269
269
|
const handled = await requestHandler(serverRequestEv, opts);
|
|
270
270
|
if (handled) {
|
|
271
271
|
const err = await handled.completion;
|
|
272
|
+
if (err) {
|
|
273
|
+
if (res.headersSent && !res.writableEnded) {
|
|
274
|
+
res.destroy();
|
|
275
|
+
res.end();
|
|
276
|
+
}
|
|
277
|
+
throw err;
|
|
278
|
+
}
|
|
272
279
|
if (handled.requestEv.headersSent) return;
|
|
273
|
-
if (err) throw err;
|
|
274
280
|
}
|
|
275
281
|
next();
|
|
276
282
|
} catch (e) {
|
|
@@ -849,8 +849,8 @@ export declare interface ServerRenderOptions extends RenderOptions {
|
|
|
849
849
|
/**
|
|
850
850
|
* Protection against cross-site request forgery (CSRF) attacks.
|
|
851
851
|
*
|
|
852
|
-
* When `true`, for every incoming POST, PUT, PATCH, or DELETE
|
|
853
|
-
*
|
|
852
|
+
* When `true`, for every incoming POST, PUT, PATCH, or DELETE request, the request origin is
|
|
853
|
+
* checked to match the server's origin. `lax-proto` is for SSL-terminating proxies
|
|
854
854
|
*
|
|
855
855
|
* Be careful when disabling this option as it may lead to CSRF attacks.
|
|
856
856
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as resolveValidInternalFullPathname, l as trimInternalPathname, s as recognizeRequest, u as trimRecognizedInternalPathname } from "../../chunks/request-path.mjs";
|
|
3
|
-
import { i as RedirectMessage, r as AbortMessage, t as ServerError } from "../../chunks/server-error.mjs";
|
|
1
|
+
import { o as loadRoute, pt as _asyncRequestStore, z as getRouterConfig } from "../../chunks/head.qwik.mjs";
|
|
4
2
|
import { t as devPreloadedRouteLoaders } from "../../chunks/dev-preloaded-route-loader.mjs";
|
|
5
|
-
import { a as getStaticPathRedirect,
|
|
3
|
+
import { a as getStaticPathRedirect, d as RewriteMessage, f as mergeHeadersCookies, h as clearSsrCache, i as resolveRequestHandlers, m as clearLoaderCache, n as getErrorHtml, o as isStaticPath, p as resolveLoaderPagePathname, r as renderQwikMiddleware, t as runQwikRouter } from "../../chunks/user-response.mjs";
|
|
4
|
+
import { c as recognizeRequest, d as trimRecognizedInternalPathname, u as trimInternalPathname } from "../../chunks/request-path.mjs";
|
|
5
|
+
import { i as RedirectMessage, r as AbortMessage, t as ServerError } from "../../chunks/server-error.mjs";
|
|
6
6
|
import { isDev } from "@qwik.dev/core";
|
|
7
7
|
/**
|
|
8
8
|
* The request handler for QwikRouter. Called by every adapter.
|
|
@@ -34,8 +34,7 @@ function getRequestHandlerPathname(serverRequestEv, isDevRequest = isDev) {
|
|
|
34
34
|
if (!recognized) return serverRequestEv.url.pathname;
|
|
35
35
|
const loaderPathname = trimRecognizedInternalPathname(serverRequestEv.url.pathname, recognized);
|
|
36
36
|
if (recognized.type !== "@isQLoader") return loaderPathname;
|
|
37
|
-
|
|
38
|
-
return resolveValidInternalFullPathname(loaderPathname, routePath) ?? loaderPathname;
|
|
37
|
+
return resolveLoaderPagePathname(serverRequestEv.request, loaderPathname, isDevRequest) ?? loaderPathname;
|
|
39
38
|
}
|
|
40
39
|
async function loadRequestHandlers(qwikRouterConfig, pathname, method, opts, serverRequestEv) {
|
|
41
40
|
const { routes, serverPlugins, cacheModules } = qwikRouterConfig;
|
package/lib/ssg/index.d.ts
CHANGED
|
@@ -67,6 +67,12 @@ export declare interface SsgRenderOptions extends RenderOptions {
|
|
|
67
67
|
maxWorkers?: number;
|
|
68
68
|
/** Maximum number of tasks to be running at one time per worker. Defaults to `20`. */
|
|
69
69
|
maxTasksPerWorker?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Number of times to retry a route whose render failed or timed out, or an `onStaticGenerate`
|
|
72
|
+
* call that threw, before recording the error. Each retry waits 500ms, doubling up to 2s, plus up
|
|
73
|
+
* to 30% at random. Defaults to `0` (the first failure is final).
|
|
74
|
+
*/
|
|
75
|
+
retries?: number;
|
|
70
76
|
/**
|
|
71
77
|
* File system path to write the `sitemap.xml` to. Defaults to `sitemap.xml` and written to the
|
|
72
78
|
* root of the `outDir`. Setting to `null` will prevent the sitemap from being created.
|
|
@@ -114,6 +120,7 @@ export declare interface StaticGenerateResult {
|
|
|
114
120
|
duration: number;
|
|
115
121
|
rendered: number;
|
|
116
122
|
errors: number;
|
|
123
|
+
retried: number;
|
|
117
124
|
staticPaths: string[];
|
|
118
125
|
}
|
|
119
126
|
|
package/lib/ssg/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { r as msToString } from "../chunks/format.mjs";
|
|
1
2
|
import { n as getPathnameForDynamicRoute, t as ensureSlash } from "../chunks/pathname.mjs";
|
|
2
3
|
import { n as isStaticTrieKey, r as unescapeStaticTrieKey } from "../chunks/route-trie-key.mjs";
|
|
3
|
-
import { r as msToString } from "../chunks/format.mjs";
|
|
4
4
|
import { t as createRouteTester } from "../chunks/routes.mjs";
|
|
5
5
|
import { relative } from "node:path";
|
|
6
6
|
import { bold, dim, green, magenta, red } from "kleur/colors";
|
|
@@ -12,6 +12,18 @@ async function mainThread(sys) {
|
|
|
12
12
|
log.info("\n" + bold(green("Starting Qwik Router SSG...")));
|
|
13
13
|
const qwikRouterConfig = opts.qwikRouterConfig;
|
|
14
14
|
const renderTimeout = 3e4;
|
|
15
|
+
const maxRetries = opts.retries ?? 0;
|
|
16
|
+
const failedAttempts = /* @__PURE__ */ new Map();
|
|
17
|
+
const callWithRetries = async (label, call) => {
|
|
18
|
+
for (let attempt = 1;; attempt++) try {
|
|
19
|
+
return await call();
|
|
20
|
+
} catch (e) {
|
|
21
|
+
if (attempt > maxRetries) throw e;
|
|
22
|
+
const reason = e instanceof Error ? e.message : String(e);
|
|
23
|
+
log.warn(`Retrying ${label} after it failed (${attempt} of ${maxRetries}): ${reason}`);
|
|
24
|
+
await new Promise((resolve) => setTimeout(resolve, getRetryDelay(attempt)));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
15
27
|
const queue = [];
|
|
16
28
|
const active = /* @__PURE__ */ new Set();
|
|
17
29
|
const routes = qwikRouterConfig.routes;
|
|
@@ -24,6 +36,7 @@ async function mainThread(sys) {
|
|
|
24
36
|
duration: 0,
|
|
25
37
|
rendered: 0,
|
|
26
38
|
errors: 0,
|
|
39
|
+
retried: 0,
|
|
27
40
|
staticPaths: []
|
|
28
41
|
};
|
|
29
42
|
let isCompleted = false;
|
|
@@ -34,6 +47,7 @@ async function mainThread(sys) {
|
|
|
34
47
|
if (generatorResult.errors === 0) {
|
|
35
48
|
log.info(`\n${green("SSG results")}`);
|
|
36
49
|
if (generatorResult.rendered > 0) log.info(`- Generated: ${dim(`${generatorResult.rendered} page${generatorResult.rendered === 1 ? "" : "s"}`)}`);
|
|
50
|
+
if (generatorResult.retried > 0) log.info(`- Retried: ${dim(`${generatorResult.retried} route${generatorResult.retried === 1 ? "" : "s"}`)}`);
|
|
37
51
|
log.info(`- Duration: ${dim(msToString(generatorResult.duration))}`);
|
|
38
52
|
const total = generatorResult.rendered + generatorResult.errors;
|
|
39
53
|
if (total > 0) log.info(`- Average: ${dim(msToString(generatorResult.duration / total) + " per page")}`);
|
|
@@ -67,6 +81,17 @@ async function mainThread(sys) {
|
|
|
67
81
|
});
|
|
68
82
|
}
|
|
69
83
|
};
|
|
84
|
+
const hasRetriesLeft = (staticRoute) => (failedAttempts.get(staticRoute.pathname) ?? 0) < maxRetries;
|
|
85
|
+
const retryLater = (staticRoute, reason) => {
|
|
86
|
+
const attempt = (failedAttempts.get(staticRoute.pathname) ?? 0) + 1;
|
|
87
|
+
failedAttempts.set(staticRoute.pathname, attempt);
|
|
88
|
+
if (attempt === 1) generatorResult.retried++;
|
|
89
|
+
log.warn(`Retrying ${magenta(staticRoute.pathname)} after a failed render (${attempt} of ${maxRetries}): ${reason}`);
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
queue.push(staticRoute);
|
|
92
|
+
next();
|
|
93
|
+
}, getRetryDelay(attempt));
|
|
94
|
+
};
|
|
70
95
|
const render = async (staticRoute) => {
|
|
71
96
|
try {
|
|
72
97
|
active.add(staticRoute.pathname);
|
|
@@ -74,9 +99,27 @@ async function mainThread(sys) {
|
|
|
74
99
|
const result = await Promise.race([main.render({
|
|
75
100
|
type: "render",
|
|
76
101
|
...staticRoute
|
|
77
|
-
}), new Promise((
|
|
78
|
-
active.delete(staticRoute.pathname);
|
|
102
|
+
}), new Promise((resolve) => setTimeout(() => resolve(void 0), renderTimeout))]);
|
|
79
103
|
log.debug(`render done: ${staticRoute.pathname}`);
|
|
104
|
+
if (!result) {
|
|
105
|
+
const timeoutMessage = `SSG render timed out after ${renderTimeout}ms`;
|
|
106
|
+
if (!hasRetriesLeft(staticRoute)) throw new Error(timeoutMessage);
|
|
107
|
+
await main.restartWorker(staticRoute.pathname);
|
|
108
|
+
retryLater(staticRoute, timeoutMessage);
|
|
109
|
+
flushQueue();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (result.isInterrupted) {
|
|
113
|
+
queue.push(staticRoute);
|
|
114
|
+
flushQueue();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (result.error && hasRetriesLeft(staticRoute)) {
|
|
118
|
+
retryLater(staticRoute, result.error.message);
|
|
119
|
+
flushQueue();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
active.delete(staticRoute.pathname);
|
|
80
123
|
if (result.error) {
|
|
81
124
|
const err = new Error(result.error.message);
|
|
82
125
|
err.stack = result.error.stack;
|
|
@@ -138,11 +181,11 @@ async function mainThread(sys) {
|
|
|
138
181
|
else {
|
|
139
182
|
const pageLoader = pageLoaders[pageLoaders.length - 1];
|
|
140
183
|
if (typeof pageLoader === "function") {
|
|
141
|
-
const
|
|
142
|
-
if (typeof
|
|
143
|
-
const staticGenerate = await
|
|
184
|
+
const onStaticGenerate = (await pageLoader()).onStaticGenerate;
|
|
185
|
+
if (typeof onStaticGenerate === "function") {
|
|
186
|
+
const staticGenerate = await callWithRetries(`onStaticGenerate for ${magenta(originalPathname)}`, () => onStaticGenerate({ env: { get(key) {
|
|
144
187
|
return sys.getEnv(key);
|
|
145
|
-
} } });
|
|
188
|
+
} } }));
|
|
146
189
|
if (Array.isArray(staticGenerate.params)) for (const params of staticGenerate.params) {
|
|
147
190
|
const pathname = getPathnameForDynamicRoute(originalPathname, paramNames, params);
|
|
148
191
|
addToQueue(pathname, params);
|
|
@@ -193,6 +236,9 @@ async function mainThread(sys) {
|
|
|
193
236
|
}
|
|
194
237
|
});
|
|
195
238
|
}
|
|
239
|
+
function getRetryDelay(attempt) {
|
|
240
|
+
return Math.min(500 * 2 ** (attempt - 1), 2e3) * (1 + Math.random() * .3);
|
|
241
|
+
}
|
|
196
242
|
function validateOptions(opts) {
|
|
197
243
|
if (!opts.qwikRouterConfig) throw new Error(`Missing "qwikRouterConfig" option`);
|
|
198
244
|
let siteOrigin = opts.origin;
|
package/lib/vite/index.d.ts
CHANGED
|
@@ -109,7 +109,7 @@ declare interface PluginOptions {
|
|
|
109
109
|
platform?: Record<string, unknown>;
|
|
110
110
|
/** Configuration to rewrite url paths */
|
|
111
111
|
rewriteRoutes?: RewriteRouteOption[];
|
|
112
|
-
/** The serialization strategy for route loaders. Defaults to `
|
|
112
|
+
/** The serialization strategy for route loaders. Defaults to `auto`. */
|
|
113
113
|
defaultLoadersSerializationStrategy?: SerializationStrategy;
|
|
114
114
|
/**
|
|
115
115
|
* Enable strict mode for route loaders and actions by default.
|
package/lib/vite/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { _ as normalizePath$1, a as getPathnameFromDirPath, b as parseRouteIndexName, c as isIndexModule, d as isMenuFileName, f as isModuleExt, g as isServiceWorkerName, h as isPluginModule, i as getMenuPathname, l as isLayoutModule, m as isPageModuleExt, n as createFileId, o as isEntryName, p as isPageExt, r as getExtension, s as isErrorName, t as caughtErrorName, u as isMarkdownExt, v as normalizePathKey, x as removeExtension } from "../chunks/fs.mjs";
|
|
2
|
+
import { n as addWarning, t as addError } from "../chunks/format.mjs";
|
|
1
3
|
import { r as isSameOriginUrl, t as ensureSlash } from "../chunks/pathname.mjs";
|
|
2
|
-
import {
|
|
4
|
+
import { t as createRouteTester } from "../chunks/routes.mjs";
|
|
3
5
|
import { t as escapeStaticTrieKey } from "../chunks/route-trie-key.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { _ as normalizePath$1, a as getPathnameFromDirPath, b as parseRouteIndexName, c as isIndexModule, d as isMenuFileName, f as isModuleExt, g as isServiceWorkerName, h as isPluginModule, i as getMenuPathname, l as isLayoutModule, m as isPageModuleExt, n as createFileId, o as isEntryName, p as isPageExt, r as getExtension, s as isErrorName, t as caughtErrorName, u as isMarkdownExt, v as normalizePathKey, x as removeExtension } from "../chunks/fs.mjs";
|
|
6
|
+
import { c as recognizeRequest, d as trimRecognizedInternalPathname, l as resolveValidInternalFullPathname } from "../chunks/request-path.mjs";
|
|
6
7
|
import { t as devPreloadedRouteLoaders } from "../chunks/dev-preloaded-route-loader.mjs";
|
|
7
|
-
import { t as createRouteTester } from "../chunks/routes.mjs";
|
|
8
8
|
import fs, { existsSync } from "node:fs";
|
|
9
|
-
import path, { basename, dirname, extname, isAbsolute, join, resolve } from "node:path";
|
|
9
|
+
import path, { basename, dirname, extname, isAbsolute, join, posix, resolve } from "node:path";
|
|
10
10
|
import { readFile } from "node:fs/promises";
|
|
11
|
-
import { loadEnv, mergeConfig, normalizePath } from "vite";
|
|
11
|
+
import { build, loadEnv, mergeConfig, normalizePath } from "vite";
|
|
12
12
|
import { findExports, findStaticImports, parseStaticImport } from "mlly";
|
|
13
13
|
import { marked } from "marked";
|
|
14
14
|
import { createHash } from "node:crypto";
|
|
@@ -1029,6 +1029,7 @@ function createRoutes(ctx, qwikPlugin, c, esmImports, isSSR, loadersByFile, serv
|
|
|
1029
1029
|
esmImports.push(`import * as ${id}_ from ${importPath};`);
|
|
1030
1030
|
c.push(`const ${id} = ()=>${id}_;`);
|
|
1031
1031
|
}
|
|
1032
|
+
c.push(`${id}._K = ${JSON.stringify(id)};`);
|
|
1032
1033
|
}
|
|
1033
1034
|
}
|
|
1034
1035
|
if (menuCount > 0) {
|
|
@@ -1310,33 +1311,124 @@ function isFileServerFree(filePath, cache) {
|
|
|
1310
1311
|
}
|
|
1311
1312
|
return pending;
|
|
1312
1313
|
}
|
|
1314
|
+
var CHUNK_ID_PREFIX = "\0qwik-router-sw-chunk:";
|
|
1315
|
+
async function bundleServiceWorkerChunks(bundle, serviceWorkerChunks, minify = false) {
|
|
1316
|
+
for (const swChunk of serviceWorkerChunks) {
|
|
1317
|
+
if (!hasChunkImports(swChunk)) continue;
|
|
1318
|
+
swChunk.code = await bundleAsClassicScript(swChunk.fileName, bundle, minify);
|
|
1319
|
+
swChunk.imports = [];
|
|
1320
|
+
swChunk.dynamicImports = [];
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
function hasChunkImports(chunk) {
|
|
1324
|
+
return chunk.imports.length > 0 || chunk.dynamicImports.length > 0;
|
|
1325
|
+
}
|
|
1326
|
+
async function bundleAsClassicScript(entryFileName, bundle, minify) {
|
|
1327
|
+
const result = await build({
|
|
1328
|
+
configFile: false,
|
|
1329
|
+
envDir: false,
|
|
1330
|
+
publicDir: false,
|
|
1331
|
+
logLevel: "silent",
|
|
1332
|
+
plugins: [builtChunksPlugin(bundle)],
|
|
1333
|
+
build: {
|
|
1334
|
+
write: false,
|
|
1335
|
+
minify,
|
|
1336
|
+
modulePreload: false,
|
|
1337
|
+
reportCompressedSize: false,
|
|
1338
|
+
rolldownOptions: {
|
|
1339
|
+
input: CHUNK_ID_PREFIX + entryFileName,
|
|
1340
|
+
output: {
|
|
1341
|
+
format: "iife",
|
|
1342
|
+
codeSplitting: false
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
});
|
|
1347
|
+
return (Array.isArray(result) ? result : [result])[0].output[0].code;
|
|
1348
|
+
}
|
|
1349
|
+
function builtChunksPlugin(bundle) {
|
|
1350
|
+
return {
|
|
1351
|
+
name: "vite-plugin-qwik-router-sw-chunks",
|
|
1352
|
+
resolveId(source, importer) {
|
|
1353
|
+
if (source.startsWith(CHUNK_ID_PREFIX)) return source;
|
|
1354
|
+
if (!importer?.startsWith(CHUNK_ID_PREFIX)) return null;
|
|
1355
|
+
const importerFileName = importer.slice(22);
|
|
1356
|
+
const fileName = posix.join(posix.dirname(importerFileName), source);
|
|
1357
|
+
return bundle[fileName]?.type === "chunk" ? CHUNK_ID_PREFIX + fileName : null;
|
|
1358
|
+
},
|
|
1359
|
+
load(id) {
|
|
1360
|
+
if (!id.startsWith(CHUNK_ID_PREFIX)) return null;
|
|
1361
|
+
const output = bundle[id.slice(22)];
|
|
1362
|
+
return output?.type === "chunk" ? output.code : null;
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1313
1366
|
function getRouteImports(routes, manifest) {
|
|
1314
1367
|
const result = {};
|
|
1368
|
+
const layouts = /* @__PURE__ */ new Map();
|
|
1315
1369
|
routes.forEach((route) => {
|
|
1316
|
-
const
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1370
|
+
const bundles = getBundlesOfFile(manifest, route.filePath);
|
|
1371
|
+
if (bundles.length > 0) result[ensureSlash(route.routeName)] = { dynamicImports: bundles };
|
|
1372
|
+
route.layouts?.forEach((layout) => layouts.set(layout.id, layout));
|
|
1373
|
+
});
|
|
1374
|
+
layouts.forEach((layout) => {
|
|
1375
|
+
const bundles = getBundlesOfFile(manifest, layout.filePath);
|
|
1376
|
+
if (bundles.length > 0) result[layout.id] = { dynamicImports: bundles };
|
|
1320
1377
|
});
|
|
1321
1378
|
for (const bundleName of Object.keys(manifest.bundles)) {
|
|
1322
1379
|
const bundle = manifest.bundles[bundleName];
|
|
1323
1380
|
if (bundle.origins?.some((s) => s.endsWith("@qwik-router-config"))) {
|
|
1324
1381
|
result[bundleName] = {
|
|
1325
1382
|
...bundle,
|
|
1326
|
-
dynamicImports: bundle.dynamicImports?.filter((d) => manifest.bundles[d].origins?.some((s) => s.endsWith("menu.md")))
|
|
1383
|
+
dynamicImports: bundle.dynamicImports?.filter((d) => bundle.qrlImports?.includes(d) || manifest.bundles[d].origins?.some((s) => s.endsWith("menu.md")))
|
|
1327
1384
|
};
|
|
1385
|
+
addRouterConfigToItsImporters(manifest, bundleName, result);
|
|
1328
1386
|
break;
|
|
1329
1387
|
}
|
|
1330
1388
|
}
|
|
1331
1389
|
return result;
|
|
1332
1390
|
}
|
|
1333
|
-
function
|
|
1334
|
-
if (
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1391
|
+
function addRouterConfigToItsImporters(manifest, routerConfigBundleName, result) {
|
|
1392
|
+
for (const [bundleName, bundle] of Object.entries(manifest.bundles)) if (bundle.dynamicImports?.includes(routerConfigBundleName)) result[bundleName] = {
|
|
1393
|
+
...bundle,
|
|
1394
|
+
dynamicImports: [...bundle.qrlImports ?? [], routerConfigBundleName]
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
function getBundlesOfFile(manifest, filePath) {
|
|
1398
|
+
const extlessFilePath = removeExtension(filePath);
|
|
1399
|
+
const bundles = [];
|
|
1400
|
+
for (const [bundleName, bundle] of Object.entries(manifest.bundles)) if (isBundleOfFile(bundle, extlessFilePath)) bundles.push(bundleName);
|
|
1401
|
+
return bundles;
|
|
1339
1402
|
}
|
|
1403
|
+
function isBundleOfFile(bundle, extlessFilePath) {
|
|
1404
|
+
if (!bundle.origins) return false;
|
|
1405
|
+
return bundle.origins.some((bundleOrigin) => extlessFilePath.endsWith(removeExtension(bundleOrigin)));
|
|
1406
|
+
}
|
|
1407
|
+
var ROUTER_CHUNK_NAME = "qwik-router";
|
|
1408
|
+
var ROUTER_RUNTIME_MODULE = /[/\\](?:qwik-router|@qwik\.dev[/\\]router)[/\\]lib[/\\](?:index\.qwik|chunks[/\\][^/\\]+?)\.mjs(?:_\w+\.\w+)?$/;
|
|
1409
|
+
var LOADED_ON_DEMAND = /_(?:serverQrl|QwikRouterMockProvider|useQwikMockRouter)_/;
|
|
1410
|
+
var getRouterChunkName = (moduleId) => (moduleId === "@qwik-router-config" || ROUTER_RUNTIME_MODULE.test(moduleId)) && !LOADED_ON_DEMAND.test(moduleId) ? ROUTER_CHUNK_NAME : null;
|
|
1411
|
+
var addRouterChunkGroup = (output) => {
|
|
1412
|
+
const codeSplitting = typeof output.codeSplitting === "object" ? output.codeSplitting : {};
|
|
1413
|
+
return {
|
|
1414
|
+
...output,
|
|
1415
|
+
codeSplitting: {
|
|
1416
|
+
...codeSplitting,
|
|
1417
|
+
groups: [...codeSplitting.groups ?? [], {
|
|
1418
|
+
name: getRouterChunkName,
|
|
1419
|
+
priority: Number.MAX_SAFE_INTEGER,
|
|
1420
|
+
minSize: 0,
|
|
1421
|
+
minModuleSize: 0,
|
|
1422
|
+
minShareCount: 1,
|
|
1423
|
+
maxSize: Infinity,
|
|
1424
|
+
maxModuleSize: Infinity
|
|
1425
|
+
}]
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
};
|
|
1429
|
+
var registerRouterChunkAsEager = (api) => {
|
|
1430
|
+
if (!api.getOptions().experimental?.noSPA) api.registerEagerModules?.((id) => getRouterChunkName(id) !== null);
|
|
1431
|
+
};
|
|
1340
1432
|
var findLocation = (e) => {
|
|
1341
1433
|
const stack = e.stack;
|
|
1342
1434
|
if (typeof stack === "string") {
|
|
@@ -1433,6 +1525,8 @@ function parseId(originalId) {
|
|
|
1433
1525
|
params: new URLSearchParams(queryStr)
|
|
1434
1526
|
};
|
|
1435
1527
|
}
|
|
1528
|
+
new TextEncoder();
|
|
1529
|
+
new TextDecoder();
|
|
1436
1530
|
var supportedExtensions = [
|
|
1437
1531
|
".jpg",
|
|
1438
1532
|
".jpeg",
|
|
@@ -2272,7 +2366,7 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2272
2366
|
viteCommand = viteEnv.command;
|
|
2273
2367
|
return {
|
|
2274
2368
|
define: {
|
|
2275
|
-
"globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__": JSON.stringify(userOpts?.defaultLoadersSerializationStrategy || "
|
|
2369
|
+
"globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__": JSON.stringify(userOpts?.defaultLoadersSerializationStrategy || "auto"),
|
|
2276
2370
|
"globalThis.__NO_TRAILING_SLASH__": JSON.stringify(userOpts?.trailingSlash === false),
|
|
2277
2371
|
"globalThis.__QWIK_ROUTER_BASE_PATHNAME__": JSON.stringify(resolveBasePathname(userOpts, _viteConfig.base || "/")),
|
|
2278
2372
|
"globalThis.__SSR_CACHE_SIZE__": JSON.stringify(viteEnv.command === "serve" ? 0 : userOpts?.ssrCacheSize ?? 50),
|
|
@@ -2361,6 +2455,7 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2361
2455
|
qwikPlugin.api.registerBundleGraphAdder?.((manifest) => {
|
|
2362
2456
|
return getRouteImports(ctx.routes, manifest);
|
|
2363
2457
|
});
|
|
2458
|
+
registerRouterChunkAsEager(qwikPlugin.api);
|
|
2364
2459
|
outDir = config.build?.outDir;
|
|
2365
2460
|
serverEntryIds = getServerEntryIds(rootDir, qwikPlugin.api.getOptions().srcDir ?? void 0, config.build?.ssr, config.build?.rolldownOptions?.input);
|
|
2366
2461
|
},
|
|
@@ -2477,7 +2572,11 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2477
2572
|
}
|
|
2478
2573
|
return null;
|
|
2479
2574
|
},
|
|
2480
|
-
|
|
2575
|
+
outputOptions(output) {
|
|
2576
|
+
if (this.environment.config.consumer !== "client") return null;
|
|
2577
|
+
return addRouterChunkGroup(output);
|
|
2578
|
+
},
|
|
2579
|
+
async generateBundle(_, bundles) {
|
|
2481
2580
|
const manifest = qwikPlugin.api.getManifest();
|
|
2482
2581
|
if (manifest) {
|
|
2483
2582
|
const srcDir = qwikPlugin.api.getOptions().srcDir;
|
|
@@ -2485,21 +2584,10 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2485
2584
|
}
|
|
2486
2585
|
for (const chunk of Object.values(bundles)) if (chunk.type === "chunk" && chunk.code.includes("__LOADERS:")) chunk.code = replaceLoaderPlaceholders(chunk.code, loadersByFile);
|
|
2487
2586
|
if (this.environment.config.consumer === "client") {
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
};
|
|
2493
|
-
});
|
|
2494
|
-
for (const entry of entries) for (const fileName in bundles) {
|
|
2495
|
-
const c = bundles[fileName];
|
|
2496
|
-
if (c.type === "chunk" && c.isDynamicEntry && c.facadeModuleId) {
|
|
2497
|
-
const extensionlessFilePath = removeExtension(normalizePath$1(c.facadeModuleId));
|
|
2498
|
-
if (entry.extensionlessFilePath === extensionlessFilePath) {
|
|
2499
|
-
c.fileName = entry.chunkFileName;
|
|
2500
|
-
continue;
|
|
2501
|
-
}
|
|
2502
|
-
}
|
|
2587
|
+
await bundleServiceWorkerChunks(bundles, ctx.serviceWorkers.map((sw) => findEntryChunk(bundles, sw.filePath)).filter((c) => !!c), this.environment.config.build.minify);
|
|
2588
|
+
for (const entry of [...ctx.entries, ...ctx.serviceWorkers]) {
|
|
2589
|
+
const c = findEntryChunk(bundles, entry.filePath);
|
|
2590
|
+
if (c) c.fileName = entry.chunkFileName;
|
|
2503
2591
|
}
|
|
2504
2592
|
}
|
|
2505
2593
|
},
|
|
@@ -2511,6 +2599,10 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2511
2599
|
}
|
|
2512
2600
|
};
|
|
2513
2601
|
}
|
|
2602
|
+
function findEntryChunk(bundles, filePath) {
|
|
2603
|
+
const extensionlessFilePath = removeExtension(filePath);
|
|
2604
|
+
for (const output of Object.values(bundles)) if (output.type === "chunk" && output.isDynamicEntry && output.facadeModuleId && removeExtension(normalizePath$1(output.facadeModuleId)) === extensionlessFilePath) return output;
|
|
2605
|
+
}
|
|
2514
2606
|
async function generateServerPackageJson(outDir) {
|
|
2515
2607
|
await fs.promises.mkdir(outDir, { recursive: true });
|
|
2516
2608
|
const serverPackageJsonPath = join(outDir, "package.json");
|
|
@@ -2532,7 +2624,7 @@ async function generateServerPackageJson(outDir) {
|
|
|
2532
2624
|
* their `_regSymbol` side effects run before any RPC request arrives.
|
|
2533
2625
|
*/
|
|
2534
2626
|
function serverFnsPlugin(buildContextRef) {
|
|
2535
|
-
const RESOLVED_ID = "\
|
|
2627
|
+
const RESOLVED_ID = "\0" + VIRTUAL_SERVER_FNS;
|
|
2536
2628
|
const serverFnModules = /* @__PURE__ */ new Set();
|
|
2537
2629
|
let serverFnsReady = null;
|
|
2538
2630
|
function reset() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qwik.dev/router",
|
|
3
3
|
"description": "The router for Qwik.",
|
|
4
|
-
"version": "2.0.0-rc.
|
|
4
|
+
"version": "2.0.0-rc.6",
|
|
5
5
|
"bugs": "https://github.com/QwikDev/qwik/issues",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@azure/functions": "3.5.1",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"valibot": ">=0.36.0 <2",
|
|
29
29
|
"vfile": "6.0.3",
|
|
30
30
|
"vite-imagetools": "10.0.0",
|
|
31
|
-
"yaml": "^2.
|
|
31
|
+
"yaml": "^2.9.1",
|
|
32
32
|
"zod": "^3.25.48"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"tsm": "2.3.0",
|
|
41
41
|
"typescript": "5.9.3",
|
|
42
42
|
"uvu": "0.5.6",
|
|
43
|
-
"vite": "8.
|
|
44
|
-
"@qwik.dev/core": "2.0.0-rc.
|
|
43
|
+
"vite": "8.3.8",
|
|
44
|
+
"@qwik.dev/core": "2.0.0-rc.6"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
"main": "./lib/index.qwik.mjs",
|
|
167
167
|
"peerDependencies": {
|
|
168
168
|
"vite": ">=8 <9",
|
|
169
|
-
"@qwik.dev/core": "2.0.0-rc.
|
|
169
|
+
"@qwik.dev/core": "2.0.0-rc.6"
|
|
170
170
|
},
|
|
171
171
|
"publishConfig": {
|
|
172
172
|
"access": "public"
|