@qwik.dev/router 2.0.0-beta.10 → 2.0.0-beta.13

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 (140) hide show
  1. package/lib/adapters/azure-swa/vite/index.cjs +61 -5
  2. package/lib/adapters/azure-swa/vite/index.mjs +26 -201
  3. package/lib/adapters/bun-server/vite/index.cjs +27 -5
  4. package/lib/adapters/bun-server/vite/index.mjs +14 -196
  5. package/lib/adapters/cloud-run/vite/index.cjs +24 -5
  6. package/lib/adapters/cloud-run/vite/index.mjs +13 -195
  7. package/lib/adapters/cloudflare-pages/vite/index.cjs +65 -1
  8. package/lib/adapters/cloudflare-pages/vite/index.mjs +63 -4
  9. package/lib/adapters/deno-server/vite/index.cjs +39 -5
  10. package/lib/adapters/deno-server/vite/index.mjs +16 -198
  11. package/lib/adapters/netlify-edge/vite/index.cjs +88 -6
  12. package/lib/adapters/netlify-edge/vite/index.mjs +56 -240
  13. package/lib/adapters/node-server/vite/index.cjs +27 -5
  14. package/lib/adapters/node-server/vite/index.mjs +14 -196
  15. package/lib/adapters/shared/vite/index.cjs +303 -2
  16. package/lib/adapters/shared/vite/index.d.ts +4 -4
  17. package/lib/adapters/shared/vite/index.mjs +248 -143
  18. package/lib/adapters/ssg/vite/index.cjs +19 -5
  19. package/lib/adapters/ssg/vite/index.mjs +11 -193
  20. package/lib/adapters/vercel-edge/vite/index.cjs +81 -5
  21. package/lib/adapters/vercel-edge/vite/index.d.ts +1 -1
  22. package/lib/adapters/vercel-edge/vite/index.mjs +48 -229
  23. package/lib/chunks/error-handler.cjs +58 -0
  24. package/lib/chunks/error-handler.mjs +59 -0
  25. package/lib/chunks/format-error.cjs +136 -0
  26. package/lib/chunks/format-error.mjs +137 -0
  27. package/lib/chunks/fs.cjs +274 -0
  28. package/lib/chunks/fs.mjs +275 -0
  29. package/lib/chunks/index.cjs +877 -0
  30. package/lib/chunks/index.mjs +876 -0
  31. package/lib/chunks/mime-types.cjs +52 -0
  32. package/lib/chunks/mime-types.mjs +53 -0
  33. package/lib/chunks/routing.qwik.cjs +452 -0
  34. package/lib/chunks/routing.qwik.mjs +453 -0
  35. package/lib/chunks/types.qwik.cjs +24 -0
  36. package/lib/chunks/types.qwik.mjs +25 -0
  37. package/lib/index.d.ts +9 -3
  38. package/lib/index.qwik.cjs +543 -1001
  39. package/lib/index.qwik.mjs +512 -972
  40. package/lib/middleware/aws-lambda/index.cjs +52 -1
  41. package/lib/middleware/aws-lambda/index.mjs +37 -26
  42. package/lib/middleware/azure-swa/index.cjs +92 -1
  43. package/lib/middleware/azure-swa/index.mjs +64 -46
  44. package/lib/middleware/bun/index.cjs +143 -1
  45. package/lib/middleware/bun/index.mjs +103 -117
  46. package/lib/middleware/cloudflare-pages/index.cjs +96 -1
  47. package/lib/middleware/cloudflare-pages/index.mjs +68 -47
  48. package/lib/middleware/deno/index.cjs +130 -1
  49. package/lib/middleware/deno/index.mjs +93 -112
  50. package/lib/middleware/firebase/index.cjs +33 -1
  51. package/lib/middleware/firebase/index.mjs +25 -16
  52. package/lib/middleware/netlify-edge/index.cjs +71 -1
  53. package/lib/middleware/netlify-edge/index.mjs +52 -36
  54. package/lib/middleware/node/index.cjs +219 -1
  55. package/lib/middleware/node/index.mjs +178 -165
  56. package/lib/middleware/request-handler/index.cjs +1488 -18
  57. package/lib/middleware/request-handler/index.d.ts +20 -2
  58. package/lib/middleware/request-handler/index.mjs +1225 -873
  59. package/lib/middleware/vercel-edge/index.cjs +98 -1
  60. package/lib/middleware/vercel-edge/index.mjs +71 -47
  61. package/lib/service-worker/index.cjs +5 -0
  62. package/lib/service-worker/index.mjs +5 -0
  63. package/lib/ssg/index.cjs +15 -1
  64. package/lib/ssg/index.mjs +12 -19
  65. package/lib/vite/index.cjs +2006 -27
  66. package/lib/vite/index.d.ts +9 -9
  67. package/lib/vite/index.mjs +1597 -1216
  68. package/package.json +9 -8
  69. package/lib/adapters/azure-swa/vite/index-BqUeglYs.cjs +0 -1
  70. package/lib/adapters/azure-swa/vite/index-CBIchDYq.js +0 -651
  71. package/lib/adapters/azure-swa/vite/index-ClHGw5z1.js +0 -6
  72. package/lib/adapters/azure-swa/vite/index-CrwlB95_.js +0 -22
  73. package/lib/adapters/azure-swa/vite/index-DTIOTwZo.cjs +0 -11
  74. package/lib/adapters/azure-swa/vite/index-vQuPcef3.cjs +0 -1
  75. package/lib/adapters/bun-server/vite/index-BqUeglYs.cjs +0 -1
  76. package/lib/adapters/bun-server/vite/index-CBIchDYq.js +0 -651
  77. package/lib/adapters/bun-server/vite/index-ClHGw5z1.js +0 -6
  78. package/lib/adapters/bun-server/vite/index-CrwlB95_.js +0 -22
  79. package/lib/adapters/bun-server/vite/index-DTIOTwZo.cjs +0 -11
  80. package/lib/adapters/bun-server/vite/index-vQuPcef3.cjs +0 -1
  81. package/lib/adapters/cloud-run/vite/index-BqUeglYs.cjs +0 -1
  82. package/lib/adapters/cloud-run/vite/index-CBIchDYq.js +0 -651
  83. package/lib/adapters/cloud-run/vite/index-ClHGw5z1.js +0 -6
  84. package/lib/adapters/cloud-run/vite/index-CrwlB95_.js +0 -22
  85. package/lib/adapters/cloud-run/vite/index-DTIOTwZo.cjs +0 -11
  86. package/lib/adapters/cloud-run/vite/index-vQuPcef3.cjs +0 -1
  87. package/lib/adapters/cloudflare-pages/vite/index-BIeHg2Cj.cjs +0 -5
  88. package/lib/adapters/cloudflare-pages/vite/index-C455V8_A.cjs +0 -1
  89. package/lib/adapters/cloudflare-pages/vite/index-ClHGw5z1.js +0 -6
  90. package/lib/adapters/cloudflare-pages/vite/index-D3HITboM.js +0 -645
  91. package/lib/adapters/cloudflare-pages/vite/index-DKcVHRBy.cjs +0 -11
  92. package/lib/adapters/cloudflare-pages/vite/index-DwovcBp3.js +0 -22
  93. package/lib/adapters/cloudflare-pages/vite/index-bogwy7wh.js +0 -250
  94. package/lib/adapters/cloudflare-pages/vite/index-vQuPcef3.cjs +0 -1
  95. package/lib/adapters/deno-server/vite/index-BqUeglYs.cjs +0 -1
  96. package/lib/adapters/deno-server/vite/index-CBIchDYq.js +0 -651
  97. package/lib/adapters/deno-server/vite/index-ClHGw5z1.js +0 -6
  98. package/lib/adapters/deno-server/vite/index-CrwlB95_.js +0 -22
  99. package/lib/adapters/deno-server/vite/index-DTIOTwZo.cjs +0 -11
  100. package/lib/adapters/deno-server/vite/index-vQuPcef3.cjs +0 -1
  101. package/lib/adapters/netlify-edge/vite/index-BqUeglYs.cjs +0 -1
  102. package/lib/adapters/netlify-edge/vite/index-CBIchDYq.js +0 -651
  103. package/lib/adapters/netlify-edge/vite/index-ClHGw5z1.js +0 -6
  104. package/lib/adapters/netlify-edge/vite/index-CrwlB95_.js +0 -22
  105. package/lib/adapters/netlify-edge/vite/index-DTIOTwZo.cjs +0 -11
  106. package/lib/adapters/netlify-edge/vite/index-vQuPcef3.cjs +0 -1
  107. package/lib/adapters/node-server/vite/index-BqUeglYs.cjs +0 -1
  108. package/lib/adapters/node-server/vite/index-CBIchDYq.js +0 -651
  109. package/lib/adapters/node-server/vite/index-ClHGw5z1.js +0 -6
  110. package/lib/adapters/node-server/vite/index-CrwlB95_.js +0 -22
  111. package/lib/adapters/node-server/vite/index-DTIOTwZo.cjs +0 -11
  112. package/lib/adapters/node-server/vite/index-vQuPcef3.cjs +0 -1
  113. package/lib/adapters/shared/vite/index-BqUeglYs.cjs +0 -1
  114. package/lib/adapters/shared/vite/index-CBIchDYq.js +0 -651
  115. package/lib/adapters/shared/vite/index-ClHGw5z1.js +0 -6
  116. package/lib/adapters/shared/vite/index-CrwlB95_.js +0 -22
  117. package/lib/adapters/shared/vite/index-DTIOTwZo.cjs +0 -11
  118. package/lib/adapters/shared/vite/index-vQuPcef3.cjs +0 -1
  119. package/lib/adapters/ssg/vite/index-BqUeglYs.cjs +0 -1
  120. package/lib/adapters/ssg/vite/index-CBIchDYq.js +0 -651
  121. package/lib/adapters/ssg/vite/index-ClHGw5z1.js +0 -6
  122. package/lib/adapters/ssg/vite/index-CrwlB95_.js +0 -22
  123. package/lib/adapters/ssg/vite/index-DTIOTwZo.cjs +0 -11
  124. package/lib/adapters/ssg/vite/index-vQuPcef3.cjs +0 -1
  125. package/lib/adapters/vercel-edge/vite/index-BqUeglYs.cjs +0 -1
  126. package/lib/adapters/vercel-edge/vite/index-CBIchDYq.js +0 -651
  127. package/lib/adapters/vercel-edge/vite/index-ClHGw5z1.js +0 -6
  128. package/lib/adapters/vercel-edge/vite/index-CrwlB95_.js +0 -22
  129. package/lib/adapters/vercel-edge/vite/index-DTIOTwZo.cjs +0 -11
  130. package/lib/adapters/vercel-edge/vite/index-vQuPcef3.cjs +0 -1
  131. package/lib/service-worker.cjs +0 -1
  132. package/lib/service-worker.mjs +0 -5
  133. package/lib/ssg/deno.cjs +0 -1
  134. package/lib/ssg/deno.mjs +0 -6
  135. package/lib/ssg/index-CBIchDYq.js +0 -651
  136. package/lib/ssg/index-ClHGw5z1.js +0 -6
  137. package/lib/ssg/index-DTIOTwZo.cjs +0 -11
  138. package/lib/ssg/index-vQuPcef3.cjs +0 -1
  139. package/lib/ssg/node.cjs +0 -11
  140. package/lib/ssg/node.mjs +0 -651
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ function getErrorHtml(status, e) {
3
+ let message = "Server Error";
4
+ if (e != null) {
5
+ if (typeof e.message === "string") {
6
+ message = e.message;
7
+ } else {
8
+ message = String(e);
9
+ }
10
+ }
11
+ return `<html>` + minimalHtmlResponse(status, message) + `</html>`;
12
+ }
13
+ function minimalHtmlResponse(status, message) {
14
+ if (typeof status !== "number") {
15
+ status = 500;
16
+ }
17
+ if (typeof message === "string") {
18
+ message = escapeHtml(message);
19
+ } else {
20
+ message = "";
21
+ }
22
+ const width = typeof message === "string" ? "600px" : "300px";
23
+ const color = status >= 500 ? COLOR_500 : COLOR_400;
24
+ return `
25
+ <head>
26
+ <meta charset="utf-8">
27
+ <meta http-equiv="Status" content="${status}">
28
+ <title>${status} ${message}</title>
29
+ <meta name="viewport" content="width=device-width,initial-scale=1">
30
+ <style>
31
+ body { color: ${color}; background-color: #fafafa; padding: 30px; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif; }
32
+ p { max-width: ${width}; margin: 60px auto 30px auto; background: white; border-radius: 4px; box-shadow: 0px 0px 50px -20px ${color}; overflow: hidden; }
33
+ strong { display: inline-block; padding: 15px; background: ${color}; color: white; }
34
+ span { display: inline-block; padding: 15px; }
35
+ </style>
36
+ </head>
37
+ <body><p><strong>${status}</strong> <span>${message}</span></p></body>
38
+ `;
39
+ }
40
+ const ESCAPE_HTML = /[&<>]/g;
41
+ const escapeHtml = (s) => {
42
+ return s.replace(ESCAPE_HTML, (c) => {
43
+ switch (c) {
44
+ case "&":
45
+ return "&amp;";
46
+ case "<":
47
+ return "&lt;";
48
+ case ">":
49
+ return "&gt;";
50
+ default:
51
+ return "";
52
+ }
53
+ });
54
+ };
55
+ const COLOR_400 = "#006ce9";
56
+ const COLOR_500 = "#713fc2";
57
+ exports.getErrorHtml = getErrorHtml;
58
+ exports.minimalHtmlResponse = minimalHtmlResponse;
@@ -0,0 +1,59 @@
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);
8
+ }
9
+ }
10
+ return `<html>` + minimalHtmlResponse(status, message) + `</html>`;
11
+ }
12
+ function minimalHtmlResponse(status, message) {
13
+ if (typeof status !== "number") {
14
+ status = 500;
15
+ }
16
+ if (typeof message === "string") {
17
+ message = escapeHtml(message);
18
+ } else {
19
+ message = "";
20
+ }
21
+ const width = typeof message === "string" ? "600px" : "300px";
22
+ const color = status >= 500 ? COLOR_500 : COLOR_400;
23
+ return `
24
+ <head>
25
+ <meta charset="utf-8">
26
+ <meta http-equiv="Status" content="${status}">
27
+ <title>${status} ${message}</title>
28
+ <meta name="viewport" content="width=device-width,initial-scale=1">
29
+ <style>
30
+ body { color: ${color}; background-color: #fafafa; padding: 30px; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif; }
31
+ p { max-width: ${width}; margin: 60px auto 30px auto; background: white; border-radius: 4px; box-shadow: 0px 0px 50px -20px ${color}; overflow: hidden; }
32
+ strong { display: inline-block; padding: 15px; background: ${color}; color: white; }
33
+ span { display: inline-block; padding: 15px; }
34
+ </style>
35
+ </head>
36
+ <body><p><strong>${status}</strong> <span>${message}</span></p></body>
37
+ `;
38
+ }
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 "";
51
+ }
52
+ });
53
+ };
54
+ const COLOR_400 = "#006ce9";
55
+ const COLOR_500 = "#713fc2";
56
+ export {
57
+ getErrorHtml as g,
58
+ minimalHtmlResponse as m
59
+ };
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ const fs = require("./fs.cjs");
3
+ const fs$1 = require("node:fs");
4
+ const findLocation = (e) => {
5
+ const stack = e.stack;
6
+ if (typeof stack === "string") {
7
+ const lines = stack.split("\n").filter((l) => !l.includes("/node_modules/") && !l.includes("(node:"));
8
+ for (let i = 1; i < lines.length; i++) {
9
+ const line = lines[i].replace("file:///", "/");
10
+ if (/^\s+at/.test(line)) {
11
+ const start = line.indexOf("/");
12
+ const end = line.lastIndexOf(")", start);
13
+ if (start > 0) {
14
+ const path = line.slice(start, end);
15
+ const parts = path.split(":");
16
+ const nu0 = safeParseInt(parts[parts.length - 1]);
17
+ const nu1 = safeParseInt(parts[parts.length - 2]);
18
+ if (typeof nu0 === "number" && typeof nu1 === "number") {
19
+ parts.length -= 2;
20
+ return {
21
+ file: parts.join(":"),
22
+ line: nu1,
23
+ column: nu0
24
+ };
25
+ } else if (typeof nu0 === "number") {
26
+ parts.length -= 1;
27
+ return {
28
+ file: parts.join(":"),
29
+ line: nu0,
30
+ column: void 0
31
+ };
32
+ } else {
33
+ return {
34
+ file: parts.join(":"),
35
+ line: void 0,
36
+ column: void 0
37
+ };
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
43
+ return void 0;
44
+ };
45
+ const safeParseInt = (nu) => {
46
+ try {
47
+ return parseInt(nu, 10);
48
+ } catch {
49
+ return void 0;
50
+ }
51
+ };
52
+ const splitRE = /\r?\n/;
53
+ const range = 2;
54
+ function posToNumber(source, pos) {
55
+ if (typeof pos === "number") {
56
+ return pos;
57
+ }
58
+ if (pos.lo != null) {
59
+ return pos.lo;
60
+ }
61
+ const lines = source.split(splitRE);
62
+ const { line, column } = pos;
63
+ let start = 0;
64
+ for (let i = 0; i < line - 1 && i < lines.length; i++) {
65
+ start += lines[i].length + 1;
66
+ }
67
+ return start + column;
68
+ }
69
+ function generateCodeFrame(source, start = 0, end) {
70
+ start = posToNumber(source, start);
71
+ end = end || start;
72
+ const lines = source.split(splitRE);
73
+ let count = 0;
74
+ const res = [];
75
+ for (let i = 0; i < lines.length; i++) {
76
+ count += lines[i].length + 1;
77
+ if (count >= start) {
78
+ for (let j = i - range; j <= i + range || end > count; j++) {
79
+ if (j < 0 || j >= lines.length) {
80
+ continue;
81
+ }
82
+ const line = j + 1;
83
+ res.push(`${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
84
+ const lineLength = lines[j].length;
85
+ if (j === i) {
86
+ const pad = Math.max(start - (count - lineLength) + 1, 0);
87
+ const length = Math.max(1, end > count ? lineLength - pad : end - start);
88
+ res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
89
+ } else if (j > i) {
90
+ if (end > count) {
91
+ const length = Math.max(Math.min(end - count, lineLength), 1);
92
+ res.push(` | ` + "^".repeat(length));
93
+ }
94
+ count += lineLength + 1;
95
+ }
96
+ }
97
+ break;
98
+ }
99
+ }
100
+ return res.join("\n");
101
+ }
102
+ function parseId(originalId) {
103
+ const [pathId, query] = originalId.split("?");
104
+ const queryStr = query || "";
105
+ return {
106
+ originalId,
107
+ pathId,
108
+ query: queryStr ? `?${query}` : "",
109
+ params: new URLSearchParams(queryStr)
110
+ };
111
+ }
112
+ function formatError(e) {
113
+ if (e instanceof Error) {
114
+ const err = e;
115
+ let loc = err.loc;
116
+ if (!err.frame && !err.plugin) {
117
+ if (!loc) {
118
+ loc = findLocation(err);
119
+ }
120
+ if (loc) {
121
+ err.loc = loc;
122
+ if (loc.file) {
123
+ err.id = fs.normalizePath(err.loc.file);
124
+ try {
125
+ const code = fs$1.readFileSync(err.loc.file, "utf-8");
126
+ err.frame = generateCodeFrame(code, err.loc);
127
+ } catch {
128
+ }
129
+ }
130
+ }
131
+ }
132
+ }
133
+ return e;
134
+ }
135
+ exports.formatError = formatError;
136
+ exports.parseId = parseId;
@@ -0,0 +1,137 @@
1
+ import { l as normalizePath } from "./fs.mjs";
2
+ import fs from "node:fs";
3
+ const findLocation = (e) => {
4
+ const stack = e.stack;
5
+ if (typeof stack === "string") {
6
+ const lines = stack.split("\n").filter((l) => !l.includes("/node_modules/") && !l.includes("(node:"));
7
+ for (let i = 1; i < lines.length; i++) {
8
+ const line = lines[i].replace("file:///", "/");
9
+ if (/^\s+at/.test(line)) {
10
+ const start = line.indexOf("/");
11
+ const end = line.lastIndexOf(")", start);
12
+ if (start > 0) {
13
+ const path = line.slice(start, end);
14
+ const parts = path.split(":");
15
+ const nu0 = safeParseInt(parts[parts.length - 1]);
16
+ const nu1 = safeParseInt(parts[parts.length - 2]);
17
+ if (typeof nu0 === "number" && typeof nu1 === "number") {
18
+ parts.length -= 2;
19
+ return {
20
+ file: parts.join(":"),
21
+ line: nu1,
22
+ column: nu0
23
+ };
24
+ } else if (typeof nu0 === "number") {
25
+ parts.length -= 1;
26
+ return {
27
+ file: parts.join(":"),
28
+ line: nu0,
29
+ column: void 0
30
+ };
31
+ } else {
32
+ return {
33
+ file: parts.join(":"),
34
+ line: void 0,
35
+ column: void 0
36
+ };
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }
42
+ return void 0;
43
+ };
44
+ const safeParseInt = (nu) => {
45
+ try {
46
+ return parseInt(nu, 10);
47
+ } catch {
48
+ return void 0;
49
+ }
50
+ };
51
+ const splitRE = /\r?\n/;
52
+ const range = 2;
53
+ function posToNumber(source, pos) {
54
+ if (typeof pos === "number") {
55
+ return pos;
56
+ }
57
+ if (pos.lo != null) {
58
+ return pos.lo;
59
+ }
60
+ const lines = source.split(splitRE);
61
+ const { line, column } = pos;
62
+ let start = 0;
63
+ for (let i = 0; i < line - 1 && i < lines.length; i++) {
64
+ start += lines[i].length + 1;
65
+ }
66
+ return start + column;
67
+ }
68
+ function generateCodeFrame(source, start = 0, end) {
69
+ start = posToNumber(source, start);
70
+ end = end || start;
71
+ const lines = source.split(splitRE);
72
+ let count = 0;
73
+ const res = [];
74
+ for (let i = 0; i < lines.length; i++) {
75
+ count += lines[i].length + 1;
76
+ if (count >= start) {
77
+ for (let j = i - range; j <= i + range || end > count; j++) {
78
+ if (j < 0 || j >= lines.length) {
79
+ continue;
80
+ }
81
+ const line = j + 1;
82
+ res.push(`${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
83
+ const lineLength = lines[j].length;
84
+ if (j === i) {
85
+ const pad = Math.max(start - (count - lineLength) + 1, 0);
86
+ const length = Math.max(1, end > count ? lineLength - pad : end - start);
87
+ res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
88
+ } else if (j > i) {
89
+ if (end > count) {
90
+ const length = Math.max(Math.min(end - count, lineLength), 1);
91
+ res.push(` | ` + "^".repeat(length));
92
+ }
93
+ count += lineLength + 1;
94
+ }
95
+ }
96
+ break;
97
+ }
98
+ }
99
+ return res.join("\n");
100
+ }
101
+ function parseId(originalId) {
102
+ const [pathId, query] = originalId.split("?");
103
+ const queryStr = query || "";
104
+ return {
105
+ originalId,
106
+ pathId,
107
+ query: queryStr ? `?${query}` : "",
108
+ params: new URLSearchParams(queryStr)
109
+ };
110
+ }
111
+ function formatError(e) {
112
+ if (e instanceof Error) {
113
+ const err = e;
114
+ let loc = err.loc;
115
+ if (!err.frame && !err.plugin) {
116
+ if (!loc) {
117
+ loc = findLocation(err);
118
+ }
119
+ if (loc) {
120
+ err.loc = loc;
121
+ if (loc.file) {
122
+ err.id = normalizePath(err.loc.file);
123
+ try {
124
+ const code = fs.readFileSync(err.loc.file, "utf-8");
125
+ err.frame = generateCodeFrame(code, err.loc);
126
+ } catch {
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+ return e;
133
+ }
134
+ export {
135
+ formatError as f,
136
+ parseId as p
137
+ };
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+ const path = require("node:path");
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
+ function normalizePathname(pathname, basePathname) {
33
+ if (typeof pathname === "string") {
34
+ pathname = pathname.trim();
35
+ if (pathname !== "") {
36
+ try {
37
+ pathname = pathname.replace(/\/+/g, "/");
38
+ if (pathname.startsWith("/")) {
39
+ pathname = pathname.slice(1);
40
+ }
41
+ pathname = new URL(basePathname + pathname, `https://qwik.dev`).pathname;
42
+ if (pathname !== basePathname) {
43
+ if (!globalThis.__NO_TRAILING_SLASH__) {
44
+ if (!pathname.endsWith("/")) {
45
+ const segments = pathname.split("/");
46
+ const lastSegment = segments[segments.length - 1];
47
+ if (!lastSegment.includes(".")) {
48
+ pathname += "/";
49
+ }
50
+ }
51
+ } else {
52
+ if (pathname.endsWith("/")) {
53
+ pathname = pathname.slice(0, pathname.length - 1);
54
+ }
55
+ }
56
+ }
57
+ return pathname;
58
+ } catch (e) {
59
+ console.error(e);
60
+ }
61
+ }
62
+ }
63
+ return null;
64
+ }
65
+ function getPathnameForDynamicRoute(originalPathname, paramNames, params) {
66
+ let pathname = originalPathname;
67
+ if (paramNames && params) {
68
+ for (const paramName of paramNames) {
69
+ const paramKey = `[${paramName}]`;
70
+ const restParamKey = `[...${paramName}]`;
71
+ const paramValue = params[paramName];
72
+ pathname = pathname.replace(restParamKey, paramValue);
73
+ pathname = pathname.replace(paramKey, paramValue);
74
+ }
75
+ }
76
+ return pathname;
77
+ }
78
+ function isSameOriginUrl(url) {
79
+ if (typeof url === "string") {
80
+ url = url.trim();
81
+ if (url !== "") {
82
+ const firstChar = url.charAt(0);
83
+ if (firstChar !== "/" && firstChar !== ".") {
84
+ if (firstChar === "#") {
85
+ return false;
86
+ }
87
+ const i = url.indexOf(":");
88
+ if (i > -1) {
89
+ const protocol = url.slice(0, i).toLowerCase();
90
+ return !PROTOCOLS[protocol];
91
+ }
92
+ }
93
+ return true;
94
+ }
95
+ }
96
+ return false;
97
+ }
98
+ const PROTOCOLS = {
99
+ https: true,
100
+ http: true,
101
+ about: true,
102
+ javascript: true,
103
+ file: true
104
+ };
105
+ function parseRouteIndexName(extlessName) {
106
+ let layoutName = "";
107
+ const layoutStop = extlessName.endsWith("!");
108
+ if (layoutStop) {
109
+ extlessName = extlessName.slice(0, extlessName.length - 1);
110
+ }
111
+ const namedLayoutParts = extlessName.split("@");
112
+ if (namedLayoutParts.length > 1) {
113
+ namedLayoutParts.shift();
114
+ layoutName = namedLayoutParts.join("@");
115
+ }
116
+ return { layoutName, layoutStop };
117
+ }
118
+ function getPathnameFromDirPath(opts, dirPath) {
119
+ const relFilePath = path.relative(opts.routesDir, dirPath);
120
+ let pathname = normalizePath(relFilePath);
121
+ pathname = normalizePathname(pathname, opts.basePathname).split("/").filter((segment) => !isGroupedLayoutName(segment)).join("/");
122
+ if (pathname === "") {
123
+ return "/";
124
+ }
125
+ return pathname;
126
+ }
127
+ function getMenuPathname(opts, filePath) {
128
+ let pathname = normalizePath(path.relative(opts.routesDir, filePath));
129
+ pathname = `/` + normalizePath(path.dirname(pathname));
130
+ let result = normalizePathname(pathname, opts.basePathname);
131
+ if (!result.endsWith("/")) {
132
+ result += "/";
133
+ }
134
+ return result;
135
+ }
136
+ function getExtension(fileName) {
137
+ if (typeof fileName === "string") {
138
+ const parts = fileName.trim().toLowerCase().split(".");
139
+ if (parts.length > 1) {
140
+ const ext = parts.pop().split("?")[0].split("#")[0];
141
+ if (ext === "ts" && parts.pop() === "d") {
142
+ return ".d.ts";
143
+ }
144
+ return "." + ext;
145
+ }
146
+ }
147
+ return "";
148
+ }
149
+ function removeExtension(fileName) {
150
+ if (typeof fileName === "string") {
151
+ fileName = fileName.trim();
152
+ const ext = getExtension(fileName);
153
+ return fileName.slice(0, fileName.length - ext.length);
154
+ }
155
+ return "";
156
+ }
157
+ function normalizePath(path$1) {
158
+ return normalizePathSlash(path.normalize(path$1));
159
+ }
160
+ function normalizePathSlash(path2) {
161
+ const isExtendedLengthPath = path2.startsWith("\\\\?\\");
162
+ const hasNonAscii = /[^\u0000-\u0080]+/.test(path2);
163
+ if (isExtendedLengthPath || hasNonAscii) {
164
+ return path2;
165
+ }
166
+ path2 = path2.replace(/\\/g, "/");
167
+ if (path2.endsWith("/")) {
168
+ path2 = path2.slice(0, path2.length - 1);
169
+ }
170
+ return path2;
171
+ }
172
+ function createFileId(routesDir, fsPath, explicitFileType) {
173
+ const ids = [];
174
+ for (let i = 0; i < 25; i++) {
175
+ let baseName = removeExtension(path.basename(fsPath));
176
+ baseName = baseName.replace(/[\W_]+/g, "");
177
+ if (baseName === "") {
178
+ baseName = "Q" + i;
179
+ } else if (!isNaN(baseName.charAt(0))) {
180
+ baseName = "Q" + baseName;
181
+ }
182
+ ids.push(toTitleCase(baseName));
183
+ fsPath = normalizePath(path.dirname(fsPath));
184
+ if (fsPath === routesDir) {
185
+ break;
186
+ }
187
+ }
188
+ if (ids.length > 1 && ids[0] === "Index") {
189
+ ids.shift();
190
+ }
191
+ return ids.reverse().join("").concat(explicitFileType || "");
192
+ }
193
+ const PAGE_MODULE_EXTS = {
194
+ ".tsx": true,
195
+ ".jsx": true
196
+ };
197
+ const MODULE_EXTS = {
198
+ ".ts": true,
199
+ ".js": true
200
+ };
201
+ const MARKDOWN_EXTS = {
202
+ ".md": true,
203
+ ".mdx": true
204
+ };
205
+ function isIndexModule(extlessName) {
206
+ return /^index(|!|@.+)$/.test(extlessName);
207
+ }
208
+ function isPluginModule(extlessName) {
209
+ return /^plugin(|@.+)$/.test(extlessName);
210
+ }
211
+ function isLayoutModule(extlessName) {
212
+ return /^layout(|!|-.+)$/.test(extlessName);
213
+ }
214
+ function isPageModuleExt(ext) {
215
+ return ext in PAGE_MODULE_EXTS;
216
+ }
217
+ function isModuleExt(ext) {
218
+ return ext in MODULE_EXTS;
219
+ }
220
+ function isMarkdownExt(ext) {
221
+ return ext in MARKDOWN_EXTS;
222
+ }
223
+ function isPageExt(ext) {
224
+ return ext in PAGE_MODULE_EXTS || ext in MARKDOWN_EXTS;
225
+ }
226
+ function isMenuFileName(fileName) {
227
+ return fileName === "menu.md";
228
+ }
229
+ function isServiceWorkerName(extlessName) {
230
+ return extlessName === "service-worker";
231
+ }
232
+ function isEntryName(extlessName) {
233
+ return extlessName === "entry";
234
+ }
235
+ function isErrorName(extlessName) {
236
+ return /^[45][0-9]{2}$/.test(extlessName);
237
+ }
238
+ function isGroupedLayoutName(dirName, warn = true) {
239
+ if (dirName.startsWith("__")) {
240
+ if (warn) {
241
+ console.warn(
242
+ `Grouped (pathless) layout "${dirName}" should use the "(${dirName.slice(
243
+ 2
244
+ )})" directory name instead. Prefixing a directory with "__" has been deprecated and will be removed in future versions.`
245
+ );
246
+ }
247
+ return true;
248
+ }
249
+ return dirName.startsWith("(") && dirName.endsWith(")");
250
+ }
251
+ exports.addError = addError;
252
+ exports.addWarning = addWarning;
253
+ exports.createFileId = createFileId;
254
+ exports.getExtension = getExtension;
255
+ exports.getMenuPathname = getMenuPathname;
256
+ exports.getPathnameForDynamicRoute = getPathnameForDynamicRoute;
257
+ exports.getPathnameFromDirPath = getPathnameFromDirPath;
258
+ exports.isEntryName = isEntryName;
259
+ exports.isErrorName = isErrorName;
260
+ exports.isIndexModule = isIndexModule;
261
+ exports.isLayoutModule = isLayoutModule;
262
+ exports.isMarkdownExt = isMarkdownExt;
263
+ exports.isMenuFileName = isMenuFileName;
264
+ exports.isModuleExt = isModuleExt;
265
+ exports.isPageExt = isPageExt;
266
+ exports.isPageModuleExt = isPageModuleExt;
267
+ exports.isPluginModule = isPluginModule;
268
+ exports.isSameOriginUrl = isSameOriginUrl;
269
+ exports.isServiceWorkerName = isServiceWorkerName;
270
+ exports.msToString = msToString;
271
+ exports.normalizePath = normalizePath;
272
+ exports.normalizePathSlash = normalizePathSlash;
273
+ exports.parseRouteIndexName = parseRouteIndexName;
274
+ exports.removeExtension = removeExtension;