@qwik.dev/router 2.0.0-beta.39 → 2.0.0-beta.40

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