@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/vite/index.mjs
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
import { optimize } from "svgo";
|
|
19
|
-
import { p as parseId, f as formatError } from "../chunks/format-error.mjs";
|
|
1
|
+
import { mergeConfig, loadEnv } from 'vite';
|
|
2
|
+
import fs, { existsSync } from 'node:fs';
|
|
3
|
+
import path, { join, dirname, basename, resolve, isAbsolute, extname } from 'node:path';
|
|
4
|
+
import { g as getExtension, r as removeExtension, i as isIndexModule, a as isErrorName, b as isLayoutModule, c as isEntryName, d as isMenuFileName, e as isServiceWorkerName, f as isPageModuleExt, h as isModuleExt, j as isMarkdownExt, k as isSameOriginUrl, l as normalizePath, m as getPathnameFromDirPath, o as getMenuPathname, p as createFileId, q as parseRouteIndexName, s as isPluginModule, t as addError, u as addWarning, v as isPageExt } from '../chunks/fs.mjs';
|
|
5
|
+
import { marked } from 'marked';
|
|
6
|
+
import { SourceMapGenerator } from 'source-map';
|
|
7
|
+
import { visit } from 'unist-util-visit';
|
|
8
|
+
import { parse } from 'yaml';
|
|
9
|
+
import Slugger from 'github-slugger';
|
|
10
|
+
import { valueToEstree } from 'estree-util-value-to-estree';
|
|
11
|
+
import { headingRank } from 'hast-util-heading-rank';
|
|
12
|
+
import { toString } from 'hast-util-to-string';
|
|
13
|
+
import { refractor } from 'refractor';
|
|
14
|
+
import tsxLang from 'refractor/lang/tsx.js';
|
|
15
|
+
import { optimize } from 'svgo';
|
|
16
|
+
import { p as parseId, f as formatError } from '../chunks/format-error.mjs';
|
|
17
|
+
|
|
20
18
|
function extendConfig(baseConfigExport, serverConfigExport) {
|
|
21
19
|
return async (env) => {
|
|
22
20
|
let resolvedBase = await baseConfigExport;
|
|
@@ -30,7 +28,9 @@ function extendConfig(baseConfigExport, serverConfigExport) {
|
|
|
30
28
|
return mergeConfig(resolvedBase, resolvedServer);
|
|
31
29
|
};
|
|
32
30
|
}
|
|
31
|
+
|
|
33
32
|
const swRegister = 'export default""';
|
|
33
|
+
|
|
34
34
|
function getSourceFile(fileName) {
|
|
35
35
|
const ext = getExtension(fileName);
|
|
36
36
|
const extlessName = removeExtension(fileName);
|
|
@@ -59,6 +59,7 @@ function getSourceFile(fileName) {
|
|
|
59
59
|
}
|
|
60
60
|
return null;
|
|
61
61
|
}
|
|
62
|
+
|
|
62
63
|
function getMarkdownRelativeUrl(opts, containingFilePath, url, checkFileExists) {
|
|
63
64
|
if (typeof url !== "string" || !isSameOriginUrl(url)) {
|
|
64
65
|
return url;
|
|
@@ -68,9 +69,9 @@ function getMarkdownRelativeUrl(opts, containingFilePath, url, checkFileExists)
|
|
|
68
69
|
const strippedUrl = url.split("?")[0].split("#")[0];
|
|
69
70
|
const extension = getExtension(strippedUrl);
|
|
70
71
|
if (isMarkdownExt(extension)) {
|
|
71
|
-
const
|
|
72
|
+
const isAbsolute = strippedUrl.startsWith("/");
|
|
72
73
|
const parts = normalizePath(strippedUrl).split("/").filter((p) => p.length > 0);
|
|
73
|
-
const filePath =
|
|
74
|
+
const filePath = isAbsolute ? join(opts.routesDir, ...parts) : join(dirname(containingFilePath), ...parts);
|
|
74
75
|
if (checkFileExists && !existsSync(filePath)) {
|
|
75
76
|
console.warn(
|
|
76
77
|
`
|
|
@@ -101,6 +102,7 @@ The link "${url}", found within "${containingFilePath}" does not have a matching
|
|
|
101
102
|
}
|
|
102
103
|
return url;
|
|
103
104
|
}
|
|
105
|
+
|
|
104
106
|
function createMenu(opts, filePath) {
|
|
105
107
|
const menu = {
|
|
106
108
|
pathname: getMenuPathname(opts, filePath),
|
|
@@ -207,6 +209,7 @@ function parseMenu(opts, filePath, content, checkFileExists = true) {
|
|
|
207
209
|
}
|
|
208
210
|
return stack[0];
|
|
209
211
|
}
|
|
212
|
+
|
|
210
213
|
function parseRoutePathname(basePathname, pathname) {
|
|
211
214
|
if (pathname === basePathname) {
|
|
212
215
|
return {
|
|
@@ -263,6 +266,7 @@ function parseRoutePathname(basePathname, pathname) {
|
|
|
263
266
|
}
|
|
264
267
|
const PARAM_PATTERN = /^(\.\.\.)?(\w+)?$/;
|
|
265
268
|
const DYNAMIC_SEGMENT = /\[(.+?)\]/;
|
|
269
|
+
|
|
266
270
|
function routeSortCompare(a, b) {
|
|
267
271
|
const maxSegments = Math.max(a.segments.length, b.segments.length);
|
|
268
272
|
for (let i = 0; i < maxSegments; i += 1) {
|
|
@@ -299,6 +303,7 @@ function routeSortCompare(a, b) {
|
|
|
299
303
|
}
|
|
300
304
|
return a.pathname < b.pathname ? -1 : 1;
|
|
301
305
|
}
|
|
306
|
+
|
|
302
307
|
function resolveSourceFiles(opts, sourceFiles) {
|
|
303
308
|
const layouts = sourceFiles.filter((s) => s.type === "layout").map((s) => resolveLayout(opts, s)).sort((a, b) => {
|
|
304
309
|
return a.id < b.id ? -1 : 1;
|
|
@@ -428,6 +433,7 @@ function resolveServiceWorkerEntry(opts, sourceFile) {
|
|
|
428
433
|
};
|
|
429
434
|
return buildEntry;
|
|
430
435
|
}
|
|
436
|
+
|
|
431
437
|
async function walkRoutes(routesDir) {
|
|
432
438
|
const sourceFiles = [];
|
|
433
439
|
await walkRouteDir(sourceFiles, normalizePath(routesDir), basename(routesDir));
|
|
@@ -456,6 +462,7 @@ async function walkRouteDir(sourceFiles, dirPath, dirName) {
|
|
|
456
462
|
})
|
|
457
463
|
);
|
|
458
464
|
}
|
|
465
|
+
|
|
459
466
|
async function walkServerPlugins(opts) {
|
|
460
467
|
const dirPath = opts.serverPluginsDir;
|
|
461
468
|
const dirItemNames = await fs.promises.readdir(dirPath);
|
|
@@ -476,6 +483,7 @@ async function walkServerPlugins(opts) {
|
|
|
476
483
|
);
|
|
477
484
|
return sourceFiles;
|
|
478
485
|
}
|
|
486
|
+
|
|
479
487
|
async function parseRoutesDir(ctx) {
|
|
480
488
|
try {
|
|
481
489
|
await updateRoutingContext(ctx);
|
|
@@ -492,9 +500,9 @@ async function parseRoutesDir(ctx) {
|
|
|
492
500
|
}
|
|
493
501
|
}
|
|
494
502
|
function updateRoutingContext(ctx) {
|
|
495
|
-
ctx.activeBuild
|
|
503
|
+
ctx.activeBuild ||= _updateRoutingContext(ctx).finally(() => {
|
|
496
504
|
ctx.activeBuild = null;
|
|
497
|
-
})
|
|
505
|
+
});
|
|
498
506
|
return ctx.activeBuild;
|
|
499
507
|
}
|
|
500
508
|
async function _updateRoutingContext(ctx) {
|
|
@@ -605,6 +613,7 @@ ${foundRoutes.map((r) => ` - ${r.filePath}`).join("\n")}`
|
|
|
605
613
|
);
|
|
606
614
|
});
|
|
607
615
|
}
|
|
616
|
+
|
|
608
617
|
function createBuildContext(rootDir, viteBasePath, userOpts, target, dynamicImports) {
|
|
609
618
|
const ctx = {
|
|
610
619
|
rootDir: normalizePath(rootDir),
|
|
@@ -675,6 +684,7 @@ function normalizeOptions(rootDir, viteBasePath, userOpts) {
|
|
|
675
684
|
opts.platform = opts.platform || {};
|
|
676
685
|
return opts;
|
|
677
686
|
}
|
|
687
|
+
|
|
678
688
|
function parseFrontmatter(ctx) {
|
|
679
689
|
return (mdast, vfile) => {
|
|
680
690
|
const attrs = {};
|
|
@@ -766,6 +776,7 @@ function frontmatterAttrsToDocumentHead(attrs) {
|
|
|
766
776
|
}
|
|
767
777
|
return null;
|
|
768
778
|
}
|
|
779
|
+
|
|
769
780
|
function rehypeSlug() {
|
|
770
781
|
return (ast) => {
|
|
771
782
|
const mdast = ast;
|
|
@@ -904,6 +915,7 @@ function hasProperty(node, propName) {
|
|
|
904
915
|
const value = node && typeof node === "object" && node.type === "element" && node.properties && own.call(node.properties, propName) && node.properties[propName];
|
|
905
916
|
return value != null && value !== false;
|
|
906
917
|
}
|
|
918
|
+
|
|
907
919
|
function rehypeSyntaxHighlight() {
|
|
908
920
|
refractor.register(tsxLang);
|
|
909
921
|
return async (ast) => {
|
|
@@ -939,12 +951,13 @@ function getLanguage(className) {
|
|
|
939
951
|
}
|
|
940
952
|
return null;
|
|
941
953
|
}
|
|
954
|
+
|
|
942
955
|
async function createMdxTransformer(ctx) {
|
|
943
|
-
const { compile } = await import(
|
|
944
|
-
const { default: remarkFrontmatter } = await import(
|
|
945
|
-
const { default: remarkGfm } = await import(
|
|
946
|
-
const { default: rehypeAutolinkHeadings } = await import(
|
|
947
|
-
const { VFile } = await import(
|
|
956
|
+
const { compile } = await import('@mdx-js/mdx');
|
|
957
|
+
const { default: remarkFrontmatter } = await import('remark-frontmatter');
|
|
958
|
+
const { default: remarkGfm } = await import('remark-gfm');
|
|
959
|
+
const { default: rehypeAutolinkHeadings } = await import('rehype-autolink-headings');
|
|
960
|
+
const { VFile } = await import('vfile');
|
|
948
961
|
const userMdxOpts = ctx.opts.mdx;
|
|
949
962
|
const userRemarkPlugins = userMdxOpts.remarkPlugins || [];
|
|
950
963
|
const userRehypePlugins = userMdxOpts.rehypePlugins || [];
|
|
@@ -1010,6 +1023,7 @@ export default WrappedMdxContent;
|
|
|
1010
1023
|
}
|
|
1011
1024
|
};
|
|
1012
1025
|
}
|
|
1026
|
+
|
|
1013
1027
|
function createEntries(ctx, c) {
|
|
1014
1028
|
const isClient = ctx.target === "client";
|
|
1015
1029
|
const entries = [...ctx.entries, ...ctx.serviceWorkers];
|
|
@@ -1031,6 +1045,7 @@ function generateQwikRouterEntries(ctx) {
|
|
|
1031
1045
|
}
|
|
1032
1046
|
return c.join("\n") + "\n";
|
|
1033
1047
|
}
|
|
1048
|
+
|
|
1034
1049
|
function getImportPath(importPath) {
|
|
1035
1050
|
const lowerCasePath = importPath.toLowerCase();
|
|
1036
1051
|
if (lowerCasePath.endsWith(".tsx") || lowerCasePath.endsWith(".jsx")) {
|
|
@@ -1041,6 +1056,7 @@ function getImportPath(importPath) {
|
|
|
1041
1056
|
}
|
|
1042
1057
|
return importPath;
|
|
1043
1058
|
}
|
|
1059
|
+
|
|
1044
1060
|
function createMenus(ctx, c, esmImports, isSSR) {
|
|
1045
1061
|
c.push(`
|
|
1046
1062
|
/** Qwik Router Menus (${ctx.menus.length}) */`);
|
|
@@ -1059,6 +1075,7 @@ function createMenus(ctx, c, esmImports, isSSR) {
|
|
|
1059
1075
|
}
|
|
1060
1076
|
c.push(`];`);
|
|
1061
1077
|
}
|
|
1078
|
+
|
|
1062
1079
|
function createRoutes(ctx, qwikPlugin, c, esmImports, isSSR) {
|
|
1063
1080
|
const includeEndpoints = isSSR;
|
|
1064
1081
|
const dynamicImports = ctx.dynamicImports;
|
|
@@ -1143,6 +1160,7 @@ function getClientRouteBundleNames(qwikPlugin, r) {
|
|
|
1143
1160
|
}
|
|
1144
1161
|
return bundlesNames;
|
|
1145
1162
|
}
|
|
1163
|
+
|
|
1146
1164
|
function createServerPlugins(ctx, _qwikPlugin, c, esmImports, isSSR) {
|
|
1147
1165
|
c.push(`
|
|
1148
1166
|
/** Qwik Router ServerPlugins (${ctx.serverPlugins.length}) */`);
|
|
@@ -1158,6 +1176,7 @@ function createServerPlugins(ctx, _qwikPlugin, c, esmImports, isSSR) {
|
|
|
1158
1176
|
}
|
|
1159
1177
|
c.push(`];`);
|
|
1160
1178
|
}
|
|
1179
|
+
|
|
1161
1180
|
function generateQwikRouterConfig(ctx, qwikPlugin, isSSR) {
|
|
1162
1181
|
const esmImports = [];
|
|
1163
1182
|
const c = [];
|
|
@@ -1177,13 +1196,14 @@ import { isDev } from '@qwik.dev/core/build';`);
|
|
|
1177
1196
|
);
|
|
1178
1197
|
return esmImports.join("\n") + c.join("\n");
|
|
1179
1198
|
}
|
|
1180
|
-
|
|
1199
|
+
|
|
1200
|
+
function generateServiceWorkerRegister(ctx, swRegister) {
|
|
1181
1201
|
let swReg;
|
|
1182
1202
|
let swUrl = "/service-worker.js";
|
|
1183
1203
|
if (ctx.serviceWorkers.length === 0) {
|
|
1184
1204
|
swReg = SW_UNREGISTER;
|
|
1185
1205
|
} else {
|
|
1186
|
-
swReg =
|
|
1206
|
+
swReg = swRegister;
|
|
1187
1207
|
const sw = ctx.serviceWorkers.sort(
|
|
1188
1208
|
(a, b) => a.chunkFileName.length < b.chunkFileName.length ? -1 : 1
|
|
1189
1209
|
)[0];
|
|
@@ -1195,6 +1215,7 @@ function generateServiceWorkerRegister(ctx, swRegister2) {
|
|
|
1195
1215
|
const SW_UNREGISTER = `
|
|
1196
1216
|
"serviceWorker"in navigator&&navigator.serviceWorker.getRegistrations().then(r=>{for(const e of r){const c='__url'.split("/").pop();e.active?.scriptURL.endsWith(c||"service-worker.js")&&e.unregister().catch(console.error)}}),"caches"in window&&caches.keys().then(r=>{const e=r.find(c=>c.startsWith("QwikBuild"));e&&caches.delete(e).catch(console.error)}).catch(console.error)
|
|
1197
1217
|
`;
|
|
1218
|
+
|
|
1198
1219
|
function getRouteImports(routes, manifest) {
|
|
1199
1220
|
const result = {};
|
|
1200
1221
|
routes.forEach((route) => {
|
|
@@ -1231,13 +1252,14 @@ function isBundlePartOfRoute(bundle, routeAndLayoutPaths) {
|
|
|
1231
1252
|
}
|
|
1232
1253
|
for (const bundleOrigin of bundle.origins) {
|
|
1233
1254
|
const originPath = removeExtension(bundleOrigin);
|
|
1234
|
-
return routeAndLayoutPaths.some((
|
|
1255
|
+
return routeAndLayoutPaths.some((path) => path.endsWith(originPath));
|
|
1235
1256
|
}
|
|
1236
1257
|
}
|
|
1258
|
+
|
|
1237
1259
|
function imagePlugin(userOpts) {
|
|
1238
1260
|
const supportedExtensions = [".jpg", ".jpeg", ".png", ".webp", ".gif", ".avif", ".tiff"];
|
|
1239
1261
|
return [
|
|
1240
|
-
import(
|
|
1262
|
+
import('vite-imagetools').then(
|
|
1241
1263
|
({ imagetools }) => imagetools({
|
|
1242
1264
|
exclude: [],
|
|
1243
1265
|
extendOutputFormats(builtins) {
|
|
@@ -1395,6 +1417,7 @@ function optimizeSvg({ code, path: path2 }, userOpts) {
|
|
|
1395
1417
|
svgAttributes
|
|
1396
1418
|
};
|
|
1397
1419
|
}
|
|
1420
|
+
|
|
1398
1421
|
async function validatePlugin(opts) {
|
|
1399
1422
|
if (typeof opts.routesDir !== "string") {
|
|
1400
1423
|
throw new Error(`qwikRouter plugin "routesDir" option missing`);
|
|
@@ -1415,22 +1438,23 @@ async function validatePlugin(opts) {
|
|
|
1415
1438
|
throw new Error(`qwikRouter plugin "routesDir" not found: ${e}`);
|
|
1416
1439
|
}
|
|
1417
1440
|
}
|
|
1441
|
+
|
|
1418
1442
|
class HtmlTransformPatcher {
|
|
1443
|
+
state = 0 /* BUFFERING */;
|
|
1444
|
+
buffer = "";
|
|
1445
|
+
headInnerIndex = -1;
|
|
1446
|
+
bodyInnerIndex = -1;
|
|
1447
|
+
isHtmlResponse = false;
|
|
1448
|
+
bodyPostContent = "";
|
|
1449
|
+
response;
|
|
1450
|
+
server;
|
|
1451
|
+
request;
|
|
1452
|
+
origWrite;
|
|
1453
|
+
origEnd;
|
|
1454
|
+
origSetHeader;
|
|
1455
|
+
origWriteHead;
|
|
1456
|
+
processingPromise = null;
|
|
1419
1457
|
constructor(req, res, server) {
|
|
1420
|
-
__publicField(this, "state", 0);
|
|
1421
|
-
__publicField(this, "buffer", "");
|
|
1422
|
-
__publicField(this, "headInnerIndex", -1);
|
|
1423
|
-
__publicField(this, "bodyInnerIndex", -1);
|
|
1424
|
-
__publicField(this, "isHtmlResponse", false);
|
|
1425
|
-
__publicField(this, "bodyPostContent", "");
|
|
1426
|
-
__publicField(this, "response");
|
|
1427
|
-
__publicField(this, "server");
|
|
1428
|
-
__publicField(this, "request");
|
|
1429
|
-
__publicField(this, "origWrite");
|
|
1430
|
-
__publicField(this, "origEnd");
|
|
1431
|
-
__publicField(this, "origSetHeader");
|
|
1432
|
-
__publicField(this, "origWriteHead");
|
|
1433
|
-
__publicField(this, "processingPromise", null);
|
|
1434
1458
|
this.request = req;
|
|
1435
1459
|
this.response = res;
|
|
1436
1460
|
this.server = server;
|
|
@@ -1471,7 +1495,7 @@ class HtmlTransformPatcher {
|
|
|
1471
1495
|
};
|
|
1472
1496
|
}
|
|
1473
1497
|
handleWrite(chunk, encoding, callback) {
|
|
1474
|
-
if (!this.isHtmlResponse || this.state === 3) {
|
|
1498
|
+
if (!this.isHtmlResponse || this.state === 3 /* PASSTHROUGH */) {
|
|
1475
1499
|
return this.origWrite(chunk, encoding, callback);
|
|
1476
1500
|
}
|
|
1477
1501
|
if (typeof encoding === "function") {
|
|
@@ -1490,7 +1514,7 @@ class HtmlTransformPatcher {
|
|
|
1490
1514
|
}
|
|
1491
1515
|
this.buffer += data;
|
|
1492
1516
|
switch (this.state) {
|
|
1493
|
-
case 0
|
|
1517
|
+
case 0 /* BUFFERING */:
|
|
1494
1518
|
if (this.headInnerIndex === -1) {
|
|
1495
1519
|
const headMatch = this.buffer.match(/<head[^>]*>/i);
|
|
1496
1520
|
if (headMatch) {
|
|
@@ -1501,16 +1525,16 @@ class HtmlTransformPatcher {
|
|
|
1501
1525
|
if (this.headInnerIndex !== -1) {
|
|
1502
1526
|
const bodyMatch = this.buffer.slice(this.headInnerIndex).match(/<body[^>]*>/i);
|
|
1503
1527
|
if (bodyMatch) {
|
|
1504
|
-
this.state = 1
|
|
1528
|
+
this.state = 1 /* PROCESSING_HEAD */;
|
|
1505
1529
|
const bodyOuterIndex = this.buffer.indexOf(bodyMatch[0]);
|
|
1506
1530
|
this.bodyInnerIndex = bodyOuterIndex + bodyMatch[0].length;
|
|
1507
1531
|
this.processingPromise = this.processHead();
|
|
1508
1532
|
}
|
|
1509
1533
|
}
|
|
1510
1534
|
break;
|
|
1511
|
-
case 1
|
|
1535
|
+
case 1 /* PROCESSING_HEAD */:
|
|
1512
1536
|
break;
|
|
1513
|
-
case 2
|
|
1537
|
+
case 2 /* STREAMING_BODY */:
|
|
1514
1538
|
this.handleStreamingBodyState();
|
|
1515
1539
|
break;
|
|
1516
1540
|
default:
|
|
@@ -1556,7 +1580,7 @@ class HtmlTransformPatcher {
|
|
|
1556
1580
|
}
|
|
1557
1581
|
this.buffer = this.buffer.slice(0, this.headInnerIndex) + headPreContent + this.buffer.slice(this.headInnerIndex, headCloseIndex) + headPostContent + this.buffer.slice(headCloseIndex, this.bodyInnerIndex) + bodyPreContent + this.buffer.slice(this.bodyInnerIndex);
|
|
1558
1582
|
if (this.bodyPostContent.length > 0) {
|
|
1559
|
-
this.state = 2
|
|
1583
|
+
this.state = 2 /* STREAMING_BODY */;
|
|
1560
1584
|
this.handleStreamingBodyState();
|
|
1561
1585
|
return;
|
|
1562
1586
|
}
|
|
@@ -1579,7 +1603,7 @@ class HtmlTransformPatcher {
|
|
|
1579
1603
|
this.flushBuffer(6);
|
|
1580
1604
|
}
|
|
1581
1605
|
transitionToPassthrough() {
|
|
1582
|
-
this.state = 3
|
|
1606
|
+
this.state = 3 /* PASSTHROUGH */;
|
|
1583
1607
|
this.flushBuffer();
|
|
1584
1608
|
}
|
|
1585
1609
|
flushBuffer(keep = 0) {
|
|
@@ -1610,6 +1634,7 @@ function wrapResponseForHtmlTransform(request, response, server) {
|
|
|
1610
1634
|
new HtmlTransformPatcher(request, response, server);
|
|
1611
1635
|
return response;
|
|
1612
1636
|
}
|
|
1637
|
+
|
|
1613
1638
|
const makeRouterDevMiddleware = (server, ctx) => async (req, res, next) => {
|
|
1614
1639
|
const mod = await server.ssrLoadModule("src/entry.ssr");
|
|
1615
1640
|
if (!mod.default) {
|
|
@@ -1649,7 +1674,11 @@ const makeRouterDevMiddleware = (server, ctx) => async (req, res, next) => {
|
|
|
1649
1674
|
const render = (async (opts) => {
|
|
1650
1675
|
return await renderer(opts);
|
|
1651
1676
|
});
|
|
1652
|
-
const { router, staticFile, notFound } = createQwikRouter({
|
|
1677
|
+
const { router, staticFile, notFound } = createQwikRouter({
|
|
1678
|
+
render,
|
|
1679
|
+
// inject the platform from dev middleware options
|
|
1680
|
+
platform: ctx.opts.platform
|
|
1681
|
+
});
|
|
1653
1682
|
const wrappedRes = wrapResponseForHtmlTransform(req, res, server);
|
|
1654
1683
|
staticFile(req, wrappedRes, () => {
|
|
1655
1684
|
router(req, wrappedRes, () => {
|
|
@@ -1705,6 +1734,7 @@ const getRouterIndexTags = (server) => {
|
|
|
1705
1734
|
attrs: { rel: "stylesheet", href: url }
|
|
1706
1735
|
}));
|
|
1707
1736
|
};
|
|
1737
|
+
|
|
1708
1738
|
const QWIK_ROUTER_CONFIG_ID = "@qwik-router-config";
|
|
1709
1739
|
const QWIK_ROUTER_ENTRIES_ID = "@qwik-router-entries";
|
|
1710
1740
|
const QWIK_ROUTER = "@qwik.dev/router";
|
|
@@ -1720,7 +1750,6 @@ function qwikRouterPlugin(userOpts) {
|
|
|
1720
1750
|
let mdxTransform = null;
|
|
1721
1751
|
let rootDir = null;
|
|
1722
1752
|
let qwikPlugin;
|
|
1723
|
-
let ssrFormat = "esm";
|
|
1724
1753
|
let outDir = null;
|
|
1725
1754
|
let viteCommand;
|
|
1726
1755
|
let devServer = null;
|
|
@@ -1820,9 +1849,6 @@ function qwikRouterPlugin(userOpts) {
|
|
|
1820
1849
|
qwikPlugin.api.registerBundleGraphAdder?.((manifest) => {
|
|
1821
1850
|
return getRouteImports(ctx.routes, manifest);
|
|
1822
1851
|
});
|
|
1823
|
-
if (config.ssr?.format === "cjs") {
|
|
1824
|
-
ssrFormat = "cjs";
|
|
1825
|
-
}
|
|
1826
1852
|
outDir = config.build?.outDir;
|
|
1827
1853
|
},
|
|
1828
1854
|
async configureServer(server) {
|
|
@@ -1833,8 +1859,8 @@ function qwikRouterPlugin(userOpts) {
|
|
|
1833
1859
|
);
|
|
1834
1860
|
server.watcher.add(toWatch);
|
|
1835
1861
|
await new Promise((resolve2) => setTimeout(resolve2, 1e3));
|
|
1836
|
-
server.watcher.on("change", (
|
|
1837
|
-
if (!/\/(index[.@]|layout[.-]|entry\.|service-worker\.)[^/]*$/.test(
|
|
1862
|
+
server.watcher.on("change", (path) => {
|
|
1863
|
+
if (!/\/(index[.@]|layout[.-]|entry\.|service-worker\.)[^/]*$/.test(path)) {
|
|
1838
1864
|
return;
|
|
1839
1865
|
}
|
|
1840
1866
|
ctx.isDirty = true;
|
|
@@ -1968,14 +1994,14 @@ function qwikRouterPlugin(userOpts) {
|
|
|
1968
1994
|
sequential: true,
|
|
1969
1995
|
async handler() {
|
|
1970
1996
|
if (ctx?.target === "ssr" && outDir) {
|
|
1971
|
-
await generateServerPackageJson(outDir
|
|
1997
|
+
await generateServerPackageJson(outDir);
|
|
1972
1998
|
}
|
|
1973
1999
|
}
|
|
1974
2000
|
}
|
|
1975
2001
|
};
|
|
1976
2002
|
return plugin;
|
|
1977
2003
|
}
|
|
1978
|
-
async function generateServerPackageJson(outDir
|
|
2004
|
+
async function generateServerPackageJson(outDir) {
|
|
1979
2005
|
await fs.promises.mkdir(outDir, { recursive: true });
|
|
1980
2006
|
const serverPackageJsonPath = join(outDir, "package.json");
|
|
1981
2007
|
let packageJson = {};
|
|
@@ -1988,13 +2014,10 @@ async function generateServerPackageJson(outDir, ssrFormat) {
|
|
|
1988
2014
|
}
|
|
1989
2015
|
packageJson = {
|
|
1990
2016
|
...packageJson,
|
|
1991
|
-
type:
|
|
2017
|
+
type: "module"
|
|
1992
2018
|
};
|
|
1993
2019
|
const serverPackageJsonCode = JSON.stringify(packageJson, null, 2);
|
|
1994
2020
|
await fs.promises.writeFile(serverPackageJsonPath, serverPackageJsonCode);
|
|
1995
2021
|
}
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
qwikCity,
|
|
1999
|
-
qwikRouter
|
|
2000
|
-
};
|
|
2022
|
+
|
|
2023
|
+
export { extendConfig, qwikCity, qwikRouter };
|
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-beta.
|
|
4
|
+
"version": "2.0.0-beta.15",
|
|
5
5
|
"bugs": "https://github.com/QwikDev/qwik/issues",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@azure/functions": "3.5.1",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"tsm": "2.3.0",
|
|
41
41
|
"typescript": "5.9.3",
|
|
42
42
|
"uvu": "0.5.6",
|
|
43
|
-
"@qwik.dev/core": "2.0.0-beta.
|
|
43
|
+
"@qwik.dev/core": "2.0.0-beta.15"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
@@ -48,63 +48,51 @@
|
|
|
48
48
|
"exports": {
|
|
49
49
|
".": {
|
|
50
50
|
"types": "./lib/index.d.ts",
|
|
51
|
-
"import": "./lib/index.qwik.mjs"
|
|
52
|
-
"require": "./lib/index.qwik.cjs"
|
|
51
|
+
"import": "./lib/index.qwik.mjs"
|
|
53
52
|
},
|
|
54
53
|
"./adapters/azure-swa/vite": {
|
|
55
54
|
"types": "./lib/adapters/azure-swa/vite/index.d.ts",
|
|
56
|
-
"import": "./lib/adapters/azure-swa/vite/index.mjs"
|
|
57
|
-
"require": "./lib/adapters/azure-swa/vite/index.cjs"
|
|
55
|
+
"import": "./lib/adapters/azure-swa/vite/index.mjs"
|
|
58
56
|
},
|
|
59
57
|
"./adapters/cloudflare-pages/vite": {
|
|
60
58
|
"types": "./lib/adapters/cloudflare-pages/vite/index.d.ts",
|
|
61
|
-
"import": "./lib/adapters/cloudflare-pages/vite/index.mjs"
|
|
62
|
-
"require": "./lib/adapters/cloudflare-pages/vite/index.cjs"
|
|
59
|
+
"import": "./lib/adapters/cloudflare-pages/vite/index.mjs"
|
|
63
60
|
},
|
|
64
61
|
"./adapters/cloud-run/vite": {
|
|
65
62
|
"types": "./lib/adapters/cloud-run/vite/index.d.ts",
|
|
66
|
-
"import": "./lib/adapters/cloud-run/vite/index.mjs"
|
|
67
|
-
"require": "./lib/adapters/cloud-run/vite/index.cjs"
|
|
63
|
+
"import": "./lib/adapters/cloud-run/vite/index.mjs"
|
|
68
64
|
},
|
|
69
65
|
"./adapters/bun-server/vite": {
|
|
70
66
|
"types": "./lib/adapters/bun-server/vite/index.d.ts",
|
|
71
|
-
"import": "./lib/adapters/bun-server/vite/index.mjs"
|
|
72
|
-
"require": "./lib/adapters/bun-server/vite/index.cjs"
|
|
67
|
+
"import": "./lib/adapters/bun-server/vite/index.mjs"
|
|
73
68
|
},
|
|
74
69
|
"./adapters/deno-server/vite": {
|
|
75
70
|
"types": "./lib/adapters/deno-server/vite/index.d.ts",
|
|
76
|
-
"import": "./lib/adapters/deno-server/vite/index.mjs"
|
|
77
|
-
"require": "./lib/adapters/deno-server/vite/index.cjs"
|
|
71
|
+
"import": "./lib/adapters/deno-server/vite/index.mjs"
|
|
78
72
|
},
|
|
79
73
|
"./adapters/node-server/vite": {
|
|
80
74
|
"types": "./lib/adapters/node-server/vite/index.d.ts",
|
|
81
|
-
"import": "./lib/adapters/node-server/vite/index.mjs"
|
|
82
|
-
"require": "./lib/adapters/node-server/vite/index.cjs"
|
|
75
|
+
"import": "./lib/adapters/node-server/vite/index.mjs"
|
|
83
76
|
},
|
|
84
77
|
"./adapters/netlify-edge/vite": {
|
|
85
78
|
"types": "./lib/adapters/netlify-edge/vite/index.d.ts",
|
|
86
|
-
"import": "./lib/adapters/netlify-edge/vite/index.mjs"
|
|
87
|
-
"require": "./lib/adapters/netlify-edge/vite/index.cjs"
|
|
79
|
+
"import": "./lib/adapters/netlify-edge/vite/index.mjs"
|
|
88
80
|
},
|
|
89
81
|
"./adapters/shared/vite": {
|
|
90
82
|
"types": "./lib/adapters/shared/vite/index.d.ts",
|
|
91
|
-
"import": "./lib/adapters/shared/vite/index.mjs"
|
|
92
|
-
"require": "./lib/adapters/shared/vite/index.cjs"
|
|
83
|
+
"import": "./lib/adapters/shared/vite/index.mjs"
|
|
93
84
|
},
|
|
94
85
|
"./adapters/static/vite": {
|
|
95
86
|
"types": "./lib/adapters/ssg/vite/index.d.ts",
|
|
96
|
-
"import": "./lib/adapters/ssg/vite/index.mjs"
|
|
97
|
-
"require": "./lib/adapters/ssg/vite/index.cjs"
|
|
87
|
+
"import": "./lib/adapters/ssg/vite/index.mjs"
|
|
98
88
|
},
|
|
99
89
|
"./adapters/ssg/vite": {
|
|
100
90
|
"types": "./lib/adapters/ssg/vite/index.d.ts",
|
|
101
|
-
"import": "./lib/adapters/ssg/vite/index.mjs"
|
|
102
|
-
"require": "./lib/adapters/ssg/vite/index.cjs"
|
|
91
|
+
"import": "./lib/adapters/ssg/vite/index.mjs"
|
|
103
92
|
},
|
|
104
93
|
"./adapters/vercel-edge/vite": {
|
|
105
94
|
"types": "./lib/adapters/vercel-edge/vite/index.d.ts",
|
|
106
|
-
"import": "./lib/adapters/vercel-edge/vite/index.mjs"
|
|
107
|
-
"require": "./lib/adapters/vercel-edge/vite/index.cjs"
|
|
95
|
+
"import": "./lib/adapters/vercel-edge/vite/index.mjs"
|
|
108
96
|
},
|
|
109
97
|
"./middleware/azure-swa": {
|
|
110
98
|
"types": "./lib/middleware/azure-swa/index.d.ts",
|
|
@@ -136,13 +124,11 @@
|
|
|
136
124
|
},
|
|
137
125
|
"./middleware/node": {
|
|
138
126
|
"types": "./lib/middleware/node/index.d.ts",
|
|
139
|
-
"import": "./lib/middleware/node/index.mjs"
|
|
140
|
-
"require": "./lib/middleware/node/index.cjs"
|
|
127
|
+
"import": "./lib/middleware/node/index.mjs"
|
|
141
128
|
},
|
|
142
129
|
"./middleware/request-handler": {
|
|
143
130
|
"types": "./lib/middleware/request-handler/index.d.ts",
|
|
144
|
-
"import": "./lib/middleware/request-handler/index.mjs"
|
|
145
|
-
"require": "./lib/middleware/request-handler/index.cjs"
|
|
131
|
+
"import": "./lib/middleware/request-handler/index.mjs"
|
|
146
132
|
},
|
|
147
133
|
"./middleware/vercel-edge": {
|
|
148
134
|
"types": "./lib/middleware/vercel-edge/index.d.ts",
|
|
@@ -150,23 +136,19 @@
|
|
|
150
136
|
},
|
|
151
137
|
"./static": {
|
|
152
138
|
"types": "./lib/ssg/index.d.ts",
|
|
153
|
-
"import": "./lib/ssg/index.mjs"
|
|
154
|
-
"require": "./lib/ssg/index.cjs"
|
|
139
|
+
"import": "./lib/ssg/index.mjs"
|
|
155
140
|
},
|
|
156
141
|
"./ssg": {
|
|
157
142
|
"types": "./lib/ssg/index.d.ts",
|
|
158
|
-
"import": "./lib/ssg/index.mjs"
|
|
159
|
-
"require": "./lib/ssg/index.cjs"
|
|
143
|
+
"import": "./lib/ssg/index.mjs"
|
|
160
144
|
},
|
|
161
145
|
"./vite": {
|
|
162
146
|
"types": "./lib/vite/index.d.ts",
|
|
163
|
-
"import": "./lib/vite/index.mjs"
|
|
164
|
-
"require": "./lib/vite/index.cjs"
|
|
147
|
+
"import": "./lib/vite/index.mjs"
|
|
165
148
|
},
|
|
166
149
|
"./service-worker": {
|
|
167
150
|
"types": "./service-worker.d.ts",
|
|
168
|
-
"import": "./lib/service-worker.mjs"
|
|
169
|
-
"require": "./lib/service-worker.cjs"
|
|
151
|
+
"import": "./lib/service-worker.mjs"
|
|
170
152
|
},
|
|
171
153
|
"./package.json": "./package.json"
|
|
172
154
|
},
|
|
@@ -187,7 +169,7 @@
|
|
|
187
169
|
"main": "./lib/index.qwik.mjs",
|
|
188
170
|
"peerDependencies": {
|
|
189
171
|
"vite": ">=5 <8",
|
|
190
|
-
"@qwik.dev/core": "^2.0.0-beta.
|
|
172
|
+
"@qwik.dev/core": "^2.0.0-beta.15"
|
|
191
173
|
},
|
|
192
174
|
"publishConfig": {
|
|
193
175
|
"access": "public"
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const fs = require("node:fs");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const adapters_shared_vite = require("../../shared/vite/index.cjs");
|
|
6
|
-
require("../../../chunks/error-handler.cjs");
|
|
7
|
-
function azureSwaAdapter(opts = {}) {
|
|
8
|
-
const env = process?.env;
|
|
9
|
-
return adapters_shared_vite.viteAdapter({
|
|
10
|
-
name: "azure-swa",
|
|
11
|
-
origin: env?.ORIGIN ?? env?.URL ?? "https://yoursitename.region.2.azurestaticapps.net",
|
|
12
|
-
ssg: opts.ssg,
|
|
13
|
-
cleanStaticGenerated: true,
|
|
14
|
-
async generate({ outputEntries, serverOutDir, clientPublicOutDir }) {
|
|
15
|
-
const serverPackageJsonPath = path.join(serverOutDir, "package.json");
|
|
16
|
-
const serverPackageJsonCode = `{"type":"module"}`;
|
|
17
|
-
await fs.promises.mkdir(serverOutDir, { recursive: true });
|
|
18
|
-
await fs.promises.writeFile(serverPackageJsonPath, serverPackageJsonCode);
|
|
19
|
-
const azureSwaModulePath = outputEntries.find(
|
|
20
|
-
(entryName) => entryName.indexOf("entry.azure-swa") === 0
|
|
21
|
-
);
|
|
22
|
-
const funcJsonPath = path.join(serverOutDir, "function.json");
|
|
23
|
-
const funcJson = JSON.stringify(
|
|
24
|
-
{
|
|
25
|
-
bindings: [
|
|
26
|
-
{
|
|
27
|
-
authLevel: "anonymous",
|
|
28
|
-
type: "httpTrigger",
|
|
29
|
-
direction: "in",
|
|
30
|
-
name: "req",
|
|
31
|
-
methods: [
|
|
32
|
-
"get",
|
|
33
|
-
"head",
|
|
34
|
-
"post",
|
|
35
|
-
"put",
|
|
36
|
-
"delete",
|
|
37
|
-
"connect",
|
|
38
|
-
"options",
|
|
39
|
-
"trace",
|
|
40
|
-
"patch"
|
|
41
|
-
]
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
type: "http",
|
|
45
|
-
direction: "out",
|
|
46
|
-
name: "$return"
|
|
47
|
-
}
|
|
48
|
-
],
|
|
49
|
-
scriptFile: azureSwaModulePath
|
|
50
|
-
},
|
|
51
|
-
null,
|
|
52
|
-
2
|
|
53
|
-
);
|
|
54
|
-
await fs.promises.writeFile(funcJsonPath, funcJson);
|
|
55
|
-
if (!fs.existsSync(path.join(clientPublicOutDir, "index.html"))) {
|
|
56
|
-
await fs.promises.writeFile(path.join(clientPublicOutDir, "index.html"), "");
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
exports.azureSwaAdapter = azureSwaAdapter;
|