@ogygia/compiler 0.0.0 → 0.14.1
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.
- package/LICENSE +21 -0
- package/README.md +62 -1
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/app-spec.d.ts +18 -0
- package/dist/app-spec.js +22 -0
- package/dist/blank-styles.d.ts +1 -0
- package/dist/blank-styles.js +24 -0
- package/dist/bom.d.ts +2 -0
- package/dist/bom.js +7 -0
- package/dist/build-cache.d.ts +13 -0
- package/dist/build-cache.js +65 -0
- package/dist/ctx.d.ts +238 -0
- package/dist/ctx.js +221 -0
- package/dist/dev/css-scope.d.ts +16 -0
- package/dist/dev/css-scope.js +32 -0
- package/dist/dev/dev-hmr.d.ts +24 -0
- package/dist/dev/dev-hmr.js +51 -0
- package/dist/dev/hmr.d.ts +34 -0
- package/dist/dev/hmr.js +52 -0
- package/dist/driver.d.ts +351 -0
- package/dist/driver.js +1402 -0
- package/dist/exports/index.d.ts +77 -0
- package/dist/exports/index.js +349 -0
- package/dist/exports/parse.d.ts +65 -0
- package/dist/exports/parse.js +251 -0
- package/dist/fouc-css.d.ts +112 -0
- package/dist/fouc-css.js +314 -0
- package/dist/free-vars.d.ts +32 -0
- package/dist/free-vars.js +454 -0
- package/dist/fs.d.ts +31 -0
- package/dist/fs.js +82 -0
- package/dist/ids.d.ts +49 -0
- package/dist/ids.js +52 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +23 -0
- package/dist/kit.d.ts +204 -0
- package/dist/kit.js +554 -0
- package/dist/leg.d.ts +34 -0
- package/dist/leg.js +26 -0
- package/dist/link/analyses.d.ts +26 -0
- package/dist/link/analyses.js +237 -0
- package/dist/link/build-output.d.ts +47 -0
- package/dist/link/build-output.js +168 -0
- package/dist/link/caps.d.ts +32 -0
- package/dist/link/caps.js +39 -0
- package/dist/link/context-detect.d.ts +28 -0
- package/dist/link/context-detect.js +143 -0
- package/dist/link/emit-gate.d.ts +43 -0
- package/dist/link/emit-gate.js +55 -0
- package/dist/link/file-token.d.ts +11 -0
- package/dist/link/file-token.js +15 -0
- package/dist/link/island-deps.d.ts +183 -0
- package/dist/link/island-deps.js +802 -0
- package/dist/link/location-map.d.ts +24 -0
- package/dist/link/location-map.js +51 -0
- package/dist/link/own-reach.d.ts +15 -0
- package/dist/link/own-reach.js +188 -0
- package/dist/link/registry-stub.d.ts +50 -0
- package/dist/link/registry-stub.js +163 -0
- package/dist/link/relocations.d.ts +79 -0
- package/dist/link/relocations.js +204 -0
- package/dist/link/router-css.d.ts +38 -0
- package/dist/link/router-css.js +124 -0
- package/dist/link/runtime-entry.d.ts +103 -0
- package/dist/link/runtime-entry.js +183 -0
- package/dist/link/server-manifest.d.ts +25 -0
- package/dist/link/server-manifest.js +102 -0
- package/dist/link/transport.d.ts +42 -0
- package/dist/link/transport.js +91 -0
- package/dist/macros/dollar.d.ts +24 -0
- package/dist/macros/dollar.js +397 -0
- package/dist/macros/pipeline.d.ts +50 -0
- package/dist/macros/pipeline.js +133 -0
- package/dist/macros/source.d.ts +9 -0
- package/dist/macros/source.js +115 -0
- package/dist/macros/store.d.ts +22 -0
- package/dist/macros/store.js +217 -0
- package/dist/macros/wire.d.ts +17 -0
- package/dist/macros/wire.js +116 -0
- package/dist/map-chain.d.ts +18 -0
- package/dist/map-chain.js +42 -0
- package/dist/messages.d.ts +673 -0
- package/dist/messages.js +938 -0
- package/dist/ownership-stamps.d.ts +11 -0
- package/dist/ownership-stamps.js +112 -0
- package/dist/parse/oxc.d.ts +36 -0
- package/dist/parse/oxc.js +35 -0
- package/dist/parse/roots.d.ts +4 -0
- package/dist/parse/roots.js +27 -0
- package/dist/parse/scan.d.ts +65 -0
- package/dist/parse/scan.js +297 -0
- package/dist/parse/svelte-ast.d.ts +7 -0
- package/dist/parse/svelte-ast.js +99 -0
- package/dist/program.d.ts +140 -0
- package/dist/program.js +304 -0
- package/dist/queries.d.ts +105 -0
- package/dist/queries.js +326 -0
- package/dist/region/emit.d.ts +168 -0
- package/dist/region/emit.js +292 -0
- package/dist/region/identity.d.ts +32 -0
- package/dist/region/identity.js +46 -0
- package/dist/region/ir.d.ts +56 -0
- package/dist/region/ir.js +0 -0
- package/dist/region/marked-imports.d.ts +27 -0
- package/dist/region/marked-imports.js +265 -0
- package/dist/region/transform.d.ts +189 -0
- package/dist/region/transform.js +1565 -0
- package/dist/scan-facts.d.ts +36 -0
- package/dist/scan-facts.js +54 -0
- package/dist/script-request.d.ts +1 -0
- package/dist/script-request.js +33 -0
- package/dist/splice.d.ts +11 -0
- package/dist/splice.js +33 -0
- package/dist/transportables.d.ts +23 -0
- package/dist/transportables.js +144 -0
- package/dist/virtual/core.d.ts +158 -0
- package/dist/virtual/core.js +588 -0
- package/dist/virtual/resolver.d.ts +62 -0
- package/dist/virtual/resolver.js +265 -0
- package/dist/virtual/specifier.d.ts +10 -0
- package/dist/virtual/specifier.js +6 -0
- package/dist/virtual/table.d.ts +120 -0
- package/dist/virtual/table.js +54 -0
- package/dist/virtual/types.d.ts +17 -0
- package/dist/virtual/types.js +100 -0
- package/dist/virtual/value-names.d.ts +2 -0
- package/dist/virtual/value-names.js +18 -0
- package/dist/vite/definers.d.ts +16 -0
- package/dist/vite/definers.js +69 -0
- package/dist/vite/dev-maps.d.ts +34 -0
- package/dist/vite/dev-maps.js +91 -0
- package/dist/vite/index.d.ts +21 -0
- package/dist/vite/index.js +890 -0
- package/dist/vite/kit-dirs.d.ts +6 -0
- package/dist/vite/kit-dirs.js +53 -0
- package/dist/vite/late-island.d.ts +8 -0
- package/dist/vite/late-island.js +18 -0
- package/dist/vite/lazy-files.d.ts +2 -0
- package/dist/vite/lazy-files.js +72 -0
- package/dist/vite/options.d.ts +195 -0
- package/dist/vite/options.js +72 -0
- package/dist/vite/package-files.d.ts +3 -0
- package/dist/vite/package-files.js +88 -0
- package/dist/vite/paths.d.ts +16 -0
- package/dist/vite/paths.js +39 -0
- package/dist/vite/plugin-api.d.ts +316 -0
- package/dist/vite/plugin-api.js +328 -0
- package/dist/vite/route-watch.d.ts +15 -0
- package/dist/vite/route-watch.js +32 -0
- package/dist/vite/session.d.ts +28 -0
- package/dist/vite/session.js +43 -0
- package/dist/vite/sourcemaps.d.ts +19 -0
- package/dist/vite/sourcemaps.js +75 -0
- package/dist/vite/style-preprocess.d.ts +2 -0
- package/dist/vite/style-preprocess.js +84 -0
- package/dist/vite/svelte-entries.d.ts +4 -0
- package/dist/vite/svelte-entries.js +10 -0
- package/dist/vite/svelte-options.d.ts +20 -0
- package/dist/vite/svelte-options.js +22 -0
- package/package.json +87 -12
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// src/link/analyses.ts
|
|
2
|
+
/** The open issue that tracks every analysis with no oracle yet. */
|
|
3
|
+
const ORACLE_GAPS = 1489;
|
|
4
|
+
const ANALYSES = [
|
|
5
|
+
{
|
|
6
|
+
name: "seed_keys",
|
|
7
|
+
predicts: "the page.data keys an island's client code reads",
|
|
8
|
+
direction: "over",
|
|
9
|
+
fallback: "'unknown' (the whole page.data ships; all of it without dataShake())",
|
|
10
|
+
where: {
|
|
11
|
+
file: "data-shake/src/analysis.ts",
|
|
12
|
+
symbol: "page_data_keys_answer"
|
|
13
|
+
},
|
|
14
|
+
gap: null
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "hole_reads_page",
|
|
18
|
+
predicts: "whether a server hole's tree reads page.data",
|
|
19
|
+
direction: "over",
|
|
20
|
+
fallback: "true (the hole looks page.data up)",
|
|
21
|
+
where: {
|
|
22
|
+
file: "compiler/src/link/relocations.ts",
|
|
23
|
+
symbol: "PAGE_DATA_READS"
|
|
24
|
+
},
|
|
25
|
+
gap: ORACLE_GAPS
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "island_reads_page",
|
|
29
|
+
predicts: "whether an island's code reaches Kit's page world",
|
|
30
|
+
direction: "over",
|
|
31
|
+
fallback: "a reader (the page shim is linked)",
|
|
32
|
+
where: {
|
|
33
|
+
file: "compiler/src/driver.ts",
|
|
34
|
+
symbol: "mark_island_closure"
|
|
35
|
+
},
|
|
36
|
+
gap: ORACLE_GAPS
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "wire_crossing",
|
|
40
|
+
predicts: "whether the server encodes a live value into an island's props",
|
|
41
|
+
direction: "over",
|
|
42
|
+
fallback: "none in the build; the codec loads on use (#1306)",
|
|
43
|
+
where: {
|
|
44
|
+
file: "compiler/src/region/transform.ts",
|
|
45
|
+
symbol: "hasWireCrossing"
|
|
46
|
+
},
|
|
47
|
+
gap: ORACLE_GAPS
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "transportable",
|
|
51
|
+
predicts: "which modules define wire classes (loaders, eager list, the wire mark)",
|
|
52
|
+
direction: "over",
|
|
53
|
+
fallback: "true (the module counts)",
|
|
54
|
+
where: {
|
|
55
|
+
file: "compiler/src/transportables.ts",
|
|
56
|
+
symbol: "moduleHasTransportable"
|
|
57
|
+
},
|
|
58
|
+
gap: null
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "context_mark",
|
|
62
|
+
predicts: "whether the app provides ogygia context (the bridge feature)",
|
|
63
|
+
direction: "over",
|
|
64
|
+
fallback: "all: a form the walk cannot narrow reaches every export",
|
|
65
|
+
where: {
|
|
66
|
+
file: "compiler/src/link/own-reach.ts",
|
|
67
|
+
symbol: "reaches_context"
|
|
68
|
+
},
|
|
69
|
+
gap: ORACLE_GAPS
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "crosses_kit_wire",
|
|
73
|
+
predicts: "whether Kit's transport must carry ogygia codecs",
|
|
74
|
+
direction: "over",
|
|
75
|
+
fallback: "all: a form the walk cannot narrow reaches every export",
|
|
76
|
+
where: {
|
|
77
|
+
file: "compiler/src/link/own-reach.ts",
|
|
78
|
+
symbol: "reaches_wire"
|
|
79
|
+
},
|
|
80
|
+
gap: ORACLE_GAPS
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: "route_csr",
|
|
84
|
+
predicts: "Kit's csr for a route option file",
|
|
85
|
+
direction: "exact",
|
|
86
|
+
fallback: "undefined (Kit's default)",
|
|
87
|
+
where: {
|
|
88
|
+
file: "compiler/src/kit.ts",
|
|
89
|
+
symbol: "read_csr"
|
|
90
|
+
},
|
|
91
|
+
gap: null
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "route_config",
|
|
95
|
+
predicts: "each page's merged route config",
|
|
96
|
+
direction: "exact",
|
|
97
|
+
fallback: "no keys",
|
|
98
|
+
where: {
|
|
99
|
+
file: "compiler/src/kit.ts",
|
|
100
|
+
symbol: "page_route_config"
|
|
101
|
+
},
|
|
102
|
+
gap: ORACLE_GAPS
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "free_vars",
|
|
106
|
+
predicts: "the names a portable snippet must import or receive",
|
|
107
|
+
direction: "over",
|
|
108
|
+
fallback: "none: an unseen name is a miss",
|
|
109
|
+
where: {
|
|
110
|
+
file: "compiler/src/free-vars.ts",
|
|
111
|
+
symbol: "collectCaptureInfo"
|
|
112
|
+
},
|
|
113
|
+
gap: ORACLE_GAPS
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: "dollar_captures",
|
|
117
|
+
predicts: "the names a hoisted og.$ factory closes over",
|
|
118
|
+
direction: "exact",
|
|
119
|
+
fallback: "none: a wrong capture throws at the site",
|
|
120
|
+
where: {
|
|
121
|
+
file: "compiler/src/macros/dollar.ts",
|
|
122
|
+
symbol: "rewrite_dollar"
|
|
123
|
+
},
|
|
124
|
+
gap: ORACLE_GAPS
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: "barrel_pure",
|
|
128
|
+
predicts: "a barrel import can be dropped",
|
|
129
|
+
direction: "under",
|
|
130
|
+
fallback: "impure (the import stays)",
|
|
131
|
+
where: {
|
|
132
|
+
file: "compiler/src/exports/parse.ts",
|
|
133
|
+
symbol: "analyze_exports"
|
|
134
|
+
},
|
|
135
|
+
gap: ORACLE_GAPS
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "export_walk",
|
|
139
|
+
predicts: "the module each exported name comes from (and the walk ends)",
|
|
140
|
+
direction: "exact",
|
|
141
|
+
fallback: "no map (the import stays as written)",
|
|
142
|
+
where: {
|
|
143
|
+
file: "compiler/src/exports/index.ts",
|
|
144
|
+
symbol: "Walk"
|
|
145
|
+
},
|
|
146
|
+
gap: ORACLE_GAPS
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: "css_reach",
|
|
150
|
+
predicts: "the CSS a lake, hole, router page or content module needs",
|
|
151
|
+
direction: "over",
|
|
152
|
+
fallback: "none: an unseen stylesheet is a miss",
|
|
153
|
+
where: {
|
|
154
|
+
file: "compiler/src/fouc-css.ts",
|
|
155
|
+
symbol: "collectFoucCssReachable"
|
|
156
|
+
},
|
|
157
|
+
gap: ORACLE_GAPS
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
name: "ownership_stamps",
|
|
161
|
+
predicts: "the elements Svelte hydration never walks",
|
|
162
|
+
direction: "under",
|
|
163
|
+
fallback: "no stamps",
|
|
164
|
+
where: {
|
|
165
|
+
file: "compiler/src/ownership-stamps.ts",
|
|
166
|
+
symbol: "stamp_opaque"
|
|
167
|
+
},
|
|
168
|
+
gap: ORACLE_GAPS
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
name: "csr_true_degrade",
|
|
172
|
+
predicts: "which regions Kit owns on a csr=true page",
|
|
173
|
+
direction: "exact",
|
|
174
|
+
fallback: "none",
|
|
175
|
+
where: {
|
|
176
|
+
file: "compiler/src/region/transform.ts",
|
|
177
|
+
symbol: "#kit_owns"
|
|
178
|
+
},
|
|
179
|
+
gap: ORACLE_GAPS
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
name: "registry_reach",
|
|
183
|
+
predicts: "whether a csr=false route edge reaches a region registry",
|
|
184
|
+
direction: "over",
|
|
185
|
+
fallback: "reaches (the full registry stays in the graph)",
|
|
186
|
+
where: {
|
|
187
|
+
file: "compiler/src/driver.ts",
|
|
188
|
+
symbol: "#reaches_registry"
|
|
189
|
+
},
|
|
190
|
+
gap: ORACLE_GAPS
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
name: "emit_gate",
|
|
194
|
+
predicts: "the islands whose host the server bundle loads",
|
|
195
|
+
direction: "over",
|
|
196
|
+
fallback: "every island (no handoff emits all)",
|
|
197
|
+
where: {
|
|
198
|
+
file: "compiler/src/link/emit-gate.ts",
|
|
199
|
+
symbol: "island_host_loaded"
|
|
200
|
+
},
|
|
201
|
+
gap: ORACLE_GAPS
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: "island_remotes",
|
|
205
|
+
predicts: "the remote seeds and page seed each island needs",
|
|
206
|
+
direction: "over",
|
|
207
|
+
fallback: "all (no map fails open)",
|
|
208
|
+
where: {
|
|
209
|
+
file: "compiler/src/link/island-deps.ts",
|
|
210
|
+
symbol: "collectIslandDepModulepreloads"
|
|
211
|
+
},
|
|
212
|
+
gap: ORACLE_GAPS
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: "runtime_features",
|
|
216
|
+
predicts: "the runtime features a page needs",
|
|
217
|
+
direction: "over",
|
|
218
|
+
fallback: "every feature (incomplete marks ship the full runtime)",
|
|
219
|
+
where: {
|
|
220
|
+
file: "compiler/src/link/runtime-entry.ts",
|
|
221
|
+
symbol: "resolveFeatures"
|
|
222
|
+
},
|
|
223
|
+
gap: ORACLE_GAPS
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: "region_options",
|
|
227
|
+
predicts: "the region config an import attribute or option asks for",
|
|
228
|
+
direction: "exact",
|
|
229
|
+
fallback: "a build error naming the option",
|
|
230
|
+
where: {
|
|
231
|
+
file: "compiler/src/region/transform.ts",
|
|
232
|
+
symbol: "transformHost"
|
|
233
|
+
},
|
|
234
|
+
gap: ORACLE_GAPS
|
|
235
|
+
}
|
|
236
|
+
];
|
|
237
|
+
export { ANALYSES, ORACLE_GAPS };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SECRET-SPLIT, checked on the finished CLIENT bundle (internal/notes/INVARIANTS.md): no chunk or
|
|
3
|
+
* asset holds a signing secret (`OGYGIA_SECRET`, the build's own key), and no chunk holds a module
|
|
4
|
+
* that signs. Whatever put one there, the browser could then mint capabilities: the build fails.
|
|
5
|
+
* `secrets` shorter than 16 characters are not looked for (too likely to match by chance; a
|
|
6
|
+
* production `OGYGIA_SECRET` that short is refused earlier).
|
|
7
|
+
*/
|
|
8
|
+
export declare function refuse_client_secrets(bundle: Record<string, unknown>, secrets: readonly string[]): void;
|
|
9
|
+
/**
|
|
10
|
+
* Write the island-deps handoff JSON (the map SSR reads at render): the stable path under Kit's
|
|
11
|
+
* `outDir` (`.svelte-kit` unless the app configured `kit.outDir`), an adapter-friendly copy next
|
|
12
|
+
* to the server bundle, AND an in-place inline into every server chunk that carries the token slot
|
|
13
|
+
* — inlining is what makes it survive serverless tracing (@vercel/nft only bundles *imported*
|
|
14
|
+
* files, not runtime fs reads, so the co-located JSON is dropped there; that is why held/dual
|
|
15
|
+
* regions that cross the wire rendered unstyled on Vercel/Netlify). Unpatched builds keep the fs
|
|
16
|
+
* fallback (adapter-node, dev-preview).
|
|
17
|
+
*/
|
|
18
|
+
export declare function emit_island_deps_handoff(root: string, json: string, out_dir: string, counts: Map<string, number>): void;
|
|
19
|
+
/**
|
|
20
|
+
* SEED SHAPING report (client `writeBundle`): which islands read `page.data` through the shim, how
|
|
21
|
+
* many keys they were pinned to, and — the actionable part — the modules whose reads could not be
|
|
22
|
+
* pinned, each with its line and why, since one such module makes every page carrying that island
|
|
23
|
+
* ship its whole `page.data`. Same shape as the barrels report: a few lines, a count for the rest.
|
|
24
|
+
*
|
|
25
|
+
* @param reason_of a module (query-less id) → why its reads could not be pinned (the seed-shaping
|
|
26
|
+
* plugin's `why`)
|
|
27
|
+
* @param file_of an entry's identity (the maps' key) → its emitted file; absent → the key is the
|
|
28
|
+
* file (a bundle from before content hashing)
|
|
29
|
+
*/
|
|
30
|
+
export declare function report_seed_shaping(map: {
|
|
31
|
+
page: Record<string, boolean>;
|
|
32
|
+
page_keys: Record<string, string[] | null>;
|
|
33
|
+
}, bundle: Record<string, {
|
|
34
|
+
type: string;
|
|
35
|
+
moduleIds?: string[];
|
|
36
|
+
imports?: string[];
|
|
37
|
+
}>, reason_of: (module: string) => {
|
|
38
|
+
why: string;
|
|
39
|
+
line: number | null;
|
|
40
|
+
} | null, root: string, file_of?: (identity: string) => string): Record<string, SeedWhy[]>;
|
|
41
|
+
/** a module that made an island ship all of `page.data`: where (root-relative when inside the app)
|
|
42
|
+
* and why — what the profiler points at when the island's own file reads nothing whole */
|
|
43
|
+
export interface SeedWhy {
|
|
44
|
+
file: string;
|
|
45
|
+
line: number | null;
|
|
46
|
+
why: string;
|
|
47
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { islandDepsHandoffPath } from "./island-deps.js";
|
|
2
|
+
import { WRITTEN_RELOCATIONS, relocate } from "./relocations.js";
|
|
3
|
+
import { OgygiaError, line } from "../messages.js";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
// src/link/build-output.ts
|
|
7
|
+
const SECRET_MODULE_RE = /[\\/](?:src|dist)[\\/]server[\\/](?:hmac|signing-key)\.[jt]s$/;
|
|
8
|
+
const ESCAPE_G = /\\(?:x([0-9a-fA-F]{2})|u\{([0-9a-fA-F]{1,6})\}|u([0-9a-fA-F]{4})|([\s\S]))/g;
|
|
9
|
+
const SINGLE_ESCAPES = {
|
|
10
|
+
n: "\n",
|
|
11
|
+
r: "\r",
|
|
12
|
+
t: " ",
|
|
13
|
+
b: "\b",
|
|
14
|
+
f: "\f",
|
|
15
|
+
v: "\v",
|
|
16
|
+
"0": "\0",
|
|
17
|
+
"\n": ""
|
|
18
|
+
};
|
|
19
|
+
function unescaped(text) {
|
|
20
|
+
if (!text.includes("\\")) return text;
|
|
21
|
+
return text.replace(ESCAPE_G, (_m, x, cp, u, c) => {
|
|
22
|
+
if (x !== void 0) return String.fromCharCode(parseInt(x, 16));
|
|
23
|
+
if (cp !== void 0) {
|
|
24
|
+
const n = parseInt(cp, 16);
|
|
25
|
+
return n <= 1114111 ? String.fromCodePoint(n) : "";
|
|
26
|
+
}
|
|
27
|
+
if (u !== void 0) return String.fromCharCode(parseInt(u, 16));
|
|
28
|
+
return SINGLE_ESCAPES[c] ?? c;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* SECRET-SPLIT, checked on the finished CLIENT bundle (internal/notes/INVARIANTS.md): no chunk or
|
|
33
|
+
* asset holds a signing secret (`OGYGIA_SECRET`, the build's own key), and no chunk holds a module
|
|
34
|
+
* that signs. Whatever put one there, the browser could then mint capabilities: the build fails.
|
|
35
|
+
* `secrets` shorter than 16 characters are not looked for (too likely to match by chance; a
|
|
36
|
+
* production `OGYGIA_SECRET` that short is refused earlier).
|
|
37
|
+
*/
|
|
38
|
+
function refuse_client_secrets(bundle, secrets) {
|
|
39
|
+
const sought = secrets.filter((s) => s.length >= 16);
|
|
40
|
+
for (const [key, out] of Object.entries(bundle)) {
|
|
41
|
+
const o = out;
|
|
42
|
+
const file = o.fileName ?? key;
|
|
43
|
+
let text = typeof o.source === "string" ? o.source : "";
|
|
44
|
+
if (o.type === "chunk") text = o.code;
|
|
45
|
+
const read = text ? unescaped(text) : "";
|
|
46
|
+
if (text && sought.some((s) => text.includes(s) || read.includes(s))) throw new OgygiaError("secret_in_client_chunk", {
|
|
47
|
+
file,
|
|
48
|
+
what: "a signing secret"
|
|
49
|
+
});
|
|
50
|
+
const signer = o.type === "chunk" ? o.moduleIds?.find((id) => SECRET_MODULE_RE.test(id)) : void 0;
|
|
51
|
+
if (signer) throw new OgygiaError("secret_in_client_chunk", {
|
|
52
|
+
file,
|
|
53
|
+
what: `the server module ${path.basename(signer)}`
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Write the island-deps handoff JSON (the map SSR reads at render): the stable path under Kit's
|
|
59
|
+
* `outDir` (`.svelte-kit` unless the app configured `kit.outDir`), an adapter-friendly copy next
|
|
60
|
+
* to the server bundle, AND an in-place inline into every server chunk that carries the token slot
|
|
61
|
+
* — inlining is what makes it survive serverless tracing (@vercel/nft only bundles *imported*
|
|
62
|
+
* files, not runtime fs reads, so the co-located JSON is dropped there; that is why held/dual
|
|
63
|
+
* regions that cross the wire rendered unstyled on Vercel/Netlify). Unpatched builds keep the fs
|
|
64
|
+
* fallback (adapter-node, dev-preview).
|
|
65
|
+
*/
|
|
66
|
+
function emit_island_deps_handoff(root, json, out_dir, counts) {
|
|
67
|
+
const handoff = islandDepsHandoffPath(out_dir);
|
|
68
|
+
fs.mkdirSync(path.dirname(handoff), { recursive: true });
|
|
69
|
+
fs.writeFileSync(handoff, json);
|
|
70
|
+
const server_copy = path.join(out_dir, "output", "server", "og-region-deps.json");
|
|
71
|
+
try {
|
|
72
|
+
fs.mkdirSync(path.dirname(server_copy), { recursive: true });
|
|
73
|
+
fs.writeFileSync(server_copy, json);
|
|
74
|
+
} catch {}
|
|
75
|
+
try {
|
|
76
|
+
const server_dir = path.join(out_dir, "output", "server");
|
|
77
|
+
const cx = { island_deps: json };
|
|
78
|
+
const patch_server = (dir) => {
|
|
79
|
+
let entries;
|
|
80
|
+
try {
|
|
81
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
82
|
+
} catch {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
for (const e of entries) {
|
|
86
|
+
const full = path.join(dir, e.name);
|
|
87
|
+
if (e.isDirectory()) {
|
|
88
|
+
patch_server(full);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (!e.name.endsWith(".js")) continue;
|
|
92
|
+
let code;
|
|
93
|
+
try {
|
|
94
|
+
code = fs.readFileSync(full, "utf8");
|
|
95
|
+
} catch {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const patched = relocate(code, WRITTEN_RELOCATIONS, counts, cx);
|
|
99
|
+
if (patched) fs.writeFileSync(full, patched.s.toString());
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
patch_server(server_dir);
|
|
103
|
+
} catch {}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* SEED SHAPING report (client `writeBundle`): which islands read `page.data` through the shim, how
|
|
107
|
+
* many keys they were pinned to, and — the actionable part — the modules whose reads could not be
|
|
108
|
+
* pinned, each with its line and why, since one such module makes every page carrying that island
|
|
109
|
+
* ship its whole `page.data`. Same shape as the barrels report: a few lines, a count for the rest.
|
|
110
|
+
*
|
|
111
|
+
* @param reason_of a module (query-less id) → why its reads could not be pinned (the seed-shaping
|
|
112
|
+
* plugin's `why`)
|
|
113
|
+
* @param file_of an entry's identity (the maps' key) → its emitted file; absent → the key is the
|
|
114
|
+
* file (a bundle from before content hashing)
|
|
115
|
+
*/
|
|
116
|
+
function report_seed_shaping(map, bundle, reason_of, root, file_of = (identity) => identity) {
|
|
117
|
+
const why_of = {};
|
|
118
|
+
const readers = Object.keys(map.page).filter((e) => map.page[e]);
|
|
119
|
+
if (!readers.length) return why_of;
|
|
120
|
+
const pinned = readers.filter((e) => Array.isArray(map.page_keys[e]));
|
|
121
|
+
const unpinned = readers.filter((e) => !Array.isArray(map.page_keys[e]));
|
|
122
|
+
const key_count = new Set(pinned.flatMap((e) => map.page_keys[e] ?? [])).size;
|
|
123
|
+
const rel = (p) => p.startsWith(root) ? p.slice(root.length).replace(/^\//, "") : p;
|
|
124
|
+
const lines = [];
|
|
125
|
+
lines.push(line("page_seed_report", {
|
|
126
|
+
islands: readers.length,
|
|
127
|
+
pinned: pinned.length,
|
|
128
|
+
keys: key_count,
|
|
129
|
+
unpinned: unpinned.length
|
|
130
|
+
}));
|
|
131
|
+
if (unpinned.length) {
|
|
132
|
+
const closure = (entry) => {
|
|
133
|
+
const seen = /* @__PURE__ */ new Set();
|
|
134
|
+
const queue = [file_of(entry).replace(/^\//, "")];
|
|
135
|
+
while (queue.length) {
|
|
136
|
+
const f = queue.pop();
|
|
137
|
+
if (seen.has(f)) continue;
|
|
138
|
+
seen.add(f);
|
|
139
|
+
for (const i of bundle[f]?.imports ?? []) queue.push(i);
|
|
140
|
+
}
|
|
141
|
+
return seen;
|
|
142
|
+
};
|
|
143
|
+
const blamed = /* @__PURE__ */ new Map();
|
|
144
|
+
for (const e of unpinned) {
|
|
145
|
+
const own = /* @__PURE__ */ new Set();
|
|
146
|
+
for (const chunk of closure(e)) for (const id of bundle[chunk]?.moduleIds ?? []) {
|
|
147
|
+
const clean = id.split("?")[0].split("\\").join("/");
|
|
148
|
+
const r = reason_of(clean);
|
|
149
|
+
if (!r) continue;
|
|
150
|
+
if (!blamed.has(clean)) blamed.set(clean, r);
|
|
151
|
+
if (own.has(clean)) continue;
|
|
152
|
+
own.add(clean);
|
|
153
|
+
(why_of[e] ??= []).push({
|
|
154
|
+
file: rel(clean),
|
|
155
|
+
line: r.line,
|
|
156
|
+
why: r.why
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const rows = [...blamed].slice(0, 8);
|
|
161
|
+
for (const [file, r] of rows) lines.push(` ${rel(file)}${r.line === null ? "" : `:${r.line}`} — ${r.why}`);
|
|
162
|
+
if (blamed.size > rows.length) lines.push(` … and ${blamed.size - rows.length} more module${blamed.size - rows.length === 1 ? "" : "s"}`);
|
|
163
|
+
if (!blamed.size) lines.push(` (read through code the build never saw — a dependency, or a foreign fragment)`);
|
|
164
|
+
}
|
|
165
|
+
console.log(lines.join("\n"));
|
|
166
|
+
return why_of;
|
|
167
|
+
}
|
|
168
|
+
export { emit_island_deps_handoff, refuse_client_secrets, report_seed_shaping };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Routes } from "../kit.js";
|
|
2
|
+
/** One plugin's server realm, as the build wires it. */
|
|
3
|
+
export interface ServerRealm {
|
|
4
|
+
/** the plugin's (package) name */
|
|
5
|
+
name: string;
|
|
6
|
+
/** the realm module's absolute POSIX path (the plugin's `server`) */
|
|
7
|
+
module: string;
|
|
8
|
+
/** the plugin's options (JSON) */
|
|
9
|
+
options: unknown;
|
|
10
|
+
}
|
|
11
|
+
/** A plugin's browser realm, as the boot entry imports it. */
|
|
12
|
+
export interface ClientRealmFile {
|
|
13
|
+
/** the plugin's (package) name */
|
|
14
|
+
name: string;
|
|
15
|
+
/** the realm module's absolute POSIX path (the plugin's `client`) */
|
|
16
|
+
module: string;
|
|
17
|
+
}
|
|
18
|
+
/** The boot entry's plugin list (`[{ name, client }, …]`) and the imports it names, in plugin order. */
|
|
19
|
+
export declare function client_realms_source(clients: readonly ClientRealmFile[]): {
|
|
20
|
+
imports: string;
|
|
21
|
+
list: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* `server-plugins` — SERVER only: each plugin's server half, one static import per plugin, in the
|
|
25
|
+
* order the app listed them. The handle runs their stages straight off this list; an app with no
|
|
26
|
+
* plugins gets an empty one (and the client always does).
|
|
27
|
+
*/
|
|
28
|
+
export declare function server_plugins_module(ssr: boolean, realms: readonly ServerRealm[]): string;
|
|
29
|
+
/** `route-config` — SERVER only: every Kit page route id → the keys the plugins claim inside Kit's
|
|
30
|
+
* `config` page option, merged the way Kit merges it (a key no level sets is absent). Empty on the
|
|
31
|
+
* client, and when no plugin claims a key: the route list never ships to the browser. */
|
|
32
|
+
export declare function route_config_module(ssr: boolean, routes: Routes, routesDir: string, keys: readonly string[]): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { page_route_config } from "../kit.js";
|
|
2
|
+
import { dedent } from "@ogygia/core/contract";
|
|
3
|
+
// src/link/caps.ts
|
|
4
|
+
/** The boot entry's plugin list (`[{ name, client }, …]`) and the imports it names, in plugin order. */
|
|
5
|
+
function client_realms_source(clients) {
|
|
6
|
+
if (!clients.length) return {
|
|
7
|
+
imports: "",
|
|
8
|
+
list: ""
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
imports: clients.map((c, i) => `import __og_client_${i} from ${JSON.stringify(c.module)};\n`).join(""),
|
|
12
|
+
list: `[${clients.map((c, i) => `{ name: ${JSON.stringify(c.name)}, client: __og_client_${i} }`).join(", ")}]`
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `server-plugins` — SERVER only: each plugin's server half, one static import per plugin, in the
|
|
17
|
+
* order the app listed them. The handle runs their stages straight off this list; an app with no
|
|
18
|
+
* plugins gets an empty one (and the client always does).
|
|
19
|
+
*/
|
|
20
|
+
function server_plugins_module(ssr, realms) {
|
|
21
|
+
if (!ssr || realms.length === 0) return `export const plugins = [];`;
|
|
22
|
+
const imports = realms.map((r, i) => `import p${i} from ${JSON.stringify(r.module)};`).join("\n");
|
|
23
|
+
const list = realms.map((r, i) => `{ name: ${JSON.stringify(r.name)}, options: ${JSON.stringify(r.options)}, server: p${i} }`).join(",\n ");
|
|
24
|
+
return dedent`
|
|
25
|
+
${imports}
|
|
26
|
+
|
|
27
|
+
export const plugins = [
|
|
28
|
+
${list}
|
|
29
|
+
];
|
|
30
|
+
`;
|
|
31
|
+
}
|
|
32
|
+
/** `route-config` — SERVER only: every Kit page route id → the keys the plugins claim inside Kit's
|
|
33
|
+
* `config` page option, merged the way Kit merges it (a key no level sets is absent). Empty on the
|
|
34
|
+
* client, and when no plugin claims a key: the route list never ships to the browser. */
|
|
35
|
+
function route_config_module(ssr, routes, routesDir, keys) {
|
|
36
|
+
if (!ssr || keys.length === 0) return `export const route_config = {};`;
|
|
37
|
+
return `export const route_config = ${JSON.stringify(page_route_config(routes, routesDir, keys))};`;
|
|
38
|
+
}
|
|
39
|
+
export { client_realms_source, route_config_module, server_plugins_module };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** The context keys a file READS via getContext and SETS via setContext, each by the name it crosses
|
|
2
|
+
* under (`key_name`), and the one-off `Symbol()` keys ogygia's own setContext is handed (as written).
|
|
3
|
+
* Each call is PROVEN, by following the import binding rather than matching text, to be
|
|
4
|
+
* Svelte/ogygia's. */
|
|
5
|
+
export interface ContextKeys {
|
|
6
|
+
reads: string[];
|
|
7
|
+
sets: string[];
|
|
8
|
+
one_off: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the keys a file reads via `getContext(…)` and sets via `setContext(…)` (a string literal, a
|
|
12
|
+
* `Symbol.for('…')`, or a module-level const bound to one), where each call is PROVEN — by following
|
|
13
|
+
* the import binding, not by matching text — to be Svelte's or ogygia's. Counts a `getContext as gc`
|
|
14
|
+
* alias and a namespace `ns.getContext(…)`; ignores a local function of the same name, a
|
|
15
|
+
* `foo.getContext(…)` on an unrelated object, and a dynamic key.
|
|
16
|
+
*
|
|
17
|
+
* `one_off` names each one-off `Symbol()` key handed to ogygia's own `setContext` with no options
|
|
18
|
+
* (`{ islands: false }` keeps a key off the page on purpose): it cannot cross.
|
|
19
|
+
*
|
|
20
|
+
* `reads` drives the WARNING: on a csr=false page the page/layout `<script>` never runs on the client,
|
|
21
|
+
* so a value set with Svelte's own `setContext` in a page/layout is gone by the time an island hydrates
|
|
22
|
+
* in isolation — the island reads `undefined`, renders a different tree, and Svelte discards its server
|
|
23
|
+
* DOM (a silent full re-render). `sets` is what makes the warning precise: a key an island's OWN code
|
|
24
|
+
* both sets and reads lives inside one hydration root (a component library using context internally) and
|
|
25
|
+
* needs no bridge — the caller subtracts island sets from island reads so only a key provided OUTSIDE
|
|
26
|
+
* the island is flagged. Empty on a file with no such call, or one that cannot be parsed.
|
|
27
|
+
*/
|
|
28
|
+
export declare function context_keys(src: string, kind: "svelte" | "script"): ContextKeys;
|