@qwik.dev/router 2.0.0-beta.28 → 2.0.0-beta.29

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 (42) hide show
  1. package/lib/adapters/azure-swa/vite/index.mjs +31 -36
  2. package/lib/adapters/bun-server/vite/index.mjs +0 -3
  3. package/lib/adapters/cloud-run/vite/index.mjs +0 -3
  4. package/lib/adapters/cloudflare-pages/vite/index.mjs +15 -9
  5. package/lib/adapters/deno-server/vite/index.mjs +7 -5
  6. package/lib/adapters/netlify-edge/vite/index.mjs +13 -23
  7. package/lib/adapters/node-server/vite/index.mjs +0 -3
  8. package/lib/adapters/shared/vite/index.d.ts +1 -7
  9. package/lib/adapters/shared/vite/index.mjs +164 -136
  10. package/lib/adapters/ssg/vite/index.mjs +3 -4
  11. package/lib/adapters/vercel-edge/vite/index.mjs +25 -9
  12. package/lib/chunks/error-handler.mjs +26 -26
  13. package/lib/chunks/fs.mjs +28 -138
  14. package/lib/chunks/http-error.qwik.mjs +27 -0
  15. package/lib/chunks/not-found-wrapper.qwik.mjs +25 -0
  16. package/lib/chunks/pathname.mjs +105 -0
  17. package/lib/chunks/routing.qwik.mjs +592 -216
  18. package/lib/chunks/system.mjs +328 -0
  19. package/lib/chunks/use-functions.qwik.mjs +35 -0
  20. package/lib/chunks/worker-thread.mjs +271 -0
  21. package/lib/index.d.ts +136 -102
  22. package/lib/index.qwik.mjs +699 -751
  23. package/lib/middleware/aws-lambda/index.mjs +7 -1
  24. package/lib/middleware/azure-swa/index.mjs +7 -2
  25. package/lib/middleware/bun/index.mjs +20 -5
  26. package/lib/middleware/cloudflare-pages/index.mjs +8 -2
  27. package/lib/middleware/deno/index.mjs +19 -5
  28. package/lib/middleware/netlify-edge/index.mjs +8 -2
  29. package/lib/middleware/node/index.mjs +10 -14
  30. package/lib/middleware/request-handler/index.d.ts +82 -12
  31. package/lib/middleware/request-handler/index.mjs +661 -524
  32. package/lib/middleware/vercel-edge/index.mjs +8 -2
  33. package/lib/modules.d.ts +7 -4
  34. package/lib/ssg/index.d.ts +48 -16
  35. package/lib/ssg/index.mjs +320 -7
  36. package/lib/vite/index.d.ts +6 -0
  37. package/lib/vite/index.mjs +1098 -641
  38. package/modules.d.ts +7 -4
  39. package/package.json +4 -4
  40. package/lib/chunks/format-error.mjs +0 -137
  41. package/lib/chunks/index.mjs +0 -896
  42. package/lib/chunks/types.qwik.mjs +0 -22
@@ -1,14 +1,13 @@
1
1
  import { viteAdapter } from '../../shared/vite/index.mjs';
2
- import 'node:path';
3
- import 'node:fs';
4
- import '../../../chunks/error-handler.mjs';
5
2
 
6
3
  function ssgAdapter(opts) {
7
4
  return viteAdapter({
8
5
  name: "static-site-generation",
9
6
  origin: opts.origin,
10
7
  ssg: {
11
- include: ["/*"],
8
+ include: [
9
+ "/*"
10
+ ],
12
11
  ...opts
13
12
  }
14
13
  });
@@ -1,7 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import { join, dirname } from 'node:path';
3
3
  import { viteAdapter, getParentDir } from '../../shared/vite/index.mjs';
4
- import '../../../chunks/error-handler.mjs';
5
4
 
6
5
  function vercelEdgeAdapter(opts = {}) {
7
6
  return viteAdapter({
@@ -14,7 +13,20 @@ function vercelEdgeAdapter(opts = {}) {
14
13
  const outDir = config.build?.outDir || join(".vercel", "output", "functions", "_qwik-router.func");
15
14
  return {
16
15
  resolve: {
17
- conditions: opts.target === "node" ? ["node", "import", "module", "browser", "default"] : ["edge-light", "webworker", "worker", "browser", "module", "main"]
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
+ ]
18
30
  },
19
31
  ssr: {
20
32
  target: opts.target === "node" ? "node" : "webworker",
@@ -38,7 +50,9 @@ function vercelEdgeAdapter(opts = {}) {
38
50
  if (opts.outputConfig !== false) {
39
51
  const vercelOutputConfig = {
40
52
  routes: [
41
- { handle: "filesystem" },
53
+ {
54
+ handle: "filesystem"
55
+ },
42
56
  {
43
57
  src: basePathname + ".*",
44
58
  dest: "/_qwik-router"
@@ -46,10 +60,7 @@ function vercelEdgeAdapter(opts = {}) {
46
60
  ],
47
61
  version: 3
48
62
  };
49
- await fs.promises.writeFile(
50
- join(vercelOutputDir, "config.json"),
51
- JSON.stringify(vercelOutputConfig, null, 2)
52
- );
63
+ await fs.promises.writeFile(join(vercelOutputDir, "config.json"), JSON.stringify(vercelOutputConfig, null, 2));
53
64
  }
54
65
  let entrypoint = opts.vcConfigEntryPoint;
55
66
  if (!entrypoint) {
@@ -71,8 +82,13 @@ function vercelEdgeAdapter(opts = {}) {
71
82
  if (basePathnameParts.length > 0) {
72
83
  vercelStaticDir = join(vercelStaticDir, ...basePathnameParts);
73
84
  }
74
- await fs.promises.rm(vercelStaticDir, { recursive: true, force: true });
75
- await fs.promises.mkdir(dirname(vercelStaticDir), { recursive: true });
85
+ await fs.promises.rm(vercelStaticDir, {
86
+ recursive: true,
87
+ force: true
88
+ });
89
+ await fs.promises.mkdir(dirname(vercelStaticDir), {
90
+ recursive: true
91
+ });
76
92
  await fs.promises.rename(clientPublicOutDir, vercelStaticDir);
77
93
  }
78
94
  });
@@ -1,14 +1,20 @@
1
- function getErrorHtml(status, e) {
2
- let message = "Server Error";
3
- if (e != null) {
4
- if (typeof e.message === "string") {
5
- message = e.message;
6
- } else {
7
- message = String(e);
1
+ const ESCAPE_HTML = /[&<>]/g;
2
+ const escapeHtml = (s) => {
3
+ return s.replace(ESCAPE_HTML, (c) => {
4
+ switch (c) {
5
+ case "&":
6
+ return "&amp;";
7
+ case "<":
8
+ return "&lt;";
9
+ case ">":
10
+ return "&gt;";
11
+ default:
12
+ return "";
8
13
  }
9
- }
10
- return `<html>` + minimalHtmlResponse(status, message) + `</html>`;
11
- }
14
+ });
15
+ };
16
+ const COLOR_400 = "#006ce9";
17
+ const COLOR_500 = "#713fc2";
12
18
  function minimalHtmlResponse(status, message) {
13
19
  if (typeof status !== "number") {
14
20
  status = 500;
@@ -36,22 +42,16 @@ function minimalHtmlResponse(status, message) {
36
42
  <body><p><strong>${status}</strong> <span>${message}</span></p></body>
37
43
  `;
38
44
  }
39
- const ESCAPE_HTML = /[&<>]/g;
40
- const escapeHtml = (s) => {
41
- return s.replace(ESCAPE_HTML, (c) => {
42
- switch (c) {
43
- case "&":
44
- return "&amp;";
45
- case "<":
46
- return "&lt;";
47
- case ">":
48
- return "&gt;";
49
- default:
50
- return "";
45
+ function getErrorHtml(status, e) {
46
+ let message = "Server Error";
47
+ if (e != null) {
48
+ if (typeof e.message === "string") {
49
+ message = e.message;
50
+ } else {
51
+ message = String(e);
51
52
  }
52
- });
53
- };
54
- const COLOR_400 = "#006ce9";
55
- const COLOR_500 = "#713fc2";
53
+ }
54
+ return `<html>` + minimalHtmlResponse(status, message) + `</html>`;
55
+ }
56
56
 
57
57
  export { getErrorHtml as g, minimalHtmlResponse as m };
package/lib/chunks/fs.mjs CHANGED
@@ -1,108 +1,5 @@
1
1
  import { normalize, basename, dirname, relative } from 'node:path';
2
-
3
- function toTitleCase(str) {
4
- return str.replace(/\w\S*/g, (txt) => {
5
- return txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase();
6
- });
7
- }
8
- function addError(ctx, e) {
9
- ctx.diagnostics.push({
10
- type: "error",
11
- message: e ? String(e.stack || e) : "Error"
12
- });
13
- }
14
- function addWarning(ctx, message) {
15
- ctx.diagnostics.push({
16
- type: "warn",
17
- message: String(message)
18
- });
19
- }
20
- function msToString(ms) {
21
- if (ms < 1) {
22
- return ms.toFixed(2) + " ms";
23
- }
24
- if (ms < 1e3) {
25
- return ms.toFixed(1) + " ms";
26
- }
27
- if (ms < 6e4) {
28
- return (ms / 1e3).toFixed(1) + " s";
29
- }
30
- return (ms / 6e4).toFixed(1) + " m";
31
- }
32
-
33
- function normalizePathname(pathname, basePathname) {
34
- if (typeof pathname === "string") {
35
- pathname = pathname.trim();
36
- if (pathname !== "") {
37
- try {
38
- pathname = pathname.replace(/\/+/g, "/");
39
- if (pathname.startsWith("/")) {
40
- pathname = pathname.slice(1);
41
- }
42
- pathname = new URL(basePathname + pathname, `https://qwik.dev`).pathname;
43
- if (pathname !== basePathname) {
44
- if (!globalThis.__NO_TRAILING_SLASH__) {
45
- if (!pathname.endsWith("/")) {
46
- const segments = pathname.split("/");
47
- const lastSegment = segments[segments.length - 1];
48
- if (!lastSegment.includes(".")) {
49
- pathname += "/";
50
- }
51
- }
52
- } else {
53
- if (pathname.endsWith("/")) {
54
- pathname = pathname.slice(0, pathname.length - 1);
55
- }
56
- }
57
- }
58
- return pathname;
59
- } catch (e) {
60
- console.error(e);
61
- }
62
- }
63
- }
64
- return null;
65
- }
66
- function getPathnameForDynamicRoute(originalPathname, paramNames, params) {
67
- let pathname = originalPathname;
68
- if (paramNames && params) {
69
- for (const paramName of paramNames) {
70
- const paramKey = `[${paramName}]`;
71
- const restParamKey = `[...${paramName}]`;
72
- const paramValue = params[paramName];
73
- pathname = pathname.replace(restParamKey, paramValue);
74
- pathname = pathname.replace(paramKey, paramValue);
75
- }
76
- }
77
- return pathname;
78
- }
79
- function isSameOriginUrl(url) {
80
- if (typeof url === "string") {
81
- url = url.trim();
82
- if (url !== "") {
83
- const firstChar = url.charAt(0);
84
- if (firstChar !== "/" && firstChar !== ".") {
85
- if (firstChar === "#") {
86
- return false;
87
- }
88
- const i = url.indexOf(":");
89
- if (i > -1) {
90
- const protocol = url.slice(0, i).toLowerCase();
91
- return !PROTOCOLS[protocol];
92
- }
93
- }
94
- return true;
95
- }
96
- }
97
- return false;
98
- }
99
- const PROTOCOLS = {
100
- https: true,
101
- http: true,
102
- about: true,
103
- javascript: true,
104
- file: true
105
- };
2
+ import { t as toTitleCase, n as normalizePathname } from './pathname.mjs';
106
3
 
107
4
  function parseRouteIndexName(extlessName) {
108
5
  let layoutName = "";
@@ -115,25 +12,10 @@ function parseRouteIndexName(extlessName) {
115
12
  namedLayoutParts.shift();
116
13
  layoutName = namedLayoutParts.join("@");
117
14
  }
118
- return { layoutName, layoutStop };
119
- }
120
- function getPathnameFromDirPath(opts, dirPath) {
121
- const relFilePath = relative(opts.routesDir, dirPath);
122
- let pathname = normalizePath(relFilePath);
123
- pathname = normalizePathname(pathname, opts.basePathname).split("/").filter((segment) => !isGroupedLayoutName(segment)).join("/");
124
- if (pathname === "") {
125
- return "/";
126
- }
127
- return pathname;
128
- }
129
- function getMenuPathname(opts, filePath) {
130
- let pathname = normalizePath(relative(opts.routesDir, filePath));
131
- pathname = `/` + normalizePath(dirname(pathname));
132
- let result = normalizePathname(pathname, opts.basePathname);
133
- if (!result.endsWith("/")) {
134
- result += "/";
135
- }
136
- return result;
15
+ return {
16
+ layoutName,
17
+ layoutStop
18
+ };
137
19
  }
138
20
  function getExtension(fileName) {
139
21
  if (typeof fileName === "string") {
@@ -156,9 +38,6 @@ function removeExtension(fileName) {
156
38
  }
157
39
  return "";
158
40
  }
159
- function normalizePath(path) {
160
- return normalizePathSlash(normalize(path));
161
- }
162
41
  function normalizePathSlash(path) {
163
42
  const isExtendedLengthPath = path.startsWith("\\\\?\\");
164
43
  const hasNonAscii = /[^\u0000-\u0080]+/.test(path);
@@ -171,6 +50,18 @@ function normalizePathSlash(path) {
171
50
  }
172
51
  return path;
173
52
  }
53
+ function normalizePath(path) {
54
+ return normalizePathSlash(normalize(path));
55
+ }
56
+ function getMenuPathname(opts, filePath) {
57
+ let pathname = normalizePath(relative(opts.routesDir, filePath));
58
+ pathname = `/` + normalizePath(dirname(pathname));
59
+ let result = normalizePathname(pathname, opts.basePathname);
60
+ if (!result.endsWith("/")) {
61
+ result += "/";
62
+ }
63
+ return result;
64
+ }
174
65
  function createFileId(routesDir, fsPath, explicitFileType) {
175
66
  const ids = [];
176
67
  for (let i = 0; i < 25; i++) {
@@ -235,20 +126,19 @@ function isEntryName(extlessName) {
235
126
  return extlessName === "entry";
236
127
  }
237
128
  function isErrorName(extlessName) {
238
- return /^[45][0-9]{2}$/.test(extlessName);
129
+ return extlessName === "error" || extlessName === "404";
239
130
  }
240
131
  function isGroupedLayoutName(dirName, warn = true) {
241
- if (dirName.startsWith("__")) {
242
- if (warn) {
243
- console.warn(
244
- `Grouped (pathless) layout "${dirName}" should use the "(${dirName.slice(
245
- 2
246
- )})" directory name instead. Prefixing a directory with "__" has been deprecated and will be removed in future versions.`
247
- );
248
- }
249
- return true;
250
- }
251
132
  return dirName.startsWith("(") && dirName.endsWith(")");
252
133
  }
134
+ function getPathnameFromDirPath(opts, dirPath) {
135
+ const relFilePath = relative(opts.routesDir, dirPath);
136
+ let pathname = normalizePath(relFilePath);
137
+ pathname = normalizePathname(pathname, opts.basePathname).split("/").filter((segment) => !isGroupedLayoutName(segment)).join("/");
138
+ if (pathname === "") {
139
+ return "/";
140
+ }
141
+ return pathname;
142
+ }
253
143
 
254
- export { isErrorName as a, isLayoutModule as b, isEntryName as c, isMenuFileName as d, isServiceWorkerName as e, isPageModuleExt as f, getExtension as g, isModuleExt as h, isIndexModule as i, isMarkdownExt as j, isSameOriginUrl as k, normalizePath as l, getPathnameFromDirPath as m, normalizePathSlash as n, getMenuPathname as o, createFileId as p, parseRouteIndexName as q, removeExtension as r, isPluginModule as s, addError as t, addWarning as u, isPageExt as v, msToString as w, getPathnameForDynamicRoute as x };
144
+ export { isErrorName as a, isLayoutModule as b, isEntryName as c, isMenuFileName as d, isServiceWorkerName as e, isPageModuleExt as f, getExtension as g, isModuleExt as h, isIndexModule as i, isMarkdownExt as j, normalizePath as k, getPathnameFromDirPath as l, getMenuPathname as m, normalizePathSlash as n, createFileId as o, parseRouteIndexName as p, isPluginModule as q, removeExtension as r, isPageExt as s };
@@ -0,0 +1,27 @@
1
+ import { componentQrl, inlinedQrl, _jsxSorted } from '@qwik.dev/core';
2
+ import { k as useHttpStatus } from './use-functions.qwik.mjs';
3
+
4
+ const cacheKey = (status) => String(status);
5
+ const COLOR_400 = "#006ce9";
6
+ const COLOR_500 = "#713fc2";
7
+ const DisplayHttpStatus = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl(() => {
8
+ const { status, message } = useHttpStatus();
9
+ const width = message ? "600px" : "300px";
10
+ const color = status < 500 ? COLOR_400 : COLOR_500;
11
+ const style = `
12
+ body { color: ${color}; background-color: #fafafa; padding: 30px; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif; }
13
+ p { max-width: ${width}; margin: 60px auto 30px auto; background: white; border-radius: 4px; box-shadow: 0px 0px 50px -20px ${color}; overflow: hidden; }
14
+ strong { display: inline-block; padding: 15px; background: ${color}; color: white; }
15
+ span { display: inline-block; padding: 15px; }
16
+ `;
17
+ return /* @__PURE__ */ _jsxSorted("p", null, null, [
18
+ /* @__PURE__ */ _jsxSorted("style", {
19
+ dangerouslySetInnerHTML: style
20
+ }, null, null, 3, null),
21
+ /* @__PURE__ */ _jsxSorted("strong", null, null, status || 500, 3, null),
22
+ " ",
23
+ /* @__PURE__ */ _jsxSorted("span", null, null, message || "", 3, null)
24
+ ], 1, "vY_0");
25
+ }, "DisplayHttpStatus_component_PJf4K4PL7Oc"));
26
+
27
+ export { cacheKey, DisplayHttpStatus as default };
@@ -0,0 +1,25 @@
1
+ import { k as useHttpStatus } from './use-functions.qwik.mjs';
2
+
3
+ function createNotFoundWrapper(notFoundMod, errorMod) {
4
+ const NotFound = notFoundMod.default;
5
+ const ErrorPage = errorMod.default;
6
+ const Component = () => {
7
+ const { status } = useHttpStatus();
8
+ if (status === 404 && NotFound) {
9
+ return NotFound({});
10
+ }
11
+ if (ErrorPage) {
12
+ return ErrorPage({});
13
+ }
14
+ return null;
15
+ };
16
+ const notFoundHead = notFoundMod.routeConfig && typeof notFoundMod.routeConfig !== "function" ? notFoundMod.routeConfig.head : notFoundMod.head;
17
+ const errorHead = errorMod.routeConfig && typeof errorMod.routeConfig !== "function" ? errorMod.routeConfig.head : errorMod.head;
18
+ return {
19
+ default: Component,
20
+ head: notFoundHead ?? errorHead,
21
+ cacheKey: (status) => String(status)
22
+ };
23
+ }
24
+
25
+ export { createNotFoundWrapper };
@@ -0,0 +1,105 @@
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) {
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";
29
+ }
30
+
31
+ function normalizePathname(pathname, basePathname) {
32
+ if (typeof pathname === "string") {
33
+ pathname = pathname.trim();
34
+ if (pathname !== "") {
35
+ try {
36
+ pathname = pathname.replace(/\/+/g, "/");
37
+ if (pathname.startsWith("/")) {
38
+ pathname = pathname.slice(1);
39
+ }
40
+ pathname = new URL(basePathname + pathname, `https://qwik.dev`).pathname;
41
+ if (pathname !== basePathname) {
42
+ if (!globalThis.__NO_TRAILING_SLASH__) {
43
+ if (!pathname.endsWith("/")) {
44
+ const segments = pathname.split("/");
45
+ const lastSegment = segments[segments.length - 1];
46
+ if (!lastSegment.includes(".")) {
47
+ pathname += "/";
48
+ }
49
+ }
50
+ } else {
51
+ if (pathname.endsWith("/")) {
52
+ pathname = pathname.slice(0, pathname.length - 1);
53
+ }
54
+ }
55
+ }
56
+ return pathname;
57
+ } catch (e) {
58
+ console.error(e);
59
+ }
60
+ }
61
+ }
62
+ return null;
63
+ }
64
+ function getPathnameForDynamicRoute(originalPathname, paramNames, params) {
65
+ let pathname = originalPathname;
66
+ if (paramNames && params) {
67
+ for (const paramName of paramNames) {
68
+ const paramKey = `[${paramName}]`;
69
+ const restParamKey = `[...${paramName}]`;
70
+ const paramValue = params[paramName];
71
+ pathname = pathname.replace(restParamKey, paramValue);
72
+ pathname = pathname.replace(paramKey, paramValue);
73
+ }
74
+ }
75
+ return pathname;
76
+ }
77
+ const PROTOCOLS = {
78
+ https: true,
79
+ http: true,
80
+ about: true,
81
+ javascript: true,
82
+ file: true
83
+ };
84
+ function isSameOriginUrl(url) {
85
+ if (typeof url === "string") {
86
+ url = url.trim();
87
+ if (url !== "") {
88
+ const firstChar = url.charAt(0);
89
+ if (firstChar !== "/" && firstChar !== ".") {
90
+ if (firstChar === "#") {
91
+ return false;
92
+ }
93
+ const i = url.indexOf(":");
94
+ if (i > -1) {
95
+ const protocol = url.slice(0, i).toLowerCase();
96
+ return !PROTOCOLS[protocol];
97
+ }
98
+ }
99
+ return true;
100
+ }
101
+ }
102
+ return false;
103
+ }
104
+
105
+ export { addError as a, addWarning as b, getPathnameForDynamicRoute as g, isSameOriginUrl as i, msToString as m, normalizePathname as n, toTitleCase as t };