@ogygia/compiler 0.14.2 → 0.15.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/dist/driver.d.ts +23 -8
- package/dist/driver.js +157 -23
- package/dist/kit.d.ts +17 -0
- package/dist/kit.js +51 -1
- package/dist/link/caps.d.ts +7 -1
- package/dist/link/caps.js +10 -2
- package/dist/link/dead-exports.d.ts +49 -0
- package/dist/link/dead-exports.js +500 -0
- package/dist/link/emit-gate.d.ts +13 -2
- package/dist/link/emit-gate.js +11 -3
- package/dist/link/hooks.d.ts +17 -0
- package/dist/link/hooks.js +35 -0
- package/dist/link/island-deps.d.ts +8 -1
- package/dist/link/island-deps.js +27 -1
- package/dist/link/relocations.d.ts +2 -0
- package/dist/link/relocations.js +11 -1
- package/dist/link/runtime-entry.d.ts +79 -17
- package/dist/link/runtime-entry.js +134 -32
- package/dist/link/server-manifest.d.ts +3 -0
- package/dist/link/server-manifest.js +4 -1
- package/dist/messages.d.ts +24 -0
- package/dist/messages.js +57 -2
- package/dist/program.d.ts +13 -1
- package/dist/program.js +26 -0
- package/dist/region/transform.js +3 -1
- package/dist/virtual/core.d.ts +23 -44
- package/dist/virtual/core.js +107 -78
- package/dist/virtual/resolver.d.ts +2 -0
- package/dist/virtual/resolver.js +5 -0
- package/dist/virtual/table.d.ts +6 -0
- package/dist/vite/graph-compiled.d.ts +21 -0
- package/dist/vite/graph-compiled.js +24 -0
- package/dist/vite/index.js +29 -19
- package/dist/vite/plugin-api.d.ts +10 -6
- package/dist/vite/plugin-api.js +39 -22
- package/package.json +4 -4
package/dist/link/island-deps.js
CHANGED
|
@@ -68,9 +68,14 @@ const TRAILING_SLASH_RE = /\/+$/;
|
|
|
68
68
|
* @param entries Which emitted file is which entry. Every map is keyed by an entry's IDENTITY (the
|
|
69
69
|
* stable public URL SSR bakes), never by its hashed name. `islands`: hashed file name →
|
|
70
70
|
* identity; `runtime`: the runtime's identity. Absent → a facade-named file is its own identity.
|
|
71
|
+
* @param hydrate_core The hydrate core's module id (`<runtime dir>/hydrate-core.js`, real path).
|
|
72
|
+
* The chunk that bundles it and that chunk's static imports are `wake`: what the runtime's first
|
|
73
|
+
* island wake imports, which a page whose islands wake at load can start early. Matched exactly.
|
|
74
|
+
* The runtime's own static imports are left out (the runtime's bootstrap preloads them). Absent →
|
|
75
|
+
* `wake` is empty.
|
|
71
76
|
* @internal Exported for unit tests.
|
|
72
77
|
*/
|
|
73
|
-
function collectIslandDepModulepreloads(bundle, page_reader_files = [], remote_hash = null, page_keys_of = null, read_source = null, runtime_file = null, entries = null) {
|
|
78
|
+
function collectIslandDepModulepreloads(bundle, page_reader_files = [], remote_hash = null, page_keys_of = null, read_source = null, runtime_file = null, entries = null, hydrate_core = null) {
|
|
74
79
|
const js = {};
|
|
75
80
|
const css = {};
|
|
76
81
|
const page = {};
|
|
@@ -243,6 +248,17 @@ function collectIslandDepModulepreloads(bundle, page_reader_files = [], remote_h
|
|
|
243
248
|
const chunk = bundle[runtime_key];
|
|
244
249
|
if (chunk && chunk.type === "chunk") js[entries?.runtime ?? `/${runtime_key}`] = [...new Set(walk(runtime_key, /* @__PURE__ */ new Set([runtime_key]), []))];
|
|
245
250
|
}
|
|
251
|
+
const wake = [];
|
|
252
|
+
if (hydrate_core) {
|
|
253
|
+
const core_id = norm(hydrate_core);
|
|
254
|
+
const boot = new Set(runtime_file ? js[entries?.runtime ?? `/${norm(runtime_file).replace(LEADING_SLASH, "")}`] : []);
|
|
255
|
+
for (const [key, chunk] of Object.entries(bundle)) {
|
|
256
|
+
if (chunk.type !== "chunk" || !chunk.moduleIds?.some((id) => norm(id) === core_id)) continue;
|
|
257
|
+
const file = norm(chunk.fileName || key).replace(LEADING_SLASH, "");
|
|
258
|
+
for (const href of [`/${file}`, ...new Set(walk(file, /* @__PURE__ */ new Set([file]), []))]) if (!boot.has(href)) wake.push(href);
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
246
262
|
const contents = {};
|
|
247
263
|
const heavy = {};
|
|
248
264
|
const summarize = (s) => {
|
|
@@ -267,6 +283,7 @@ function collectIslandDepModulepreloads(bundle, page_reader_files = [], remote_h
|
|
|
267
283
|
for (const [key, chunk] of Object.entries(bundle)) if (chunk.type === "chunk") summarize(chunk.fileName || key);
|
|
268
284
|
return {
|
|
269
285
|
js,
|
|
286
|
+
wake,
|
|
270
287
|
css,
|
|
271
288
|
page,
|
|
272
289
|
page_keys,
|
|
@@ -532,6 +549,7 @@ const DEV_FN_MANIFEST_KEY = "ogygia.dev.fn-manifest";
|
|
|
532
549
|
function island_deps_module(ssr, is_dev, out_dir_rel = ".svelte-kit") {
|
|
533
550
|
if (!ssr) return dedent`
|
|
534
551
|
export function region_deps(_entry) { return []; }
|
|
552
|
+
export function wake_code() { return []; }
|
|
535
553
|
export function region_css(_entry) { return []; }
|
|
536
554
|
export function region_css_inline(_href) { return null; }
|
|
537
555
|
export function content_css(_id) { return []; }
|
|
@@ -552,6 +570,7 @@ function island_deps_module(ssr, is_dev, out_dir_rel = ".svelte-kit") {
|
|
|
552
570
|
`;
|
|
553
571
|
if (is_dev) return dedent`
|
|
554
572
|
export function region_deps(_entry) { return []; }
|
|
573
|
+
export function wake_code() { return []; }
|
|
555
574
|
export function region_css(entry) { return entry ? [entry] : []; }
|
|
556
575
|
export function region_css_inline(_href) { return null; }
|
|
557
576
|
export function content_css(_id) { return []; }
|
|
@@ -683,6 +702,13 @@ function island_deps_module(ssr, is_dev, out_dir_rel = ".svelte-kit") {
|
|
|
683
702
|
return entry ? pick('js', entry) : [];
|
|
684
703
|
}
|
|
685
704
|
|
|
705
|
+
// THE FIRST WAKE'S CODE: the hydrate core's chunk and its static imports, which the runtime
|
|
706
|
+
// imports when its first island wakes. [] = none known (a handoff from before it).
|
|
707
|
+
export function wake_code() {
|
|
708
|
+
const v = load().wake;
|
|
709
|
+
return Array.isArray(v) ? v : [];
|
|
710
|
+
}
|
|
711
|
+
|
|
686
712
|
export function region_css(entry) {
|
|
687
713
|
return entry ? pick('css', entry) : [];
|
|
688
714
|
}
|
|
@@ -23,6 +23,8 @@ export interface RelocateCx {
|
|
|
23
23
|
/** The seed-shaping plugin's answers (`dataShake()`); null when none is listed, and then every
|
|
24
24
|
* hole looks the page up. */
|
|
25
25
|
readonly page_reads: Pick<PageReadsSink, "keys"> | null;
|
|
26
|
+
/** The URL of the runtime the server leg's pages load, named from everything it compiled. */
|
|
27
|
+
runtime_url(): string;
|
|
26
28
|
}
|
|
27
29
|
export interface Relocation<Cx = RelocateCx> {
|
|
28
30
|
readonly name: string;
|
package/dist/link/relocations.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LATE_SERVER_REGIONS_TOKEN, PAGE_DATA_READS_TOKEN, SERVER_MAP_TOKENS, server_manifest_maps, server_regions } from "./server-manifest.js";
|
|
1
|
+
import { LATE_SERVER_REGIONS_TOKEN, PAGE_DATA_READS_TOKEN, RUNTIME_URL_TOKEN, SERVER_MAP_TOKENS, server_manifest_maps, server_regions } from "./server-manifest.js";
|
|
2
2
|
import { FILE_TOKEN_MARK, FILE_TOKEN_RE, file_token_id } from "./file-token.js";
|
|
3
3
|
import { ISLAND_DEPS_INLINE_TOKEN } from "./island-deps.js";
|
|
4
4
|
import { by_key } from "./location-map.js";
|
|
@@ -105,6 +105,15 @@ const server_map = (name) => ({
|
|
|
105
105
|
return (quote) => in_literal(json, quote);
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
|
+
const RUNTIME_URL = {
|
|
109
|
+
name: "runtime url",
|
|
110
|
+
token: RUNTIME_URL_TOKEN,
|
|
111
|
+
server_only: true,
|
|
112
|
+
value(cx) {
|
|
113
|
+
const url = cx.runtime_url();
|
|
114
|
+
return (quote) => in_literal(url, quote);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
108
117
|
const LATE_SERVER_REGIONS = {
|
|
109
118
|
name: "late server regions",
|
|
110
119
|
token: LATE_SERVER_REGIONS_TOKEN,
|
|
@@ -152,6 +161,7 @@ const RELOCATIONS = [
|
|
|
152
161
|
server_map("region_render"),
|
|
153
162
|
server_map("render_region"),
|
|
154
163
|
LATE_SERVER_REGIONS,
|
|
164
|
+
RUNTIME_URL,
|
|
155
165
|
FILE
|
|
156
166
|
];
|
|
157
167
|
/** The values a later leg writes into this leg's files after they were written. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ClientRealmFile } from "./caps.js";
|
|
2
|
+
import { FeatureName } from "@ogygia/core/contract";
|
|
2
3
|
/**
|
|
3
4
|
* Runtime feature catalog — maps build-time marks → installable plugins.
|
|
4
5
|
* Module paths are absolute file URLs resolved by the Vite plugin against dist/src.
|
|
@@ -8,6 +9,10 @@ export type RuntimeMarks = {
|
|
|
8
9
|
complete?: boolean;
|
|
9
10
|
hydrate?: string[];
|
|
10
11
|
defer?: string[];
|
|
12
|
+
/** A hole's `prefetch` schedules (warming its HTML ahead of its `fetch`). */
|
|
13
|
+
prefetch?: string[];
|
|
14
|
+
/** A lake's `remount.revalidate` schedules (a cached lake fetched again). */
|
|
15
|
+
revalidate?: string[];
|
|
11
16
|
persist?: boolean;
|
|
12
17
|
persistKeys?: string[];
|
|
13
18
|
router?: boolean;
|
|
@@ -23,8 +28,8 @@ export type RuntimeMarks = {
|
|
|
23
28
|
context?: boolean;
|
|
24
29
|
/** Island code can reach Kit's page world: `$app/state` / `$app/stores` / `$app/navigation`
|
|
25
30
|
* (anything under `$app/` but `environment` and `paths`), or code the driver's island-closure walk
|
|
26
|
-
* cannot follow (a package, an unresolvable import), or
|
|
27
|
-
*
|
|
31
|
+
* cannot follow (a package, an unresolvable import), or federation, which hands the runtime
|
|
32
|
+
* islands the walk never saw. Gates the page seed and the MPA navigation handle. */
|
|
28
33
|
page?: boolean;
|
|
29
34
|
/** The page can carry regions this build never compiled (federation: a peer's fragment brings its
|
|
30
35
|
* own islands, holes and lakes, at run time). Their kinds are unknown here, so every feature a
|
|
@@ -33,9 +38,11 @@ export type RuntimeMarks = {
|
|
|
33
38
|
* build's own classes, which a peer's props never name. */
|
|
34
39
|
foreign?: boolean;
|
|
35
40
|
};
|
|
36
|
-
|
|
41
|
+
/** A runtime feature, numbered by core's feature word (`@ogygia/core/contract` features.ts). */
|
|
42
|
+
export type FeatureId = FeatureName;
|
|
37
43
|
/**
|
|
38
|
-
* WHICH CHUNK a feature lives in. The runtime ships as two static, feature-sized phases
|
|
44
|
+
* WHICH CHUNK a feature lives in. The runtime ships as two static, feature-sized phases (and code
|
|
45
|
+
* the element itself keeps or folds):
|
|
39
46
|
*
|
|
40
47
|
* - `boot` — the runtime entry (`og-runtime.*.js`), loaded by the `<script>` in `<head>`. Defines
|
|
41
48
|
* `<ogygia-region>`, schedules wakes, fetches holes, morphs, routes. It must never reach Svelte:
|
|
@@ -44,14 +51,17 @@ export type FeatureId = "remote-seeds" | "page" | "wire" | "wire-classes" | "fra
|
|
|
44
51
|
* - `hydrate` — the hydrate core (`runtime/hydrate-core.js`), loaded by the runtime's single existing
|
|
45
52
|
* `import()` when the first island wakes, together with Svelte (which `hydrate()` needs anyway). A
|
|
46
53
|
* feature whose slot only the hydrate core reads belongs here, installed as the chunk evaluates.
|
|
54
|
+
* - `element` — no module: code inside the always-on region element, kept or folded by the
|
|
55
|
+
* feature's bit in `HAS` alone (a schedule's arm: `idle`, `visible`, `media`; the island graph's
|
|
56
|
+
* reader: `graph`).
|
|
47
57
|
*
|
|
48
58
|
* Both phases are generated from the same marks, so each is exactly as big as the app needs; no
|
|
49
59
|
* feature adds a dynamic import of its own. `test/runtime-boot-svelte-free.test.ts` pins the boot.
|
|
50
60
|
*/
|
|
51
|
-
export type FeaturePhase = "boot" | "hydrate";
|
|
61
|
+
export type FeaturePhase = "boot" | "hydrate" | "element";
|
|
52
62
|
export type FeatureDef = {
|
|
53
|
-
/** Path relative to `runtime/` (no leading ./). */
|
|
54
|
-
module
|
|
63
|
+
/** Path relative to `runtime/` (no leading ./). None for an `element` feature. */
|
|
64
|
+
module?: string;
|
|
55
65
|
deps: FeatureId[];
|
|
56
66
|
detect: (m: RuntimeMarks) => boolean;
|
|
57
67
|
/** Default `boot`. See {@link FeaturePhase}. */
|
|
@@ -61,11 +71,14 @@ export declare const FEATURES: Record<FeatureId, FeatureDef>;
|
|
|
61
71
|
export declare const FEATURE_ORDER: FeatureId[];
|
|
62
72
|
/** Resolve the closed feature set for a marks manifest. */
|
|
63
73
|
export declare function resolveFeatures(marks: RuntimeMarks): FeatureId[];
|
|
74
|
+
/** A runtime module's path in `runtimeDir`, as an import names it (POSIX). */
|
|
75
|
+
export declare const runtime_path: (runtimeDir: string, mod: string) => string;
|
|
64
76
|
/** The selected features of one {@link FeaturePhase}, in FEATURE_ORDER. */
|
|
65
77
|
export declare function phaseFeatures(marks: RuntimeMarks, phase: FeaturePhase): FeatureId[];
|
|
66
78
|
/**
|
|
67
|
-
* Emit the BOOT entry: core
|
|
68
|
-
*
|
|
79
|
+
* Emit the BOOT entry: core, booted with the plugins' browser halves. Core installs the selected
|
|
80
|
+
* boot-phase features itself (see {@link FeaturePhase}), from `ogygia:boot/feature-code`
|
|
81
|
+
* ({@link generateFeatureCodeSource}, the same marks). The entry boots and exports nothing.
|
|
69
82
|
* @param runtimeDir Absolute directory containing `core.js` + the feature modules.
|
|
70
83
|
* @param clientPlugins the plugins' browser halves, in plugin order
|
|
71
84
|
*/
|
|
@@ -73,16 +86,31 @@ export declare function generateRuntimeEntrySource(marks: RuntimeMarks, runtimeD
|
|
|
73
86
|
code: string;
|
|
74
87
|
features: FeatureId[];
|
|
75
88
|
};
|
|
89
|
+
/** The hydrate-phase features the hydrate core reads (`ogygia:boot/hydrate-features`); remote
|
|
90
|
+
* seeds are a module of their own ({@link generateRemoteSeedsSource}). */
|
|
91
|
+
export declare const HYDRATE_CODE: readonly FeatureId[];
|
|
76
92
|
/**
|
|
77
|
-
* Emit the HYDRATE-phase feature module (`ogygia:boot/hydrate-features`)
|
|
78
|
-
*
|
|
79
|
-
*
|
|
93
|
+
* Emit the HYDRATE-phase feature module (`ogygia:boot/hydrate-features`): {@link HYDRATE_CODE}'s
|
|
94
|
+
* modules, each `null` where the build leaves the feature out (a hyphen in an id is an underscore
|
|
95
|
+
* in its name), and each as a boolean, `<name>_on`, which the hydrate core tests in place of `HAS`
|
|
96
|
+
* (a namespace tested as a value is built as an object; a boolean is inlined into every chunk that
|
|
97
|
+
* reads it). The hydrate core imports it statically, so these features ride its one existing
|
|
98
|
+
* `import()`, sized by the same marks as the boot. `all` (dev / no marks): every one.
|
|
80
99
|
* @param runtimeDir Absolute directory containing the feature modules.
|
|
100
|
+
* @param ext the modules' extension (`.ts` where the dev server serves core's source)
|
|
81
101
|
*/
|
|
82
|
-
export declare function generateHydrateFeaturesSource(marks: RuntimeMarks, runtimeDir: string, all?: boolean): {
|
|
102
|
+
export declare function generateHydrateFeaturesSource(marks: RuntimeMarks, runtimeDir: string, all?: boolean, ext?: string): {
|
|
83
103
|
code: string;
|
|
84
104
|
features: FeatureId[];
|
|
85
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* Emit `ogygia:boot/remote-seeds`: the remote-seeds feature's module, or `null` where the build leaves
|
|
108
|
+
* it out. The hydrate core and the page feature read it; the navigation chunk imports the page
|
|
109
|
+
* feature too, and seeds the next page's remote queries whether or not an island woke before.
|
|
110
|
+
* @param runtimeDir Absolute directory containing the feature modules.
|
|
111
|
+
* @param ext the modules' extension (`.ts` where the dev server serves core's source)
|
|
112
|
+
*/
|
|
113
|
+
export declare function generateRemoteSeedsSource(marks: RuntimeMarks, runtimeDir: string, all?: boolean, ext?: string): string;
|
|
86
114
|
/**
|
|
87
115
|
* Emit `ogygia:boot/runtime-flags`: build-time constants for code that lives INSIDE the always-on
|
|
88
116
|
* region element rather than in a feature module, because it works on the element's own state. The
|
|
@@ -90,9 +118,10 @@ export declare function generateHydrateFeaturesSource(marks: RuntimeMarks, runti
|
|
|
90
118
|
* guards ships exactly when the feature it serves does. Same marks as the entries; `all` (dev / no
|
|
91
119
|
* marks): every flag on.
|
|
92
120
|
*
|
|
93
|
-
* - `
|
|
94
|
-
*
|
|
95
|
-
*
|
|
121
|
+
* - `HAS`: the build's feature word, a bit per selected feature (core contract/features.ts). The
|
|
122
|
+
* element tests it: without `F_FRAMES` (no region streams HTML: a deferred hole, a live region, a
|
|
123
|
+
* lake) a region's fetch has nowhere to land, so its fetch / apply / morph / renew path is dead
|
|
124
|
+
* code. `all`: every feature's bit.
|
|
96
125
|
* - `load_wire_codec`: `null` where the `wire` feature (the codec) is in the build up front, else
|
|
97
126
|
* the codec's `import()`, for a wake whose props carry a live value the marks did not predict
|
|
98
127
|
* (core runtime/wire-on-use.ts). Generated here, not written in core, so a build with the codec
|
|
@@ -100,4 +129,37 @@ export declare function generateHydrateFeaturesSource(marks: RuntimeMarks, runti
|
|
|
100
129
|
* two (apps/palaestra/e2e/lazy-chunks.spec.ts, the boot-file budget).
|
|
101
130
|
* @param runtimeDir Absolute directory containing `core.js` + the feature modules.
|
|
102
131
|
*/
|
|
103
|
-
export declare function generateRuntimeFlagsSource(marks: RuntimeMarks, runtimeDir: string, all?: boolean): string;
|
|
132
|
+
export declare function generateRuntimeFlagsSource(marks: RuntimeMarks, runtimeDir: string, all?: boolean): string;
|
|
133
|
+
/** The boot features whose module the boot calls directly (`ogygia:boot/feature-code`): every
|
|
134
|
+
* boot-phase feature with a module. */
|
|
135
|
+
export declare const FEATURE_CODE: readonly FeatureId[];
|
|
136
|
+
/**
|
|
137
|
+
* Emit `ogygia:boot/feature-code`: each of {@link FEATURE_CODE}'s modules as a namespace where the
|
|
138
|
+
* build selects the feature, else `null` (`mpa-nav` as `mpa_nav`). The boot calls them under the
|
|
139
|
+
* feature's bit in `HAS` ({@link generateRuntimeFlagsSource}, the same marks), so the bundler binds
|
|
140
|
+
* each call to the function itself, and a build without the feature imports nothing of its module:
|
|
141
|
+
* no call, no state. `all` (dev / no marks): every one.
|
|
142
|
+
* @param runtimeDir Absolute directory containing the feature modules.
|
|
143
|
+
* @param ext the modules' extension (`.ts` where the dev server serves core's source)
|
|
144
|
+
*/
|
|
145
|
+
export declare function generateFeatureCodeSource(marks: RuntimeMarks, runtimeDir: string, all?: boolean, ext?: string): string;
|
|
146
|
+
/** The server's feature word for `marks` (`all`: every feature), as
|
|
147
|
+
* {@link generateServerFlagsSource} writes it. */
|
|
148
|
+
export declare function server_feature_word(marks: RuntimeMarks, all?: boolean): number;
|
|
149
|
+
/**
|
|
150
|
+
* Emit `ogygia:server/runtime-flags`: the same feature word as the browser's `HAS`
|
|
151
|
+
* ({@link generateRuntimeFlagsSource}), for the server build. The server's code for a feature (a
|
|
152
|
+
* hole's render and endpoint, a lake's, a live region's) is written against it, so a server only
|
|
153
|
+
* writes into a page what the page's runtime can revive. The marks only grow while a build runs and
|
|
154
|
+
* the server leg reads them first, so its word never holds a feature the browser's lacks.
|
|
155
|
+
*/
|
|
156
|
+
export declare function generateServerFlagsSource(marks: RuntimeMarks, all?: boolean): string;
|
|
157
|
+
/**
|
|
158
|
+
* Emit `ogygia:region/programs`: the three programs a region's render writes for, as booleans, on
|
|
159
|
+
* each leg from the same marks as its word ({@link generateRuntimeFlagsSource},
|
|
160
|
+
* {@link generateServerFlagsSource}). `HAS_FRAMES` (a hole's fetch, a deferred region's),
|
|
161
|
+
* `HAS_LAKES`, `HAS_LIVE` (a held region's updates). Region.svelte reads them in both realms, so a
|
|
162
|
+
* region whose program the build left out renders its waiting UI on the server and in the browser
|
|
163
|
+
* alike (a hydration that agrees), and the browser's island code drops the branches they switch off.
|
|
164
|
+
*/
|
|
165
|
+
export declare function generateProgramsSource(marks: RuntimeMarks, all?: boolean): string;
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { client_realms_source } from "./caps.js";
|
|
2
|
-
import { dedent } from "@ogygia/core/contract";
|
|
2
|
+
import { F_FRAMES, F_LAKES, F_LIVE, WAKE, dedent, feature_word, parse_trigger } from "@ogygia/core/contract";
|
|
3
3
|
// src/link/runtime-entry.ts
|
|
4
4
|
const HYPHEN = /-/g;
|
|
5
5
|
const BACKSLASH = /\\/g;
|
|
6
|
+
const JS_EXT = /\.js$/;
|
|
7
|
+
function schedules(m) {
|
|
8
|
+
return [
|
|
9
|
+
...m.hydrate || [],
|
|
10
|
+
...m.defer || [],
|
|
11
|
+
...m.prefetch || [],
|
|
12
|
+
...m.revalidate || []
|
|
13
|
+
];
|
|
14
|
+
}
|
|
15
|
+
function schedules_unseen(m) {
|
|
16
|
+
return m.foreign === true || m.live === true;
|
|
17
|
+
}
|
|
6
18
|
const FEATURES = {
|
|
7
19
|
interaction: {
|
|
8
20
|
module: "interaction.js",
|
|
@@ -17,7 +29,7 @@ const FEATURES = {
|
|
|
17
29
|
"mpa-nav": {
|
|
18
30
|
module: "nav-handle.js",
|
|
19
31
|
deps: [],
|
|
20
|
-
detect: (m) => m.page !== false
|
|
32
|
+
detect: (m) => m.page !== false && m.router !== true
|
|
21
33
|
},
|
|
22
34
|
router: {
|
|
23
35
|
module: "router.js",
|
|
@@ -73,6 +85,26 @@ const FEATURES = {
|
|
|
73
85
|
deps: [],
|
|
74
86
|
phase: "hydrate",
|
|
75
87
|
detect: (m) => m.foreign === true || m.context === true
|
|
88
|
+
},
|
|
89
|
+
idle: {
|
|
90
|
+
deps: [],
|
|
91
|
+
phase: "element",
|
|
92
|
+
detect: (m) => schedules_unseen(m) || schedules(m).includes("idle")
|
|
93
|
+
},
|
|
94
|
+
visible: {
|
|
95
|
+
deps: [],
|
|
96
|
+
phase: "element",
|
|
97
|
+
detect: (m) => schedules_unseen(m) || schedules(m).includes("visible")
|
|
98
|
+
},
|
|
99
|
+
graph: {
|
|
100
|
+
deps: [],
|
|
101
|
+
phase: "element",
|
|
102
|
+
detect: (m) => schedules_unseen(m) || (m.hydrate || []).some((w) => w !== "none")
|
|
103
|
+
},
|
|
104
|
+
media: {
|
|
105
|
+
deps: [],
|
|
106
|
+
phase: "element",
|
|
107
|
+
detect: (m) => schedules_unseen(m) || schedules(m).some((w) => parse_trigger(w, WAKE)?.on === "media")
|
|
76
108
|
}
|
|
77
109
|
};
|
|
78
110
|
const FEATURE_ORDER = [
|
|
@@ -88,7 +120,11 @@ const FEATURE_ORDER = [
|
|
|
88
120
|
"forms",
|
|
89
121
|
"mpa-nav",
|
|
90
122
|
"router",
|
|
91
|
-
"context"
|
|
123
|
+
"context",
|
|
124
|
+
"idle",
|
|
125
|
+
"visible",
|
|
126
|
+
"media",
|
|
127
|
+
"graph"
|
|
92
128
|
];
|
|
93
129
|
/** Resolve the closed feature set for a marks manifest. */
|
|
94
130
|
function resolveFeatures(marks) {
|
|
@@ -106,14 +142,16 @@ function resolveFeatures(marks) {
|
|
|
106
142
|
return FEATURE_ORDER.filter((id) => selected.has(id));
|
|
107
143
|
}
|
|
108
144
|
const to_alias = (id) => id.replace(HYPHEN, "_");
|
|
145
|
+
/** A runtime module's path in `runtimeDir`, as an import names it (POSIX). */
|
|
109
146
|
const runtime_path = (runtimeDir, mod) => `${runtimeDir}/${mod}`.replace(BACKSLASH, "/");
|
|
110
147
|
/** The selected features of one {@link FeaturePhase}, in FEATURE_ORDER. */
|
|
111
148
|
function phaseFeatures(marks, phase) {
|
|
112
149
|
return resolveFeatures(marks).filter((id) => (FEATURES[id].phase ?? "boot") === phase);
|
|
113
150
|
}
|
|
114
151
|
/**
|
|
115
|
-
* Emit the BOOT entry: core
|
|
116
|
-
*
|
|
152
|
+
* Emit the BOOT entry: core, booted with the plugins' browser halves. Core installs the selected
|
|
153
|
+
* boot-phase features itself (see {@link FeaturePhase}), from `ogygia:boot/feature-code`
|
|
154
|
+
* ({@link generateFeatureCodeSource}, the same marks). The entry boots and exports nothing.
|
|
117
155
|
* @param runtimeDir Absolute directory containing `core.js` + the feature modules.
|
|
118
156
|
* @param clientPlugins the plugins' browser halves, in plugin order
|
|
119
157
|
*/
|
|
@@ -123,46 +161,65 @@ function generateRuntimeEntrySource(marks, runtimeDir, clientPlugins = []) {
|
|
|
123
161
|
const lines = [];
|
|
124
162
|
lines.push(`/** generated ogygia runtime — features: ${features.join(", ") || "(core only)"} */`);
|
|
125
163
|
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
164
|
if (cp.imports) lines.push(cp.imports.slice(0, -1));
|
|
128
165
|
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});` : "]);");
|
|
166
|
+
lines.push(cp.list ? `boot(${cp.list});` : "boot();");
|
|
132
167
|
return {
|
|
133
168
|
code: `${lines.join("\n")}\n`,
|
|
134
169
|
features
|
|
135
170
|
};
|
|
136
171
|
}
|
|
137
|
-
/**
|
|
138
|
-
*
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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("}");
|
|
172
|
+
/** The hydrate-phase features the hydrate core reads (`ogygia:boot/hydrate-features`); remote
|
|
173
|
+
* seeds are a module of their own ({@link generateRemoteSeedsSource}). */
|
|
174
|
+
const HYDRATE_CODE = FEATURE_ORDER.filter((id) => FEATURES[id].phase === "hydrate" && id !== "remote-seeds");
|
|
175
|
+
function feature_modules(ids, marks, runtimeDir, all, ext, on = false) {
|
|
176
|
+
const selected = all ? FEATURE_ORDER : resolveFeatures(marks);
|
|
177
|
+
const features = ids.filter((id) => selected.includes(id));
|
|
151
178
|
return {
|
|
152
|
-
code: `${
|
|
179
|
+
code: `${ids.flatMap((id) => {
|
|
180
|
+
const file = FEATURES[id].module.replace(JS_EXT, ext);
|
|
181
|
+
const name = to_alias(id);
|
|
182
|
+
const has = features.includes(id);
|
|
183
|
+
const code = has ? `export * as ${name} from ${JSON.stringify(runtime_path(runtimeDir, file))};` : `export const ${name} = null;`;
|
|
184
|
+
return on ? [code, `export const ${name}_on = ${has};`] : [code];
|
|
185
|
+
}).join("\n")}\n`,
|
|
153
186
|
features
|
|
154
187
|
};
|
|
155
188
|
}
|
|
156
189
|
/**
|
|
190
|
+
* Emit the HYDRATE-phase feature module (`ogygia:boot/hydrate-features`): {@link HYDRATE_CODE}'s
|
|
191
|
+
* modules, each `null` where the build leaves the feature out (a hyphen in an id is an underscore
|
|
192
|
+
* in its name), and each as a boolean, `<name>_on`, which the hydrate core tests in place of `HAS`
|
|
193
|
+
* (a namespace tested as a value is built as an object; a boolean is inlined into every chunk that
|
|
194
|
+
* reads it). The hydrate core imports it statically, so these features ride its one existing
|
|
195
|
+
* `import()`, sized by the same marks as the boot. `all` (dev / no marks): every one.
|
|
196
|
+
* @param runtimeDir Absolute directory containing the feature modules.
|
|
197
|
+
* @param ext the modules' extension (`.ts` where the dev server serves core's source)
|
|
198
|
+
*/
|
|
199
|
+
function generateHydrateFeaturesSource(marks, runtimeDir, all = false, ext = ".js") {
|
|
200
|
+
return feature_modules(HYDRATE_CODE, marks, runtimeDir, all, ext, true);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Emit `ogygia:boot/remote-seeds`: the remote-seeds feature's module, or `null` where the build leaves
|
|
204
|
+
* it out. The hydrate core and the page feature read it; the navigation chunk imports the page
|
|
205
|
+
* feature too, and seeds the next page's remote queries whether or not an island woke before.
|
|
206
|
+
* @param runtimeDir Absolute directory containing the feature modules.
|
|
207
|
+
* @param ext the modules' extension (`.ts` where the dev server serves core's source)
|
|
208
|
+
*/
|
|
209
|
+
function generateRemoteSeedsSource(marks, runtimeDir, all = false, ext = ".js") {
|
|
210
|
+
return feature_modules(["remote-seeds"], marks, runtimeDir, all, ext, true).code;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
157
213
|
* Emit `ogygia:boot/runtime-flags`: build-time constants for code that lives INSIDE the always-on
|
|
158
214
|
* region element rather than in a feature module, because it works on the element's own state. The
|
|
159
215
|
* bundler inlines an imported `const` and drops the branches it switches off, so the code a flag
|
|
160
216
|
* guards ships exactly when the feature it serves does. Same marks as the entries; `all` (dev / no
|
|
161
217
|
* marks): every flag on.
|
|
162
218
|
*
|
|
163
|
-
* - `
|
|
164
|
-
*
|
|
165
|
-
*
|
|
219
|
+
* - `HAS`: the build's feature word, a bit per selected feature (core contract/features.ts). The
|
|
220
|
+
* element tests it: without `F_FRAMES` (no region streams HTML: a deferred hole, a live region, a
|
|
221
|
+
* lake) a region's fetch has nowhere to land, so its fetch / apply / morph / renew path is dead
|
|
222
|
+
* code. `all`: every feature's bit.
|
|
166
223
|
* - `load_wire_codec`: `null` where the `wire` feature (the codec) is in the build up front, else
|
|
167
224
|
* the codec's `import()`, for a wake whose props carry a live value the marks did not predict
|
|
168
225
|
* (core runtime/wire-on-use.ts). Generated here, not written in core, so a build with the codec
|
|
@@ -171,13 +228,58 @@ function generateHydrateFeaturesSource(marks, runtimeDir, all = false) {
|
|
|
171
228
|
* @param runtimeDir Absolute directory containing `core.js` + the feature modules.
|
|
172
229
|
*/
|
|
173
230
|
function generateRuntimeFlagsSource(marks, runtimeDir, all = false) {
|
|
174
|
-
const features = resolveFeatures(marks);
|
|
175
|
-
const frames = all || features.includes("frames");
|
|
231
|
+
const features = all ? FEATURE_ORDER : resolveFeatures(marks);
|
|
176
232
|
const codec = JSON.stringify(runtime_path(runtimeDir, FEATURES.wire.module));
|
|
177
|
-
const load_wire_codec =
|
|
233
|
+
const load_wire_codec = features.includes("wire") ? "null" : `() => import(${codec})`;
|
|
178
234
|
return `${dedent`
|
|
179
|
-
export const
|
|
235
|
+
export const HAS = ${feature_word(features)};
|
|
180
236
|
export const load_wire_codec = ${load_wire_codec};
|
|
181
237
|
`}\n`;
|
|
182
238
|
}
|
|
183
|
-
|
|
239
|
+
/** The boot features whose module the boot calls directly (`ogygia:boot/feature-code`): every
|
|
240
|
+
* boot-phase feature with a module. */
|
|
241
|
+
const FEATURE_CODE = FEATURE_ORDER.filter((id) => (FEATURES[id].phase ?? "boot") === "boot" && FEATURES[id].module !== void 0);
|
|
242
|
+
/**
|
|
243
|
+
* Emit `ogygia:boot/feature-code`: each of {@link FEATURE_CODE}'s modules as a namespace where the
|
|
244
|
+
* build selects the feature, else `null` (`mpa-nav` as `mpa_nav`). The boot calls them under the
|
|
245
|
+
* feature's bit in `HAS` ({@link generateRuntimeFlagsSource}, the same marks), so the bundler binds
|
|
246
|
+
* each call to the function itself, and a build without the feature imports nothing of its module:
|
|
247
|
+
* no call, no state. `all` (dev / no marks): every one.
|
|
248
|
+
* @param runtimeDir Absolute directory containing the feature modules.
|
|
249
|
+
* @param ext the modules' extension (`.ts` where the dev server serves core's source)
|
|
250
|
+
*/
|
|
251
|
+
function generateFeatureCodeSource(marks, runtimeDir, all = false, ext = ".js") {
|
|
252
|
+
return feature_modules(FEATURE_CODE, marks, runtimeDir, all, ext).code;
|
|
253
|
+
}
|
|
254
|
+
/** The server's feature word for `marks` (`all`: every feature), as
|
|
255
|
+
* {@link generateServerFlagsSource} writes it. */
|
|
256
|
+
function server_feature_word(marks, all = false) {
|
|
257
|
+
return feature_word(all ? FEATURE_ORDER : resolveFeatures(marks));
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Emit `ogygia:server/runtime-flags`: the same feature word as the browser's `HAS`
|
|
261
|
+
* ({@link generateRuntimeFlagsSource}), for the server build. The server's code for a feature (a
|
|
262
|
+
* hole's render and endpoint, a lake's, a live region's) is written against it, so a server only
|
|
263
|
+
* writes into a page what the page's runtime can revive. The marks only grow while a build runs and
|
|
264
|
+
* the server leg reads them first, so its word never holds a feature the browser's lacks.
|
|
265
|
+
*/
|
|
266
|
+
function generateServerFlagsSource(marks, all = false) {
|
|
267
|
+
return `export const HAS = ${server_feature_word(marks, all)};\n`;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Emit `ogygia:region/programs`: the three programs a region's render writes for, as booleans, on
|
|
271
|
+
* each leg from the same marks as its word ({@link generateRuntimeFlagsSource},
|
|
272
|
+
* {@link generateServerFlagsSource}). `HAS_FRAMES` (a hole's fetch, a deferred region's),
|
|
273
|
+
* `HAS_LAKES`, `HAS_LIVE` (a held region's updates). Region.svelte reads them in both realms, so a
|
|
274
|
+
* region whose program the build left out renders its waiting UI on the server and in the browser
|
|
275
|
+
* alike (a hydration that agrees), and the browser's island code drops the branches they switch off.
|
|
276
|
+
*/
|
|
277
|
+
function generateProgramsSource(marks, all = false) {
|
|
278
|
+
const word = feature_word(all ? FEATURE_ORDER : resolveFeatures(marks));
|
|
279
|
+
return `${dedent`
|
|
280
|
+
export const HAS_FRAMES = ${(word & F_FRAMES) !== 0};
|
|
281
|
+
export const HAS_LAKES = ${(word & F_LAKES) !== 0};
|
|
282
|
+
export const HAS_LIVE = ${(word & F_LIVE) !== 0};
|
|
283
|
+
`}\n`;
|
|
284
|
+
}
|
|
285
|
+
export { FEATURES, FEATURE_CODE, FEATURE_ORDER, HYDRATE_CODE, generateFeatureCodeSource, generateHydrateFeaturesSource, generateProgramsSource, generateRemoteSeedsSource, generateRuntimeEntrySource, generateRuntimeFlagsSource, generateServerFlagsSource, phaseFeatures, resolveFeatures, runtime_path, server_feature_word };
|
|
@@ -14,6 +14,9 @@ export declare function server_manifest_module(ssr: boolean, program: Program, i
|
|
|
14
14
|
/** In a build's `server-regions`, the loaders of the regions found after it was written: an
|
|
15
15
|
* identifier no module defines, so the bundler keeps it as written (link/relocations.ts). */
|
|
16
16
|
export declare const LATE_SERVER_REGIONS_TOKEN = "__OGYGIA_LATE_SERVER_REGIONS__";
|
|
17
|
+
/** In a build's `runtime-url`, the runtime's URL: named only once the server leg has compiled every
|
|
18
|
+
* module (`Compiler.server_runtime`), inside a string literal (link/relocations.ts). */
|
|
19
|
+
export declare const RUNTIME_URL_TOKEN = "__OGYGIA_RUNTIME_URL__";
|
|
17
20
|
/** `ogygia:server/server-regions`: each SERVER island's loader, `id → () => import(entry)` (empty on
|
|
18
21
|
* the client). Imported only by the manifest's `load_islands()` — never statically. `late`: a
|
|
19
22
|
* build's, which names the loaders of regions found after it (`Program.server_regions_written`). */
|
|
@@ -81,6 +81,9 @@ function server_manifest_module(ssr, program, is_dev, devUrlFor) {
|
|
|
81
81
|
/** In a build's `server-regions`, the loaders of the regions found after it was written: an
|
|
82
82
|
* identifier no module defines, so the bundler keeps it as written (link/relocations.ts). */
|
|
83
83
|
const LATE_SERVER_REGIONS_TOKEN = "__OGYGIA_LATE_SERVER_REGIONS__";
|
|
84
|
+
/** In a build's `runtime-url`, the runtime's URL: named only once the server leg has compiled every
|
|
85
|
+
* module (`Compiler.server_runtime`), inside a string literal (link/relocations.ts). */
|
|
86
|
+
const RUNTIME_URL_TOKEN = "__OGYGIA_RUNTIME_URL__";
|
|
84
87
|
/** `ogygia:server/server-regions`: each SERVER island's loader, `id → () => import(entry)` (empty on
|
|
85
88
|
* the client). Imported only by the manifest's `load_islands()` — never statically. `late`: a
|
|
86
89
|
* build's, which names the loaders of regions found after it (`Program.server_regions_written`). */
|
|
@@ -99,4 +102,4 @@ function server_regions_module(ssr, program, late) {
|
|
|
99
102
|
* was (every hole then looked its page up). Unpatched it parses to nothing → `null`. */
|
|
100
103
|
const PAGE_DATA_READS_TOKEN = "__OGYGIA_PAGE_DATA_READS__";
|
|
101
104
|
const PAGE_DATA_READS_PLACEHOLDER = `(() => { try { return JSON.parse("${PAGE_DATA_READS_TOKEN}"); } catch { return null; } })()`;
|
|
102
|
-
export { LATE_SERVER_REGIONS_TOKEN, PAGE_DATA_READS_PLACEHOLDER, PAGE_DATA_READS_TOKEN, SERVER_MAP_TOKENS, server_island_ids, server_manifest_maps, server_manifest_module, server_regions, server_regions_module };
|
|
105
|
+
export { LATE_SERVER_REGIONS_TOKEN, PAGE_DATA_READS_PLACEHOLDER, PAGE_DATA_READS_TOKEN, RUNTIME_URL_TOKEN, SERVER_MAP_TOKENS, server_island_ids, server_manifest_maps, server_manifest_module, server_regions, server_regions_module };
|
package/dist/messages.d.ts
CHANGED
|
@@ -346,6 +346,23 @@ export declare const BUILD_ERRORS: {
|
|
|
346
346
|
}) => string;
|
|
347
347
|
details: () => string;
|
|
348
348
|
};
|
|
349
|
+
runtime_features_unnamed: {
|
|
350
|
+
text: (a: {
|
|
351
|
+
features: string;
|
|
352
|
+
}) => string;
|
|
353
|
+
details: () => string;
|
|
354
|
+
};
|
|
355
|
+
server_features_late: {
|
|
356
|
+
text: (a: {
|
|
357
|
+
features: string;
|
|
358
|
+
modules: string;
|
|
359
|
+
}) => string;
|
|
360
|
+
details: () => string;
|
|
361
|
+
};
|
|
362
|
+
server_runtime_unnamed: {
|
|
363
|
+
text: () => string;
|
|
364
|
+
details: () => string;
|
|
365
|
+
};
|
|
349
366
|
plugin_without_ogygia: {
|
|
350
367
|
text: (a: {
|
|
351
368
|
plugin: string;
|
|
@@ -536,6 +553,13 @@ declare const WARNED: {
|
|
|
536
553
|
}) => string;
|
|
537
554
|
details: () => string;
|
|
538
555
|
};
|
|
556
|
+
server_exports_kept: {
|
|
557
|
+
text: (a: {
|
|
558
|
+
file: string;
|
|
559
|
+
reason: string;
|
|
560
|
+
}) => string;
|
|
561
|
+
details: () => string;
|
|
562
|
+
};
|
|
539
563
|
relocation_unpatched: {
|
|
540
564
|
text: (a: {
|
|
541
565
|
name: string;
|