@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.
- 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 +349 -0
- package/dist/driver.js +1401 -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 +102 -0
- package/dist/fouc-css.js +304 -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 +198 -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 +672 -0
- package/dist/messages.js +938 -0
- package/dist/ownership-stamps.d.ts +9 -0
- package/dist/ownership-stamps.js +101 -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 +56 -0
- package/dist/virtual/resolver.js +249 -0
- package/dist/virtual/specifier.d.ts +10 -0
- package/dist/virtual/specifier.js +6 -0
- package/dist/virtual/table.d.ts +118 -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 +874 -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 +11 -0
- package/dist/vite/late-island.js +19 -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 +14 -0
- package/dist/vite/paths.js +37 -0
- package/dist/vite/plugin-api.d.ts +316 -0
- package/dist/vite/plugin-api.js +328 -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/package.json +87 -12
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { parse_roots } from "../parse/roots.js";
|
|
2
|
+
import { OWN_PACKAGE_NAMES, key_name } from "@ogygia/core/contract";
|
|
3
|
+
// src/link/context-detect.ts
|
|
4
|
+
const CTX_MODULES = /* @__PURE__ */ new Set(["svelte", ...OWN_PACKAGE_NAMES]);
|
|
5
|
+
const NODE_SKIP = /* @__PURE__ */ new Set([
|
|
6
|
+
"start",
|
|
7
|
+
"end",
|
|
8
|
+
"loc",
|
|
9
|
+
"range",
|
|
10
|
+
"parent",
|
|
11
|
+
"metadata",
|
|
12
|
+
"leadingComments",
|
|
13
|
+
"trailingComments",
|
|
14
|
+
"__parent",
|
|
15
|
+
"__key"
|
|
16
|
+
]);
|
|
17
|
+
function name_of(n) {
|
|
18
|
+
if (!n) return null;
|
|
19
|
+
if (n.type === "Identifier") return n.name ?? null;
|
|
20
|
+
if (n.type === "Literal" && typeof n.value === "string") return n.value;
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
function literal_string(n) {
|
|
24
|
+
return n && n.type === "Literal" && typeof n.value === "string" ? n.value : null;
|
|
25
|
+
}
|
|
26
|
+
function symbol_key(n) {
|
|
27
|
+
if (n?.type !== "CallExpression") return null;
|
|
28
|
+
const callee = n.callee;
|
|
29
|
+
if (callee?.type === "Identifier" && callee.name === "Symbol") return { one_off: true };
|
|
30
|
+
if (callee?.type === "MemberExpression" && !callee.computed && callee.object?.type === "Identifier" && callee.object.name === "Symbol" && name_of(callee.property) === "for") {
|
|
31
|
+
const shared = literal_string(n.arguments?.[0]);
|
|
32
|
+
return shared === null ? null : { name: key_name(Symbol.for(shared)) ?? "" };
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
function key_expr(n, consts) {
|
|
37
|
+
const s = literal_string(n);
|
|
38
|
+
if (s !== null) return { name: key_name(s) ?? s };
|
|
39
|
+
if (n?.type === "Identifier") return consts.get(n.name) ?? null;
|
|
40
|
+
return symbol_key(n);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolve the keys a file reads via `getContext(…)` and sets via `setContext(…)` (a string literal, a
|
|
44
|
+
* `Symbol.for('…')`, or a module-level const bound to one), where each call is PROVEN — by following
|
|
45
|
+
* the import binding, not by matching text — to be Svelte's or ogygia's. Counts a `getContext as gc`
|
|
46
|
+
* alias and a namespace `ns.getContext(…)`; ignores a local function of the same name, a
|
|
47
|
+
* `foo.getContext(…)` on an unrelated object, and a dynamic key.
|
|
48
|
+
*
|
|
49
|
+
* `one_off` names each one-off `Symbol()` key handed to ogygia's own `setContext` with no options
|
|
50
|
+
* (`{ islands: false }` keeps a key off the page on purpose): it cannot cross.
|
|
51
|
+
*
|
|
52
|
+
* `reads` drives the WARNING: on a csr=false page the page/layout `<script>` never runs on the client,
|
|
53
|
+
* so a value set with Svelte's own `setContext` in a page/layout is gone by the time an island hydrates
|
|
54
|
+
* in isolation — the island reads `undefined`, renders a different tree, and Svelte discards its server
|
|
55
|
+
* DOM (a silent full re-render). `sets` is what makes the warning precise: a key an island's OWN code
|
|
56
|
+
* both sets and reads lives inside one hydration root (a component library using context internally) and
|
|
57
|
+
* needs no bridge — the caller subtracts island sets from island reads so only a key provided OUTSIDE
|
|
58
|
+
* the island is flagged. Empty on a file with no such call, or one that cannot be parsed.
|
|
59
|
+
*/
|
|
60
|
+
function context_keys(src, kind) {
|
|
61
|
+
const none = {
|
|
62
|
+
reads: [],
|
|
63
|
+
sets: [],
|
|
64
|
+
one_off: []
|
|
65
|
+
};
|
|
66
|
+
const wants_get = src.includes("getContext");
|
|
67
|
+
const wants_set = src.includes("setContext");
|
|
68
|
+
if (!wants_get && !wants_set) return none;
|
|
69
|
+
const roots = parse_roots(src, "ogygia:context-detect", kind);
|
|
70
|
+
if (!roots) return none;
|
|
71
|
+
const get_locals = /* @__PURE__ */ new Set();
|
|
72
|
+
const set_locals = /* @__PURE__ */ new Set();
|
|
73
|
+
const own_set_locals = /* @__PURE__ */ new Set();
|
|
74
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
75
|
+
const own_namespaces = /* @__PURE__ */ new Set();
|
|
76
|
+
const consts = /* @__PURE__ */ new Map();
|
|
77
|
+
for (const root of roots) {
|
|
78
|
+
if (root.type !== "Program") continue;
|
|
79
|
+
for (const decl of root.body ?? []) {
|
|
80
|
+
if (decl.type !== "VariableDeclaration" || decl.kind !== "const") continue;
|
|
81
|
+
for (const d of decl.declarations ?? []) {
|
|
82
|
+
const key = d.id?.type === "Identifier" ? symbol_key(d.init) : null;
|
|
83
|
+
if (key) consts.set(d.id.name, key);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const calls = [];
|
|
88
|
+
const walk = (node) => {
|
|
89
|
+
if (!node || typeof node !== "object") return;
|
|
90
|
+
if (Array.isArray(node)) {
|
|
91
|
+
for (const c of node) walk(c);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (node.type === "ImportDeclaration" && CTX_MODULES.has(String(node.source?.value ?? ""))) {
|
|
95
|
+
const own = OWN_PACKAGE_NAMES.includes(String(node.source?.value));
|
|
96
|
+
for (const s of node.specifiers ?? []) if (s.type === "ImportSpecifier" && s.local?.name) {
|
|
97
|
+
const imported = name_of(s.imported);
|
|
98
|
+
if (imported === "getContext") get_locals.add(s.local.name);
|
|
99
|
+
else if (imported === "setContext") {
|
|
100
|
+
set_locals.add(s.local.name);
|
|
101
|
+
if (own) own_set_locals.add(s.local.name);
|
|
102
|
+
}
|
|
103
|
+
} else if (s.type === "ImportNamespaceSpecifier" && s.local?.name) {
|
|
104
|
+
namespaces.add(s.local.name);
|
|
105
|
+
if (own) own_namespaces.add(s.local.name);
|
|
106
|
+
}
|
|
107
|
+
} else if (node.type === "CallExpression") calls.push(node);
|
|
108
|
+
for (const k in node) {
|
|
109
|
+
if (NODE_SKIP.has(k)) continue;
|
|
110
|
+
const v = node[k];
|
|
111
|
+
if (v && typeof v === "object") walk(v);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
for (const root of roots) walk(root);
|
|
115
|
+
if (get_locals.size === 0 && set_locals.size === 0 && namespaces.size === 0) return none;
|
|
116
|
+
const reads = /* @__PURE__ */ new Set();
|
|
117
|
+
const sets = /* @__PURE__ */ new Set();
|
|
118
|
+
const one_off = [];
|
|
119
|
+
for (const call of calls) {
|
|
120
|
+
const arg = call.arguments?.[0];
|
|
121
|
+
const key = key_expr(arg, consts);
|
|
122
|
+
if (key === null) continue;
|
|
123
|
+
const callee = call.callee;
|
|
124
|
+
let op = null;
|
|
125
|
+
if (callee?.type === "Identifier") {
|
|
126
|
+
if (get_locals.has(callee.name)) op = "get";
|
|
127
|
+
else if (set_locals.has(callee.name)) op = own_set_locals.has(callee.name) ? "own_set" : "set";
|
|
128
|
+
} else if (callee?.type === "MemberExpression" && !callee.computed && callee.object?.type === "Identifier" && namespaces.has(callee.object.name)) {
|
|
129
|
+
const member = name_of(callee.property);
|
|
130
|
+
if (member === "getContext") op = "get";
|
|
131
|
+
else if (member === "setContext") op = own_namespaces.has(callee.object.name) ? "own_set" : "set";
|
|
132
|
+
}
|
|
133
|
+
if (op === null) continue;
|
|
134
|
+
if ("name" in key) (op === "get" ? reads : sets).add(key.name);
|
|
135
|
+
else if (op === "own_set" && (call.arguments?.length ?? 0) < 3) one_off.push(src.slice(arg.start, arg.end));
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
reads: [...reads],
|
|
139
|
+
sets: [...sets],
|
|
140
|
+
one_off
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
export { context_keys };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const SERVER_HANDOFF = "og-server-handoff.json";
|
|
2
|
+
/** `<outDir>/og-server-handoff.json`: written by the server leg, read by the client leg. */
|
|
3
|
+
export declare function server_handoff_path(out_dir: string): string;
|
|
4
|
+
/** A server-only region and the component file it renders (`Compiler.server_island_css_roots`). */
|
|
5
|
+
export interface ServerRegionRoot {
|
|
6
|
+
iid: string;
|
|
7
|
+
abs: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* What the server leg used, for the client leg, which may be another plugin instance (Kit 2 loads
|
|
11
|
+
* the config once per leg). A file between ogygia's own legs, under Kit's `outDir` beside the server
|
|
12
|
+
* bundle that already holds the key; never shipped. `hosts`: the server bundle's transformed modules
|
|
13
|
+
* (the emit gate). `build_key`: the signing key the server bundle baked, for the client bundle's
|
|
14
|
+
* secret check (link/build-output.ts `refuse_client_secrets`). `server_regions`: its FINAL
|
|
15
|
+
* server-only regions, a library host it reached late included: the client leg builds each one's
|
|
16
|
+
* styles from this list, since in Kit 2 its own program never sees a host only the server bundle
|
|
17
|
+
* imports (test/server-region-late.test.ts).
|
|
18
|
+
*/
|
|
19
|
+
export interface ServerHandoff {
|
|
20
|
+
readonly hosts: Set<string>;
|
|
21
|
+
readonly build_key: string;
|
|
22
|
+
readonly server_regions: ServerRegionRoot[];
|
|
23
|
+
}
|
|
24
|
+
/** The handoff file's text. */
|
|
25
|
+
export declare function server_handoff_json(hosts: readonly string[], build_key: string, server_regions: readonly ServerRegionRoot[]): string;
|
|
26
|
+
/** The handoff file's contents. A malformed field reads as empty: nothing gated, no region named,
|
|
27
|
+
* never a throw. */
|
|
28
|
+
export declare function parse_server_handoff(json: string): ServerHandoff;
|
|
29
|
+
/** The server leg's handoff under `out_dir`, or null when there is none (a standalone or
|
|
30
|
+
* client-only build). */
|
|
31
|
+
export declare function read_server_handoff(out_dir: string): ServerHandoff | null;
|
|
32
|
+
/**
|
|
33
|
+
* Should an island whose host module is `host_path` get a client chunk? `loaded` is the server
|
|
34
|
+
* leg's transformed-module set (`host_key`-normalised), or `null` when there is no handoff.
|
|
35
|
+
* An island with no recorded host (a library island registered through a bridge) is always emitted.
|
|
36
|
+
*
|
|
37
|
+
* The prescan registers every marked import under `src/`, but a host nothing imports (a second
|
|
38
|
+
* route tree, a retired component) is no island the app serves, and its imports would enter a
|
|
39
|
+
* client build whose server pass never analysed them (a `.remote.ts` there fails Kit's remote
|
|
40
|
+
* metadata check). Kit builds the server bundle first; its transform pass is the ground truth for
|
|
41
|
+
* reachability.
|
|
42
|
+
*/
|
|
43
|
+
export declare function island_host_loaded(host_path: string | null | undefined, loaded: Set<string> | null | undefined): boolean;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { host_key } from "../program.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
// src/link/emit-gate.ts
|
|
5
|
+
const SERVER_HANDOFF = "og-server-handoff.json";
|
|
6
|
+
/** `<outDir>/og-server-handoff.json`: written by the server leg, read by the client leg. */
|
|
7
|
+
function server_handoff_path(out_dir) {
|
|
8
|
+
return path.join(out_dir, SERVER_HANDOFF);
|
|
9
|
+
}
|
|
10
|
+
/** The handoff file's text. */
|
|
11
|
+
function server_handoff_json(hosts, build_key, server_regions) {
|
|
12
|
+
return JSON.stringify({
|
|
13
|
+
hosts,
|
|
14
|
+
build_key,
|
|
15
|
+
server_regions
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** The handoff file's contents. A malformed field reads as empty: nothing gated, no region named,
|
|
19
|
+
* never a throw. */
|
|
20
|
+
function parse_server_handoff(json) {
|
|
21
|
+
const o = JSON.parse(json);
|
|
22
|
+
const hosts = Array.isArray(o?.hosts) ? o.hosts.filter((x) => typeof x === "string") : [];
|
|
23
|
+
const regions = Array.isArray(o?.server_regions) ? o.server_regions : [];
|
|
24
|
+
return {
|
|
25
|
+
hosts: new Set(hosts),
|
|
26
|
+
build_key: typeof o?.build_key === "string" ? o.build_key : "",
|
|
27
|
+
server_regions: regions.filter((r) => !!r && typeof r === "object" && typeof r.iid === "string" && typeof r.abs === "string")
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** The server leg's handoff under `out_dir`, or null when there is none (a standalone or
|
|
31
|
+
* client-only build). */
|
|
32
|
+
function read_server_handoff(out_dir) {
|
|
33
|
+
try {
|
|
34
|
+
return parse_server_handoff(fs.readFileSync(server_handoff_path(out_dir), "utf8"));
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Should an island whose host module is `host_path` get a client chunk? `loaded` is the server
|
|
41
|
+
* leg's transformed-module set (`host_key`-normalised), or `null` when there is no handoff.
|
|
42
|
+
* An island with no recorded host (a library island registered through a bridge) is always emitted.
|
|
43
|
+
*
|
|
44
|
+
* The prescan registers every marked import under `src/`, but a host nothing imports (a second
|
|
45
|
+
* route tree, a retired component) is no island the app serves, and its imports would enter a
|
|
46
|
+
* client build whose server pass never analysed them (a `.remote.ts` there fails Kit's remote
|
|
47
|
+
* metadata check). Kit builds the server bundle first; its transform pass is the ground truth for
|
|
48
|
+
* reachability.
|
|
49
|
+
*/
|
|
50
|
+
function island_host_loaded(host_path, loaded) {
|
|
51
|
+
if (!loaded) return true;
|
|
52
|
+
if (!host_path) return true;
|
|
53
|
+
return loaded.has(host_key(host_path));
|
|
54
|
+
}
|
|
55
|
+
export { SERVER_HANDOFF, island_host_loaded, parse_server_handoff, read_server_handoff, server_handoff_json, server_handoff_path };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A module's own file, named in generated code before the bundler has named it: a token that
|
|
3
|
+
* vite/lazy-files.ts replaces (dev: the module's URL; build: the path to its own chunk, or `null`).
|
|
4
|
+
*/
|
|
5
|
+
export declare const FILE_TOKEN_MARK = "__OGYGIA_FILE_";
|
|
6
|
+
/** A token in code, in any quotes (a minifier may change them): its hex-encoded module id. */
|
|
7
|
+
export declare const FILE_TOKEN_RE: RegExp;
|
|
8
|
+
/** The string literal that stands for `id`'s own file, quotes included. */
|
|
9
|
+
export declare function file_token(id: string): string;
|
|
10
|
+
/** The module id a token's hex part names. */
|
|
11
|
+
export declare const file_token_id: (hex: string) => string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/link/file-token.ts
|
|
2
|
+
/**
|
|
3
|
+
* A module's own file, named in generated code before the bundler has named it: a token that
|
|
4
|
+
* vite/lazy-files.ts replaces (dev: the module's URL; build: the path to its own chunk, or `null`).
|
|
5
|
+
*/
|
|
6
|
+
const FILE_TOKEN_MARK = "__OGYGIA_FILE_";
|
|
7
|
+
/** A token in code, in any quotes (a minifier may change them): its hex-encoded module id. */
|
|
8
|
+
const FILE_TOKEN_RE = /(["'`])__OGYGIA_FILE_([0-9a-f]+)__\1/g;
|
|
9
|
+
/** The string literal that stands for `id`'s own file, quotes included. */
|
|
10
|
+
function file_token(id) {
|
|
11
|
+
return JSON.stringify(`${FILE_TOKEN_MARK}${Buffer.from(id).toString("hex")}__`);
|
|
12
|
+
}
|
|
13
|
+
/** The module id a token's hex part names. */
|
|
14
|
+
const file_token_id = (hex) => Buffer.from(hex, "hex").toString();
|
|
15
|
+
export { FILE_TOKEN_MARK, FILE_TOKEN_RE, file_token, file_token_id };
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { IslandHazard } from "@ogygia/core/contract";
|
|
2
|
+
type PageKeys = ReadonlySet<string> | "unknown";
|
|
3
|
+
/** The server module's string slot the client leg writes the deps JSON into (link/relocations.ts). */
|
|
4
|
+
export declare const ISLAND_DEPS_INLINE_TOKEN = "__OGYGIA_ISLAND_DEPS_INLINE__";
|
|
5
|
+
/**
|
|
6
|
+
* Kit's own `hash()` (`@sveltejs/kit/src/utils/hash.js`: djb2 ×33 xor, unsigned, base36) — the
|
|
7
|
+
* function a remote's id is minted with: `${hash(file)}/${exportName}`, `file` the module's path
|
|
8
|
+
* relative to `process.cwd()`, posix. Mirrored here (Kit does not export it) so the build can
|
|
9
|
+
* name a remote by the same id the server sees on `internals.id` at render time. Covered by a
|
|
10
|
+
* vector test against ids observed from a real Kit build.
|
|
11
|
+
*/
|
|
12
|
+
export declare function kit_remote_hash(file: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* The Kit remote id-hash of a CLIENT module id, or `null` for a module that is not a remote file.
|
|
15
|
+
* `cwd` is what Kit hashed the file against (`process.cwd()` at build), either separator.
|
|
16
|
+
*
|
|
17
|
+
* @internal Exported for the plugin and unit tests.
|
|
18
|
+
*/
|
|
19
|
+
export declare function remote_hash_of(module_id: string, cwd: string): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* From a client `generateBundle` output, collect transitive static `imports` for each
|
|
22
|
+
* `og-region.<id>.js` facade. Keys/values are public URLs (`/_app/immutable/…`).
|
|
23
|
+
* Used so SSR can `modulepreload` hashed dependency chunks for `hydrate: 'load'` islands
|
|
24
|
+
* (Vite’s auto graph does not apply to `@vite-ignore` `import(entry)`).
|
|
25
|
+
*
|
|
26
|
+
* @param page_reader_files Source files whose presence in an island's chunk closure means the
|
|
27
|
+
* island READS THE PAGE (the `$app/state` / `$app/stores` shims). Per entry, `page[entryUrl]`
|
|
28
|
+
* says whether any chunk in its closure bundles one of them — what lets the handle skip the page
|
|
29
|
+
* seed on a page whose islands never read it. Absolute paths, either separator.
|
|
30
|
+
* @param remote_hash Names a bundled module's Kit remote id-hash (`remote_hash_of`), or `null` for
|
|
31
|
+
* a module that is no remote file. Per entry, `remotes[entryUrl]` lists every remote module in
|
|
32
|
+
* the island's chunk closure, static AND dynamic imports, which is what lets the handle seed a
|
|
33
|
+
* remote's SSR result only when some island on the page can call it. Absent → every entry `[]`.
|
|
34
|
+
* @param page_keys_of SEED SHAPING: the top-level `page.data` keys a bundled module reads (the
|
|
35
|
+
* seed-shaping plugin's answer), `'unknown'` when its reads could not be pinned, `null` for a
|
|
36
|
+
* module it never saw read the page. Per entry, `page_keys[entryUrl]` is the union over its chunk
|
|
37
|
+
* closure, or `null` (ship all) when any module said `'unknown'`, or when the closure reads the
|
|
38
|
+
* page through a module the plugin never saw. Absent (no plugin) → every reader `null`.
|
|
39
|
+
* @param read_source WAKE ADVISOR: reads a bundled `.svelte` source by id so the collector can
|
|
40
|
+
* count what the island's components do. Per entry, `interactivity[entryUrl]` is the union over
|
|
41
|
+
* its closure's own components (dependencies and ogygia's wrappers skipped). Absent → no facts.
|
|
42
|
+
* @param runtime_file The runtime entry chunk's exact file name (compiler
|
|
43
|
+
* `runtime_chunk_filename`). Its static imports are recorded under its URL so SSR hints them
|
|
44
|
+
* beside the runtime script. Matched exactly, never by pattern. Absent → no runtime entry.
|
|
45
|
+
* @param entries Which emitted file is which entry. Every map is keyed by an entry's IDENTITY (the
|
|
46
|
+
* stable public URL SSR bakes), never by its hashed name. `islands`: hashed file name →
|
|
47
|
+
* identity; `runtime`: the runtime's identity. Absent → a facade-named file is its own identity.
|
|
48
|
+
* @internal Exported for unit tests.
|
|
49
|
+
*/
|
|
50
|
+
export declare function collectIslandDepModulepreloads(bundle: Record<string, {
|
|
51
|
+
type: string;
|
|
52
|
+
fileName?: string;
|
|
53
|
+
imports?: string[];
|
|
54
|
+
dynamicImports?: string[];
|
|
55
|
+
/** The source module ids bundled into this chunk (Rollup/rolldown `OutputChunk`). */
|
|
56
|
+
moduleIds?: string[];
|
|
57
|
+
/** Vite/rolldown-vite chunk metadata — `importedCss` lists the CSS assets a chunk owns. */
|
|
58
|
+
viteMetadata?: {
|
|
59
|
+
importedCss?: Set<string> | string[];
|
|
60
|
+
};
|
|
61
|
+
}>, page_reader_files?: readonly string[], remote_hash?: ((module_id: string) => string | null) | null, page_keys_of?: ((module_id: string) => PageKeys | null) | null, read_source?: ((id: string) => string | null) | null, runtime_file?: string | null, entries?: {
|
|
62
|
+
islands: ReadonlyMap<string, string>;
|
|
63
|
+
runtime: string | null;
|
|
64
|
+
} | null): {
|
|
65
|
+
js: Record<string, string[]>;
|
|
66
|
+
css: Record<string, string[]>;
|
|
67
|
+
page: Record<string, boolean>;
|
|
68
|
+
page_keys: Record<string, string[] | null>;
|
|
69
|
+
remotes: Record<string, string[]>;
|
|
70
|
+
interactivity: Record<string, IslandInteractivityFacts>;
|
|
71
|
+
/** each island's components' lines that draw differently in the browser (hydration-hazards.ts),
|
|
72
|
+
* by entry — the app's own and the site kit's (ogygia's content components); not other packages */
|
|
73
|
+
hazards: Record<string, IslandHazard[]>;
|
|
74
|
+
/** what is inside each chunk an island pulls: a readable source list per public href */
|
|
75
|
+
contents: Record<string, string[]>;
|
|
76
|
+
/** each chunk's heaviest named modules with their rendered bytes (a package sums its modules):
|
|
77
|
+
* what the report names as most of an island's code. Apart from `contents`, which stays names
|
|
78
|
+
* only (a chunk's identity across builds) */
|
|
79
|
+
heavy: Record<string, ChunkHeavy>;
|
|
80
|
+
/** modules the build shipped as two copies (one package file by two paths), each copy's chunk */
|
|
81
|
+
dupes: DuplicateModule[];
|
|
82
|
+
};
|
|
83
|
+
/** One module the build shipped as two (or more) copies: the same file of a package reached by two
|
|
84
|
+
* paths (its source and its build, two versions in node_modules), each copy in its chunk. */
|
|
85
|
+
export interface DuplicateModule {
|
|
86
|
+
/** the module, package-relative (`ogygia/runtime/beacon`, `svelte/internal/client/index`) */
|
|
87
|
+
name: string;
|
|
88
|
+
/** `from`: where the copy came from — the package's folder (`ogygia/src`, `ogygia/dist`) or its
|
|
89
|
+
* installed version (`svelte@5.56.8`) — the two paths, told apart */
|
|
90
|
+
copies: {
|
|
91
|
+
file: string;
|
|
92
|
+
bytes: number;
|
|
93
|
+
from?: string;
|
|
94
|
+
}[];
|
|
95
|
+
}
|
|
96
|
+
/** Where a module id's copy came from: an installed package's version (`name@1.2.3`, from a pnpm
|
|
97
|
+
* store path), else the package's top folder (`name/src`, `name/dist`). */
|
|
98
|
+
export declare function module_origin(id: string): string | undefined;
|
|
99
|
+
/** A module id as the file of its package, the build-or-source folder and the extension left out:
|
|
100
|
+
* two ids with one key are one module twice. Null for ids that are no file (virtual, `\0`). */
|
|
101
|
+
export declare function module_key(id: string): string | null;
|
|
102
|
+
/** Every module the build shipped more than once: one key, two or more ids (a single id is in one
|
|
103
|
+
* chunk only). The heaviest first, copies of 512 bytes or more, at most 50.
|
|
104
|
+
* @internal exported for the tests */
|
|
105
|
+
export declare function duplicate_modules(chunks: readonly {
|
|
106
|
+
file: string;
|
|
107
|
+
ids: readonly string[];
|
|
108
|
+
size_of?: (id: string) => number;
|
|
109
|
+
}[]): DuplicateModule[];
|
|
110
|
+
/** A chunk's rendered size and its heaviest named modules. */
|
|
111
|
+
export interface ChunkHeavy {
|
|
112
|
+
/** every module's rendered bytes in the chunk */
|
|
113
|
+
total: number;
|
|
114
|
+
/** the five heaviest, by the names `contents` uses (a package's modules summed) */
|
|
115
|
+
top: {
|
|
116
|
+
name: string;
|
|
117
|
+
bytes: number;
|
|
118
|
+
}[];
|
|
119
|
+
}
|
|
120
|
+
/** A chunk's modules as readable names (the same names `contents` uses) with their rendered bytes,
|
|
121
|
+
* heaviest first, the five heaviest; a package's modules summed under its name.
|
|
122
|
+
* @internal exported for the tests */
|
|
123
|
+
export declare function chunk_module_bytes(module_ids: readonly string[], size_of: (id: string) => number): ChunkHeavy;
|
|
124
|
+
/**
|
|
125
|
+
* A chunk's source modules as a short readable list: the app's own files first (relative to
|
|
126
|
+
* `src/`), then the packages, the framework runtimes named plainly. Capped; the tail is "+N more".
|
|
127
|
+
* @internal exported for the tests
|
|
128
|
+
*/
|
|
129
|
+
export declare function summarize_chunk_contents(module_ids: readonly string[], max_files?: number, max_pkgs?: number, size_of?: (id: string) => number): string[];
|
|
130
|
+
/** What an island's components do (the wake advisor's evidence) — see `interactivity_facts`. */
|
|
131
|
+
export interface IslandInteractivityFacts {
|
|
132
|
+
handlers: number;
|
|
133
|
+
state: number;
|
|
134
|
+
effects: number;
|
|
135
|
+
binds: number;
|
|
136
|
+
actions: number;
|
|
137
|
+
/** remote modules its closure can call (set per island from the remotes scan) */
|
|
138
|
+
remotes?: number;
|
|
139
|
+
/** `{await …}` / `{#await …}` in its markup: a value that lands after it wakes */
|
|
140
|
+
awaits?: number;
|
|
141
|
+
/** context reads and rune-module imports: state another island can change */
|
|
142
|
+
shared?: number;
|
|
143
|
+
files: number;
|
|
144
|
+
}
|
|
145
|
+
/** Count a component source's interactivity markers. */
|
|
146
|
+
export declare function interactivity_facts(src: string): IslandInteractivityFacts;
|
|
147
|
+
/** Stable handoff path under Kit's `outDir`: client `generateBundle` writes; SSR reads at render
|
|
148
|
+
* (Kit is SSR-first). */
|
|
149
|
+
export declare function islandDepsHandoffPath(out_dir: string): string;
|
|
150
|
+
/**
|
|
151
|
+
* INLINE REGION CSS. For every region CSS asset (`hrefs`: the union of the handoff's `css` and
|
|
152
|
+
* `content_css` lists) whose bytes are under `threshold` — Kit's `inlineStyleThreshold`, the same
|
|
153
|
+
* number Kit inlines its own route sheets under — keep the asset's text, keyed by its public href.
|
|
154
|
+
* The render then emits `<style data-ogygia-region-css="href">` in place of a blocking `<link>`:
|
|
155
|
+
* a page carrying twenty-five small island sheets (42 KB on a measured home page, twenty of them
|
|
156
|
+
* under 3 KB) stops paying twenty-five requests before first paint. `0` = keep nothing (Kit's
|
|
157
|
+
* default: never inline). Above the threshold, or not an emitted asset, → not in the map → linked.
|
|
158
|
+
*
|
|
159
|
+
* @internal Exported for unit tests.
|
|
160
|
+
*/
|
|
161
|
+
export declare function collect_inline_css(bundle: Record<string, {
|
|
162
|
+
type: string;
|
|
163
|
+
fileName?: string;
|
|
164
|
+
source?: string | Uint8Array;
|
|
165
|
+
}>, hrefs: Iterable<string>, threshold: number): Record<string, string>;
|
|
166
|
+
/** The global (by `Symbol.for` name) the dev server's plugin fills with a reader of the og.$
|
|
167
|
+
* factories the compiler holds now (tag → factory source): the dev `fn_manifest()` asks it, so a
|
|
168
|
+
* page carries the factories of a module that never runs in the browser, as a build's handoff
|
|
169
|
+
* does (apps/palaestra/e2e/dev-dollar-fn.spec.ts). */
|
|
170
|
+
export declare const DEV_FN_MANIFEST_KEY = "ogygia.dev.fn-manifest";
|
|
171
|
+
/**
|
|
172
|
+
* `ogygia:server/region-deps` emitter — the SSR-render-time reader of the deps handoff.
|
|
173
|
+
* Client: every reader answers none (the SSR HTML carries every hint). Dev: a region's CSS is its
|
|
174
|
+
* module URL (the client imports it), the page always seeds, remotes are `null` (may call
|
|
175
|
+
* anything), and an identity is its own location. SSR: read the handoff JSON at *render* time —
|
|
176
|
+
* Kit builds the server bundle before the client, so baking at `load()` would always be empty;
|
|
177
|
+
* prerender/live SSR run after client generateBundle. Resolve via import.meta.url walk (not absolute
|
|
178
|
+
* build-machine paths) so adapters find `output/server/og-region-deps.json` next to the server bundle.
|
|
179
|
+
* `out_dir_rel` — Kit's `outDir` relative to the app root (`.svelte-kit` by default) — is the cwd
|
|
180
|
+
* fallback for adapter-node / preview run from the app root.
|
|
181
|
+
*/
|
|
182
|
+
export declare function island_deps_module(ssr: boolean, is_dev: boolean, out_dir_rel?: string): string;
|
|
183
|
+
export {};
|