@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
@@ -0,0 +1,198 @@
1
+ import { LATE_SERVER_REGIONS_TOKEN, PAGE_DATA_READS_TOKEN, SERVER_MAP_TOKENS, server_manifest_maps, server_regions } from "./server-manifest.js";
2
+ import { FILE_TOKEN_MARK, FILE_TOKEN_RE, file_token_id } from "./file-token.js";
3
+ import { ISLAND_DEPS_INLINE_TOKEN } from "./island-deps.js";
4
+ import { by_key } from "./location-map.js";
5
+ import path from "node:path";
6
+ import MagicString from "magic-string";
7
+ // src/link/relocations.ts
8
+ const KIT_PAGE_MODULE_RE = /\/@sveltejs\/kit\/src\/runtime\/app\/(?:state|stores)(?:[/.]|$)/;
9
+ const LINE_SEPARATOR = String.fromCharCode(8232);
10
+ const PARAGRAPH_SEPARATOR = String.fromCharCode(8233);
11
+ const ANY_LITERAL_ESCAPE = /* @__PURE__ */ new Map([
12
+ ["\\", "\\\\"],
13
+ ["'", "\\'"],
14
+ ["\"", "\\\""],
15
+ [LINE_SEPARATOR, "\\u2028"],
16
+ [PARAGRAPH_SEPARATOR, "\\u2029"]
17
+ ]);
18
+ const LITERAL_ESCAPE = /* @__PURE__ */ new Map([
19
+ ["\\", "\\\\"],
20
+ ["\n", "\\n"],
21
+ ["\r", "\\r"],
22
+ [LINE_SEPARATOR, "\\u2028"],
23
+ [PARAGRAPH_SEPARATOR, "\\u2029"]
24
+ ]);
25
+ function in_any_literal(text) {
26
+ let out = "";
27
+ for (const c of text) out += ANY_LITERAL_ESCAPE.get(c) ?? c;
28
+ return out;
29
+ }
30
+ function relative_file(from, to) {
31
+ const up = from.split("/").slice(0, -1);
32
+ const down = to.split("/");
33
+ while (up.length && down.length > 1 && up[0] === down[0]) {
34
+ up.shift();
35
+ down.shift();
36
+ }
37
+ return up.length ? `${"../".repeat(up.length)}${down.join("/")}` : `./${down.join("/")}`;
38
+ }
39
+ const PAGE_DATA_READS = {
40
+ name: "page data reads",
41
+ token: PAGE_DATA_READS_TOKEN,
42
+ server_only: true,
43
+ value(cx) {
44
+ const page_reads = cx.page_reads;
45
+ if (!page_reads) return () => "null";
46
+ const clean = (id) => id.split("?")[0].split("\\").join("/");
47
+ const imports_kit_page = (ids) => ids.some((d) => KIT_PAGE_MODULE_RE.test(clean(d)));
48
+ const reads_itself = (id, info) => {
49
+ const c = clean(id);
50
+ const k = page_reads.keys(c);
51
+ if (k !== null) return k === "unknown" || k.size > 0;
52
+ if (KIT_PAGE_MODULE_RE.test(c)) return false;
53
+ return !!info && (imports_kit_page(info.importedIds) || imports_kit_page(info.dynamicallyImportedIds));
54
+ };
55
+ const ids_by_path = /* @__PURE__ */ new Map();
56
+ for (const id of cx.module_ids()) if (!id.startsWith("\0")) ids_by_path.set(clean(id), id);
57
+ const proven_clean = /* @__PURE__ */ new Set();
58
+ const reads = (root) => {
59
+ const seen = /* @__PURE__ */ new Set([root]);
60
+ const queue = [root];
61
+ for (let i = 0; i < queue.length; i++) {
62
+ const id = queue[i];
63
+ if (proven_clean.has(id)) continue;
64
+ const info = cx.graph(id);
65
+ if (reads_itself(id, info)) return true;
66
+ if (!info) continue;
67
+ for (const next of info.importedIds) if (!seen.has(next)) {
68
+ seen.add(next);
69
+ queue.push(next);
70
+ }
71
+ for (const next of info.dynamicallyImportedIds) if (!seen.has(next)) {
72
+ seen.add(next);
73
+ queue.push(next);
74
+ }
75
+ }
76
+ for (const id of seen) proven_clean.add(id);
77
+ return false;
78
+ };
79
+ const out = {};
80
+ for (const [iid, , reg] of server_regions(cx.program)) {
81
+ const root = reg.componentPath ? ids_by_path.get(clean(reg.componentPath)) : void 0;
82
+ out[iid] = root === void 0 ? true : reads(root);
83
+ }
84
+ const json = JSON.stringify(out);
85
+ return (quote) => in_literal(json, quote);
86
+ }
87
+ };
88
+ function in_literal(text, quote) {
89
+ let out = "";
90
+ for (const c of text) out += c === quote || quote === "`" && c === "$" ? `\\${c}` : LITERAL_ESCAPE.get(c) ?? c;
91
+ return out;
92
+ }
93
+ const server_map = (name) => ({
94
+ name: `server ${name}`,
95
+ token: SERVER_MAP_TOKENS[name],
96
+ server_only: true,
97
+ value(cx) {
98
+ const json = JSON.stringify(server_manifest_maps(cx.program, (iid) => cx.public_url(iid))[name]);
99
+ return (quote) => in_literal(json, quote);
100
+ }
101
+ });
102
+ const LATE_SERVER_REGIONS = {
103
+ name: "late server regions",
104
+ token: LATE_SERVER_REGIONS_TOKEN,
105
+ server_only: true,
106
+ value(cx) {
107
+ const from = path.posix.dirname(cx.chunk_file);
108
+ const object = `{${[...cx.late_server_regions].sort(by_key).map(([iid, ref]) => {
109
+ const rel = path.posix.relative(from, cx.file_name(ref));
110
+ const spec = rel.startsWith(".") ? rel : `./${rel}`;
111
+ return `${JSON.stringify(iid)}: () => import(${JSON.stringify(spec)})`;
112
+ }).join(", ")}}`;
113
+ return () => object;
114
+ }
115
+ };
116
+ /**
117
+ * Each lazy loader's own file (vite/lazy-files.ts): the path from the chunk being finished to the
118
+ * module's own chunk, or `null` when it has none (it shares a chunk with others: the bundler reads
119
+ * it out of that chunk's exports, which a plain import of the file would not).
120
+ */
121
+ const FILE = {
122
+ name: "lazy loader file",
123
+ token: FILE_TOKEN_MARK,
124
+ pattern: FILE_TOKEN_RE,
125
+ server_only: false,
126
+ mapped: true,
127
+ value(cx) {
128
+ return (_quote, hex) => {
129
+ const file = cx.facade_file(file_token_id(hex));
130
+ return file === void 0 ? "null" : JSON.stringify(relative_file(cx.chunk_file, file));
131
+ };
132
+ }
133
+ };
134
+ /**
135
+ * Values known only at the end of a leg. A virtual module loads before the bundler has transformed
136
+ * every module, so a value that needs every transform (which holes read `page.data`) is written as
137
+ * a token, and each finished chunk has its tokens replaced at renderChunk from the final records.
138
+ * A token is a string or an expression the bundler keeps, never a comment, which it drops before
139
+ * renderChunk. This table is every such token. A leg whose output still holds a token is said
140
+ * (`relocation_unpatched`). One value comes from a later leg: {@link WRITTEN_RELOCATIONS}.
141
+ */
142
+ const RELOCATIONS = [
143
+ PAGE_DATA_READS,
144
+ server_map("region_url"),
145
+ server_map("region_name"),
146
+ server_map("region_render"),
147
+ server_map("render_region"),
148
+ LATE_SERVER_REGIONS,
149
+ FILE
150
+ ];
151
+ /** The values a later leg writes into this leg's files after they were written. */
152
+ const WRITTEN_RELOCATIONS = [{
153
+ name: "island deps",
154
+ token: ISLAND_DEPS_INLINE_TOKEN,
155
+ server_only: true,
156
+ value(cx) {
157
+ const inline = in_any_literal(cx.island_deps);
158
+ return () => inline;
159
+ }
160
+ }];
161
+ /** The relocations a leg's chunks carry. */
162
+ const relocations_of = (server) => server ? RELOCATIONS : RELOCATIONS.filter((r) => !r.server_only);
163
+ /**
164
+ * Replace every token of `table` in a finished chunk (each found in the chunk as it was given),
165
+ * counting each patch into `counts` (by name). `null` when the chunk carries none. `mapped`: a
166
+ * `mapped` relocation patched it.
167
+ */
168
+ function relocate(code, table, counts, cx) {
169
+ let s = null;
170
+ let mapped = false;
171
+ for (const r of table) {
172
+ if (!code.includes(r.token)) continue;
173
+ const value = r.value(cx);
174
+ let n = 0;
175
+ const patch = (start, end, text) => {
176
+ s ??= new MagicString(code);
177
+ mapped ||= r.mapped === true;
178
+ if (text) s.overwrite(start, end, text);
179
+ else s.remove(start, end);
180
+ n++;
181
+ };
182
+ if (r.pattern) for (const m of code.matchAll(r.pattern)) patch(m.index, m.index + m[0].length, value(m[1], m[2]));
183
+ else for (let at = code.indexOf(r.token); at !== -1; at = code.indexOf(r.token, at + r.token.length)) patch(at, at + r.token.length, value(code[at - 1] ?? "", ""));
184
+ if (n) counts.set(r.name, (counts.get(r.name) ?? 0) + n);
185
+ }
186
+ return s === null ? null : {
187
+ s,
188
+ mapped
189
+ };
190
+ }
191
+ /** A relocation a leg's output left unpatched: a chunk still holds its token. */
192
+ function unpatched(server, chunks) {
193
+ const left = /* @__PURE__ */ new Set();
194
+ const own = relocations_of(server);
195
+ for (const chunk of chunks) for (const r of own) if (chunk.code.includes(r.token)) left.add(r);
196
+ return own.filter((r) => left.has(r));
197
+ }
198
+ export { FILE, RELOCATIONS, WRITTEN_RELOCATIONS, relocate, relocations_of, unpatched };
@@ -0,0 +1,38 @@
1
+ import { PreprocessCss, WalkResolve } from "../fouc-css.js";
2
+ import { AppSpecCtx } from "../app-spec.js";
3
+ import { ExportIndex } from "../exports/index.js";
4
+ export declare const ROUTER_CSS_KEY_PREFIX = "rcss:";
5
+ /** The handoff css-map key for one root component (posix-rel to the app root). */
6
+ export declare function router_css_key(root: string, abs: string): string;
7
+ /**
8
+ * The `.svelte` ROOTS of the app's router modules: BFS from every page module (`b.pageModules()`),
9
+ * through the app's own `.ts`/`.js` re-exports (barrels — resolved as build DATA by the app spec
10
+ * rule, imports untouched), collecting `.svelte` leaves. `module_specs` is the prescan's import-spec
11
+ * record (module abs path → its import/export-from specifiers). Sorted for determinism across legs.
12
+ */
13
+ export declare function router_css_roots(router_modules: ReadonlySet<string>, module_specs: ReadonlyMap<string, readonly string[]>, spec_ctx: AppSpecCtx, exists: (p: string) => boolean): string[];
14
+ /**
15
+ * Emit the `ogygia:server/router-css` source. Empty (`export {}`) when the app has no router
16
+ * modules — the router's dynamic import of this virtual then registers nothing, zero cost.
17
+ *
18
+ * Router routes are values rendered through `document()`, not Kit routes, so Kit never links their
19
+ * CSS. Each root (`router_css_roots`) is registered with a thunk for its stylesheet entries, and
20
+ * the router hands the components it renders to `componentCssHead()`, which claims them deduped
21
+ * with held-region links. Prod: each root is imported by absolute path (the module instance the
22
+ * router holds) and links the base plus its handoff hrefs. Dev: the compiled CSS is inlined as
23
+ * `path → entries` data with no component import, keyed by both the root-relative and the
24
+ * absolute path (svelte's dev filename metadata carries either), so Kit's dev style collector
25
+ * cannot crawl router trees into other pages.
26
+ */
27
+ export declare function router_css_module(roots: readonly string[], opts: {
28
+ root: string;
29
+ lib_dir: string;
30
+ is_dev: boolean;
31
+ read_file: (p: string) => string | null;
32
+ /** the plugin's CSS preprocessor: dev compiles a component as the build does */
33
+ preprocess?: PreprocessCss;
34
+ /** the bundler's resolver, for the dev tree-CSS walk (compiler/fouc-css.ts) */
35
+ resolve?: (spec: string, importer: string) => Promise<string | null>;
36
+ /** `resolve`'s export index */
37
+ exports?: ExportIndex<WalkResolve>;
38
+ }): Promise<string>;
@@ -0,0 +1,124 @@
1
+ import { collectFoucCssReachable, scoped_component_css } from "../fouc-css.js";
2
+ import { resolve_app_spec } from "../app-spec.js";
3
+ import path from "node:path";
4
+ import { dedent } from "@ogygia/core/contract";
5
+ // src/link/router-css.ts
6
+ const PATH_SEP = /[/\\]/;
7
+ const SVELTE_RE = /\.svelte$/;
8
+ const BARREL_RE = /\.(?:ts|js|mjs)$/;
9
+ const CSS_EXT_RE = /\.css$/;
10
+ const RESOLVE_SUFFIXES = [
11
+ "",
12
+ ".ts",
13
+ ".js",
14
+ ".mjs",
15
+ ".svelte",
16
+ "/index.ts",
17
+ "/index.js"
18
+ ];
19
+ const ROUTER_CSS_KEY_PREFIX = "rcss:";
20
+ const posix = (p) => p.split(PATH_SEP).join("/");
21
+ /** The handoff css-map key for one root component (posix-rel to the app root). */
22
+ function router_css_key(root, abs) {
23
+ return ROUTER_CSS_KEY_PREFIX + posix(path.relative(root, abs));
24
+ }
25
+ /**
26
+ * The `.svelte` ROOTS of the app's router modules: BFS from every page module (`b.pageModules()`),
27
+ * through the app's own `.ts`/`.js` re-exports (barrels — resolved as build DATA by the app spec
28
+ * rule, imports untouched), collecting `.svelte` leaves. `module_specs` is the prescan's import-spec
29
+ * record (module abs path → its import/export-from specifiers). Sorted for determinism across legs.
30
+ */
31
+ function router_css_roots(router_modules, module_specs, spec_ctx, exists) {
32
+ const roots = /* @__PURE__ */ new Set();
33
+ const visited = /* @__PURE__ */ new Set();
34
+ const resolve_spec = (spec, importer) => {
35
+ const base = resolve_app_spec(spec.split("?")[0], importer, spec_ctx);
36
+ if (!base) return null;
37
+ for (const suffix of RESOLVE_SUFFIXES) {
38
+ const candidate = path.normalize(base + suffix);
39
+ if (exists(candidate)) return candidate;
40
+ }
41
+ return null;
42
+ };
43
+ const visit = (mod) => {
44
+ if (visited.has(mod)) return;
45
+ visited.add(mod);
46
+ for (const spec of module_specs.get(mod) ?? []) {
47
+ const resolved = resolve_spec(spec, mod);
48
+ if (!resolved) continue;
49
+ if (SVELTE_RE.test(resolved)) roots.add(resolved);
50
+ else if (BARREL_RE.test(resolved)) visit(resolved);
51
+ }
52
+ };
53
+ for (const mod of router_modules) visit(mod);
54
+ return [...roots].sort();
55
+ }
56
+ /**
57
+ * Emit the `ogygia:server/router-css` source. Empty (`export {}`) when the app has no router
58
+ * modules — the router's dynamic import of this virtual then registers nothing, zero cost.
59
+ *
60
+ * Router routes are values rendered through `document()`, not Kit routes, so Kit never links their
61
+ * CSS. Each root (`router_css_roots`) is registered with a thunk for its stylesheet entries, and
62
+ * the router hands the components it renders to `componentCssHead()`, which claims them deduped
63
+ * with held-region links. Prod: each root is imported by absolute path (the module instance the
64
+ * router holds) and links the base plus its handoff hrefs. Dev: the compiled CSS is inlined as
65
+ * `path → entries` data with no component import, keyed by both the root-relative and the
66
+ * absolute path (svelte's dev filename metadata carries either), so Kit's dev style collector
67
+ * cannot crawl router trees into other pages.
68
+ */
69
+ async function router_css_module(roots, opts) {
70
+ if (roots.length === 0) return "export {};\n";
71
+ const lines = [`import { register_router_css } from 'ogygia/internal/register';`];
72
+ if (opts.is_dev) {
73
+ const assignments = [];
74
+ for (const abs of roots) {
75
+ const entries = [];
76
+ for (const e of await collectFoucCssReachable(abs, {
77
+ resolve: opts.resolve,
78
+ exports: opts.exports,
79
+ root: opts.root,
80
+ libDir: opts.lib_dir,
81
+ readFile: opts.read_file
82
+ })) {
83
+ const e_rel = posix(path.relative(opts.root, e.abs));
84
+ if (e.kind === "scoped") {
85
+ const source = opts.read_file(e.abs);
86
+ if (source == null) continue;
87
+ const css = await scoped_component_css(e.abs, source, opts.preprocess);
88
+ if (css) entries.push({
89
+ key: `rcss-dev:${e_rel}`,
90
+ css
91
+ });
92
+ } else {
93
+ if (!CSS_EXT_RE.test(e.abs)) continue;
94
+ const css = opts.read_file(e.abs);
95
+ if (css) entries.push({
96
+ key: `rcss-dev:${e_rel}`,
97
+ css
98
+ });
99
+ }
100
+ }
101
+ if (!entries.length) continue;
102
+ const abs_key = JSON.stringify(posix(abs));
103
+ const rel = posix(path.relative(opts.root, abs));
104
+ const keys = rel.startsWith("..") || path.isAbsolute(rel) ? [abs_key] : [abs_key, JSON.stringify(rel)];
105
+ assignments.push(`m[${keys.join("] = m[")}] = ${JSON.stringify(entries)};`);
106
+ }
107
+ return `${dedent`
108
+ import { register_router_css_paths } from 'ogygia/internal/register';
109
+ const m = {};
110
+ ${assignments.join("\n")}
111
+ register_router_css_paths(m);
112
+ `}\n`;
113
+ }
114
+ lines.push(`import { region_css } from 'ogygia:server/region-deps';`);
115
+ lines.push(`const base = typeof __SVELTEKIT_PATHS_BASE__ !== 'undefined' ? __SVELTEKIT_PATHS_BASE__ : '';`);
116
+ for (let i = 0; i < roots.length; i++) {
117
+ const abs = roots[i];
118
+ const key = router_css_key(opts.root, abs);
119
+ lines.push(`import __OgRcss${i} from ${JSON.stringify(abs)};`);
120
+ lines.push(`register_router_css(__OgRcss${i}, () => region_css(${JSON.stringify(key)}).map((h) => ({ key: h, href: base + h })));`);
121
+ }
122
+ return `${lines.join("\n")}\n`;
123
+ }
124
+ export { ROUTER_CSS_KEY_PREFIX, router_css_key, router_css_module, router_css_roots };
@@ -0,0 +1,103 @@
1
+ import { ClientRealmFile } from "./caps.js";
2
+ /**
3
+ * Runtime feature catalog — maps build-time marks → installable plugins.
4
+ * Module paths are absolute file URLs resolved by the Vite plugin against dist/src.
5
+ */
6
+ export type RuntimeMarks = {
7
+ /** When false/undefined, emit kitchen-sink (safe default). */
8
+ complete?: boolean;
9
+ hydrate?: string[];
10
+ defer?: string[];
11
+ persist?: boolean;
12
+ persistKeys?: string[];
13
+ router?: boolean;
14
+ live?: boolean;
15
+ morph?: boolean;
16
+ lakes?: boolean;
17
+ forms?: boolean;
18
+ wire?: boolean;
19
+ remoteSeeds?: boolean;
20
+ /** App imports an ogygia context provider (`Provide` / `setContext` / `createContext`). Set by the
21
+ * driver's import scan; gates the cross-island context bridge (~4.7 kB) out of apps that never
22
+ * provide context. Read-only providers (`getContext`) don't set it — there's nothing to bridge. */
23
+ context?: boolean;
24
+ /** Island code can reach Kit's page world: `$app/state` / `$app/stores` / `$app/navigation`
25
+ * (anything under `$app/` but `environment` and `paths`), or code the driver's island-closure walk
26
+ * cannot follow (a package, an unresolvable import), or a client plugin / federation that hands
27
+ * the runtime islands the walk never saw. Gates the page seed and the MPA navigation handle. */
28
+ page?: boolean;
29
+ /** The page can carry regions this build never compiled (federation: a peer's fragment brings its
30
+ * own islands, holes and lakes, at run time). Their kinds are unknown here, so every feature a
31
+ * region in the HTML can need is in: test/page-mark.test.ts › "foreign regions" (#909, #1931).
32
+ * Two are not: `wire` loads on use (`load_wire_codec`), and `wire-classes` loads only this
33
+ * build's own classes, which a peer's props never name. */
34
+ foreign?: boolean;
35
+ };
36
+ export type FeatureId = "remote-seeds" | "page" | "wire" | "wire-classes" | "frames" | "lakes" | "morph" | "live" | "interaction" | "forms" | "mpa-nav" | "router" | "context";
37
+ /**
38
+ * WHICH CHUNK a feature lives in. The runtime ships as two static, feature-sized phases:
39
+ *
40
+ * - `boot` — the runtime entry (`og-runtime.*.js`), loaded by the `<script>` in `<head>`. Defines
41
+ * `<ogygia-region>`, schedules wakes, fetches holes, morphs, routes. It must never reach Svelte:
42
+ * in a real app Svelte's client runtime is ONE shared chunk (~200 KB), and anything in the boot's
43
+ * static graph downloads first, ahead of the page's own LCP image, before any island needs it.
44
+ * - `hydrate` — the hydrate core (`runtime/hydrate-core.js`), loaded by the runtime's single existing
45
+ * `import()` when the first island wakes, together with Svelte (which `hydrate()` needs anyway). A
46
+ * feature whose slot only the hydrate core reads belongs here, installed as the chunk evaluates.
47
+ *
48
+ * Both phases are generated from the same marks, so each is exactly as big as the app needs; no
49
+ * feature adds a dynamic import of its own. `test/runtime-boot-svelte-free.test.ts` pins the boot.
50
+ */
51
+ export type FeaturePhase = "boot" | "hydrate";
52
+ export type FeatureDef = {
53
+ /** Path relative to `runtime/` (no leading ./). */
54
+ module: string;
55
+ deps: FeatureId[];
56
+ detect: (m: RuntimeMarks) => boolean;
57
+ /** Default `boot`. See {@link FeaturePhase}. */
58
+ phase?: FeaturePhase;
59
+ };
60
+ export declare const FEATURES: Record<FeatureId, FeatureDef>;
61
+ export declare const FEATURE_ORDER: FeatureId[];
62
+ /** Resolve the closed feature set for a marks manifest. */
63
+ export declare function resolveFeatures(marks: RuntimeMarks): FeatureId[];
64
+ /** The selected features of one {@link FeaturePhase}, in FEATURE_ORDER. */
65
+ export declare function phaseFeatures(marks: RuntimeMarks, phase: FeaturePhase): FeatureId[];
66
+ /**
67
+ * Emit the BOOT entry: core + the selected boot-phase features (see {@link FeaturePhase}). The
68
+ * entry boots and exports nothing.
69
+ * @param runtimeDir Absolute directory containing `core.js` + the feature modules.
70
+ * @param clientPlugins the plugins' browser halves, in plugin order
71
+ */
72
+ export declare function generateRuntimeEntrySource(marks: RuntimeMarks, runtimeDir: string, clientPlugins?: readonly ClientRealmFile[]): {
73
+ code: string;
74
+ features: FeatureId[];
75
+ };
76
+ /**
77
+ * Emit the HYDRATE-phase feature module (`ogygia:boot/hydrate-features`), which the hydrate core
78
+ * imports statically and installs as its chunk evaluates — so these features ride the hydrate core's
79
+ * one existing `import()`, sized by the same marks as the boot. `all` (dev / no marks): every one.
80
+ * @param runtimeDir Absolute directory containing the feature modules.
81
+ */
82
+ export declare function generateHydrateFeaturesSource(marks: RuntimeMarks, runtimeDir: string, all?: boolean): {
83
+ code: string;
84
+ features: FeatureId[];
85
+ };
86
+ /**
87
+ * Emit `ogygia:boot/runtime-flags`: build-time constants for code that lives INSIDE the always-on
88
+ * region element rather than in a feature module, because it works on the element's own state. The
89
+ * bundler inlines an imported `const` and drops the branches it switches off, so the code a flag
90
+ * guards ships exactly when the feature it serves does. Same marks as the entries; `all` (dev / no
91
+ * marks): every flag on.
92
+ *
93
+ * - `FRAMES`: the `frames` feature is in the build — some region streams HTML (a deferred hole, a
94
+ * live region, a lake). Without the frame store a region's fetch has nowhere to land, so the
95
+ * element's fetch / apply / morph / renew path is dead code then.
96
+ * - `load_wire_codec`: `null` where the `wire` feature (the codec) is in the build up front, else
97
+ * the codec's `import()`, for a wake whose props carry a live value the marks did not predict
98
+ * (core runtime/wire-on-use.ts). Generated here, not written in core, so a build with the codec
99
+ * has no `import()` of it in the boot's graph: that edge alone splits the boot's shared chunk in
100
+ * two (apps/palaestra/e2e/lazy-chunks.spec.ts, the boot-file budget).
101
+ * @param runtimeDir Absolute directory containing `core.js` + the feature modules.
102
+ */
103
+ export declare function generateRuntimeFlagsSource(marks: RuntimeMarks, runtimeDir: string, all?: boolean): string;
@@ -0,0 +1,183 @@
1
+ import { client_realms_source } from "./caps.js";
2
+ import { dedent } from "@ogygia/core/contract";
3
+ // src/link/runtime-entry.ts
4
+ const HYPHEN = /-/g;
5
+ const BACKSLASH = /\\/g;
6
+ const FEATURES = {
7
+ interaction: {
8
+ module: "interaction.js",
9
+ deps: [],
10
+ detect: (m) => m.foreign === true || (m.hydrate || []).some((w) => w !== "none")
11
+ },
12
+ forms: {
13
+ module: "form-continuity.js",
14
+ deps: [],
15
+ detect: (m) => m.forms === true || m.forms !== false && m.router === true
16
+ },
17
+ "mpa-nav": {
18
+ module: "nav-handle.js",
19
+ deps: [],
20
+ detect: (m) => m.page !== false
21
+ },
22
+ router: {
23
+ module: "router.js",
24
+ deps: [],
25
+ detect: (m) => m.router === true
26
+ },
27
+ lakes: {
28
+ module: "lakes.js",
29
+ deps: [],
30
+ detect: (m) => m.foreign === true || m.lakes === true || (m.hydrate || []).includes("none")
31
+ },
32
+ morph: {
33
+ module: "morph.js",
34
+ deps: [],
35
+ detect: (m) => m.foreign === true || m.live === true || m.morph === true || m.router === true || (m.defer || []).length > 0
36
+ },
37
+ live: {
38
+ module: "live.js",
39
+ deps: [],
40
+ phase: "hydrate",
41
+ detect: (m) => m.foreign === true || m.live === true || m.persist === true || (m.persistKeys || []).length > 0
42
+ },
43
+ wire: {
44
+ module: "../live-transport.js",
45
+ deps: [],
46
+ phase: "hydrate",
47
+ detect: (m) => m.wire === true
48
+ },
49
+ "wire-classes": {
50
+ module: "wire-classes.js",
51
+ deps: [],
52
+ detect: (m) => m.wire === true
53
+ },
54
+ "remote-seeds": {
55
+ module: "remote-seeds.js",
56
+ deps: [],
57
+ phase: "hydrate",
58
+ detect: (m) => m.remoteSeeds !== false
59
+ },
60
+ page: {
61
+ module: "seeds.js",
62
+ deps: [],
63
+ phase: "hydrate",
64
+ detect: (m) => m.page !== false
65
+ },
66
+ frames: {
67
+ module: "frames.js",
68
+ deps: [],
69
+ detect: (m) => m.foreign === true || (m.defer || []).length > 0 || m.live === true || m.morph === true || m.lakes === true
70
+ },
71
+ context: {
72
+ module: "context.js",
73
+ deps: [],
74
+ phase: "hydrate",
75
+ detect: (m) => m.foreign === true || m.context === true
76
+ }
77
+ };
78
+ const FEATURE_ORDER = [
79
+ "remote-seeds",
80
+ "page",
81
+ "wire",
82
+ "wire-classes",
83
+ "frames",
84
+ "lakes",
85
+ "morph",
86
+ "live",
87
+ "interaction",
88
+ "forms",
89
+ "mpa-nav",
90
+ "router",
91
+ "context"
92
+ ];
93
+ /** Resolve the closed feature set for a marks manifest. */
94
+ function resolveFeatures(marks) {
95
+ if (!marks.complete) return [...FEATURE_ORDER];
96
+ const selected = /* @__PURE__ */ new Set();
97
+ for (const id of FEATURE_ORDER) if (FEATURES[id].detect(marks)) selected.add(id);
98
+ let changed = true;
99
+ while (changed) {
100
+ changed = false;
101
+ for (const id of Array.from(selected)) for (const d of FEATURES[id].deps) if (!selected.has(d)) {
102
+ selected.add(d);
103
+ changed = true;
104
+ }
105
+ }
106
+ return FEATURE_ORDER.filter((id) => selected.has(id));
107
+ }
108
+ const to_alias = (id) => id.replace(HYPHEN, "_");
109
+ const runtime_path = (runtimeDir, mod) => `${runtimeDir}/${mod}`.replace(BACKSLASH, "/");
110
+ /** The selected features of one {@link FeaturePhase}, in FEATURE_ORDER. */
111
+ function phaseFeatures(marks, phase) {
112
+ return resolveFeatures(marks).filter((id) => (FEATURES[id].phase ?? "boot") === phase);
113
+ }
114
+ /**
115
+ * Emit the BOOT entry: core + the selected boot-phase features (see {@link FeaturePhase}). The
116
+ * entry boots and exports nothing.
117
+ * @param runtimeDir Absolute directory containing `core.js` + the feature modules.
118
+ * @param clientPlugins the plugins' browser halves, in plugin order
119
+ */
120
+ function generateRuntimeEntrySource(marks, runtimeDir, clientPlugins = []) {
121
+ const cp = client_realms_source(clientPlugins);
122
+ const features = phaseFeatures(marks, "boot");
123
+ const lines = [];
124
+ lines.push(`/** generated ogygia runtime — features: ${features.join(", ") || "(core only)"} */`);
125
+ lines.push(`import { boot } from ${JSON.stringify(runtime_path(runtimeDir, "core.js"))};`);
126
+ for (const id of features) lines.push(`import * as ${to_alias(id)} from ${JSON.stringify(runtime_path(runtimeDir, FEATURES[id].module))};`);
127
+ if (cp.imports) lines.push(cp.imports.slice(0, -1));
128
+ lines.push("");
129
+ lines.push("boot([");
130
+ for (const id of features) lines.push(` ${to_alias(id)}.install,`);
131
+ lines.push(cp.list ? `], ${cp.list});` : "]);");
132
+ return {
133
+ code: `${lines.join("\n")}\n`,
134
+ features
135
+ };
136
+ }
137
+ /**
138
+ * Emit the HYDRATE-phase feature module (`ogygia:boot/hydrate-features`), which the hydrate core
139
+ * imports statically and installs as its chunk evaluates — so these features ride the hydrate core's
140
+ * one existing `import()`, sized by the same marks as the boot. `all` (dev / no marks): every one.
141
+ * @param runtimeDir Absolute directory containing the feature modules.
142
+ */
143
+ function generateHydrateFeaturesSource(marks, runtimeDir, all = false) {
144
+ const features = all ? FEATURE_ORDER.filter((id) => FEATURES[id].phase === "hydrate") : phaseFeatures(marks, "hydrate");
145
+ const lines = [];
146
+ lines.push(`/** generated ogygia hydrate-phase features: ${features.join(", ") || "(none)"} */`);
147
+ for (const id of features) lines.push(`import * as ${to_alias(id)} from ${JSON.stringify(runtime_path(runtimeDir, FEATURES[id].module))};`);
148
+ lines.push("export function install() {");
149
+ for (const id of features) lines.push(` ${to_alias(id)}.install();`);
150
+ lines.push("}");
151
+ return {
152
+ code: `${lines.join("\n")}\n`,
153
+ features
154
+ };
155
+ }
156
+ /**
157
+ * Emit `ogygia:boot/runtime-flags`: build-time constants for code that lives INSIDE the always-on
158
+ * region element rather than in a feature module, because it works on the element's own state. The
159
+ * bundler inlines an imported `const` and drops the branches it switches off, so the code a flag
160
+ * guards ships exactly when the feature it serves does. Same marks as the entries; `all` (dev / no
161
+ * marks): every flag on.
162
+ *
163
+ * - `FRAMES`: the `frames` feature is in the build — some region streams HTML (a deferred hole, a
164
+ * live region, a lake). Without the frame store a region's fetch has nowhere to land, so the
165
+ * element's fetch / apply / morph / renew path is dead code then.
166
+ * - `load_wire_codec`: `null` where the `wire` feature (the codec) is in the build up front, else
167
+ * the codec's `import()`, for a wake whose props carry a live value the marks did not predict
168
+ * (core runtime/wire-on-use.ts). Generated here, not written in core, so a build with the codec
169
+ * has no `import()` of it in the boot's graph: that edge alone splits the boot's shared chunk in
170
+ * two (apps/palaestra/e2e/lazy-chunks.spec.ts, the boot-file budget).
171
+ * @param runtimeDir Absolute directory containing `core.js` + the feature modules.
172
+ */
173
+ function generateRuntimeFlagsSource(marks, runtimeDir, all = false) {
174
+ const features = resolveFeatures(marks);
175
+ const frames = all || features.includes("frames");
176
+ const codec = JSON.stringify(runtime_path(runtimeDir, FEATURES.wire.module));
177
+ const load_wire_codec = all || features.includes("wire") ? "null" : `() => import(${codec})`;
178
+ return `${dedent`
179
+ export const FRAMES = ${frames};
180
+ export const load_wire_codec = ${load_wire_codec};
181
+ `}\n`;
182
+ }
183
+ export { FEATURES, FEATURE_ORDER, generateHydrateFeaturesSource, generateRuntimeEntrySource, generateRuntimeFlagsSource, phaseFeatures, resolveFeatures };
@@ -0,0 +1,25 @@
1
+ import { Program, RegistryEntry } from "../program.js";
2
+ /** The SERVER regions (deferred / server-picked), sorted by id: what the server leg writes is a
3
+ * function of the set, never of the order hosts registered in (test/server-manifest-late-order.test.ts). */
4
+ export declare function server_regions(program: Program): Array<[string, string, RegistryEntry]>;
5
+ /** The SERVER-island ids the manifest carries right now (deferred / server-picked regions). */
6
+ export declare function server_island_ids(program: Program): string[];
7
+ /** The manifest's four maps, by export name. */
8
+ export type ServerManifestMaps = Record<"region_url" | "region_name" | "region_render" | "render_region", Record<string, string>>;
9
+ /** The manifest's maps from the program's registry; `url_for` names a region's CSS-key URL. */
10
+ export declare function server_manifest_maps(program: Program, url_for: (iid: string, virtual_path: string) => string): ServerManifestMaps;
11
+ /** The token a build writes for each map, inside a string literal the bundler cannot fold. */
12
+ export declare const SERVER_MAP_TOKENS: Record<keyof ServerManifestMaps, string>;
13
+ export declare function server_manifest_module(ssr: boolean, program: Program, is_dev: boolean, devUrlFor: (virtualPath: string) => string): string;
14
+ /** In a build's `server-regions`, the loaders of the regions found after it was written: an
15
+ * identifier no module defines, so the bundler keeps it as written (link/relocations.ts). */
16
+ export declare const LATE_SERVER_REGIONS_TOKEN = "__OGYGIA_LATE_SERVER_REGIONS__";
17
+ /** `ogygia:server/server-regions`: each SERVER island's loader, `id → () => import(entry)` (empty on
18
+ * the client). Imported only by the manifest's `load_islands()` — never statically. `late`: a
19
+ * build's, which names the loaders of regions found after it (`Program.server_regions_written`). */
20
+ export declare function server_regions_module(ssr: boolean, program: Program, late: boolean): string;
21
+ /** The token the build replaces with its answer (link/relocations.ts), inside a string literal the
22
+ * bundler cannot fold: a plain `null` placeholder was inlined into every reader as the constant it
23
+ * was (every hole then looked its page up). Unpatched it parses to nothing → `null`. */
24
+ export declare const PAGE_DATA_READS_TOKEN = "__OGYGIA_PAGE_DATA_READS__";
25
+ export declare const PAGE_DATA_READS_PLACEHOLDER: `(() => { try { return JSON.parse("${typeof PAGE_DATA_READS_TOKEN}"); } catch { return null; } })()`;