@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
@@ -1,16 +1,15 @@
1
- // packages/qwik-router/src/adapters/shared/vite/index.ts
2
- import fs2 from "node:fs";
3
- import { basename, dirname, join as join2, resolve } from "node:path";
1
+ import { join, resolve, dirname, basename } from 'node:path';
2
+ import fs from 'node:fs';
3
+ import { g as getErrorHtml } from '../../../chunks/error-handler.mjs';
4
4
 
5
- // packages/qwik-router/src/adapters/shared/vite/post-build.ts
6
- import { getErrorHtml } from "../../../middleware/request-handler/index.mjs";
7
- import fs from "node:fs";
8
- import { join } from "node:path";
9
- async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanStatic) {
5
+ async function postBuild(clientOutDir, serverOutDir, pathName, userStaticPaths, cleanStatic) {
10
6
  if (pathName && !pathName.endsWith("/")) {
11
7
  pathName += "/";
12
8
  }
13
- const ignorePathnames = /* @__PURE__ */ new Set([pathName + "build/", pathName + "assets/"]);
9
+ const ignorePathnames = /* @__PURE__ */ new Set([
10
+ pathName + "/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/",
11
+ pathName + "/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/"
12
+ ]);
14
13
  const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash));
15
14
  const notFounds = [];
16
15
  const loadItem = async (fsDir, fsName, pathname) => {
@@ -44,12 +43,9 @@ async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanS
44
43
  if (fs.existsSync(clientOutDir)) {
45
44
  await loadDir(clientOutDir, pathName);
46
45
  }
47
- const notFoundPathsCode = createNotFoundPathsModule(pathName, notFounds, format);
48
- const staticPathsCode = createStaticPathsModule(pathName, staticPaths, format);
49
- return {
50
- notFoundPathsCode,
51
- staticPathsCode
52
- };
46
+ const notFoundPathsCode = createNotFoundPathsCode(pathName, notFounds);
47
+ const staticPathsCode = createStaticPathsCode(staticPaths);
48
+ await injectStatics(staticPathsCode, notFoundPathsCode, serverOutDir);
53
49
  }
54
50
  function normalizeTrailingSlash(pathname) {
55
51
  if (!pathname.endsWith("/")) {
@@ -57,7 +53,7 @@ function normalizeTrailingSlash(pathname) {
57
53
  }
58
54
  return pathname;
59
55
  }
60
- function createNotFoundPathsModule(basePathname, notFounds, format) {
56
+ function createNotFoundPathsCode(basePathname, notFounds) {
61
57
  notFounds.sort((a, b) => {
62
58
  if (a[0].length > b[0].length) {
63
59
  return -1;
@@ -77,66 +73,44 @@ function createNotFoundPathsModule(basePathname, notFounds, format) {
77
73
  const html = getErrorHtml(404, "Resource Not Found");
78
74
  notFounds.push([basePathname, html]);
79
75
  }
80
- const c = [];
81
- c.push(`const notFounds = ${JSON.stringify(notFounds, null, 2)};`);
82
- c.push(`function getNotFound(p) {`);
83
- c.push(` for (const r of notFounds) {`);
84
- c.push(` if (p.startsWith(r[0])) {`);
85
- c.push(` return r[1];`);
86
- c.push(` }`);
87
- c.push(` }`);
88
- c.push(` return "Resource Not Found";`);
89
- c.push(`}`);
90
- if (format === "cjs") {
91
- c.push("exports.getNotFound = getNotFound;");
92
- } else {
93
- c.push("export { getNotFound };");
94
- }
95
- return c.join("\n");
76
+ return JSON.stringify(notFounds, null, 2).slice(1, -1);
96
77
  }
97
- function createStaticPathsModule(basePathname, staticPaths, format) {
98
- const assetsPath = basePathname + "assets/";
99
- const baseBuildPath = basePathname + "build/";
100
- const c = [];
101
- c.push(
102
- `const staticPaths = new Set(${JSON.stringify(
103
- Array.from(new Set(staticPaths)).sort()
104
- )});`
105
- );
106
- c.push(`function isStaticPath(method, url) {`);
107
- c.push(` if (method.toUpperCase() !== 'GET') {`);
108
- c.push(` return false;`);
109
- c.push(` }`);
110
- c.push(` const p = url.pathname;`);
111
- c.push(` if (p.startsWith(${JSON.stringify(baseBuildPath)})) {`);
112
- c.push(` return true;`);
113
- c.push(` }`);
114
- c.push(` if (p.startsWith(${JSON.stringify(assetsPath)})) {`);
115
- c.push(` return true;`);
116
- c.push(` }`);
117
- c.push(` if (staticPaths.has(p)) {`);
118
- c.push(` return true;`);
119
- c.push(` }`);
120
- c.push(` if (p.endsWith('/q-data.json')) {`);
121
- c.push(` const pWithoutQdata = p.replace(/\\/q-data.json$/, '');`);
122
- c.push(` if (staticPaths.has(pWithoutQdata + '/')) {`);
123
- c.push(` return true;`);
124
- c.push(` }`);
125
- c.push(` if (staticPaths.has(pWithoutQdata)) {`);
126
- c.push(` return true;`);
127
- c.push(` }`);
128
- c.push(` }`);
129
- c.push(` return false;`);
130
- c.push(`}`);
131
- if (format === "cjs") {
132
- c.push("exports.isStaticPath = isStaticPath;");
133
- } else {
134
- c.push("export { isStaticPath };");
135
- }
136
- return c.join("\n");
78
+ function createStaticPathsCode(staticPaths) {
79
+ return JSON.stringify(Array.from(new Set(staticPaths)).sort()).slice(1, -1);
137
80
  }
81
+ const injectStatics = async (staticPathsCode, notFoundPathsCode, outDir) => {
82
+ const promises = /* @__PURE__ */ new Set();
83
+ const doReplace = async (path) => {
84
+ const code = await fs.promises.readFile(path, "utf-8");
85
+ let replaced = false;
86
+ const newCode = code.replace(
87
+ /(['"])__QWIK_ROUTER_(STATIC_PATHS|NOT_FOUND)_ARRAY__\1/g,
88
+ (_, _quote, type) => {
89
+ replaced = true;
90
+ return type === "STATIC_PATHS" ? staticPathsCode : notFoundPathsCode;
91
+ }
92
+ );
93
+ if (replaced) {
94
+ await fs.promises.writeFile(path, newCode);
95
+ }
96
+ };
97
+ const walk = async (dir) => {
98
+ const entries = await fs.promises.readdir(dir, { withFileTypes: true });
99
+ for (const entry of entries) {
100
+ if (entry.isDirectory()) {
101
+ await walk(join(dir, entry.name));
102
+ } else if (entry.name.endsWith("js")) {
103
+ const p = doReplace(join(dir, entry.name)).finally(() => {
104
+ promises.delete(p);
105
+ });
106
+ promises.add(p);
107
+ }
108
+ }
109
+ };
110
+ await walk(outDir);
111
+ await Promise.all(promises);
112
+ };
138
113
 
139
- // packages/qwik-router/src/adapters/shared/vite/index.ts
140
114
  function viteAdapter(opts) {
141
115
  let qwikRouterPlugin = null;
142
116
  let qwikVitePlugin = null;
@@ -144,10 +118,10 @@ function viteAdapter(opts) {
144
118
  let renderModulePath = null;
145
119
  let qwikRouterConfigModulePath = null;
146
120
  let isSsrBuild = false;
147
- let format = "esm";
121
+ let viteCommand;
148
122
  const outputEntries = [];
149
123
  const plugin = {
150
- name: `vite-plugin-qwik-router-${opts.name}`,
124
+ name: `vite-plugin-qwik-router-ssg-${opts.name}`,
151
125
  enforce: "post",
152
126
  apply: "build",
153
127
  config(config) {
@@ -161,8 +135,8 @@ function viteAdapter(opts) {
161
135
  return config;
162
136
  },
163
137
  configResolved(config) {
164
- var _a, _b, _c, _d;
165
138
  isSsrBuild = !!config.build.ssr;
139
+ viteCommand = config.command;
166
140
  if (isSsrBuild) {
167
141
  qwikRouterPlugin = config.plugins.find(
168
142
  (p) => p.name === "vite-plugin-qwik-router"
@@ -177,18 +151,32 @@ function viteAdapter(opts) {
177
151
  throw new Error("Missing vite-plugin-qwik");
178
152
  }
179
153
  serverOutDir = config.build.outDir;
180
- if (((_a = config.build) == null ? void 0 : _a.ssr) !== true) {
154
+ if (config.build?.ssr !== true) {
181
155
  throw new Error(
182
156
  `"build.ssr" must be set to "true" in order to use the "${opts.name}" adapter.`
183
157
  );
184
158
  }
185
- if (!((_c = (_b = config.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.input)) {
159
+ if (!config.build?.rollupOptions?.input) {
186
160
  throw new Error(
187
161
  `"build.rollupOptions.input" must be set in order to use the "${opts.name}" adapter.`
188
162
  );
189
163
  }
190
- if (((_d = config.ssr) == null ? void 0 : _d.format) === "cjs") {
191
- format = "cjs";
164
+ }
165
+ },
166
+ buildStart() {
167
+ if (isSsrBuild && opts.ssg !== null) {
168
+ const { srcDir } = qwikVitePlugin.api.getOptions();
169
+ if (viteCommand === "build" && serverOutDir && srcDir) {
170
+ this.emitFile({
171
+ id: "@qwik-router-config",
172
+ type: "chunk",
173
+ fileName: "@qwik-router-config.js"
174
+ });
175
+ this.emitFile({
176
+ id: `${srcDir}/entry.ssr`,
177
+ type: "chunk",
178
+ fileName: "entry.ssr.js"
179
+ });
192
180
  }
193
181
  }
194
182
  },
@@ -200,29 +188,18 @@ function viteAdapter(opts) {
200
188
  if (chunk.type === "chunk" && chunk.isEntry) {
201
189
  outputEntries.push(fileName);
202
190
  if (chunk.name === "entry.ssr") {
203
- renderModulePath = join2(serverOutDir, fileName);
191
+ renderModulePath = join(serverOutDir, fileName);
204
192
  } else if (chunk.name === "@qwik-router-config") {
205
- qwikRouterConfigModulePath = join2(serverOutDir, fileName);
193
+ qwikRouterConfigModulePath = join(serverOutDir, fileName);
206
194
  }
207
195
  }
208
196
  }
209
- if (!renderModulePath) {
210
- throw new Error(
211
- 'Unable to find "entry.ssr" entry point. Did you forget to add it to "build.rollupOptions.input"?'
212
- );
213
- }
214
- if (!qwikRouterConfigModulePath) {
215
- throw new Error(
216
- 'Unable to find "@qwik-router-config" entry point. Did you forget to add it to "build.rollupOptions.input"?'
217
- );
218
- }
219
197
  }
220
198
  },
221
199
  closeBundle: {
222
200
  sequential: true,
223
201
  async handler() {
224
- var _a;
225
- if (isSsrBuild && opts.ssg !== null && serverOutDir && (qwikRouterPlugin == null ? void 0 : qwikRouterPlugin.api) && (qwikVitePlugin == null ? void 0 : qwikVitePlugin.api)) {
202
+ if (isSsrBuild && serverOutDir && qwikRouterPlugin?.api && qwikVitePlugin?.api) {
226
203
  const staticPaths = opts.staticPaths || [];
227
204
  const routes = qwikRouterPlugin.api.getRoutes();
228
205
  const basePathname = qwikRouterPlugin.api.getBasePathname();
@@ -230,8 +207,8 @@ function viteAdapter(opts) {
230
207
  const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir();
231
208
  const assetsDir = qwikVitePlugin.api.getAssetsDir();
232
209
  const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0;
233
- if (renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
234
- let ssgOrigin = ((_a = opts.ssg) == null ? void 0 : _a.origin) ?? opts.origin;
210
+ if (opts.ssg !== null && renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
211
+ let ssgOrigin = opts.ssg?.origin ?? opts.origin;
235
212
  if (!ssgOrigin) {
236
213
  ssgOrigin = `https://yoursite.qwik.dev`;
237
214
  }
@@ -243,13 +220,13 @@ function viteAdapter(opts) {
243
220
  }
244
221
  try {
245
222
  ssgOrigin = new URL(ssgOrigin).origin;
246
- } catch (e) {
223
+ } catch {
247
224
  this.warn(
248
225
  `Invalid "origin" option: "${ssgOrigin}". Using default origin: "https://yoursite.qwik.dev"`
249
226
  );
250
227
  ssgOrigin = `https://yoursite.qwik.dev`;
251
228
  }
252
- const staticGenerate = await import("../../../static/index.mjs");
229
+ const staticGenerate = await import('../../../ssg/index.mjs');
253
230
  const generateOpts = {
254
231
  maxWorkers: opts.maxWorkers,
255
232
  basePathname,
@@ -269,40 +246,41 @@ function viteAdapter(opts) {
269
246
  this.error(err);
270
247
  }
271
248
  staticPaths.push(...staticGenerateResult.staticPaths);
272
- const { staticPathsCode, notFoundPathsCode } = await postBuild(
249
+ }
250
+ await postBuild(
251
+ clientPublicOutDir,
252
+ serverOutDir,
253
+ assetsDir ? join(basePathname, assetsDir) : basePathname,
254
+ staticPaths,
255
+ !!opts.cleanStaticGenerated
256
+ );
257
+ if (typeof opts.generate === "function") {
258
+ await opts.generate({
259
+ outputEntries,
260
+ serverOutDir,
261
+ clientOutDir,
273
262
  clientPublicOutDir,
274
- assetsDir ? join2(basePathname, assetsDir) : basePathname,
275
- staticPaths,
276
- format,
277
- !!opts.cleanStaticGenerated
278
- );
279
- await Promise.all([
280
- fs2.promises.writeFile(join2(serverOutDir, RESOLVED_STATIC_PATHS_ID), staticPathsCode),
281
- fs2.promises.writeFile(
282
- join2(serverOutDir, RESOLVED_NOT_FOUND_PATHS_ID),
283
- notFoundPathsCode
284
- )
285
- ]);
286
- if (typeof opts.generate === "function") {
287
- await opts.generate({
288
- outputEntries,
289
- serverOutDir,
290
- clientOutDir,
291
- clientPublicOutDir,
292
- basePathname,
293
- routes,
294
- assetsDir,
295
- warn: (message) => this.warn(message),
296
- error: (message) => this.error(message)
297
- });
298
- }
299
- this.warn(
300
- `
263
+ basePathname,
264
+ routes,
265
+ assetsDir,
266
+ warn: (message) => this.warn(message),
267
+ error: (message) => this.error(message)
268
+ });
269
+ }
270
+ this.warn(
271
+ `
301
272
  ==============================================
302
273
  Note: Make sure that you are serving the built files with proper cache headers.
303
274
  See https://qwik.dev/docs/deployments/#cache-headers for more information.
304
275
  ==============================================`
305
- );
276
+ );
277
+ if (opts.ssg !== null) {
278
+ setTimeout(() => {
279
+ console.warn(
280
+ "SSG seems to be hanging after completion, forcing process to exit. Everything is likely fine."
281
+ );
282
+ process.exit(0);
283
+ }, 5e3).unref();
306
284
  }
307
285
  }
308
286
  }
@@ -324,15 +302,5 @@ function getParentDir(startDir, dirName) {
324
302
  }
325
303
  throw new Error(`Unable to find "${dirName}" directory from "${startDir}"`);
326
304
  }
327
- var STATIC_PATHS_ID = "@qwik-router-static-paths";
328
- var RESOLVED_STATIC_PATHS_ID = `${STATIC_PATHS_ID}.js`;
329
- var NOT_FOUND_PATHS_ID = "@qwik-router-not-found-paths";
330
- var RESOLVED_NOT_FOUND_PATHS_ID = `${NOT_FOUND_PATHS_ID}.js`;
331
- export {
332
- NOT_FOUND_PATHS_ID,
333
- RESOLVED_NOT_FOUND_PATHS_ID,
334
- RESOLVED_STATIC_PATHS_ID,
335
- STATIC_PATHS_ID,
336
- getParentDir,
337
- viteAdapter
338
- };
305
+
306
+ export { getParentDir, viteAdapter };
@@ -0,0 +1,13 @@
1
+ import type { SsgRenderOptions } from '../../../ssg';
2
+
3
+ /** @public */
4
+ export declare function ssgAdapter(opts: SsgAdapterOptions): any;
5
+
6
+ /** @public */
7
+ export declare interface SsgAdapterOptions extends Omit<SsgRenderOptions, 'outDir'> {
8
+ }
9
+
10
+ /** @public @deprecated Use `ssgAdapter` instead. */
11
+ export declare const staticAdapter: typeof ssgAdapter;
12
+
13
+ export { }
@@ -0,0 +1,18 @@
1
+ import { viteAdapter } from '../../shared/vite/index.mjs';
2
+ import 'node:path';
3
+ import 'node:fs';
4
+ import '../../../chunks/error-handler.mjs';
5
+
6
+ function ssgAdapter(opts) {
7
+ return viteAdapter({
8
+ name: "static-site-generation",
9
+ origin: opts.origin,
10
+ ssg: {
11
+ include: ["/*"],
12
+ ...opts
13
+ }
14
+ });
15
+ }
16
+ const staticAdapter = ssgAdapter;
17
+
18
+ export { ssgAdapter, staticAdapter };
@@ -1,7 +1,7 @@
1
1
  import { ServerAdapterOptions } from '../../shared/vite';
2
- import type { StaticGenerateRenderOptions } from '@qwik.dev/router/static';
2
+ import type { SsgRenderOptions } from 'packages/qwik-router/src/ssg';
3
3
 
4
- export { StaticGenerateRenderOptions }
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.mts` file.
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,18 +1,17 @@
1
- // packages/qwik-router/src/adapters/vercel-edge/vite/index.ts
2
- import fs from "node:fs";
3
- import { dirname, join } from "node:path";
4
- import { getParentDir, viteAdapter } from "../../shared/vite/index.mjs";
1
+ import fs from 'node:fs';
2
+ import { join, dirname } from 'node:path';
3
+ import { viteAdapter, getParentDir } from '../../shared/vite/index.mjs';
4
+ import '../../../chunks/error-handler.mjs';
5
+
5
6
  function vercelEdgeAdapter(opts = {}) {
6
- var _a;
7
7
  return viteAdapter({
8
8
  name: "vercel-edge",
9
- origin: ((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.VERCEL_URL) || "https://yoursitename.vercel.app",
9
+ origin: process?.env?.VERCEL_URL || "https://yoursitename.vercel.app",
10
10
  ssg: opts.ssg,
11
11
  staticPaths: opts.staticPaths,
12
12
  cleanStaticGenerated: true,
13
13
  config(config) {
14
- var _a2;
15
- const outDir = ((_a2 = config.build) == null ? void 0 : _a2.outDir) || join(".vercel", "output", "functions", "_qwik-router.func");
14
+ const outDir = config.build?.outDir || join(".vercel", "output", "functions", "_qwik-router.func");
16
15
  return {
17
16
  resolve: {
18
17
  conditions: opts.target === "node" ? ["node", "import", "module", "browser", "default"] : ["edge-light", "webworker", "worker", "browser", "module", "main"]
@@ -78,6 +77,5 @@ function vercelEdgeAdapter(opts = {}) {
78
77
  }
79
78
  });
80
79
  }
81
- export {
82
- vercelEdgeAdapter
83
- };
80
+
81
+ export { vercelEdgeAdapter };
@@ -0,0 +1,57 @@
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
+
57
+ export { getErrorHtml as g, minimalHtmlResponse as m };
@@ -0,0 +1,137 @@
1
+ import { l as normalizePath } from './fs.mjs';
2
+ import fs from 'node:fs';
3
+
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
+
113
+ function formatError(e) {
114
+ if (e instanceof Error) {
115
+ const err = e;
116
+ let loc = err.loc;
117
+ if (!err.frame && !err.plugin) {
118
+ if (!loc) {
119
+ loc = findLocation(err);
120
+ }
121
+ if (loc) {
122
+ err.loc = loc;
123
+ if (loc.file) {
124
+ err.id = normalizePath(err.loc.file);
125
+ try {
126
+ const code = fs.readFileSync(err.loc.file, "utf-8");
127
+ err.frame = generateCodeFrame(code, err.loc);
128
+ } catch {
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
134
+ return e;
135
+ }
136
+
137
+ export { formatError as f, parseId as p };