@qwik.dev/router 2.0.0-beta.36 → 2.0.0-beta.38

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 (41) hide show
  1. package/lib/adapters/cloudflare-pages/vite/index.mjs +3 -5
  2. package/lib/adapters/shared/vite/index.d.ts +3 -4
  3. package/lib/adapters/shared/vite/index.mjs +167 -155
  4. package/lib/chunks/dev-preloaded-route-loader.mjs +3 -0
  5. package/lib/chunks/format.mjs +31 -0
  6. package/lib/chunks/fs.mjs +10 -8
  7. package/lib/chunks/head.qwik.mjs +1425 -0
  8. package/lib/chunks/http-error.qwik.mjs +2 -2
  9. package/lib/chunks/pathname.mjs +3 -32
  10. package/lib/chunks/request-body-limit.mjs +37 -0
  11. package/lib/chunks/request-path.mjs +60 -0
  12. package/lib/chunks/routes.mjs +47 -0
  13. package/lib/chunks/server-error.mjs +19 -0
  14. package/lib/chunks/system.mjs +8 -8
  15. package/lib/chunks/use-functions.qwik.mjs +3 -12
  16. package/lib/chunks/user-response.mjs +1875 -0
  17. package/lib/chunks/worker-thread.mjs +317 -0
  18. package/lib/index.d.ts +251 -44
  19. package/lib/index.qwik.mjs +734 -485
  20. package/lib/middleware/aws-lambda/index.mjs +2 -1
  21. package/lib/middleware/azure-swa/index.mjs +13 -9
  22. package/lib/middleware/cloudflare-pages/index.mjs +2 -2
  23. package/lib/middleware/deno/index.d.ts +2 -0
  24. package/lib/middleware/deno/index.mjs +2 -1
  25. package/lib/middleware/netlify-edge/index.mjs +2 -2
  26. package/lib/middleware/node/index.d.ts +9 -1
  27. package/lib/middleware/node/index.mjs +28 -3
  28. package/lib/middleware/request-handler/index.d.ts +65 -26
  29. package/lib/middleware/request-handler/index.mjs +38 -1679
  30. package/lib/middleware/vercel-edge/index.mjs +2 -2
  31. package/lib/ssg/index.d.ts +5 -13
  32. package/lib/ssg/index.mjs +14 -53
  33. package/lib/vite/index.d.ts +23 -0
  34. package/lib/vite/index.mjs +533 -122
  35. package/package.json +4 -3
  36. package/lib/chunks/deepFreeze.qwik.mjs +0 -18
  37. package/lib/chunks/error-handler.mjs +0 -57
  38. package/lib/chunks/not-found-wrapper.qwik.mjs +0 -25
  39. package/lib/chunks/redirect-handler.mjs +0 -6
  40. package/lib/chunks/routing.qwik.mjs +0 -821
  41. package/lib/chunks/worker-thread.qwik.mjs +0 -2585
@@ -1,5 +1,5 @@
1
1
  import { setServerPlatform } from '@qwik.dev/core/server';
2
- import { isStaticPath, mergeHeadersCookies, requestHandler, getNotFound } from '@qwik.dev/router/middleware/request-handler';
2
+ import { isStaticPath, mergeHeadersCookies, requestHandler, getErrorHtml } from '@qwik.dev/router/middleware/request-handler';
3
3
  import { isDev } from '@qwik.dev/core/build';
4
4
 
5
5
  const COUNTRY_HEADER_NAME = "x-vercel-ip-country";
@@ -74,7 +74,7 @@ function createQwikRouter(opts) {
74
74
  return response;
75
75
  }
76
76
  }
77
- const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
77
+ const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getErrorHtml(404, "Not Found");
78
78
  return new Response(notFoundHtml, {
79
79
  status: 404,
80
80
  headers: {
@@ -26,14 +26,11 @@ export declare function runSsg(opts: SsgInternalOptions): Promise<never>;
26
26
  * @public
27
27
  */
28
28
  export declare interface SsgInternalOptions extends SsgOptions {
29
- /** The SSR render function (default export from entry.ssr). */
29
+ /** SSR render function (default export from `entry.ssr`); worker-only — the main entry omits it. */
30
30
  render: Render;
31
31
  /** The Qwik Router Config object (default export from `@qwik-router-config`). */
32
32
  qwikRouterConfig: QwikRouterConfig;
33
- /**
34
- * Path or URL to the worker entry file. Workers are spawned using this file. When run-ssg.js
35
- * serves as both main and worker entry, this should be `import.meta.url` of that file.
36
- */
33
+ /** Path or URL to the worker entry file (`run-ssg-worker.js`); workers are spawned from it. */
37
34
  workerFilePath?: string | URL;
38
35
  }
39
36
 
@@ -79,20 +76,15 @@ export declare interface SsgRenderOptions extends RenderOptions {
79
76
  log?: 'debug' | 'quiet';
80
77
  /**
81
78
  * Set to `false` if the generated static HTML files should not be written to disk. Setting to
82
- * `false` is useful if the SSG should only write the `q-data.json` files to disk. Defaults to
79
+ * `false` is useful if the SSG should only write the per-loader data files to disk. Defaults to
83
80
  * `true`.
84
81
  */
85
82
  emitHtml?: boolean;
86
83
  /**
87
- * Set to `false` if the generated `q-data.json` data files should not be written to disk.
88
- * Defaults to `true`.
84
+ * Set to `false` if the generated per-loader data files should not be written to disk. Defaults
85
+ * to `true`.
89
86
  */
90
87
  emitData?: boolean;
91
- /**
92
- * Set to `false` if the static build should not write custom or default `404.html` pages.
93
- * Defaults to `true`.
94
- */
95
- emit404Pages?: boolean;
96
88
  /**
97
89
  * Defines file system routes relative to the source `routes` directory that should be static
98
90
  * generated. Accepts wildcard behavior. This should not include the "base" pathname. If not
package/lib/ssg/index.mjs CHANGED
@@ -1,57 +1,10 @@
1
1
  import { bold, green, dim, red, magenta } from 'kleur/colors';
2
2
  import { relative } from 'node:path';
3
- import { m as msToString, g as getPathnameForDynamicRoute } from '../chunks/pathname.mjs';
4
-
5
- function routeToRegExp(rule) {
6
- let transformedRule;
7
- if (rule === "/" || rule === "/*") {
8
- transformedRule = rule;
9
- } else if (rule.endsWith("/*")) {
10
- transformedRule = `${rule.substring(0, rule.length - 2)}(/*)?`;
11
- } else if (rule.endsWith("/")) {
12
- transformedRule = `${rule.substring(0, rule.length - 1)}(/)?`;
13
- } else if (rule.endsWith("*")) {
14
- transformedRule = rule;
15
- } else {
16
- transformedRule = `${rule}(/)?`;
17
- }
18
- transformedRule = `^${transformedRule.replace(/\*/g, ".*")}$`;
19
- return new RegExp(transformedRule);
20
- }
21
- function routesToRegExps(routes) {
22
- if (!Array.isArray(routes)) {
23
- return [];
24
- }
25
- return routes.filter((r) => typeof r === "string").map(routeToRegExp);
26
- }
27
- function createRouteTester(basePathname, includeRoutes, excludeRoutes) {
28
- const includes = routesToRegExps(includeRoutes);
29
- const excludes = routesToRegExps(excludeRoutes);
30
- return (pathname) => {
31
- if (pathname.endsWith("404.html")) {
32
- return true;
33
- }
34
- if (basePathname !== "/") {
35
- pathname = pathname.slice(basePathname.length - 1);
36
- }
37
- for (const exclude of excludes) {
38
- if (exclude.test(pathname)) {
39
- return false;
40
- }
41
- }
42
- for (const include of includes) {
43
- if (include.test(pathname)) {
44
- return true;
45
- }
46
- }
47
- return false;
48
- };
49
- }
3
+ import { m as msToString } from '../chunks/format.mjs';
4
+ import { e as ensureSlash, g as getPathnameForDynamicRoute } from '../chunks/pathname.mjs';
5
+ import { c as createRouteTester } from '../chunks/routes.mjs';
50
6
 
51
7
  function validateOptions(opts) {
52
- if (!opts.render) {
53
- throw new Error(`Missing "render" option`);
54
- }
55
8
  if (!opts.qwikRouterConfig) {
56
9
  throw new Error(`Missing "qwikRouterConfig" option`);
57
10
  }
@@ -190,7 +143,7 @@ ${bold(red(`!!! ${result.pathname}: Error during SSG`))}`);
190
143
  const segments = pathname.split("/");
191
144
  const lastSegment = segments[segments.length - 1];
192
145
  if (!lastSegment.includes(".")) {
193
- pathname += "/";
146
+ pathname = ensureSlash(pathname);
194
147
  }
195
148
  }
196
149
  } else {
@@ -220,7 +173,7 @@ ${bold(red(`!!! ${result.pathname}: Error during SSG`))}`);
220
173
  index
221
174
  ];
222
175
  const joinedParts = pathParts.join("/");
223
- const originalPathname = basePathname + (joinedParts ? joinedParts + "/" : "");
176
+ const originalPathname = basePathname + (joinedParts ? ensureSlash(joinedParts) : "");
224
177
  const paramNames = pathParts.filter((p) => p.startsWith("[") && p.endsWith("]")).map((p) => p.startsWith("[...") ? p.slice(4, -1) : p.slice(1, -1));
225
178
  if (paramNames.length === 0) {
226
179
  addToQueue(originalPathname, void 0);
@@ -246,6 +199,14 @@ ${bold(red(`!!! ${result.pathname}: Error during SSG`))}`);
246
199
  }
247
200
  }
248
201
  }
202
+ if (node._4 || node._E) {
203
+ const isStaticDir = !pathParts.some((p) => p.startsWith("["));
204
+ if (isStaticDir) {
205
+ const joinedParts = pathParts.join("/");
206
+ const dirPathname = basePathname + (joinedParts ? ensureSlash(joinedParts) : "");
207
+ addToQueue(dirPathname + "404.html", void 0);
208
+ }
209
+ }
249
210
  if (node._M) {
250
211
  for (const group of node._M) {
251
212
  await traverseRouteTree(group, pathParts, basePathname, currentLoaders);
@@ -328,7 +289,7 @@ async function startWorker(opts) {
328
289
  qwikRouterConfig: opts.qwikRouterConfig
329
290
  };
330
291
  const { createSystem } = await import('../chunks/system.mjs');
331
- const { workerThread } = await import('../chunks/worker-thread.qwik.mjs');
292
+ const { workerThread } = await import('../chunks/worker-thread.mjs');
332
293
  const sys = await createSystem(mergedOpts, workerData?.threadId);
333
294
  await workerThread(sys);
334
295
  }
@@ -111,6 +111,21 @@ declare interface PluginOptions {
111
111
  rewriteRoutes?: RewriteRouteOption[];
112
112
  /** The serialization strategy for route loaders. Defaults to `never`. */
113
113
  defaultLoadersSerializationStrategy?: SerializationStrategy;
114
+ /**
115
+ * Enable strict mode for route loaders and actions by default.
116
+ *
117
+ * When true:
118
+ *
119
+ * - Loaders without an explicit `search` option act as if `search: []` — they only re-fetch when
120
+ * the route path changes and ignore all URL search params.
121
+ * - Actions without an explicit `invalidate` option act as if `invalidate: []` — they don't re-run
122
+ * any loaders after completion.
123
+ *
124
+ * Individual loaders/actions can override this by specifying `search` or `invalidate` explicitly.
125
+ *
126
+ * Defaults to `true`.
127
+ */
128
+ strictLoaders?: boolean;
114
129
  }
115
130
 
116
131
  /**
@@ -144,6 +159,13 @@ declare interface QwikRouterPluginApi {
144
159
  getBasePathname: () => string;
145
160
  getRoutes: () => BuiltRoute[];
146
161
  getServiceWorkers: () => BuiltEntry[];
162
+ /**
163
+ * Hand the adapter's SSG include/exclude patterns to the router so the production server route
164
+ * plan can drop fully-prerendered, server-free routes. Called by the SSG adapter.
165
+ *
166
+ * @internal
167
+ */
168
+ _setSsgRoutes?: (include: string[] | undefined, exclude: string[] | undefined) => void;
147
169
  }
148
170
 
149
171
  /** @public */
@@ -177,6 +199,7 @@ export declare interface QwikRouterVitePluginOptions extends Omit<PluginOptions,
177
199
  declare interface RewriteRouteOption {
178
200
  prefix?: string;
179
201
  paths: Record<string, string>;
202
+ exclude?: string[];
180
203
  }
181
204
 
182
205
  export { }