@ogygia/compiler 0.0.0 → 0.14.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 (156) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -1
  3. package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
  4. package/dist/app-spec.d.ts +18 -0
  5. package/dist/app-spec.js +22 -0
  6. package/dist/blank-styles.d.ts +1 -0
  7. package/dist/blank-styles.js +24 -0
  8. package/dist/bom.d.ts +2 -0
  9. package/dist/bom.js +7 -0
  10. package/dist/build-cache.d.ts +13 -0
  11. package/dist/build-cache.js +65 -0
  12. package/dist/ctx.d.ts +238 -0
  13. package/dist/ctx.js +221 -0
  14. package/dist/dev/css-scope.d.ts +16 -0
  15. package/dist/dev/css-scope.js +32 -0
  16. package/dist/dev/dev-hmr.d.ts +24 -0
  17. package/dist/dev/dev-hmr.js +51 -0
  18. package/dist/dev/hmr.d.ts +34 -0
  19. package/dist/dev/hmr.js +52 -0
  20. package/dist/driver.d.ts +349 -0
  21. package/dist/driver.js +1401 -0
  22. package/dist/exports/index.d.ts +77 -0
  23. package/dist/exports/index.js +349 -0
  24. package/dist/exports/parse.d.ts +65 -0
  25. package/dist/exports/parse.js +251 -0
  26. package/dist/fouc-css.d.ts +102 -0
  27. package/dist/fouc-css.js +304 -0
  28. package/dist/free-vars.d.ts +32 -0
  29. package/dist/free-vars.js +454 -0
  30. package/dist/fs.d.ts +31 -0
  31. package/dist/fs.js +82 -0
  32. package/dist/ids.d.ts +49 -0
  33. package/dist/ids.js +52 -0
  34. package/dist/index.d.ts +23 -0
  35. package/dist/index.js +23 -0
  36. package/dist/kit.d.ts +204 -0
  37. package/dist/kit.js +554 -0
  38. package/dist/leg.d.ts +34 -0
  39. package/dist/leg.js +26 -0
  40. package/dist/link/analyses.d.ts +26 -0
  41. package/dist/link/analyses.js +237 -0
  42. package/dist/link/build-output.d.ts +47 -0
  43. package/dist/link/build-output.js +168 -0
  44. package/dist/link/caps.d.ts +32 -0
  45. package/dist/link/caps.js +39 -0
  46. package/dist/link/context-detect.d.ts +28 -0
  47. package/dist/link/context-detect.js +143 -0
  48. package/dist/link/emit-gate.d.ts +43 -0
  49. package/dist/link/emit-gate.js +55 -0
  50. package/dist/link/file-token.d.ts +11 -0
  51. package/dist/link/file-token.js +15 -0
  52. package/dist/link/island-deps.d.ts +183 -0
  53. package/dist/link/island-deps.js +802 -0
  54. package/dist/link/location-map.d.ts +24 -0
  55. package/dist/link/location-map.js +51 -0
  56. package/dist/link/own-reach.d.ts +15 -0
  57. package/dist/link/own-reach.js +188 -0
  58. package/dist/link/registry-stub.d.ts +50 -0
  59. package/dist/link/registry-stub.js +163 -0
  60. package/dist/link/relocations.d.ts +79 -0
  61. package/dist/link/relocations.js +198 -0
  62. package/dist/link/router-css.d.ts +38 -0
  63. package/dist/link/router-css.js +124 -0
  64. package/dist/link/runtime-entry.d.ts +103 -0
  65. package/dist/link/runtime-entry.js +183 -0
  66. package/dist/link/server-manifest.d.ts +25 -0
  67. package/dist/link/server-manifest.js +102 -0
  68. package/dist/link/transport.d.ts +42 -0
  69. package/dist/link/transport.js +91 -0
  70. package/dist/macros/dollar.d.ts +24 -0
  71. package/dist/macros/dollar.js +397 -0
  72. package/dist/macros/pipeline.d.ts +50 -0
  73. package/dist/macros/pipeline.js +133 -0
  74. package/dist/macros/source.d.ts +9 -0
  75. package/dist/macros/source.js +115 -0
  76. package/dist/macros/store.d.ts +22 -0
  77. package/dist/macros/store.js +217 -0
  78. package/dist/macros/wire.d.ts +17 -0
  79. package/dist/macros/wire.js +116 -0
  80. package/dist/map-chain.d.ts +18 -0
  81. package/dist/map-chain.js +42 -0
  82. package/dist/messages.d.ts +672 -0
  83. package/dist/messages.js +938 -0
  84. package/dist/ownership-stamps.d.ts +9 -0
  85. package/dist/ownership-stamps.js +101 -0
  86. package/dist/parse/oxc.d.ts +36 -0
  87. package/dist/parse/oxc.js +35 -0
  88. package/dist/parse/roots.d.ts +4 -0
  89. package/dist/parse/roots.js +27 -0
  90. package/dist/parse/scan.d.ts +65 -0
  91. package/dist/parse/scan.js +297 -0
  92. package/dist/parse/svelte-ast.d.ts +7 -0
  93. package/dist/parse/svelte-ast.js +99 -0
  94. package/dist/program.d.ts +140 -0
  95. package/dist/program.js +304 -0
  96. package/dist/queries.d.ts +105 -0
  97. package/dist/queries.js +326 -0
  98. package/dist/region/emit.d.ts +168 -0
  99. package/dist/region/emit.js +292 -0
  100. package/dist/region/identity.d.ts +32 -0
  101. package/dist/region/identity.js +46 -0
  102. package/dist/region/ir.d.ts +56 -0
  103. package/dist/region/ir.js +0 -0
  104. package/dist/region/marked-imports.d.ts +27 -0
  105. package/dist/region/marked-imports.js +265 -0
  106. package/dist/region/transform.d.ts +189 -0
  107. package/dist/region/transform.js +1565 -0
  108. package/dist/scan-facts.d.ts +36 -0
  109. package/dist/scan-facts.js +54 -0
  110. package/dist/script-request.d.ts +1 -0
  111. package/dist/script-request.js +33 -0
  112. package/dist/splice.d.ts +11 -0
  113. package/dist/splice.js +33 -0
  114. package/dist/transportables.d.ts +23 -0
  115. package/dist/transportables.js +144 -0
  116. package/dist/virtual/core.d.ts +158 -0
  117. package/dist/virtual/core.js +588 -0
  118. package/dist/virtual/resolver.d.ts +56 -0
  119. package/dist/virtual/resolver.js +249 -0
  120. package/dist/virtual/specifier.d.ts +10 -0
  121. package/dist/virtual/specifier.js +6 -0
  122. package/dist/virtual/table.d.ts +118 -0
  123. package/dist/virtual/table.js +54 -0
  124. package/dist/virtual/types.d.ts +17 -0
  125. package/dist/virtual/types.js +100 -0
  126. package/dist/virtual/value-names.d.ts +2 -0
  127. package/dist/virtual/value-names.js +18 -0
  128. package/dist/vite/definers.d.ts +16 -0
  129. package/dist/vite/definers.js +69 -0
  130. package/dist/vite/dev-maps.d.ts +34 -0
  131. package/dist/vite/dev-maps.js +91 -0
  132. package/dist/vite/index.d.ts +21 -0
  133. package/dist/vite/index.js +874 -0
  134. package/dist/vite/kit-dirs.d.ts +6 -0
  135. package/dist/vite/kit-dirs.js +53 -0
  136. package/dist/vite/late-island.d.ts +11 -0
  137. package/dist/vite/late-island.js +19 -0
  138. package/dist/vite/lazy-files.d.ts +2 -0
  139. package/dist/vite/lazy-files.js +72 -0
  140. package/dist/vite/options.d.ts +195 -0
  141. package/dist/vite/options.js +72 -0
  142. package/dist/vite/package-files.d.ts +3 -0
  143. package/dist/vite/package-files.js +88 -0
  144. package/dist/vite/paths.d.ts +14 -0
  145. package/dist/vite/paths.js +37 -0
  146. package/dist/vite/plugin-api.d.ts +316 -0
  147. package/dist/vite/plugin-api.js +328 -0
  148. package/dist/vite/session.d.ts +28 -0
  149. package/dist/vite/session.js +43 -0
  150. package/dist/vite/sourcemaps.d.ts +19 -0
  151. package/dist/vite/sourcemaps.js +75 -0
  152. package/dist/vite/style-preprocess.d.ts +2 -0
  153. package/dist/vite/style-preprocess.js +84 -0
  154. package/dist/vite/svelte-entries.d.ts +4 -0
  155. package/dist/vite/svelte-entries.js +10 -0
  156. package/package.json +87 -12
package/dist/kit.js ADDED
@@ -0,0 +1,554 @@
1
+ import "./region/transform.js";
2
+ import { parse_module } from "./parse/oxc.js";
3
+ import { OgygiaError } from "./messages.js";
4
+ import { Queries, derived, input } from "./queries.js";
5
+ import path from "node:path";
6
+ import { dedent } from "@ogygia/core/contract";
7
+ import fs from "node:fs";
8
+ import { createRequire } from "node:module";
9
+ // src/kit.ts
10
+ const keyed = ([file, keys]) => `${file}\0${keys.join(",")}`;
11
+ const own = (k) => k;
12
+ const routes_by_fs = /* @__PURE__ */ new WeakMap();
13
+ /** The route reader for one file system: the same one each time it is asked for, so the disk has
14
+ * one set of answers however many compile contexts read it. */
15
+ function route_reader(files) {
16
+ let r = routes_by_fs.get(files);
17
+ if (r) return r;
18
+ const db = new Queries("routes");
19
+ const text = input("route text", own, (abs) => files.read(abs));
20
+ const listing = input("route listing", own, (dir) => files.list(dir));
21
+ const at = input("route stat", own, (abs) => files.stat(abs));
22
+ const route_tree = derived("route tree", own, (_cx, routesDir) => build_route_tree(routes, routesDir), Object.is);
23
+ const routes = {
24
+ fs: files,
25
+ db,
26
+ text,
27
+ listing,
28
+ at,
29
+ csr_of_file: derived("route csr", own, (cx, file) => csr_of_text(cx.get(text, file), file)),
30
+ config_of_file: derived("route config", keyed, (cx, [file, keys]) => route_config_of_text(cx.get(text, file), file, keys)),
31
+ route_tree,
32
+ node_csr: derived("route node csr", own, (cx, routesDir) => {
33
+ const tree = cx.get(route_tree, routesDir);
34
+ const out = [];
35
+ const of = (node) => {
36
+ if (node.index in out) return out[node.index];
37
+ const csr = node_own_csr(routes, node) ?? (node.parent ? of(node.parent) : void 0);
38
+ out[node.index] = csr;
39
+ return csr;
40
+ };
41
+ for (const node of tree.nodes) of(node);
42
+ return out;
43
+ }),
44
+ page_config: derived("page config", keyed, (cx, [routesDir, keys]) => {
45
+ const m = {};
46
+ for (const leaf of cx.get(route_tree, routesDir).nodes) if (leaf.kind === "leaf") m[route_id_of(leaf.route, routesDir)] = page_config(routes, leaf, keys);
47
+ return m;
48
+ }),
49
+ has_csr_true: derived("routes csr true", own, (_cx, routesDir) => csrTrueRouteIds(routes, routesDir).length > 0),
50
+ touch(abs, event) {
51
+ const before = db.revision;
52
+ db.refresh(text, abs);
53
+ db.refresh(at, abs);
54
+ if (event !== "update") for (let dir = path.dirname(abs);; dir = path.dirname(dir)) {
55
+ db.refresh(listing, dir);
56
+ db.refresh(at, dir);
57
+ if (path.dirname(dir) === dir) break;
58
+ }
59
+ return db.revision !== before && db.answers_changed_since(before);
60
+ }
61
+ };
62
+ routes_by_fs.set(files, routes);
63
+ return routes;
64
+ }
65
+ /**
66
+ * Locate Kit's internal wire-protocol + client remote-functions modules by resolving `@sveltejs/kit`'s
67
+ * package.json (that IS exported) and joining the src path — deep-importing the file bypasses the exports
68
+ * map. Also finds the app's universal hooks. Resolved from the APP root (`createRequire` off a root path),
69
+ * so a monorepo sub-package still finds Kit. Never throws (a missing Kit → the devalue-codec fallback).
70
+ */
71
+ function resolve_kit_paths(root) {
72
+ let kit_wire_path = null;
73
+ let kit_remote_index = null;
74
+ let universal_hooks = null;
75
+ let kit_transport_init = null;
76
+ try {
77
+ const require = createRequire(path.join(root, "noop.js"));
78
+ const kitRoot = path.dirname(require.resolve("@sveltejs/kit/package.json"));
79
+ const candidate = path.join(kitRoot, "src", "runtime", "shared.js");
80
+ if (fs.existsSync(candidate)) kit_wire_path = candidate;
81
+ const codec = path.join(kitRoot, "src", "runtime", "app", "internal", "transport.js");
82
+ if (fs.existsSync(codec)) kit_transport_init = codec;
83
+ const remoteIdx = path.join(kitRoot, "src", "runtime", "client", "remote-functions", "index.js");
84
+ if (fs.existsSync(remoteIdx)) kit_remote_index = remoteIdx;
85
+ } catch {
86
+ kit_wire_path = null;
87
+ }
88
+ for (const f of ["hooks.ts", "hooks.js"]) {
89
+ const abs = path.join(root, "src", f);
90
+ if (fs.existsSync(abs)) {
91
+ universal_hooks = abs;
92
+ break;
93
+ }
94
+ }
95
+ let client_hooks = null;
96
+ for (const f of ["hooks.client.ts", "hooks.client.js"]) {
97
+ const abs = path.join(root, "src", f);
98
+ if (fs.existsSync(abs)) {
99
+ client_hooks = abs;
100
+ break;
101
+ }
102
+ }
103
+ return {
104
+ kit_wire_path,
105
+ kit_remote_index,
106
+ universal_hooks,
107
+ client_hooks,
108
+ kit_transport_init
109
+ };
110
+ }
111
+ /**
112
+ * The app's Kit MAJOR version (resolved off the app root, like {@link resolve_kit_paths}), or null when
113
+ * no Kit resolves. The one fact `kit_asset` needs: Kit 2's `asset()` takes a path with its leading
114
+ * slash, Kit 3's without — and no runtime probe can tell them apart (Kit 2 refuses a slash-less path
115
+ * only in dev; in a build it returns it page-relative, and every island entry on a nested page 404'd).
116
+ */
117
+ function kit_major(root) {
118
+ try {
119
+ const require = createRequire(path.join(root, "noop.js"));
120
+ const pkg = JSON.parse(fs.readFileSync(require.resolve("@sveltejs/kit/package.json"), "utf8"));
121
+ const major = Number.parseInt(pkg.version ?? "", 10);
122
+ return Number.isFinite(major) ? major : null;
123
+ } catch {
124
+ return null;
125
+ }
126
+ }
127
+ const DEFAULT_KIT_DIRS = {
128
+ routes: "src/routes",
129
+ out: ".svelte-kit"
130
+ };
131
+ /** The dirs an app with no Kit config has. */
132
+ function default_kit_dirs(root) {
133
+ return {
134
+ routes_dir: path.join(root, DEFAULT_KIT_DIRS.routes),
135
+ out_dir: path.join(root, DEFAULT_KIT_DIRS.out)
136
+ };
137
+ }
138
+ /** Read `export const csr = true|false` from a route options file; `undefined` if unset/absent. */
139
+ function read_csr(r, file) {
140
+ return r.db.get(r.csr_of_file, file);
141
+ }
142
+ function csr_of_text(src, file) {
143
+ if (src === null) return void 0;
144
+ if (!src.includes("csr")) return void 0;
145
+ const { program } = parse_module(src, file);
146
+ if (!program) return void 0;
147
+ const value = literal_value(page_option(program, "csr"));
148
+ return typeof value === "boolean" ? value : void 0;
149
+ }
150
+ function unwrap_expression(node) {
151
+ let n = node ?? null;
152
+ while (n && (n.type === "TSAsExpression" || n.type === "TSSatisfiesExpression" || n.type === "TSTypeAssertion" || n.type === "TSNonNullExpression" || n.type === "ParenthesizedExpression")) n = n.expression;
153
+ return n;
154
+ }
155
+ function page_option(program, name) {
156
+ const body = program.body ?? [];
157
+ const declared = (local) => {
158
+ for (const statement of body) {
159
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
160
+ if (declaration?.type !== "VariableDeclaration") continue;
161
+ for (const d of declaration.declarations ?? []) if (d.id?.type === "Identifier" && d.id.name === local) return d.init ?? null;
162
+ }
163
+ return null;
164
+ };
165
+ const name_of = (n) => {
166
+ if (n?.type === "Identifier") return n.name;
167
+ return typeof n?.value === "string" ? n.value : null;
168
+ };
169
+ for (const statement of body) {
170
+ if (statement.type !== "ExportNamedDeclaration") continue;
171
+ for (const d of statement.declaration?.declarations ?? []) if (d.id?.type === "Identifier" && d.id.name === name) return d.init ?? null;
172
+ for (const s of statement.specifiers ?? []) {
173
+ if (name_of(s.exported) !== name) continue;
174
+ const local = name_of(s.local);
175
+ return statement.source || local === null ? null : declared(local);
176
+ }
177
+ }
178
+ return null;
179
+ }
180
+ function config_object(program) {
181
+ const init = unwrap_expression(page_option(program, "config"));
182
+ return init?.type === "ObjectExpression" ? init : null;
183
+ }
184
+ const NOT_LITERAL = Symbol("not-literal");
185
+ function literal_value(node) {
186
+ const n = unwrap_expression(node);
187
+ if (n?.type !== "Literal" || n.regex || n.bigint !== void 0) return NOT_LITERAL;
188
+ return n.value;
189
+ }
190
+ /**
191
+ * The claimed keys `export const config = {…}` sets in one route module: its literal-valued top-level
192
+ * properties named in `keys`. `{}` when the file, the export or the keys are absent (a spread or a
193
+ * `config` that is not an object literal is Kit's to read, not ours). A claimed key with a computed
194
+ * value is a build error: it is read at build time, so ogygia could not honour it.
195
+ */
196
+ function read_route_config(r, file, keys) {
197
+ return r.db.get(r.config_of_file, [file, keys]);
198
+ }
199
+ function route_config_of_text(src, file, keys) {
200
+ const out = {};
201
+ if (src === null) return out;
202
+ if (!src.includes("config") || !keys.some((k) => src.includes(k))) return out;
203
+ const { program } = parse_module(src, file);
204
+ const object = program && config_object(program);
205
+ if (!object) return out;
206
+ for (const property of object.properties ?? []) {
207
+ if (property.type !== "Property" || property.computed) continue;
208
+ const key = property.key?.type === "Identifier" ? property.key.name : property.key?.value;
209
+ if (typeof key !== "string" || !keys.includes(key)) continue;
210
+ const value = literal_value(property.value);
211
+ if (value === NOT_LITERAL) throw new OgygiaError("kit_config_not_literal", {
212
+ file,
213
+ key
214
+ });
215
+ out[key] = value;
216
+ }
217
+ return out;
218
+ }
219
+ const PAGE_UNIVERSAL = ["+page.js", "+page.ts"];
220
+ const PAGE_SERVER = ["+page.server.js", "+page.server.ts"];
221
+ const LAYOUT_UNIVERSAL = ["+layout.js", "+layout.ts"];
222
+ const LAYOUT_SERVER = ["+layout.server.js", "+layout.server.ts"];
223
+ function own_csr(r, dir, universal, server) {
224
+ let csr;
225
+ for (const f of server) csr = read_csr(r, path.join(dir, f)) ?? csr;
226
+ for (const f of universal) csr = read_csr(r, path.join(dir, f)) ?? csr;
227
+ return csr;
228
+ }
229
+ const ROUTE_COMPONENT_RE = /^\+(?:(page|layout)(?:@(.*))?|(error))\.[^.]+$/;
230
+ const SCRIPT_FILE_RE = /\.[cm]?[jt]s$/;
231
+ const ROUTE_MODULE_RE = /^\+(page|layout)(\.server)?\.[jt]s$/;
232
+ function route_component(name) {
233
+ if (SCRIPT_FILE_RE.test(name)) return null;
234
+ const m = ROUTE_COMPONENT_RE.exec(name);
235
+ if (!m) return null;
236
+ return m[3] ? { kind: "error" } : {
237
+ kind: m[1],
238
+ reset: m[2]
239
+ };
240
+ }
241
+ /**
242
+ * A route COMPONENT of `kind`: `+page.svelte`, a page with a layout reset (`+page@.svelte`,
243
+ * `+page@(app).svelte`), or either in any other extension the app compiles to a component
244
+ * (`+page.md`, `+page.svx`): every `+page` file but the option scripts, as Kit routes them.
245
+ */
246
+ function is_route_component(name, kind) {
247
+ return route_component(name)?.kind === kind;
248
+ }
249
+ function route_tree(r, routesDir) {
250
+ return r.db.get(r.route_tree, routesDir);
251
+ }
252
+ function layouts_up(route, reset) {
253
+ const out = [];
254
+ for (let current = route; current; current = current.parent) {
255
+ if (reset !== void 0 && current.segment !== reset) continue;
256
+ if (current.layout) {
257
+ out.push(current.layout);
258
+ reset = current.layout.reset;
259
+ } else reset = void 0;
260
+ }
261
+ return out;
262
+ }
263
+ function build_route_tree(r, routesDir) {
264
+ const routes = [];
265
+ const node = (kind, route) => ({
266
+ kind,
267
+ route,
268
+ component: null,
269
+ reset: void 0,
270
+ parent: null,
271
+ layouts: [],
272
+ pages: [],
273
+ index: -1
274
+ });
275
+ const walk = (dir, segment, parent) => {
276
+ const route = {
277
+ dir,
278
+ segment,
279
+ parent,
280
+ layout: null,
281
+ error: null,
282
+ leaf: null
283
+ };
284
+ routes.push(route);
285
+ const entries = route_entries(r, dir);
286
+ for (const e of entries) {
287
+ if (!e.is_file) continue;
288
+ const component = route_component(e.name);
289
+ const kind = component?.kind ?? ROUTE_MODULE_RE.exec(e.name)?.[1];
290
+ let owner = route.error;
291
+ if (kind === "error") owner = route.error ??= node("error", route);
292
+ else if (kind === "layout") owner = route.layout ??= node("layout", route);
293
+ else if (kind === "page") owner = route.leaf ??= node("leaf", route);
294
+ if (component && owner) {
295
+ owner.component = e.name;
296
+ owner.reset = component.reset;
297
+ }
298
+ }
299
+ for (const e of entries) if (e.is_dir && e.name !== ".ogygia-keep-client") walk(path.join(dir, e.name), e.name, route);
300
+ };
301
+ walk(routesDir, "", null);
302
+ const root = routes[0];
303
+ root.layout ??= node("layout", root);
304
+ for (const route of routes) {
305
+ const leaf = route.leaf;
306
+ if (!leaf) continue;
307
+ let at = leaf;
308
+ for (const layout of layouts_up(route, leaf.reset)) {
309
+ leaf.layouts.unshift(layout);
310
+ layout.pages.push(leaf);
311
+ at.parent = at = layout;
312
+ }
313
+ }
314
+ for (const route of routes) {
315
+ if (!route.error) continue;
316
+ for (let current = route; current; current = current.parent) if (current.layout) {
317
+ route.error.parent = current.layout;
318
+ break;
319
+ }
320
+ }
321
+ const nodes = routes.flatMap((x) => [
322
+ x.layout,
323
+ x.error,
324
+ x.leaf
325
+ ].filter((n) => n !== null));
326
+ nodes.forEach((n, i) => n.index = i);
327
+ return {
328
+ routes,
329
+ nodes
330
+ };
331
+ }
332
+ function node_csr(r, tree, node) {
333
+ return r.db.get(r.node_csr, tree.routes[0].dir)[node.index];
334
+ }
335
+ function node_own_csr(r, node) {
336
+ const dir = node.route.dir;
337
+ if (node.kind === "leaf") return own_csr(r, dir, PAGE_UNIVERSAL, PAGE_SERVER);
338
+ if (node.kind === "layout") return own_csr(r, dir, LAYOUT_UNIVERSAL, LAYOUT_SERVER);
339
+ }
340
+ function layout_chain_csr(r, layout) {
341
+ let csr;
342
+ for (const node of [...layouts_up(layout.route.parent, layout.reset).reverse(), layout]) csr = node_own_csr(r, node) ?? csr;
343
+ return csr;
344
+ }
345
+ function page_leaves(tree) {
346
+ return tree.nodes.filter((n) => n.kind === "leaf" && n.component !== null);
347
+ }
348
+ function host_node(r, hostFile, routesDir) {
349
+ const kind = route_component(path.basename(hostFile))?.kind;
350
+ if (kind !== "page" && kind !== "layout") return null;
351
+ const dir = path.dirname(hostFile);
352
+ const route = route_tree(r, routesDir).routes.find((x) => x.dir === dir);
353
+ return (kind === "page" ? route?.leaf : route?.layout) ?? null;
354
+ }
355
+ function route_id_of(route, routesDir) {
356
+ const rel = path.relative(routesDir, route.dir);
357
+ return normalize_route_id(`/${rel ? rel.split(path.sep).join("/") : ""}`);
358
+ }
359
+ /**
360
+ * The ERROR-RENDER csr of every page route: Kit renders a page's `+error.svelte` with the page's
361
+ * layouts only (`PageNodes(layouts)` in its server renderer, the page node dropped), so `csr` for a
362
+ * 404 / 500 under a `csr = false` page is the layouts' answer, usually `true`.
363
+ */
364
+ function errorCsrTrueRouteIds(r, routesDir) {
365
+ const tree = route_tree(r, routesDir);
366
+ const ids = /* @__PURE__ */ new Set();
367
+ for (const leaf of page_leaves(tree)) {
368
+ const deepest = leaf.layouts.at(-1);
369
+ if (deepest && node_csr(r, tree, deepest) === false) continue;
370
+ ids.add(route_id_of(leaf.route, routesDir));
371
+ }
372
+ return [...ids];
373
+ }
374
+ /** The error-render csr of a ROUTELESS response (no route matched: Kit renders the root layout and
375
+ * the root error page) — the root layout's own option, Kit's default `true` when unset. */
376
+ function rootLayoutCsrTrue(r, routesDir) {
377
+ const tree = route_tree(r, routesDir);
378
+ return node_csr(r, tree, tree.routes[0].layout) !== false;
379
+ }
380
+ function layout_page_worlds(r, tree, layout) {
381
+ let any_false = false;
382
+ let any_true = false;
383
+ for (const leaf of layout.pages) {
384
+ if (leaf.component === null) continue;
385
+ if (node_csr(r, tree, leaf) === false) any_false = true;
386
+ else any_true = true;
387
+ }
388
+ return {
389
+ any_false,
390
+ any_true
391
+ };
392
+ }
393
+ /**
394
+ * Kit-effective `csr === false` for a page or layout host. A page reads Kit's chain: its own
395
+ * option, else the layouts it renders in (a `@` reset skips the ones between). A LAYOUT is
396
+ * csr=false exactly when EVERY page it serves is csr=false; a layout no page renders in reads its
397
+ * own chain.
398
+ * @param hostFile abs path to a route component
399
+ * @param routesDir abs `src/routes`
400
+ */
401
+ function routeCsrIsFalse(r, hostFile, routesDir) {
402
+ const node = host_node(r, hostFile, routesDir);
403
+ if (!node) return false;
404
+ const tree = route_tree(r, routesDir);
405
+ if (node.kind === "leaf") return node_csr(r, tree, node) === false;
406
+ const { any_false, any_true } = layout_page_worlds(r, tree, node);
407
+ if (any_false && !any_true) return true;
408
+ if (any_true) return false;
409
+ return layout_chain_csr(r, node) === false;
410
+ }
411
+ /**
412
+ * True when `hostFile` is a route host whose islands ogygia must STRIP (Kit hydrates every page
413
+ * this host serves). Pages: Kit's own-chain rule (default true, or an explicit `csr = true` that
414
+ * beats a `false` up the chain). LAYOUTS: strippable ONLY when no page at/below them is
415
+ * csr=false — on a mixed layout both this and {@link routeCsrIsFalse} are false (shared world:
416
+ * islands kept, `documentIsCsrTrue` degrades them per document). `false` for non-route files
417
+ * (shared components): their csr depends on which page renders them, so they keep their islands.
418
+ */
419
+ function routeCsrIsTrue(r, hostFile, routesDir) {
420
+ const node = host_node(r, hostFile, routesDir);
421
+ if (!node) return false;
422
+ const tree = route_tree(r, routesDir);
423
+ if (node.kind === "leaf") return node_csr(r, tree, node) !== false;
424
+ const { any_false, any_true } = layout_page_worlds(r, tree, node);
425
+ if (any_false) return false;
426
+ if (any_true) return true;
427
+ return layout_chain_csr(r, node) !== false;
428
+ }
429
+ function route_entries(r, dir) {
430
+ const out = [];
431
+ for (const e of r.db.get(r.listing, dir) ?? []) {
432
+ let is_dir = e.kind === "dir";
433
+ let is_file = e.kind === "file";
434
+ if (!is_dir && !is_file) {
435
+ const st = r.db.get(r.at, path.join(dir, e.name));
436
+ if (st === null) continue;
437
+ is_dir = st === "dir";
438
+ is_file = st === "file";
439
+ }
440
+ out.push({
441
+ name: e.name,
442
+ is_dir,
443
+ is_file
444
+ });
445
+ }
446
+ return out;
447
+ }
448
+ /** Kit's `route.id` for a page host, with layout GROUP segments (`(app)`) stripped — the same
449
+ * normalization {@link csrTrueRouteIds} applies, so the two sides match whether or not Kit keeps
450
+ * groups in `route.id`. Root → `/`. */
451
+ function normalize_route_id(id) {
452
+ return `/${id.split("/").filter(Boolean).filter((s) => !(s.startsWith("(") && s.endsWith(")"))).join("/")}`;
453
+ }
454
+ /**
455
+ * The set of route ids (Kit `route.id`, group-stripped) whose EFFECTIVE csr is TRUE — i.e. Kit
456
+ * hydrates the whole document there. A csr=false layout's islands rendered under one of these must
457
+ * degrade to inline on BOTH legs (Kit owns hydration); Region reads this map on the server, and
458
+ * `kit_hydrates_page()` is the identical client signal. Empty for a fully csr=false app (the norm);
459
+ * only the csr=true exceptions land here.
460
+ */
461
+ function csrTrueRouteIds(r, routesDir) {
462
+ const tree = route_tree(r, routesDir);
463
+ const ids = /* @__PURE__ */ new Set();
464
+ for (const leaf of page_leaves(tree)) if (node_csr(r, tree, leaf) !== false) ids.add(route_id_of(leaf.route, routesDir));
465
+ return [...ids];
466
+ }
467
+ function page_config(r, leaf, keys) {
468
+ let merged = {};
469
+ for (const node of [...leaf.layouts, leaf]) {
470
+ const files = node.kind === "leaf" ? [...PAGE_UNIVERSAL, ...PAGE_SERVER] : [...LAYOUT_UNIVERSAL, ...LAYOUT_SERVER];
471
+ for (const f of files) merged = {
472
+ ...merged,
473
+ ...read_route_config(r, path.join(node.route.dir, f), keys)
474
+ };
475
+ }
476
+ return merged;
477
+ }
478
+ /** Every page route id (group-stripped) → its merged config, claimed keys only. Every route with a
479
+ * `+page` file counts, a redirect-only `+page.server.ts` too. A key no level sets is absent, so the
480
+ * plugin applies its default; a page that sets none maps to `{}`. */
481
+ function page_route_config(r, routesDir, keys) {
482
+ return r.db.get(r.page_config, [routesDir, keys]);
483
+ }
484
+ /**
485
+ * Does the app have ANY csr=true page (Kit hydrates the whole document there)? Drives whether a
486
+ * csr=false LAYOUT must link its island wrapper on the CLIENT leg: on a csr=true child page Kit
487
+ * hydrates the layout, so its chrome islands must be REAL wrappers (Region degrades them inline),
488
+ * not the thin stub the pure-csr=false path uses. A pure-csr=false app keeps the stub (thin client
489
+ * graph); only mixed apps pay for the layout wrappers.
490
+ */
491
+ function hasAnyCsrTrueRoute(r, routesDir) {
492
+ return r.db.get(r.has_csr_true, routesDir);
493
+ }
494
+ /** The directory of the build-time keepalive layout; the route tree never walks into it. */
495
+ const KEEP_CLIENT_DIR = ".ogygia-keep-client";
496
+ /**
497
+ * Replicates Kit's `manifest_data.nodes.every(n => n.page_options?.csr === false)`, the exact
498
+ * condition under which Kit skips the client build, over every node of the route tree (layouts,
499
+ * error pages and pages, Kit's fallback root layout and error page included) with each node's csr
500
+ * resolved as Kit resolves it. A single node whose csr is `true` or unset keeps the build alive.
501
+ * When this is true, ogygia's runtime is never emitted, so index.ts injects the keepalive (its own
502
+ * directory is not part of the tree). A statically unanalysable option file can only err toward a
503
+ * keepalive Kit did not need: a harmless extra client build, never a 404.
504
+ */
505
+ function clientBuildWillSkip(r, routesDir) {
506
+ const tree = route_tree(r, routesDir);
507
+ return tree.nodes.every((node) => node_csr(r, tree, node) === false);
508
+ }
509
+ /**
510
+ * True when AT LEAST ONE page route is csr=false. A pure csr=true app (this returns false) needs no
511
+ * ogygia runtime at all — Kit hydrates everything itself — so the runtime chunk is skipped entirely.
512
+ */
513
+ function hasAnyCsrFalseRoute(r, routesDir) {
514
+ const tree = route_tree(r, routesDir);
515
+ return page_leaves(tree).some((leaf) => node_csr(r, tree, leaf) === false);
516
+ }
517
+ /** On-disk path of the injected keepalive route in an app's routes dir. */
518
+ function keep_client_dir(routes_dir) {
519
+ return path.join(routes_dir, KEEP_CLIENT_DIR);
520
+ }
521
+ /** Write the URL-less `csr = true` keepalive layout into the app's routes (removed at process exit). */
522
+ function inject_keep_client_route(routes_dir) {
523
+ const dir = keep_client_dir(routes_dir);
524
+ fs.mkdirSync(dir, { recursive: true });
525
+ fs.writeFileSync(path.join(dir, "+layout.ts"), `${dedent`
526
+ // Generated by ogygia for the duration of the build, then removed. A layout-only node —
527
+ // no +page, so no servable URL — that stops SvelteKit skipping its client build when every
528
+ // real route is csr = false. Safe to delete (gitignored; ogygia self-heals it).
529
+ export const csr = true;
530
+ `}\n`);
531
+ }
532
+ /** Remove leftover on-disk `.ogygia` trees from an earlier materialization approach. */
533
+ function clean_stale_ogygia_dirs(dir) {
534
+ let entries;
535
+ try {
536
+ entries = fs.readdirSync(dir, { withFileTypes: true });
537
+ } catch {
538
+ return;
539
+ }
540
+ for (const entry of entries) {
541
+ if (!entry.isDirectory()) continue;
542
+ const full = path.join(dir, entry.name);
543
+ if (entry.name === "node_modules") continue;
544
+ if (entry.name === ".ogygia") {
545
+ fs.rmSync(full, {
546
+ recursive: true,
547
+ force: true
548
+ });
549
+ continue;
550
+ }
551
+ clean_stale_ogygia_dirs(full);
552
+ }
553
+ }
554
+ export { DEFAULT_KIT_DIRS, KEEP_CLIENT_DIR, clean_stale_ogygia_dirs, clientBuildWillSkip, csrTrueRouteIds, default_kit_dirs, errorCsrTrueRouteIds, hasAnyCsrFalseRoute, hasAnyCsrTrueRoute, inject_keep_client_route, is_route_component, keep_client_dir, kit_major, normalize_route_id, page_route_config, read_csr, read_route_config, resolve_kit_paths, rootLayoutCsrTrue, routeCsrIsFalse, routeCsrIsTrue, route_reader };
package/dist/leg.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { Machine } from "@ogygia/machine";
2
+ type LegStates = {
3
+ open: {};
4
+ closed: {};
5
+ };
6
+ declare const LEG_STEPS: {
7
+ readonly open: readonly ["closed"];
8
+ readonly closed: readonly [];
9
+ };
10
+ export interface BuildLeg {
11
+ /** The bundler environment's name (`ssr`, `client`, or the app's own). */
12
+ readonly name: string;
13
+ /** A server environment (its output runs in Node, not the browser). */
14
+ readonly server: boolean;
15
+ readonly life: Machine<LegStates, typeof LEG_STEPS>;
16
+ /** Each emitted island entry's ref, by island id (one emit per island per leg). */
17
+ readonly island_entry_refs: Map<string, string>;
18
+ runtime_entry_ref: string | null;
19
+ /** The location map's served path, once `location_maps` wrote it. */
20
+ location_map_url: string | null;
21
+ /** Each file's compiled tree CSS (null: none), compiled once per leg however many roots reach it. */
22
+ readonly compiled_css: Map<string, string | null>;
23
+ /** Emitted CSS asset refs: router page (`rcss:<rel>`), server hole (island id), content module. */
24
+ readonly router_css_refs: Map<string, string>;
25
+ readonly hole_css_refs: Map<string, string>;
26
+ readonly content_css_refs: Map<string, string>;
27
+ /** A server leg's regions found after it wrote `server-regions`: each one's emitted chunk ref, by
28
+ * island id (link/server-manifest.ts). */
29
+ readonly late_server_regions: Map<string, string>;
30
+ /** Each relocation's patches in this leg's chunks, by name (link/relocations.ts). */
31
+ readonly relocated: Map<string, number>;
32
+ }
33
+ export declare function new_leg(name: string, server: boolean): BuildLeg;
34
+ export {};
package/dist/leg.js ADDED
@@ -0,0 +1,26 @@
1
+ import { machine } from "@ogygia/machine";
2
+ const LEG = machine()({
3
+ name: "build leg",
4
+ initial: "open",
5
+ steps: {
6
+ open: ["closed"],
7
+ closed: []
8
+ }
9
+ });
10
+ function new_leg(name, server) {
11
+ return {
12
+ name,
13
+ server,
14
+ life: LEG.create(),
15
+ island_entry_refs: /* @__PURE__ */ new Map(),
16
+ runtime_entry_ref: null,
17
+ location_map_url: null,
18
+ compiled_css: /* @__PURE__ */ new Map(),
19
+ router_css_refs: /* @__PURE__ */ new Map(),
20
+ hole_css_refs: /* @__PURE__ */ new Map(),
21
+ content_css_refs: /* @__PURE__ */ new Map(),
22
+ late_server_regions: /* @__PURE__ */ new Map(),
23
+ relocated: /* @__PURE__ */ new Map()
24
+ };
25
+ }
26
+ export { new_leg };
@@ -0,0 +1,26 @@
1
+ /** The open issue that tracks every analysis with no oracle yet. */
2
+ export declare const ORACLE_GAPS = 1489;
3
+ /** An analysis that predicts what a page does at run time, as data (test/analyses.test.ts holds the table true). */
4
+ export interface Analysis {
5
+ /** snake_case; an oracle names it with `// oracle: <name>`. */
6
+ readonly name: string;
7
+ /** What it predicts, in plain words. */
8
+ readonly predicts: string;
9
+ /**
10
+ * Which way it leans when unsure. `over`: the answer must hold every run-time behavior (a miss
11
+ * breaks a page; an extra costs bytes). `under`: it must hold only safe cases (a wrong yes breaks
12
+ * a page). `exact`: both directions break a page.
13
+ */
14
+ readonly direction: "over" | "under" | "exact";
15
+ /** The safe answer it gives when it cannot decide. */
16
+ readonly fallback: string;
17
+ /** Its file under `packages/` (an analysis a plugin package owns lives there), and the function or
18
+ * class that answers. */
19
+ readonly where: {
20
+ readonly file: string;
21
+ readonly symbol: string;
22
+ };
23
+ /** The issue for an oracle while there is none; `null` once a file carries the marker. */
24
+ readonly gap: number | null;
25
+ }
26
+ export declare const ANALYSES: readonly Analysis[];