@torpor/build 1.9.0 → 1.11.0

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 (107) hide show
  1. package/README.md +1 -1
  2. package/dist/{SessionHelper-MaodMaLU.d.mts → CacheOptions-C4-ebVt9.d.mts} +58 -8
  3. package/dist/CacheOptions-C4-ebVt9.d.mts.map +1 -0
  4. package/dist/{MiddlewareFunction-BZilnEei.d.mts → MiddlewareFunction-DMYxjzF4.d.mts} +31 -2
  5. package/dist/MiddlewareFunction-DMYxjzF4.d.mts.map +1 -0
  6. package/dist/{Router-By9Nlg39.d.mts → Router-DyK3DTWQ.d.mts} +4 -4
  7. package/dist/Router-DyK3DTWQ.d.mts.map +1 -0
  8. package/dist/{Server-dcRbdPXf.mjs → Server-BCijhgZp.mjs} +3 -3
  9. package/dist/{Server-dcRbdPXf.mjs.map → Server-BCijhgZp.mjs.map} +1 -1
  10. package/dist/{Server-qn5Ws_d0.d.mts → Server-ClwvuilS.d.mts} +2 -2
  11. package/dist/{Server-qn5Ws_d0.d.mts.map → Server-ClwvuilS.d.mts.map} +1 -1
  12. package/dist/{ServerEvent-BY4f3RVF.mjs → ServerEvent-BBRkd4Ya.mjs} +136 -31
  13. package/dist/ServerEvent-BBRkd4Ya.mjs.map +1 -0
  14. package/dist/{ServerHook-W111nEhe.d.mts → ServerHook-DY-NSG6n.d.mts} +2 -2
  15. package/dist/{ServerHook-W111nEhe.d.mts.map → ServerHook-DY-NSG6n.d.mts.map} +1 -1
  16. package/dist/{ServerLoadEvent-BH6oG1o6.d.mts → ServerLoadEvent-CpcgsKCU.d.mts} +32 -8
  17. package/dist/ServerLoadEvent-CpcgsKCU.d.mts.map +1 -0
  18. package/dist/{Site-DGZJB7Do.d.mts → Site-BEMQW1_y.d.mts} +216 -11
  19. package/dist/Site-BEMQW1_y.d.mts.map +1 -0
  20. package/dist/{basePath-DQnbHc7o.mjs → basePath-B6hmOMl4.mjs} +89 -4
  21. package/dist/basePath-B6hmOMl4.mjs.map +1 -0
  22. package/dist/bin/index.js +37 -2
  23. package/dist/bin/index.js.map +1 -1
  24. package/dist/clientEntry.mjs +10 -5
  25. package/dist/clientEntry.mjs.map +1 -1
  26. package/dist/dev.d.mts +2 -2
  27. package/dist/dev.mjs +2 -2
  28. package/dist/{devPlugin-lLzauETn.mjs → devPlugin-BGrTpcC2.mjs} +3 -3
  29. package/dist/{devPlugin-lLzauETn.mjs.map → devPlugin-BGrTpcC2.mjs.map} +1 -1
  30. package/dist/discovery.d.mts +1 -1
  31. package/dist/discovery.mjs +1 -1
  32. package/dist/index.d.mts +22 -6
  33. package/dist/index.d.mts.map +1 -1
  34. package/dist/index.mjs +10 -0
  35. package/dist/index.mjs.map +1 -1
  36. package/dist/{load-BODDzmH0.mjs → load-Dw187nJ_.mjs} +95 -52
  37. package/dist/load-Dw187nJ_.mjs.map +1 -0
  38. package/dist/nav.d.mts +30 -3
  39. package/dist/nav.d.mts.map +1 -1
  40. package/dist/nav.mjs +40 -12
  41. package/dist/nav.mjs.map +1 -1
  42. package/dist/nodeDev.d.mts +1 -1
  43. package/dist/nodeDev.mjs +1 -1
  44. package/dist/openapi.d.mts +24 -80
  45. package/dist/openapi.d.mts.map +1 -1
  46. package/dist/openapi.mjs +36 -1
  47. package/dist/openapi.mjs.map +1 -0
  48. package/dist/{plugin-D8Www11B.mjs → plugin-BQsMnkTj.mjs} +42 -3
  49. package/dist/plugin-BQsMnkTj.mjs.map +1 -0
  50. package/dist/{read-DxMVAh5Y.mjs → read-CPW2iPum.mjs} +21 -2
  51. package/dist/read-CPW2iPum.mjs.map +1 -0
  52. package/dist/{response-C5EZsszY.mjs → response-B4UoOJvv.mjs} +3 -24
  53. package/dist/response-B4UoOJvv.mjs.map +1 -0
  54. package/dist/response.mjs +2 -2
  55. package/dist/run.d.mts +1 -1
  56. package/dist/run.d.mts.map +1 -1
  57. package/dist/run.mjs +1 -1
  58. package/dist/{runHooks-D5p1Rh7i.mjs → runHooks-C7kt7SEo.mjs} +36 -2
  59. package/dist/runHooks-C7kt7SEo.mjs.map +1 -0
  60. package/dist/{runOpenApi-C5yMpQU1.mjs → runOpenApi-DK-QnYEr.mjs} +279 -35
  61. package/dist/runOpenApi-DK-QnYEr.mjs.map +1 -0
  62. package/dist/server/Server.d.mts +1 -1
  63. package/dist/server/Server.mjs +1 -1
  64. package/dist/server.d.mts +30 -6
  65. package/dist/server.d.mts.map +1 -1
  66. package/dist/server.mjs +47 -3
  67. package/dist/server.mjs.map +1 -1
  68. package/dist/{serverEntry-BGii8bB6.d.mts → serverEntry-BFad1k1C.d.mts} +3 -3
  69. package/dist/serverEntry-BFad1k1C.d.mts.map +1 -0
  70. package/dist/{serverEntry-D1hE-Jzt.mjs → serverEntry-DAT7o7o2.mjs} +3 -5
  71. package/dist/serverEntry-DAT7o7o2.mjs.map +1 -0
  72. package/dist/serverEntry.d.mts +1 -1
  73. package/dist/serverEntry.mjs +1 -1
  74. package/dist/{serverHandlers-CSBUEgJt.mjs → serverHandlers-B1L8I72-.mjs} +434 -202
  75. package/dist/serverHandlers-B1L8I72-.mjs.map +1 -0
  76. package/dist/{sitemap-xmE0zfme.d.mts → sitemap-CKmagPyL.d.mts} +2 -2
  77. package/dist/{sitemap-xmE0zfme.d.mts.map → sitemap-CKmagPyL.d.mts.map} +1 -1
  78. package/dist/{sitemap-4imxJVrG.mjs → sitemap-DdzFjGlo.mjs} +2 -2
  79. package/dist/{sitemap-4imxJVrG.mjs.map → sitemap-DdzFjGlo.mjs.map} +1 -1
  80. package/dist/state.d.mts +1 -4
  81. package/dist/state.d.mts.map +1 -1
  82. package/dist/state.mjs +1 -1
  83. package/dist/test.d.mts +2 -2
  84. package/dist/test.mjs +2 -2
  85. package/dist/{unprocessable-DwAG44Rh.mjs → unprocessable-BZXwyN0n.mjs} +23 -2
  86. package/dist/unprocessable-BZXwyN0n.mjs.map +1 -0
  87. package/package.json +10 -7
  88. package/src/types/manifest.d.ts +3 -0
  89. package/dist/MiddlewareFunction-BZilnEei.d.mts.map +0 -1
  90. package/dist/Router-By9Nlg39.d.mts.map +0 -1
  91. package/dist/ServerEvent-BY4f3RVF.mjs.map +0 -1
  92. package/dist/ServerLoadEvent-BH6oG1o6.d.mts.map +0 -1
  93. package/dist/SessionHelper-MaodMaLU.d.mts.map +0 -1
  94. package/dist/Site-DGZJB7Do.d.mts.map +0 -1
  95. package/dist/_page-CW6SLuT4.mjs +0 -14
  96. package/dist/_page-CW6SLuT4.mjs.map +0 -1
  97. package/dist/basePath-DQnbHc7o.mjs.map +0 -1
  98. package/dist/load-BODDzmH0.mjs.map +0 -1
  99. package/dist/plugin-D8Www11B.mjs.map +0 -1
  100. package/dist/read-DxMVAh5Y.mjs.map +0 -1
  101. package/dist/response-C5EZsszY.mjs.map +0 -1
  102. package/dist/runHooks-D5p1Rh7i.mjs.map +0 -1
  103. package/dist/runOpenApi-C5yMpQU1.mjs.map +0 -1
  104. package/dist/serverEntry-BGii8bB6.d.mts.map +0 -1
  105. package/dist/serverEntry-D1hE-Jzt.mjs.map +0 -1
  106. package/dist/serverHandlers-CSBUEgJt.mjs.map +0 -1
  107. package/dist/unprocessable-DwAG44Rh.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { i as CookieHelper, n as HeaderHelper, r as FlashHelper, t as SessionHelper } from "./SessionHelper-MaodMaLU.mjs";
1
+ import { a as CookieHelper, i as FlashHelper, n as SessionHelper, r as HeaderHelper, t as CacheOptions } from "./CacheOptions-C4-ebVt9.mjs";
2
2
  import { a as RouteParamsOf } from "./ParseRouteParams-BtC0eH3z.mjs";
3
3
  //#region src/types/ServerLoadEvent.d.ts
4
4
  /**
@@ -30,8 +30,9 @@ interface ServerLoadEvent<Route extends string | undefined = undefined, Body = u
30
30
  */
31
31
  params: Params;
32
32
  /**
33
- * Data that is available to functions in +server hooks, layouts, endpoints
34
- * and pages. It flows down in that order.
33
+ * Data that is available to functions in +server hooks, route middleware
34
+ * (as `ev.appData`), layouts, endpoints and pages. It flows down in that
35
+ * order.
35
36
  */
36
37
  appData: Record<string, any>;
37
38
  /**
@@ -43,11 +44,21 @@ interface ServerLoadEvent<Route extends string | undefined = undefined, Body = u
43
44
  */
44
45
  json: () => Promise<Body>;
45
46
  /**
46
- * Reads the request body as form data, returning a record of field values.
47
- * When the endpoint declares a schema for the form, the values are
48
- * validated and typed by the schema's output.
47
+ * Reads the request body as form data, returning a record of the field
48
+ * values: one value per field, or an array when a field was submitted with
49
+ * multiple values (e.g. a multi select). This is a plain object, not the
50
+ * web standard `FormData` -- for that, use `formData()`. When the endpoint
51
+ * declares a schema for the form, the values are validated and typed by
52
+ * the schema's output.
49
53
  */
50
54
  form: () => Promise<FormBody>;
55
+ /**
56
+ * Reads the request body as the web standard `FormData` object, for
57
+ * `get(name)` / `getAll(name)` access to individual fields. For a plain
58
+ * record of the values -- validated and typed when the endpoint declares a
59
+ * schema for the form -- use `form()`.
60
+ */
61
+ formData: () => Promise<FormData>;
51
62
  /**
52
63
  * Reads the URL's query string, returning a record of param values. When
53
64
  * the endpoint declares a schema for the query (get/head handlers and the
@@ -66,13 +77,26 @@ interface ServerLoadEvent<Route extends string | undefined = undefined, Body = u
66
77
  session: SessionHelper;
67
78
  /**
68
79
  * A helper for setting one-time flash messages, shown on the next page
69
- * render as `$page.flash = { type, message }`.
80
+ * render as `$context.$page.flash = { type, message }`.
70
81
  */
71
82
  flash: FlashHelper;
72
83
  /**
73
84
  * A helper for getting and setting headers.
74
85
  */
75
86
  headers: HeaderHelper;
87
+ /**
88
+ * Sets how the response may be cached (`Cache-Control` and `Vary`), e.g.
89
+ * `event.cache({ maxAge: 60 })`. Calls from a request's layouts and page
90
+ * are merged, with the most restrictive setting winning. See
91
+ * [Caching](/build/caching).
92
+ */
93
+ cache: (options: CacheOptions) => void;
94
+ /**
95
+ * Keeps background work running after the response is sent (on
96
+ * Cloudflare, through the worker's `ctx.waitUntil`). A rejection is
97
+ * logged rather than left unhandled.
98
+ */
99
+ waitUntil: (promise: Promise<unknown>) => void;
76
100
  /**
77
101
  * An optional adapter object, containing adapter-specific functionality.
78
102
  */
@@ -80,4 +104,4 @@ interface ServerLoadEvent<Route extends string | undefined = undefined, Body = u
80
104
  }
81
105
  //#endregion
82
106
  export { QueryRecord as n, ServerLoadEvent as r, FormDataRecord as t };
83
- //# sourceMappingURL=ServerLoadEvent-BH6oG1o6.d.mts.map
107
+ //# sourceMappingURL=ServerLoadEvent-CpcgsKCU.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerLoadEvent-CpcgsKCU.d.mts","names":[],"sources":["../src/types/ServerLoadEvent.ts"],"mappings":";;;;;;;KAWY,iBAAiB,eAAe,qBAAqB;;;;;KAMrD,cAAc;;;;;;;;UASD,gBACxB,8CACA,gBACA,WAAW,gBACX,YAAY,aACZ,SAAS,cAAc;;;;EAKvB,KAAK;;;;;;EAML,QAAQ;;;;;;EAQR,SAAS;;;;EAIT,SAAS;;;;EAKT,YAAY,QAAQ;;;;;;;;;EASpB,YAAY,QAAQ;;;;;;;EAOpB,gBAAgB,QAAQ;;;;;;;EAOxB,aAAa,QAAQ;;;;EAIrB,SAAS;;;;;EAKT,SAAS;;;;;EAKT,OAAO;;;;EAIP,SAAS;;;;;;;EAOT,QAAQ,SAAS;;;;;;EAMjB,YAAY,SAAS;;;;EAIrB,SAAS,OAAO"}
@@ -1,9 +1,9 @@
1
- import { t as MiddlewareFunction } from "./MiddlewareFunction-BZilnEei.mjs";
2
- import { t as Server } from "./Server-qn5Ws_d0.mjs";
1
+ import { t as MiddlewareFunction } from "./MiddlewareFunction-DMYxjzF4.mjs";
2
+ import { t as Server } from "./Server-ClwvuilS.mjs";
3
3
  import { a as RouteParamsOf } from "./ParseRouteParams-BtC0eH3z.mjs";
4
- import { n as QueryRecord, r as ServerLoadEvent, t as FormDataRecord } from "./ServerLoadEvent-BH6oG1o6.mjs";
5
- import { t as ServerHook } from "./ServerHook-W111nEhe.mjs";
6
- import { a as PageLoadReturn, i as PageEndPoint, t as SitemapOptions } from "./sitemap-xmE0zfme.mjs";
4
+ import { n as QueryRecord, r as ServerLoadEvent, t as FormDataRecord } from "./ServerLoadEvent-CpcgsKCU.mjs";
5
+ import { t as ServerHook } from "./ServerHook-DY-NSG6n.mjs";
6
+ import { a as PageLoadReturn, i as PageEndPoint, t as SitemapOptions } from "./sitemap-CKmagPyL.mjs";
7
7
  import { t as StandardSchemaV1 } from "./StandardSchema-D28L8_zZ.mjs";
8
8
  import { Plugin, UserConfig } from "vite";
9
9
  //#region src/types/Adapter.d.ts
@@ -146,13 +146,176 @@ interface PageServerEndPoint<Route extends string | undefined = undefined, Data
146
146
  };
147
147
  /**
148
148
  * Route middleware, run for this route's loads and actions after the
149
- * global middleware (see `site.middleware`) and before folder hooks.
149
+ * global middleware (see `site.middleware`) and the folder hooks, so it
150
+ * can read what the hooks loaded from `ev.appData` (e.g. the user).
150
151
  * `enter` may return a Response to short-circuit; `exit` hooks run in
151
152
  * reverse. Middleware see the raw request url.
152
153
  */
153
154
  middleware?: MiddlewareFunction[];
154
155
  }
155
156
  //#endregion
157
+ //#region src/openapi/types.d.ts
158
+ /**
159
+ * A JSON Schema object, as produced by a schema library's converter (e.g.
160
+ * `z.toJSONSchema`, valibot's `toJsonSchema`, arktype's `toJsonSchema`).
161
+ */
162
+ type JsonSchema = Record<string, unknown>;
163
+ /**
164
+ * Converts a Standard Schema (zod, valibot, arktype, ...) into a JSON Schema
165
+ * object, for inclusion in an OpenAPI document. Supplied to the openApi
166
+ * plugin, since each schema library has its own conversion function:
167
+ *
168
+ * ```ts
169
+ * // zod
170
+ * openApi({ toJsonSchema: (s) => z.toJSONSchema(s as z.ZodType, { io: "input" }) })
171
+ * // arktype
172
+ * openApi({ toJsonSchema: (s) => (s as Type).toJsonSchema() })
173
+ * ```
174
+ */
175
+ type ToJsonSchema = (schema: StandardSchemaV1) => JsonSchema;
176
+ /**
177
+ * Extends the generated document per request, for documents whose content
178
+ * comes from data rather than the route tree alone: one document per
179
+ * tenant/workspace served from a dynamic route segment, extra paths built from
180
+ * a database, and so on. Gets a fresh copy of the base document (mutating it
181
+ * is safe) and the request's event, which carries `url`, `params`,
182
+ * `cookies`, `session`, `appData` and the rest.
183
+ */
184
+ type OpenApiExtend = (doc: Record<string, unknown>, event: ServerLoadEvent) => Record<string, unknown> | Promise<Record<string, unknown>>;
185
+ /**
186
+ * Options for the openApi plugin.
187
+ */
188
+ type OpenApiPluginOptions = {
189
+ /**
190
+ * The path to serve the OpenAPI document at. Defaults to `/openapi.json`.
191
+ */
192
+ path?: string;
193
+ /**
194
+ * The path to serve interactive API docs at, or `false` to disable the
195
+ * docs page. Defaults to `/docs`.
196
+ */
197
+ docs?: string | false;
198
+ /**
199
+ * The API title for the document's `info` section. Defaults to `"API"`.
200
+ */
201
+ title?: string;
202
+ /**
203
+ * The API version for the document's `info` section. Defaults to
204
+ * `"1.0.0"`.
205
+ */
206
+ version?: string;
207
+ /**
208
+ * Converts an endpoint's schemas into JSON Schema. Required for endpoints
209
+ * that declare schemas; endpoints without schemas are documented with
210
+ * their paths and methods only.
211
+ */
212
+ toJsonSchema?: ToJsonSchema;
213
+ /**
214
+ * Extends the generated document per request, e.g. for one document per
215
+ * workspace served from a dynamic route segment, or for paths built from
216
+ * data the route tree doesn't describe. The hook is given a fresh copy of
217
+ * the base document and the request's event (`params` included).
218
+ *
219
+ * `tb --openapi` writes the base document: the hook needs a request, so it
220
+ * isn't applied to the file.
221
+ */
222
+ extend?: OpenApiExtend;
223
+ /**
224
+ * Document-level components, referenced from operations with `$ref`:
225
+ * `schemas`, `responses`, `parameters`, `headers`, `securitySchemes` and
226
+ * so on. Use it for definitions shared between operations, e.g. one
227
+ * `Error` schema that every endpoint's 4xx responses reference:
228
+ *
229
+ * ```ts
230
+ * openApi({
231
+ * components: {
232
+ * schemas: { Error: { type: "object", properties: { message: { type: "string" } } } },
233
+ * },
234
+ * })
235
+ * ```
236
+ */
237
+ components?: Record<string, unknown>;
238
+ };
239
+ /**
240
+ * OpenApi options with defaults applied. Created by the openApi plugin and
241
+ * consumed by the document builder.
242
+ */
243
+ type ResolvedOpenApiOptions = {
244
+ path: string;
245
+ /** Undefined when the docs page is disabled */
246
+ docs: string | undefined;
247
+ title: string;
248
+ version: string;
249
+ toJsonSchema: ToJsonSchema | undefined;
250
+ extend: OpenApiExtend | undefined;
251
+ components: Record<string, unknown> | undefined;
252
+ };
253
+ /**
254
+ * A ServerEndPoint shape, loosely typed so that endpoint modules loaded from
255
+ * anywhere can be passed to the document builder.
256
+ */
257
+ type OpenApiEndPoint = {
258
+ schema?: Record<string, StandardSchemaV1 | undefined> | undefined;
259
+ /**
260
+ * Raw OpenAPI overrides for this endpoint's operations, keyed by handler
261
+ * name, merged over what the document builder derives from the schemas.
262
+ */
263
+ openapi?: OpenApiEndpointOverrides | undefined;
264
+ [method: string]: unknown;
265
+ };
266
+ /**
267
+ * A single API endpoint to include in an OpenAPI document: its route path
268
+ * (with `[param]` segments) and its default-exported endpoint object.
269
+ */
270
+ type OpenApiRouteEntry = {
271
+ path: string;
272
+ endPoint: OpenApiEndPoint;
273
+ };
274
+ /**
275
+ * Loads one route's default-exported endpoint module, used by the generated
276
+ * document route to import each `+server` endpoint lazily.
277
+ */
278
+ type OpenApiLoader = () => Promise<{
279
+ default: OpenApiEndPoint;
280
+ }>;
281
+ /**
282
+ * The handler names of a `+server` endpoint, as keys in its raw OpenAPI
283
+ * overrides (`del` is the DELETE handler).
284
+ */
285
+ type OpenApiMethod = "get" | "post" | "patch" | "put" | "del" | "options" | "head";
286
+ /**
287
+ * A raw OpenAPI operation, merged over the generated one. Use it for what the
288
+ * endpoint's schemas can't express:
289
+ *
290
+ * - a JSON Schema `requestBody` directly, with no Standard Schema wrapper
291
+ * - response statuses and headers (`responses` replaces the generated stubs)
292
+ * - extra `parameters` (headers like `If-Match` sit alongside the generated
293
+ * path/query parameters)
294
+ * - `summary`, `description`, `operationId` and `tags`, for tools that name
295
+ * and group operations
296
+ *
297
+ * Any other OpenAPI operation field (`security`, `deprecated`, ...) passes
298
+ * through.
299
+ */
300
+ type OpenApiOperation = {
301
+ summary?: string;
302
+ description?: string;
303
+ operationId?: string;
304
+ tags?: string[];
305
+ parameters?: Record<string, unknown>[];
306
+ requestBody?: Record<string, unknown>;
307
+ responses?: Record<string, unknown>;
308
+ [key: string]: unknown;
309
+ };
310
+ /** The raw OpenAPI overrides for one endpoint, keyed by handler name. */
311
+ type OpenApiEndpointOverrides = Partial<Record<OpenApiMethod, OpenApiOperation>> & {
312
+ /**
313
+ * Tags applied to every operation in this endpoint, for tools that group
314
+ * operations by tag. A handler's own `tags` override them.
315
+ */
316
+ tags?: string[];
317
+ };
318
+ //#endregion
156
319
  //#region src/types/ServerRequest.d.ts
157
320
  type ServerRequest<Route extends string | undefined = undefined, Body = unknown, FormBody = FormDataRecord, QueryBody = QueryRecord, Params = RouteParamsOf<Route>> = (event: ServerLoadEvent<Route, Body, FormBody, QueryBody, Params>) => Response | undefined | void | Promise<Response | undefined | void>;
158
321
  //#endregion
@@ -228,6 +391,29 @@ type ServerEndPoint<Route extends string | undefined = undefined, Schemas extend
228
391
  * ```
229
392
  */
230
393
  schema?: Schemas | undefined;
394
+ /**
395
+ * Raw OpenAPI overrides for this endpoint's operations, keyed by handler
396
+ * name (`del` for DELETE), merged over what the `openApi()` plugin derives
397
+ * from the schemas. Use it for a JSON Schema request body (no Standard
398
+ * Schema wrapper needed), response statuses and headers, extra parameters,
399
+ * or an operation's summary/operationId/tags, e.g.
400
+ *
401
+ * ```ts
402
+ * export default {
403
+ * openapi: {
404
+ * post: {
405
+ * requestBody: { content: { "application/json": { schema: postJsonSchema } } },
406
+ * responses: {
407
+ * "201": { description: "Created", headers: { Location: { schema: { type: "string" } } } },
408
+ * "409": { description: "Conflict" },
409
+ * },
410
+ * },
411
+ * },
412
+ * post: async (event) => created(await createPost(await event.json())),
413
+ * } satisfies ServerEndPoint;
414
+ * ```
415
+ */
416
+ openapi?: OpenApiEndpointOverrides | undefined;
231
417
  /**
232
418
  * Performs a GET. Its schema validates the query string.
233
419
  */
@@ -258,9 +444,10 @@ type ServerEndPoint<Route extends string | undefined = undefined, Schemas extend
258
444
  head?: ServerRequest<Route, unknown, FormDataRecord, SchemaQuery<Schemas, "head">, ParamsOf<Schemas, Route>>;
259
445
  /**
260
446
  * Route middleware, run for this endpoint's handlers after the global
261
- * middleware (see `site.middleware`). `enter` may return a Response to
262
- * short-circuit; `exit` hooks run in reverse. Middleware see the raw
263
- * request url.
447
+ * middleware (see `site.middleware`) and the folder hooks, so it can
448
+ * read what the hooks loaded from `ev.appData` (e.g. the user). `enter`
449
+ * may return a Response to short-circuit; `exit` hooks run in reverse.
450
+ * Middleware see the raw request url.
264
451
  */
265
452
  middleware?: MiddlewareFunction[];
266
453
  };
@@ -301,6 +488,15 @@ interface Route {
301
488
  subFolder?: string;
302
489
  }
303
490
  //#endregion
491
+ //#region src/types/Budgets.d.ts
492
+ /** Limits on what each page may ship (see `Site.budgets`). */
493
+ interface Budgets {
494
+ /** The most gzipped JavaScript (in bytes) a page may load before it hydrates. */
495
+ js?: number;
496
+ /** Fail the build when a page goes over, rather than warning. */
497
+ fail?: boolean;
498
+ }
499
+ //#endregion
304
500
  //#region src/site/Site.d.ts
305
501
  /**
306
502
  * The Site class contains the information necessary to setup a @torpor/build
@@ -436,6 +632,15 @@ declare class Site {
436
632
  * the XML live at that path (customizable with `path`).
437
633
  */
438
634
  sitemap?: SitemapOptions | boolean | string;
635
+ /**
636
+ * Limits on what each page may ship, checked by `tb --build`, which
637
+ * also reports how much JavaScript the heaviest pages load before they
638
+ * hydrate. `js` is the most gzipped JavaScript (in bytes) a page may load
639
+ * that way, e.g. `{ js: 250_000 }`; a page over it is a warning, or a
640
+ * build failure with `fail: true`. Chunks loaded later through dynamic
641
+ * imports don't count.
642
+ */
643
+ budgets?: Budgets;
439
644
  /**
440
645
  * A Standard Schema (zod, valibot, arktype, etc) used to validate (and
441
646
  * parse) the server environment. When set, `env()` from
@@ -538,5 +743,5 @@ declare class Site {
538
743
  }, subFolder?: string): void;
539
744
  }
540
745
  //#endregion
541
- export { ServerEndPoint as a, ActionBody as c, PageServerActionSchemas as d, PageServerEndPoint as f, Adapter as g, SitePlugin as h, SchemaQuery as i, LoadParams as l, PageServerAction as m, ParamsOf as n, ServerEndPointSchemas as o, PageServerLoad as p, SchemaBody as r, ServerRequest as s, Site as t, LoadQuery as u };
542
- //# sourceMappingURL=Site-DGZJB7Do.d.mts.map
746
+ export { PageServerActionSchemas as C, SitePlugin as D, PageServerAction as E, Adapter as O, LoadQuery as S, PageServerLoad as T, OpenApiRouteEntry as _, SchemaQuery as a, ActionBody as b, ServerRequest as c, OpenApiEndpointOverrides as d, OpenApiExtend as f, OpenApiPluginOptions as g, OpenApiOperation as h, SchemaBody as i, JsonSchema as l, OpenApiMethod as m, Budgets as n, ServerEndPoint as o, OpenApiLoader as p, ParamsOf as r, ServerEndPointSchemas as s, Site as t, OpenApiEndPoint as u, ResolvedOpenApiOptions as v, PageServerEndPoint as w, LoadParams as x, ToJsonSchema as y };
747
+ //# sourceMappingURL=Site-BEMQW1_y.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Site-BEMQW1_y.d.mts","names":[],"sources":["../src/types/Adapter.ts","../src/types/SitePlugin.ts","../src/types/PageServerAction.ts","../src/types/PageServerLoad.ts","../src/types/PageServerEndPoint.ts","../src/openapi/types.ts","../src/types/ServerRequest.ts","../src/types/ServerEndPoint.ts","../src/types/RouteType.ts","../src/types/Route.ts","../src/types/Budgets.ts","../src/site/Site.ts"],"mappings":";;;;;;;;;UAIyB;EACxB,YAAY,MAAM,SAAS;EAC3B,aAAa,MAAM,SAAS;;;;;;;EAO5B,OAAO,MAAM,SAAS,SAAS;;;;;EAK/B,QAAQ,QAAQ,QAAQ,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;KCG1C,cAAc,MAAM,gBAAgB;;;KCjBpC,iBACJ,8CACA,WAAW,gBACX,SAAS,cAAc,WAEvB,O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kBACZ,SAAS,SAAS;;;;;;;;EASnB,aAAa;;;;cCtMD;cACA;cACA;cACA;cACA;cACA;cACA;cACA;KAED,mBACF,oBACA,2BACA,sBACA,sBACA,6BACA,oBACA,2BACA;;;;;;KCRE,iBAAiB,qBAAqB,iBAAiB,aAAa;;;;UAKvD;EACxB;;;;;EAKA;;;;;;EAMA,WAAW;EACX,MAAM;EACN;;;;;UC3BwB;;EAExB;;EAEA;;;;;;;;cC+BoB;;EACpB;;;;;;;;;;EAUA;EACA,QAAQ;;;;;;EAMR;IAAgB;IAAgB;;;;;;;;EAOhC,SAAS;;;;EAIT,aAAa;;;;;;;;;;EAUb,SAAS;;;;;;EAMT;;;;;;;EAOA,aAAa;;;;;EAKb;;;;;;;;;;;;;;;;EAgBA,aAAa,IAAI;;;;;;;EAOjB;;;;;;;EAOA;;;;;;;;;EASA,sBAAsB;;;;;;EAMtB;;;;;;;;;;;;EAYA,YAAY;;;;;;;;;;;EAWZ,UAAU;;;;;;;;;EASV,UAAU;;;;;;;;;EASV,MAAM,0BAA0B;;;;;EAKhC,iBAAiB,eAAe;EAEhC;;MAKI;;;;;;;;;EAYJ,eAAqB,gBAAgB,qBAAqB;;;;;;;;;;;;EA0C1D,gBAAgB,OAAO;;;;;;;;EAyBvB,aACC,cACA,cACA,kHASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+HD,SACC,cACA;IACC;IACA,sBAAsB;IACtB,kBAAkB;IAClB;IACA,wBAAwB;IACxB,sBAAsB;IACtB;KAED"}
@@ -1,10 +1,14 @@
1
1
  //#region src/site/basePath.ts
2
2
  /**
3
3
  * The site's base path, e.g. "/app" when the site is mounted under a
4
- * subpath. Inherited from `site.basePath` through the manifest at startup
5
- * (see serverEntry and clientEntry); default "" when the site is served
4
+ * subpath. On the client it's inherited from `site.basePath` through the
5
+ * manifest at startup (see clientEntry); default "" when the site is served
6
6
  * from the root.
7
7
  *
8
+ * Server handlers don't use this module state: `createServerLoad` keeps its
9
+ * site's base in its closure and tags each request (`requestBase.ts`), so
10
+ * several sites with different bases can share a process.
11
+ *
8
12
  * Server code and user markup are written base-free: the server strips the
9
13
  * base from incoming URLs before routing (requests that don't carry it get
10
14
  * a 404), and adds it back to generated HTML attributes, redirect
@@ -83,10 +87,91 @@ function addBaseToPath(path, base) {
83
87
  * rendered HTML, so that markup can be written base-free. Values that
84
88
  * aren't absolute paths (relative, "//...", "http://...", "mailto:...")
85
89
  * are left alone, as are ones that already carry the base.
90
+ *
91
+ * Only actual tag attributes are rewritten: text nodes (so an
92
+ * `href="/..."` shown in a `<pre>`/`<code>` sample or in page copy stays
93
+ * literal), comments, and raw-text elements (`<script>`, `<style>`,
94
+ * `<textarea>`, `<title>`) are copied verbatim.
86
95
  */
87
96
  function rewriteBaseInHtml(html, base) {
88
97
  if (!base) return html;
89
- return html.replace(/\s(href|action|src)\s*=\s*("([^"]*)"|'([^']*)')/g, (match, name, _quoted, double, single) => {
98
+ let result = "";
99
+ let index = 0;
100
+ while (index < html.length) {
101
+ const open = html.indexOf("<", index);
102
+ if (open === -1) {
103
+ result += html.slice(index);
104
+ break;
105
+ }
106
+ result += html.slice(index, open);
107
+ if (html.startsWith("<!--", open)) {
108
+ const close = html.indexOf("-->", open + 4);
109
+ if (close === -1) {
110
+ result += html.slice(open);
111
+ break;
112
+ }
113
+ result += html.slice(open, close + 3);
114
+ index = close + 3;
115
+ continue;
116
+ }
117
+ let cursor = open + 1;
118
+ const closing = html[cursor] === "/";
119
+ if (closing) cursor++;
120
+ const nameStart = cursor;
121
+ while (cursor < html.length && /[a-zA-Z0-9:-]/.test(html[cursor])) cursor++;
122
+ const tagName = html.slice(nameStart, cursor).toLowerCase();
123
+ if (tagName === "") {
124
+ result += "<";
125
+ index = open + 1;
126
+ continue;
127
+ }
128
+ const tagEnd = findTagEnd(html, open);
129
+ if (tagEnd === -1) {
130
+ result += html.slice(open);
131
+ break;
132
+ }
133
+ const tag = html.slice(open, tagEnd + 1);
134
+ result += closing ? tag : rewriteTagAttributes(tag, base);
135
+ index = tagEnd + 1;
136
+ if (!closing && RAW_TEXT_ELEMENTS.has(tagName) && !tag.endsWith("/>")) {
137
+ const close = html.toLowerCase().indexOf(`</${tagName}`, index);
138
+ if (close === -1) {
139
+ result += html.slice(index);
140
+ break;
141
+ }
142
+ const closeEnd = html.indexOf(">", close);
143
+ if (closeEnd === -1) {
144
+ result += html.slice(index);
145
+ break;
146
+ }
147
+ result += html.slice(index, closeEnd + 1);
148
+ index = closeEnd + 1;
149
+ }
150
+ }
151
+ return result;
152
+ }
153
+ /** Elements whose content must not be scanned for tags or attributes. */
154
+ const RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
155
+ "script",
156
+ "style",
157
+ "textarea",
158
+ "title"
159
+ ]);
160
+ /** The index of the ">" ending the tag that starts at `start`, skipping quoted values. */
161
+ function findTagEnd(html, start) {
162
+ let quote = null;
163
+ for (let i = start + 1; i < html.length; i++) {
164
+ const char = html[i];
165
+ if (quote !== null) {
166
+ if (char === quote) quote = null;
167
+ } else if (char === "\"" || char === "'") quote = char;
168
+ else if (char === ">") return i;
169
+ }
170
+ return -1;
171
+ }
172
+ /** Rewrites base-free `href`/`action`/`src` attributes within one tag. */
173
+ function rewriteTagAttributes(tag, base) {
174
+ return tag.replace(/\s(href|action|src)\s*=\s*("([^"]*)"|'([^']*)')/gi, (match, name, _quoted, double, single) => {
90
175
  const value = double ?? single ?? "";
91
176
  const rewritten = addBaseToPath(value, base);
92
177
  if (rewritten === value) return match;
@@ -96,4 +181,4 @@ function rewriteBaseInHtml(html, base) {
96
181
  //#endregion
97
182
  export { rewriteBaseInHtml as a, normalizeOrigin as i, getBasePath as n, setBasePath as o, normalizeBasePath as r, stripBaseFromUrl as s, addBaseToPath as t };
98
183
 
99
- //# sourceMappingURL=basePath-DQnbHc7o.mjs.map
184
+ //# sourceMappingURL=basePath-B6hmOMl4.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basePath-B6hmOMl4.mjs","names":[],"sources":["../src/site/basePath.ts"],"sourcesContent":["/**\n * The site's base path, e.g. \"/app\" when the site is mounted under a\n * subpath. On the client it's inherited from `site.basePath` through the\n * manifest at startup (see clientEntry); default \"\" when the site is served\n * from the root.\n *\n * Server handlers don't use this module state: `createServerLoad` keeps its\n * site's base in its closure and tags each request (`requestBase.ts`), so\n * several sites with different bases can share a process.\n *\n * Server code and user markup are written base-free: the server strips the\n * base from incoming URLs before routing (requests that don't carry it get\n * a 404), and adds it back to generated HTML attributes, redirect\n * locations and paths built with `route()`. The client router does the\n * mirror image: strips for matching, adds for data fetches.\n */\nlet basePath = \"\";\n\n/**\n * Validates and sets the site's base path: must be \"\", start with \"/\" and\n * not end with \"/\" (a trailing slash is stripped, \"/\" is normalized to \"\")\n */\nexport function setBasePath(value: string | undefined): void {\n\tbasePath = normalizeBasePath(value);\n}\n\nexport function getBasePath(): string {\n\treturn basePath;\n}\n\n/**\n * Normalizes a base path value, throwing a descriptive error when it\n * can't be one. Trailing slashes are stripped and \"/\" is normalized to \"\".\n */\nexport function normalizeBasePath(value: string | undefined): string {\n\tconst trimmed = (value ?? \"\").trim();\n\tif (trimmed === \"\" || trimmed === \"/\") return \"\";\n\tif (!trimmed.startsWith(\"/\") || /\\s/.test(trimmed)) {\n\t\tthrow new Error(\n\t\t\t`The base path must be an absolute path without spaces (e.g. \"/app\"), ` + `got \"${value}\"`,\n\t\t);\n\t}\n\treturn trimmed.replace(/\\/+$/, \"\");\n}\n\n/**\n * Normalizes a site origin value, throwing a descriptive error when it\n * isn't an absolute http(s) origin without a path or spaces.\n */\nexport function normalizeOrigin(value: string | undefined): string {\n\tconst trimmed = (value ?? \"\").trim();\n\tif (trimmed === \"\") {\n\t\tthrow new Error(`The site origin is empty (e.g. \"https://example.com\")`);\n\t}\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(trimmed);\n\t} catch {\n\t\tthrow new Error(\n\t\t\t`The site origin must be an absolute url (e.g. \"https://example.com\"), got \"${value}\"`,\n\t\t);\n\t}\n\tif (\n\t\t(url.protocol !== \"https:\" && url.protocol !== \"http:\") ||\n\t\turl.pathname !== \"/\" ||\n\t\t/\\s/.test(trimmed)\n\t) {\n\t\tthrow new Error(\n\t\t\t`The site origin must be an http(s) url without spaces or a path ` +\n\t\t\t\t`(e.g. \"https://example.com\"), got \"${value}\"`,\n\t\t);\n\t}\n\t// A trailing slash is allowed\n\treturn url.origin;\n}\n\n/**\n * Strips the base from a URL's pathname, copying the URL so it can be used\n * for routing without disturbing the request. Returns undefined when there\n * is a base and the URL doesn't carry it -- the caller should then return\n * a not-found response, since the site only serves requests under its\n * mount point.\n */\nexport function stripBaseFromUrl(url: URL, base: string): URL | undefined {\n\tconst stripped = new URL(url);\n\tif (!base) return stripped;\n\tif (stripped.pathname === base) {\n\t\tstripped.pathname = \"/\";\n\t\treturn stripped;\n\t}\n\tif (stripped.pathname.startsWith(base + \"/\")) {\n\t\tstripped.pathname = stripped.pathname.slice(base.length) || \"/\";\n\t\treturn stripped;\n\t}\n\treturn undefined;\n}\n\n/**\n * Adds the base to an absolute path, idempotent for paths that already\n * carry it. Relative paths (\"other/page\"), protocol-relative (\"//...\") and\n * full URLs are left alone.\n */\nexport function addBaseToPath(path: string, base: string): string {\n\tif (!base || !path.startsWith(\"/\") || path.startsWith(\"//\")) return path;\n\tif (path === \"/\") return base + \"/\";\n\tif (path === base || path.startsWith(base + \"/\")) return path;\n\treturn base + path;\n}\n\n/**\n * Rewrites absolute-path `href`, `action` and `src` attribute values in\n * rendered HTML, so that markup can be written base-free. Values that\n * aren't absolute paths (relative, \"//...\", \"http://...\", \"mailto:...\")\n * are left alone, as are ones that already carry the base.\n *\n * Only actual tag attributes are rewritten: text nodes (so an\n * `href=\"/...\"` shown in a `<pre>`/`<code>` sample or in page copy stays\n * literal), comments, and raw-text elements (`<script>`, `<style>`,\n * `<textarea>`, `<title>`) are copied verbatim.\n */\nexport function rewriteBaseInHtml(html: string, base: string): string {\n\tif (!base) return html;\n\n\tlet result = \"\";\n\tlet index = 0;\n\twhile (index < html.length) {\n\t\tconst open = html.indexOf(\"<\", index);\n\n\t\t// No more tags: the rest is text, copied verbatim\n\t\tif (open === -1) {\n\t\t\tresult += html.slice(index);\n\t\t\tbreak;\n\t\t}\n\t\tresult += html.slice(index, open);\n\n\t\t// Comments are copied through unparsed\n\t\tif (html.startsWith(\"<!--\", open)) {\n\t\t\tconst close = html.indexOf(\"-->\", open + 4);\n\t\t\tif (close === -1) {\n\t\t\t\tresult += html.slice(open);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult += html.slice(open, close + 3);\n\t\t\tindex = close + 3;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Parse the tag name (if this \"<\" actually starts one; otherwise it's\n\t\t// a literal less-than in text)\n\t\tlet cursor = open + 1;\n\t\tconst closing = html[cursor] === \"/\";\n\t\tif (closing) cursor++;\n\t\tconst nameStart = cursor;\n\t\twhile (cursor < html.length && /[a-zA-Z0-9:-]/.test(html[cursor]!)) cursor++;\n\t\tconst tagName = html.slice(nameStart, cursor).toLowerCase();\n\t\tif (tagName === \"\") {\n\t\t\tresult += \"<\";\n\t\t\tindex = open + 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst tagEnd = findTagEnd(html, open);\n\t\tif (tagEnd === -1) {\n\t\t\tresult += html.slice(open);\n\t\t\tbreak;\n\t\t}\n\n\t\tconst tag = html.slice(open, tagEnd + 1);\n\t\tresult += closing ? tag : rewriteTagAttributes(tag, base);\n\t\tindex = tagEnd + 1;\n\n\t\t// Raw-text elements can hold \"<\" and attribute-looking strings (a\n\t\t// script's inline HTML template, say); copy them untouched so the\n\t\t// scanner can't mistake their text for tags\n\t\tif (!closing && RAW_TEXT_ELEMENTS.has(tagName) && !tag.endsWith(\"/>\")) {\n\t\t\tconst close = html.toLowerCase().indexOf(`</${tagName}`, index);\n\t\t\tif (close === -1) {\n\t\t\t\tresult += html.slice(index);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst closeEnd = html.indexOf(\">\", close);\n\t\t\tif (closeEnd === -1) {\n\t\t\t\tresult += html.slice(index);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult += html.slice(index, closeEnd + 1);\n\t\t\tindex = closeEnd + 1;\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/** Elements whose content must not be scanned for tags or attributes. */\nconst RAW_TEXT_ELEMENTS = new Set([\"script\", \"style\", \"textarea\", \"title\"]);\n\n/** The index of the \">\" ending the tag that starts at `start`, skipping quoted values. */\nfunction findTagEnd(html: string, start: number): number {\n\tlet quote: string | null = null;\n\tfor (let i = start + 1; i < html.length; i++) {\n\t\tconst char = html[i];\n\t\tif (quote !== null) {\n\t\t\tif (char === quote) quote = null;\n\t\t} else if (char === '\"' || char === \"'\") {\n\t\t\tquote = char;\n\t\t} else if (char === \">\") {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/** Rewrites base-free `href`/`action`/`src` attributes within one tag. */\nfunction rewriteTagAttributes(tag: string, base: string): string {\n\treturn tag.replace(\n\t\t/\\s(href|action|src)\\s*=\\s*(\"([^\"]*)\"|'([^']*)')/gi,\n\t\t(match, name: string, _quoted: string, double: string, single: string) => {\n\t\t\tconst value = double ?? single ?? \"\";\n\t\t\tconst rewritten = addBaseToPath(value, base);\n\t\t\tif (rewritten === value) return match;\n\t\t\treturn ` ${name}=\"${rewritten}\"`;\n\t\t},\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,IAAI,WAAW;;;;;AAMf,SAAgB,YAAY,OAAiC;CAC5D,WAAW,kBAAkB,KAAK;AACnC;AAEA,SAAgB,cAAsB;CACrC,OAAO;AACR;;;;;AAMA,SAAgB,kBAAkB,OAAmC;CACpE,MAAM,WAAW,SAAS,GAAA,CAAI,KAAK;CACnC,IAAI,YAAY,MAAM,YAAY,KAAK,OAAO;CAC9C,IAAI,CAAC,QAAQ,WAAW,GAAG,KAAK,KAAK,KAAK,OAAO,GAChD,MAA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oB,IAAI,IAAI;CAAC;CAAU;CAAS;CAAY;AAAO,CAAC;;AAG1E,SAAS,WAAW,MAAc,OAAuB;CACxD,IAAI,QAAuB;CAC3B,KAAK,IAAI,IAAI,QAAQ,GAAG,IAAI,KAAK,QAAQ,KAAK;EAC7C,MAAM,OAAO,KAAK;EAClB,IAAI,UAAU,MACT;OAAA,SAAS,OAAO,QAAQ;EAAA,OACtB,IAAI,SAAS,QAAO,SAAS,KACnC,QAAQ;OACF,IAAI,SAAS,KACnB,OAAO;CAET;CACA,OAAO;AACR;;AAGA,SAAS,qBAAqB,KAAa,MAAsB;CAChE,OAAO,IAAI,QACV,sDACC,OAAO,MAAc,SAAiB,QAAgB,WAAmB;EACzE,MAAM,QAAQ,UAAU,UAAU;EAClC,MAAM,YAAY,cAAc,OAAO,IAAI;EAC3C,IAAI,cAAc,OAAO,OAAO;EAChC,OAAO,IAAI,KAAK,IAAI,UAAU;CAC/B,CACD;AACD"}
package/dist/bin/index.js CHANGED
@@ -1,5 +1,39 @@
1
1
  #! /usr/bin/env node
2
- import { a as loadSite, n as run, t as runOpenApi } from "../runOpenApi-C5yMpQU1.mjs";
2
+ import { a as loadSite, n as run, t as runOpenApi } from "../runOpenApi-DK-QnYEr.mjs";
3
+ import { createRequire } from "node:module";
4
+ import fpath from "node:path";
5
+ //#region src/run/runCheck.ts
6
+ /**
7
+ * Type-checks the site's `.ts` and `.torp` files with `@torpor/check`, which
8
+ * compiles each component to TypeScript and reports diagnostics mapped back
9
+ * to the source. This is the check that `tsc --noEmit` can't do: a `.torp`
10
+ * file isn't part of the tsconfig program, so its script block is only ever
11
+ * checked by the editor.
12
+ *
13
+ * `@torpor/check` is deliberately not a dependency of `@torpor/build` (it
14
+ * pulls in a full TypeScript install), so it is resolved from the site's own
15
+ * dependencies. When it's missing, the command says what to install instead
16
+ * of failing mysteriously.
17
+ */
18
+ function runCheck(workingDir) {
19
+ const require = createRequire(fpath.join(workingDir, "package.json"));
20
+ let checker;
21
+ try {
22
+ checker = require("@torpor/check");
23
+ } catch (error) {
24
+ if (!(error instanceof Error ? error.message : String(error)).includes("@torpor/check")) throw error;
25
+ console.log("@torpor/check is not installed, so the site's .torp files can't be type-checked.\nInstall it as a dev dependency (e.g. \"npm install -D @torpor/check\") and run tb --check again.");
26
+ process.exitCode = 1;
27
+ return;
28
+ }
29
+ const errors = checker.check(workingDir);
30
+ if (errors.length > 0) {
31
+ checker.printErrors(workingDir, errors);
32
+ console.log(`Found ${errors.length} error${errors.length === 1 ? "" : "s"}`);
33
+ process.exitCode = 1;
34
+ } else console.log("No errors found");
35
+ }
36
+ //#endregion
3
37
  //#region src/bin/index.ts
4
38
  const workingDir = process.cwd();
5
39
  if (process.argv.includes("--openapi")) {
@@ -12,7 +46,8 @@ if (process.argv.includes("--openapi")) {
12
46
  } finally {
13
47
  await vite.close();
14
48
  }
15
- } else if (process.argv.includes("--dev")) await run(workingDir, "dev");
49
+ } else if (process.argv.includes("--check")) runCheck(workingDir);
50
+ else if (process.argv.includes("--dev")) await run(workingDir, "dev");
16
51
  else if (process.argv.includes("--build")) await run(workingDir, "build");
17
52
  else if (process.argv.includes("--preview")) await run(workingDir, "preview");
18
53
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/bin/index.ts"],"sourcesContent":["#! /usr/bin/env node\nimport run, { loadSite } from \"../run/run\";\nimport runOpenApi from \"../run/runOpenApi\";\n\nconst workingDir = process.cwd();\nif (process.argv.includes(\"--openapi\")) {\n\tconst flagIndex = process.argv.indexOf(\"--openapi\");\n\tconst next = process.argv[flagIndex + 1];\n\tconst outFile = next && !next.startsWith(\"-\") ? next : \"openapi.json\";\n\tconst { site, vite } = await loadSite(workingDir);\n\ttry {\n\t\tawait runOpenApi(site, vite, outFile);\n\t} finally {\n\t\tawait vite.close();\n\t}\n} else if (process.argv.includes(\"--dev\")) {\n\tawait run(workingDir, \"dev\");\n} else if (process.argv.includes(\"--build\")) {\n\tawait run(workingDir, \"build\");\n} else if (process.argv.includes(\"--preview\")) {\n\tawait run(workingDir, \"preview\");\n}\n"],"mappings":";;;AAIA,MAAM,aAAa,QAAQ,IAAI;AAC/B,IAAI,QAAQ,KAAK,SAAS,WAAW,GAAG;CACvC,MAAM,YAAY,QAAQ,KAAK,QAAQ,WAAW;CAClD,MAAM,OAAO,QAAQ,KAAK,YAAY;CACtC,MAAM,UAAU,QAAQ,CAAC,KAAK,WAAW,GAAG,IAAI,OAAO;CACvD,MAAM,EAAE,MAAM,SAAS,MAAM,SAAS,UAAU;CAChD,IAAI;EACH,MAAM,WAAW,MAAM,MAAM,OAAO;CACrC,UAAU;EACT,MAAM,KAAK,MAAM;CAClB;AACD,OAAO,IAAI,QAAQ,KAAK,SAAS,OAAO,GACvC,MAAM,IAAI,YAAY,KAAK;KACrB,IAAI,QAAQ,KAAK,SAAS,SAAS,GACzC,MAAM,IAAI,YAAY,OAAO;KACvB,IAAI,QAAQ,KAAK,SAAS,WAAW,GAC3C,MAAM,IAAI,YAAY,SAAS"}
1
+ {"version":3,"file":"index.js","names":["path"],"sources":["../../src/run/runCheck.ts","../../src/bin/index.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\n\n/**\n * The shape of the `@torpor/check` module that `tb --check` uses.\n */\ntype Diagnostic = {\n\tpath: string;\n\tmessage: string;\n\tcode?: number;\n\trange: {\n\t\tstart: { line: number; character: number };\n\t\tend: { line: number; character: number };\n\t};\n\tlineText?: string;\n};\n\ntype CheckModule = {\n\tcheck: (folder: string) => Diagnostic[];\n\tprintErrors: (folder: string, errors: Diagnostic[]) => void;\n};\n\n/**\n * Type-checks the site's `.ts` and `.torp` files with `@torpor/check`, which\n * compiles each component to TypeScript and reports diagnostics mapped back\n * to the source. This is the check that `tsc --noEmit` can't do: a `.torp`\n * file isn't part of the tsconfig program, so its script block is only ever\n * checked by the editor.\n *\n * `@torpor/check` is deliberately not a dependency of `@torpor/build` (it\n * pulls in a full TypeScript install), so it is resolved from the site's own\n * dependencies. When it's missing, the command says what to install instead\n * of failing mysteriously.\n */\nexport default function runCheck(workingDir: string): void {\n\tconst require = createRequire(path.join(workingDir, \"package.json\"));\n\tlet checker: CheckModule;\n\ttry {\n\t\tchecker = require(\"@torpor/check\") as CheckModule;\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t// Anything else is a real load error (e.g. a broken dependency of the\n\t\t// checker itself), which shouldn't be dressed up as advice\n\t\tif (!message.includes(\"@torpor/check\")) {\n\t\t\tthrow error;\n\t\t}\n\t\tconsole.log(\n\t\t\t`@torpor/check is not installed, so the site's .torp files can't be type-checked.\\n` +\n\t\t\t\t`Install it as a dev dependency (e.g. \"npm install -D @torpor/check\") and run tb --check again.`,\n\t\t);\n\t\tprocess.exitCode = 1;\n\t\treturn;\n\t}\n\n\tconst errors = checker.check(workingDir);\n\tif (errors.length > 0) {\n\t\tchecker.printErrors(workingDir, errors);\n\t\tconsole.log(`Found ${errors.length} error${errors.length === 1 ? \"\" : \"s\"}`);\n\t\tprocess.exitCode = 1;\n\t} else {\n\t\tconsole.log(\"No errors found\");\n\t}\n}\n","#! /usr/bin/env node\nimport run, { loadSite } from \"../run/run\";\nimport runCheck from \"../run/runCheck\";\nimport runOpenApi from \"../run/runOpenApi\";\n\nconst workingDir = process.cwd();\nif (process.argv.includes(\"--openapi\")) {\n\tconst flagIndex = process.argv.indexOf(\"--openapi\");\n\tconst next = process.argv[flagIndex + 1];\n\tconst outFile = next && !next.startsWith(\"-\") ? next : \"openapi.json\";\n\tconst { site, vite } = await loadSite(workingDir);\n\ttry {\n\t\tawait runOpenApi(site, vite, outFile);\n\t} finally {\n\t\tawait vite.close();\n\t}\n} else if (process.argv.includes(\"--check\")) {\n\trunCheck(workingDir);\n} else if (process.argv.includes(\"--dev\")) {\n\tawait run(workingDir, \"dev\");\n} else if (process.argv.includes(\"--build\")) {\n\tawait run(workingDir, \"build\");\n} else if (process.argv.includes(\"--preview\")) {\n\tawait run(workingDir, \"preview\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C4ADUfhv.mjs";
2
- import { o as setBasePath } from "./basePath-DQnbHc7o.mjs";
3
- import { t as $page } from "./_page-CW6SLuT4.mjs";
4
- import { a as client, n as navigate, r as loadData } from "./load-BODDzmH0.mjs";
2
+ import { n as getBasePath, o as setBasePath, t as addBaseToPath } from "./basePath-B6hmOMl4.mjs";
3
+ import { a as client, n as navigate, o as $page, r as loadData } from "./load-Dw187nJ_.mjs";
4
+ import { setUrlRewriter } from "@torpor/view";
5
5
  import manifest from "@torpor/build/manifest";
6
6
  //#region src/nav/navigationFailure.ts
7
7
  /**
@@ -40,6 +40,8 @@ function handleNavigationFailure(href, result) {
40
40
  //#endregion
41
41
  //#region src/site/clientEntry.ts
42
42
  setBasePath(manifest.base);
43
+ const base = getBasePath();
44
+ if (base) setUrlRewriter((url) => addBaseToPath(url, base));
43
45
  const router = new Router();
44
46
  router.addPages(manifest.routes);
45
47
  client.router = router;
@@ -64,7 +66,8 @@ window.addEventListener("click", async (e) => {
64
66
  if (result.type === "rendered") {
65
67
  window.history.replaceState({ scroll: window.scrollY }, "", document.location.href);
66
68
  window.history.pushState({ scroll: 0 }, "", url);
67
- } else if (handleNavigationFailure(href, result) === "document") window.location.href = href;
69
+ } else if (result.type === "superseded") return;
70
+ else if (handleNavigationFailure(href, result) === "document") window.location.href = href;
68
71
  }
69
72
  });
70
73
  window.addEventListener("mouseover", maybePrefetch);
@@ -103,7 +106,9 @@ function ignoreAnchorMouseEvent(link, e) {
103
106
  return e.defaultPrevented || mouse.altKey || mouse.ctrlKey || mouse.metaKey || mouse.shiftKey || link.target && link.target !== "_self" || link.rel === "external" || link.hasAttribute("download") || link.isContentEditable;
104
107
  }
105
108
  window.addEventListener("popstate", async () => {
106
- if ((await navigateToLocation(document.location)).type !== "rendered") {
109
+ const result = await navigateToLocation(document.location);
110
+ if (result.type === "superseded") return;
111
+ if (result.type !== "rendered") {
107
112
  window.location.reload();
108
113
  return;
109
114
  }