@qwik.dev/router 2.0.0-beta.4 → 2.0.0-beta.41
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/adapters/static/vite.d.ts +1 -1
- package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
- package/lib/adapters/azure-swa/vite/index.mjs +44 -58
- package/lib/adapters/bun-server/vite/index.d.ts +2 -2
- package/lib/adapters/bun-server/vite/index.mjs +16 -23
- package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
- package/lib/adapters/cloud-run/vite/index.mjs +15 -20
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
- package/lib/adapters/cloudflare-pages/vite/index.mjs +45 -77
- package/lib/adapters/deno-server/vite/index.d.ts +2 -2
- package/lib/adapters/deno-server/vite/index.mjs +25 -35
- package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.mjs +49 -89
- package/lib/adapters/node-server/vite/index.d.ts +2 -2
- package/lib/adapters/node-server/vite/index.mjs +16 -23
- package/lib/adapters/shared/vite/index.d.ts +9 -22
- package/lib/adapters/shared/vite/index.mjs +280 -333
- package/lib/adapters/ssg/vite/index.d.ts +13 -0
- package/lib/adapters/ssg/vite/index.mjs +13 -0
- package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
- package/lib/adapters/vercel-edge/vite/index.mjs +73 -80
- package/lib/chunks/dev-preloaded-route-loader.mjs +2 -0
- package/lib/chunks/format.mjs +24 -0
- package/lib/chunks/fs.mjs +140 -0
- package/lib/chunks/head.qwik.mjs +1202 -0
- package/lib/chunks/http-error.qwik.mjs +27 -0
- package/lib/chunks/pathname.mjs +57 -0
- package/lib/chunks/request-body-limit.mjs +27 -0
- package/lib/chunks/request-path.mjs +49 -0
- package/lib/chunks/routes.mjs +26 -0
- package/lib/chunks/server-error.mjs +16 -0
- package/lib/chunks/system.mjs +265 -0
- package/lib/chunks/url.mjs +59 -0
- package/lib/chunks/user-response.mjs +1730 -0
- package/lib/chunks/worker-thread.mjs +264 -0
- package/lib/index.d.ts +631 -174
- package/lib/index.qwik.mjs +1656 -1964
- package/lib/middleware/aws-lambda/index.d.ts +15 -16
- package/lib/middleware/aws-lambda/index.mjs +45 -54
- package/lib/middleware/azure-swa/index.mjs +85 -295
- package/lib/middleware/bun/index.d.ts +20 -5
- package/lib/middleware/bun/index.mjs +119 -205
- package/lib/middleware/cloudflare-pages/index.mjs +88 -105
- package/lib/middleware/deno/index.d.ts +22 -5
- package/lib/middleware/deno/index.mjs +105 -192
- package/lib/middleware/firebase/index.mjs +22 -35
- package/lib/middleware/netlify-edge/index.mjs +63 -81
- package/lib/middleware/node/index.d.ts +17 -5
- package/lib/middleware/node/index.mjs +299 -273
- package/lib/middleware/request-handler/index.d.ts +206 -99
- package/lib/middleware/request-handler/index.mjs +105 -1648
- package/lib/middleware/vercel-edge/index.mjs +76 -101
- package/lib/modules.d.ts +11 -16
- package/lib/service-worker/index.mjs +13 -0
- package/lib/{static → ssg}/index.d.ts +46 -22
- package/lib/ssg/index.mjs +257 -0
- package/lib/vite/index.d.ts +58 -10
- package/lib/vite/index.mjs +2471 -27446
- package/modules.d.ts +11 -16
- package/package.json +62 -70
- package/ssg.d.ts +2 -0
- package/static.d.ts +1 -1
- package/lib/adapters/azure-swa/vite/index.cjs +0 -96
- package/lib/adapters/bun-server/vite/index.cjs +0 -50
- package/lib/adapters/cloud-run/vite/index.cjs +0 -47
- package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -115
- package/lib/adapters/deno-server/vite/index.cjs +0 -62
- package/lib/adapters/netlify-edge/vite/index.cjs +0 -129
- package/lib/adapters/node-server/vite/index.cjs +0 -50
- package/lib/adapters/shared/vite/index.cjs +0 -378
- package/lib/adapters/static/vite/index.cjs +0 -368
- package/lib/adapters/static/vite/index.d.ts +0 -10
- package/lib/adapters/static/vite/index.mjs +0 -331
- package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
- package/lib/index.qwik.cjs +0 -2022
- package/lib/middleware/node/index.cjs +0 -314
- package/lib/middleware/request-handler/index.cjs +0 -1691
- package/lib/service-worker.cjs +0 -17
- package/lib/service-worker.mjs +0 -15
- package/lib/static/deno.mjs +0 -8
- package/lib/static/index.cjs +0 -67
- package/lib/static/index.mjs +0 -48
- package/lib/static/node.cjs +0 -1126
- package/lib/static/node.mjs +0 -1088
- package/lib/vite/index.cjs +0 -27525
- package/middleware/request-handler/generated/not-found-paths.ts +0 -7
- package/middleware/request-handler/generated/static-paths.ts +0 -35
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { viteAdapter } from "../../shared/vite/index.mjs";
|
|
2
|
+
/** @public */ function ssgAdapter(opts) {
|
|
3
|
+
return viteAdapter({
|
|
4
|
+
name: "static-site-generation",
|
|
5
|
+
origin: opts.origin,
|
|
6
|
+
ssg: {
|
|
7
|
+
include: ["/*"],
|
|
8
|
+
...opts
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/** @public @deprecated Use `ssgAdapter` instead. */ var staticAdapter = ssgAdapter;
|
|
13
|
+
export { ssgAdapter, staticAdapter };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ServerAdapterOptions } from '../../shared/vite';
|
|
2
|
-
import type {
|
|
2
|
+
import type { SsgRenderOptions } from 'packages/qwik-router/src/ssg';
|
|
3
3
|
|
|
4
|
-
export {
|
|
4
|
+
export { SsgRenderOptions }
|
|
5
5
|
|
|
6
6
|
/** @public */
|
|
7
7
|
export declare function vercelEdgeAdapter(opts?: VercelEdgeAdapterOptions): any;
|
|
@@ -35,7 +35,7 @@ export declare interface VercelEdgeAdapterOptions extends ServerAdapterOptions {
|
|
|
35
35
|
*/
|
|
36
36
|
staticPaths?: string[];
|
|
37
37
|
/**
|
|
38
|
-
* Define the `target` property in the `ssr` object in the `vite.config.
|
|
38
|
+
* Define the `target` property in the `ssr` object in the `vite.config.ts` file.
|
|
39
39
|
*
|
|
40
40
|
* Defaults to `webworker`.
|
|
41
41
|
*/
|
|
@@ -1,83 +1,76 @@
|
|
|
1
|
-
|
|
1
|
+
import { getParentDir, viteAdapter } from "../../shared/vite/index.mjs";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
await fs.promises.rm(vercelStaticDir, { recursive: true, force: true });
|
|
76
|
-
await fs.promises.mkdir(dirname(vercelStaticDir), { recursive: true });
|
|
77
|
-
await fs.promises.rename(clientPublicOutDir, vercelStaticDir);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
4
|
+
/** @public */ function vercelEdgeAdapter(opts = {}) {
|
|
5
|
+
return viteAdapter({
|
|
6
|
+
name: "vercel-edge",
|
|
7
|
+
origin: process?.env?.VERCEL_URL || "https://yoursitename.vercel.app",
|
|
8
|
+
ssg: opts.ssg,
|
|
9
|
+
staticPaths: opts.staticPaths,
|
|
10
|
+
cleanStaticGenerated: true,
|
|
11
|
+
config(config) {
|
|
12
|
+
const outDir = config.build?.outDir || join(".vercel", "output", "functions", "_qwik-router.func");
|
|
13
|
+
return {
|
|
14
|
+
resolve: { conditions: opts.target === "node" ? [
|
|
15
|
+
"node",
|
|
16
|
+
"import",
|
|
17
|
+
"module",
|
|
18
|
+
"browser",
|
|
19
|
+
"default"
|
|
20
|
+
] : [
|
|
21
|
+
"edge-light",
|
|
22
|
+
"webworker",
|
|
23
|
+
"worker",
|
|
24
|
+
"browser",
|
|
25
|
+
"module",
|
|
26
|
+
"main"
|
|
27
|
+
] },
|
|
28
|
+
ssr: {
|
|
29
|
+
target: opts.target === "node" ? "node" : "webworker",
|
|
30
|
+
noExternal: true
|
|
31
|
+
},
|
|
32
|
+
build: {
|
|
33
|
+
ssr: true,
|
|
34
|
+
outDir,
|
|
35
|
+
rolldownOptions: { output: { format: "es" } }
|
|
36
|
+
},
|
|
37
|
+
publicDir: false
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
async generate({ clientPublicOutDir, serverOutDir, basePathname, outputEntries }) {
|
|
41
|
+
const vercelOutputDir = getParentDir(serverOutDir, "output");
|
|
42
|
+
if (opts.outputConfig !== false) {
|
|
43
|
+
const vercelOutputConfig = {
|
|
44
|
+
routes: [{ handle: "filesystem" }, {
|
|
45
|
+
src: basePathname + ".*",
|
|
46
|
+
dest: "/_qwik-router"
|
|
47
|
+
}],
|
|
48
|
+
version: 3
|
|
49
|
+
};
|
|
50
|
+
await fs.promises.writeFile(join(vercelOutputDir, "config.json"), JSON.stringify(vercelOutputConfig, null, 2));
|
|
51
|
+
}
|
|
52
|
+
let entrypoint = opts.vcConfigEntryPoint;
|
|
53
|
+
if (!entrypoint) {
|
|
54
|
+
if (outputEntries.some((n) => n === "entry.vercel-edge.mjs")) entrypoint = "entry.vercel-edge.mjs";
|
|
55
|
+
else entrypoint = "entry.vercel-edge.js";
|
|
56
|
+
}
|
|
57
|
+
const vcConfigPath = join(serverOutDir, ".vc-config.json");
|
|
58
|
+
const vcConfig = {
|
|
59
|
+
runtime: "edge",
|
|
60
|
+
entrypoint,
|
|
61
|
+
envVarsInUse: opts.vcConfigEnvVarsInUse
|
|
62
|
+
};
|
|
63
|
+
await fs.promises.writeFile(vcConfigPath, JSON.stringify(vcConfig, null, 2));
|
|
64
|
+
let vercelStaticDir = join(vercelOutputDir, "static");
|
|
65
|
+
const basePathnameParts = basePathname.split("/").filter((p) => p.length > 0);
|
|
66
|
+
if (basePathnameParts.length > 0) vercelStaticDir = join(vercelStaticDir, ...basePathnameParts);
|
|
67
|
+
await fs.promises.rm(vercelStaticDir, {
|
|
68
|
+
recursive: true,
|
|
69
|
+
force: true
|
|
70
|
+
});
|
|
71
|
+
await fs.promises.mkdir(dirname(vercelStaticDir), { recursive: true });
|
|
72
|
+
await fs.promises.rename(clientPublicOutDir, vercelStaticDir);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
80
75
|
}
|
|
81
|
-
export {
|
|
82
|
-
vercelEdgeAdapter
|
|
83
|
-
};
|
|
76
|
+
export { vercelEdgeAdapter };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function toTitleCase(str) {
|
|
2
|
+
return str.replace(/\w\S*/g, (txt) => {
|
|
3
|
+
return txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase();
|
|
4
|
+
});
|
|
5
|
+
}
|
|
6
|
+
function addError(ctx, e) {
|
|
7
|
+
ctx.diagnostics.push({
|
|
8
|
+
type: "error",
|
|
9
|
+
message: e ? String(e.stack || e) : "Error"
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function addWarning(ctx, message) {
|
|
13
|
+
ctx.diagnostics.push({
|
|
14
|
+
type: "warn",
|
|
15
|
+
message: String(message)
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function msToString(ms) {
|
|
19
|
+
if (ms < 1) return ms.toFixed(2) + " ms";
|
|
20
|
+
if (ms < 1e3) return ms.toFixed(1) + " ms";
|
|
21
|
+
if (ms < 6e4) return (ms / 1e3).toFixed(1) + " s";
|
|
22
|
+
return (ms / 6e4).toFixed(1) + " m";
|
|
23
|
+
}
|
|
24
|
+
export { toTitleCase as i, addWarning as n, msToString as r, addError as t };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { i as normalizePathname, t as ensureSlash } from "./pathname.mjs";
|
|
2
|
+
import { i as toTitleCase } from "./format.mjs";
|
|
3
|
+
import { basename, dirname, normalize, relative } from "node:path";
|
|
4
|
+
function parseRouteIndexName(extlessName) {
|
|
5
|
+
let layoutName = "";
|
|
6
|
+
const layoutStop = extlessName.endsWith("!");
|
|
7
|
+
if (layoutStop) extlessName = extlessName.slice(0, extlessName.length - 1);
|
|
8
|
+
const namedLayoutParts = extlessName.split("@");
|
|
9
|
+
if (namedLayoutParts.length > 1) {
|
|
10
|
+
namedLayoutParts.shift();
|
|
11
|
+
layoutName = namedLayoutParts.join("@");
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
layoutName,
|
|
15
|
+
layoutStop
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function getExtension(fileName) {
|
|
19
|
+
if (typeof fileName === "string") {
|
|
20
|
+
const parts = fileName.trim().toLowerCase().split(".");
|
|
21
|
+
if (parts.length > 1) {
|
|
22
|
+
const ext = parts.pop().split("?")[0].split("#")[0];
|
|
23
|
+
if (ext === "ts" && parts.pop() === "d") return ".d.ts";
|
|
24
|
+
return "." + ext;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
function removeExtension(fileName) {
|
|
30
|
+
if (typeof fileName === "string") {
|
|
31
|
+
fileName = fileName.trim();
|
|
32
|
+
const ext = getExtension(fileName);
|
|
33
|
+
return fileName.slice(0, fileName.length - ext.length);
|
|
34
|
+
}
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
function normalizePathSlash(path) {
|
|
38
|
+
const isExtendedLengthPath = path.startsWith("\\\\?\\");
|
|
39
|
+
const hasNonAscii = /[^\u0000-\u0080]+/.test(path);
|
|
40
|
+
if (isExtendedLengthPath || hasNonAscii) return path;
|
|
41
|
+
path = path.replace(/\\/g, "/");
|
|
42
|
+
if (path.endsWith("/")) path = path.slice(0, path.length - 1);
|
|
43
|
+
return path;
|
|
44
|
+
}
|
|
45
|
+
function normalizePath(path) {
|
|
46
|
+
return normalizePathSlash(normalize(path));
|
|
47
|
+
}
|
|
48
|
+
function getMenuPathname(opts, filePath) {
|
|
49
|
+
let pathname = normalizePath(relative(opts.routesDir, filePath));
|
|
50
|
+
pathname = `/` + normalizePath(dirname(pathname));
|
|
51
|
+
const result = normalizePathname(pathname, opts.basePathname);
|
|
52
|
+
return ensureSlash(result);
|
|
53
|
+
}
|
|
54
|
+
/** Normalize equivalent filesystem paths for string-key comparisons. */ function normalizePathKey(path) {
|
|
55
|
+
if (path.startsWith("\\\\?\\UNC\\")) path = `\\\\${path.slice(8)}`;
|
|
56
|
+
else if (path.startsWith("\\\\?\\")) path = path.slice(4);
|
|
57
|
+
else if (path.startsWith("//?/UNC/")) path = `//${path.slice(8)}`;
|
|
58
|
+
else if (path.startsWith("//?/")) path = path.slice(4);
|
|
59
|
+
return normalizePath(path).replace(/\\/g, "/");
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates an id for the module, based on its path.
|
|
63
|
+
*
|
|
64
|
+
* @param routesDir
|
|
65
|
+
* @param fsPath
|
|
66
|
+
* @param explicitFileType Add to avoid collisions between different types of modules. `Menu` and
|
|
67
|
+
* `Layout` files are named based on their path (eg. /routes/about/menu.md => AboutMenu)
|
|
68
|
+
*/ function createFileId(routesDir, fsPath, explicitFileType) {
|
|
69
|
+
const ids = [];
|
|
70
|
+
for (let i = 0; i < 25; i++) {
|
|
71
|
+
let baseName = removeExtension(basename(fsPath));
|
|
72
|
+
baseName = baseName.replace(/[\W_]+/g, "");
|
|
73
|
+
if (baseName === "") baseName = "Q" + i;
|
|
74
|
+
else if (!isNaN(baseName.charAt(0))) baseName = "Q" + baseName;
|
|
75
|
+
ids.push(toTitleCase(baseName));
|
|
76
|
+
fsPath = normalizePath(dirname(fsPath));
|
|
77
|
+
if (fsPath === routesDir) break;
|
|
78
|
+
}
|
|
79
|
+
if (ids.length > 1 && ids[0] === "Index") ids.shift();
|
|
80
|
+
return ids.reverse().join("").concat(explicitFileType || "");
|
|
81
|
+
}
|
|
82
|
+
var PAGE_MODULE_EXTS = {
|
|
83
|
+
".tsx": true,
|
|
84
|
+
".jsx": true
|
|
85
|
+
};
|
|
86
|
+
var MODULE_EXTS = {
|
|
87
|
+
".ts": true,
|
|
88
|
+
".js": true
|
|
89
|
+
};
|
|
90
|
+
var MARKDOWN_EXTS = {
|
|
91
|
+
".md": true,
|
|
92
|
+
".mdx": true
|
|
93
|
+
};
|
|
94
|
+
function isIndexModule(extlessName) {
|
|
95
|
+
return /^index(|!|@.+)$/.test(extlessName);
|
|
96
|
+
}
|
|
97
|
+
function isPluginModule(extlessName) {
|
|
98
|
+
return /^plugin(|@.+)$/.test(extlessName) && !/\.(test|unit|spec)(\.[jt]s)?$/.test(extlessName);
|
|
99
|
+
}
|
|
100
|
+
function isLayoutModule(extlessName) {
|
|
101
|
+
return /^layout(|!|-.+)$/.test(extlessName);
|
|
102
|
+
}
|
|
103
|
+
function isPageModuleExt(ext) {
|
|
104
|
+
return ext in PAGE_MODULE_EXTS;
|
|
105
|
+
}
|
|
106
|
+
function isModuleExt(ext) {
|
|
107
|
+
return ext in MODULE_EXTS;
|
|
108
|
+
}
|
|
109
|
+
function isMarkdownExt(ext) {
|
|
110
|
+
return ext in MARKDOWN_EXTS;
|
|
111
|
+
}
|
|
112
|
+
function isPageExt(ext) {
|
|
113
|
+
return ext in PAGE_MODULE_EXTS || ext in MARKDOWN_EXTS;
|
|
114
|
+
}
|
|
115
|
+
function isMenuFileName(fileName) {
|
|
116
|
+
return fileName === "menu.md";
|
|
117
|
+
}
|
|
118
|
+
function isServiceWorkerName(extlessName) {
|
|
119
|
+
return extlessName === "service-worker";
|
|
120
|
+
}
|
|
121
|
+
function isEntryName(extlessName) {
|
|
122
|
+
return extlessName === "entry";
|
|
123
|
+
}
|
|
124
|
+
/** The boundary kind, ignoring any `@x`/`!` modifier: `'404'`, `'error'`, or undefined. */ function errorBoundaryName(extlessName) {
|
|
125
|
+
const match = /^(error|404)(?:|!|@.+)$/.exec(extlessName);
|
|
126
|
+
return match ? match[1] : void 0;
|
|
127
|
+
}
|
|
128
|
+
function isErrorName(extlessName) {
|
|
129
|
+
return errorBoundaryName(extlessName) !== void 0;
|
|
130
|
+
}
|
|
131
|
+
function isGroupedLayoutName(dirName, warn = true) {
|
|
132
|
+
return dirName.startsWith("(") && dirName.endsWith(")");
|
|
133
|
+
}
|
|
134
|
+
function getPathnameFromDirPath(opts, dirPath) {
|
|
135
|
+
let pathname = normalizePath(relative(opts.routesDir, dirPath));
|
|
136
|
+
pathname = normalizePathname(pathname, opts.basePathname).split("/").filter((segment) => !isGroupedLayoutName(segment)).join("/");
|
|
137
|
+
if (pathname === "") return "/";
|
|
138
|
+
return pathname;
|
|
139
|
+
}
|
|
140
|
+
export { normalizePath as _, getPathnameFromDirPath as a, parseRouteIndexName as b, isIndexModule as c, isMenuFileName as d, isModuleExt as f, isServiceWorkerName as g, isPluginModule as h, getMenuPathname as i, isLayoutModule as l, isPageModuleExt as m, errorBoundaryName as n, isEntryName as o, isPageExt as p, getExtension as r, isErrorName as s, createFileId as t, isMarkdownExt as u, normalizePathKey as v, removeExtension as x, normalizePathSlash as y };
|