@qwik.dev/router 2.0.0-beta.2 → 2.0.0-beta.21

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 (78) hide show
  1. package/adapters/static/vite.d.ts +1 -1
  2. package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
  3. package/lib/adapters/azure-swa/vite/index.mjs +9 -9
  4. package/lib/adapters/bun-server/vite/index.d.ts +2 -2
  5. package/lib/adapters/bun-server/vite/index.mjs +9 -7
  6. package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
  7. package/lib/adapters/cloud-run/vite/index.mjs +9 -7
  8. package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
  9. package/lib/adapters/cloudflare-pages/vite/index.mjs +9 -24
  10. package/lib/adapters/deno-server/vite/index.d.ts +2 -2
  11. package/lib/adapters/deno-server/vite/index.mjs +9 -7
  12. package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
  13. package/lib/adapters/netlify-edge/vite/index.mjs +10 -14
  14. package/lib/adapters/node-server/vite/index.d.ts +2 -2
  15. package/lib/adapters/node-server/vite/index.mjs +9 -7
  16. package/lib/adapters/shared/vite/index.d.ts +13 -19
  17. package/lib/adapters/shared/vite/index.mjs +107 -139
  18. package/lib/adapters/ssg/vite/index.d.ts +13 -0
  19. package/lib/adapters/ssg/vite/index.mjs +18 -0
  20. package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
  21. package/lib/adapters/vercel-edge/vite/index.mjs +9 -11
  22. package/lib/chunks/error-handler.mjs +57 -0
  23. package/lib/chunks/format-error.mjs +137 -0
  24. package/lib/chunks/fs.mjs +254 -0
  25. package/lib/{static/node.mjs → chunks/index.mjs} +361 -563
  26. package/lib/chunks/mime-types.mjs +52 -0
  27. package/lib/chunks/routing.qwik.mjs +429 -0
  28. package/lib/chunks/types.qwik.mjs +22 -0
  29. package/lib/index.d.ts +240 -60
  30. package/lib/index.qwik.mjs +698 -983
  31. package/lib/middleware/aws-lambda/index.d.ts +3 -2
  32. package/lib/middleware/aws-lambda/index.mjs +8 -12
  33. package/lib/middleware/azure-swa/index.mjs +10 -216
  34. package/lib/middleware/bun/index.d.ts +11 -0
  35. package/lib/middleware/bun/index.mjs +24 -83
  36. package/lib/middleware/cloudflare-pages/index.mjs +10 -22
  37. package/lib/middleware/deno/index.d.ts +11 -0
  38. package/lib/middleware/deno/index.mjs +24 -83
  39. package/lib/middleware/firebase/index.mjs +7 -11
  40. package/lib/middleware/netlify-edge/index.mjs +10 -23
  41. package/lib/middleware/node/index.mjs +22 -87
  42. package/lib/middleware/request-handler/index.d.ts +89 -70
  43. package/lib/middleware/request-handler/index.mjs +584 -659
  44. package/lib/middleware/vercel-edge/index.mjs +15 -27
  45. package/lib/modules.d.ts +4 -12
  46. package/lib/service-worker/index.mjs +4 -0
  47. package/lib/{static → ssg}/index.d.ts +17 -17
  48. package/lib/ssg/index.mjs +14 -0
  49. package/lib/vite/index.d.ts +32 -10
  50. package/lib/vite/index.mjs +1524 -26934
  51. package/modules.d.ts +4 -12
  52. package/package.json +62 -68
  53. package/ssg.d.ts +2 -0
  54. package/static.d.ts +1 -1
  55. package/lib/adapters/azure-swa/vite/index.cjs +0 -96
  56. package/lib/adapters/bun-server/vite/index.cjs +0 -50
  57. package/lib/adapters/cloud-run/vite/index.cjs +0 -47
  58. package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -115
  59. package/lib/adapters/deno-server/vite/index.cjs +0 -62
  60. package/lib/adapters/netlify-edge/vite/index.cjs +0 -129
  61. package/lib/adapters/node-server/vite/index.cjs +0 -50
  62. package/lib/adapters/shared/vite/index.cjs +0 -378
  63. package/lib/adapters/static/vite/index.cjs +0 -368
  64. package/lib/adapters/static/vite/index.d.ts +0 -10
  65. package/lib/adapters/static/vite/index.mjs +0 -331
  66. package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
  67. package/lib/index.qwik.cjs +0 -1947
  68. package/lib/middleware/node/index.cjs +0 -314
  69. package/lib/middleware/request-handler/index.cjs +0 -1614
  70. package/lib/service-worker.cjs +0 -17
  71. package/lib/service-worker.mjs +0 -15
  72. package/lib/static/deno.mjs +0 -8
  73. package/lib/static/index.cjs +0 -67
  74. package/lib/static/index.mjs +0 -48
  75. package/lib/static/node.cjs +0 -1124
  76. package/lib/vite/index.cjs +0 -27445
  77. package/middleware/request-handler/generated/not-found-paths.ts +0 -7
  78. package/middleware/request-handler/generated/static-paths.ts +0 -35
@@ -0,0 +1,254 @@
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
+ };
106
+
107
+ function parseRouteIndexName(extlessName) {
108
+ let layoutName = "";
109
+ const layoutStop = extlessName.endsWith("!");
110
+ if (layoutStop) {
111
+ extlessName = extlessName.slice(0, extlessName.length - 1);
112
+ }
113
+ const namedLayoutParts = extlessName.split("@");
114
+ if (namedLayoutParts.length > 1) {
115
+ namedLayoutParts.shift();
116
+ layoutName = namedLayoutParts.join("@");
117
+ }
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;
137
+ }
138
+ function getExtension(fileName) {
139
+ if (typeof fileName === "string") {
140
+ const parts = fileName.trim().toLowerCase().split(".");
141
+ if (parts.length > 1) {
142
+ const ext = parts.pop().split("?")[0].split("#")[0];
143
+ if (ext === "ts" && parts.pop() === "d") {
144
+ return ".d.ts";
145
+ }
146
+ return "." + ext;
147
+ }
148
+ }
149
+ return "";
150
+ }
151
+ function removeExtension(fileName) {
152
+ if (typeof fileName === "string") {
153
+ fileName = fileName.trim();
154
+ const ext = getExtension(fileName);
155
+ return fileName.slice(0, fileName.length - ext.length);
156
+ }
157
+ return "";
158
+ }
159
+ function normalizePath(path) {
160
+ return normalizePathSlash(normalize(path));
161
+ }
162
+ function normalizePathSlash(path) {
163
+ const isExtendedLengthPath = path.startsWith("\\\\?\\");
164
+ const hasNonAscii = /[^\u0000-\u0080]+/.test(path);
165
+ if (isExtendedLengthPath || hasNonAscii) {
166
+ return path;
167
+ }
168
+ path = path.replace(/\\/g, "/");
169
+ if (path.endsWith("/")) {
170
+ path = path.slice(0, path.length - 1);
171
+ }
172
+ return path;
173
+ }
174
+ function createFileId(routesDir, fsPath, explicitFileType) {
175
+ const ids = [];
176
+ for (let i = 0; i < 25; i++) {
177
+ let baseName = removeExtension(basename(fsPath));
178
+ baseName = baseName.replace(/[\W_]+/g, "");
179
+ if (baseName === "") {
180
+ baseName = "Q" + i;
181
+ } else if (!isNaN(baseName.charAt(0))) {
182
+ baseName = "Q" + baseName;
183
+ }
184
+ ids.push(toTitleCase(baseName));
185
+ fsPath = normalizePath(dirname(fsPath));
186
+ if (fsPath === routesDir) {
187
+ break;
188
+ }
189
+ }
190
+ if (ids.length > 1 && ids[0] === "Index") {
191
+ ids.shift();
192
+ }
193
+ return ids.reverse().join("").concat(explicitFileType || "");
194
+ }
195
+ const PAGE_MODULE_EXTS = {
196
+ ".tsx": true,
197
+ ".jsx": true
198
+ };
199
+ const MODULE_EXTS = {
200
+ ".ts": true,
201
+ ".js": true
202
+ };
203
+ const MARKDOWN_EXTS = {
204
+ ".md": true,
205
+ ".mdx": true
206
+ };
207
+ function isIndexModule(extlessName) {
208
+ return /^index(|!|@.+)$/.test(extlessName);
209
+ }
210
+ function isPluginModule(extlessName) {
211
+ return /^plugin(|@.+)$/.test(extlessName);
212
+ }
213
+ function isLayoutModule(extlessName) {
214
+ return /^layout(|!|-.+)$/.test(extlessName);
215
+ }
216
+ function isPageModuleExt(ext) {
217
+ return ext in PAGE_MODULE_EXTS;
218
+ }
219
+ function isModuleExt(ext) {
220
+ return ext in MODULE_EXTS;
221
+ }
222
+ function isMarkdownExt(ext) {
223
+ return ext in MARKDOWN_EXTS;
224
+ }
225
+ function isPageExt(ext) {
226
+ return ext in PAGE_MODULE_EXTS || ext in MARKDOWN_EXTS;
227
+ }
228
+ function isMenuFileName(fileName) {
229
+ return fileName === "menu.md";
230
+ }
231
+ function isServiceWorkerName(extlessName) {
232
+ return extlessName === "service-worker";
233
+ }
234
+ function isEntryName(extlessName) {
235
+ return extlessName === "entry";
236
+ }
237
+ function isErrorName(extlessName) {
238
+ return /^[45][0-9]{2}$/.test(extlessName);
239
+ }
240
+ 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
+ return dirName.startsWith("(") && dirName.endsWith(")");
252
+ }
253
+
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 };