@ogygia/compiler 0.0.0-stage → 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 +63 -2
- 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 +85 -3
package/dist/driver.js
ADDED
|
@@ -0,0 +1,1401 @@
|
|
|
1
|
+
import { CLIENT_BINDING_STUB, is_island_path, transformHost, transformTsRegions } from "./region/transform.js";
|
|
2
|
+
import { clean_stale_ogygia_dirs, hasAnyCsrTrueRoute, is_route_component, routeCsrIsFalse, routeCsrIsTrue } from "./kit.js";
|
|
3
|
+
import { run_module_macros } from "./macros/pipeline.js";
|
|
4
|
+
import { fn_manifest_entries } from "./macros/dollar.js";
|
|
5
|
+
import { is_script_request } from "./script-request.js";
|
|
6
|
+
import { resolveFeatures } from "./link/runtime-entry.js";
|
|
7
|
+
import { FOUC_CSS_PREFIX, FOUC_SCOPED_PREFIX } from "./fouc-css.js";
|
|
8
|
+
import { resolve_app_spec } from "./app-spec.js";
|
|
9
|
+
import { appendTransportRegistrations, moduleHasTransportable, svelteModuleHasTransportable, svelte_module_registration } from "./transportables.js";
|
|
10
|
+
import { APP_SHIM_IMPORT, FOREIGN_HYDRATE_MARK, rewrite_lake_import_to_placeholder } from "./region/emit.js";
|
|
11
|
+
import { by_code_unit, by_key, location_map_files } from "./link/location-map.js";
|
|
12
|
+
import { context_keys } from "./link/context-detect.js";
|
|
13
|
+
import { own_reach, reaches_context, reaches_wire } from "./link/own-reach.js";
|
|
14
|
+
import { router_css_roots } from "./link/router-css.js";
|
|
15
|
+
import { relocate, relocations_of } from "./link/relocations.js";
|
|
16
|
+
import { island_vpaths_affected_by_file, same_module_path } from "./dev/hmr.js";
|
|
17
|
+
import { VirtualTable } from "./virtual/resolver.js";
|
|
18
|
+
import { CORE_VALUE_NAMES } from "./virtual/value-names.js";
|
|
19
|
+
import { CORE_PARTS, CORE_VIRTUALS, core_path } from "./virtual/core.js";
|
|
20
|
+
import { host_key, strip_id } from "./program.js";
|
|
21
|
+
import { export_names, registry_client_id, registry_client_path, registry_client_source, registry_stub_source, static_script_specs } from "./link/registry-stub.js";
|
|
22
|
+
import { island_host_loaded } from "./link/emit-gate.js";
|
|
23
|
+
import { opaque_stamp_edits } from "./ownership-stamps.js";
|
|
24
|
+
import { MapChain } from "./map-chain.js";
|
|
25
|
+
import { splice_map, splice_text } from "./splice.js";
|
|
26
|
+
import { strip_bom } from "./bom.js";
|
|
27
|
+
import { RESOLVED, V_RUNTIME_ENTRY, region_family, wrapperVirtualId } from "./ids.js";
|
|
28
|
+
import { is_generated_specifier } from "./virtual/table.js";
|
|
29
|
+
import { OgygiaError, warn } from "./messages.js";
|
|
30
|
+
import { new_leg } from "./leg.js";
|
|
31
|
+
import path from "node:path";
|
|
32
|
+
import { fnv1a32, key_label, key_of } from "@ogygia/core/contract";
|
|
33
|
+
import { createHash } from "node:crypto";
|
|
34
|
+
import { cache, say } from "@ogygia/machine";
|
|
35
|
+
// src/driver.ts
|
|
36
|
+
function result_map(result) {
|
|
37
|
+
const map = result.map;
|
|
38
|
+
return map ? () => map : null;
|
|
39
|
+
}
|
|
40
|
+
const ISLAND_ENTRY_NAME_PREFIX = "og-region.";
|
|
41
|
+
const RUNTIME_ENTRY_NAME = "og-runtime";
|
|
42
|
+
const LATE_SERVER_REGION_NAME = "og-server-region";
|
|
43
|
+
const new_build = (program) => ({
|
|
44
|
+
legs: /* @__PURE__ */ new Map(),
|
|
45
|
+
begun: false,
|
|
46
|
+
program,
|
|
47
|
+
virtuals: new VirtualTable(CORE_VIRTUALS, core_path, CORE_VALUE_NAMES, CORE_PARTS, program.scan.db),
|
|
48
|
+
transform_cache: /* @__PURE__ */ new Map(),
|
|
49
|
+
dollar_hoists: /* @__PURE__ */ new Map(),
|
|
50
|
+
scan: null,
|
|
51
|
+
router_css_roots: null,
|
|
52
|
+
resolve_memo: /* @__PURE__ */ new Map(),
|
|
53
|
+
reach_memo: /* @__PURE__ */ new Map(),
|
|
54
|
+
specs_memo: /* @__PURE__ */ new Map(),
|
|
55
|
+
island_closure_seen: /* @__PURE__ */ new Set()
|
|
56
|
+
});
|
|
57
|
+
const LEADING_SLASH = /^\//;
|
|
58
|
+
const COMPONENT_EXT_RE = /\.(svelte|js|ts)$/;
|
|
59
|
+
const ROUTE_HOST_FILE_RE = /^\+(page|layout)\.(ts|js|mjs)$/;
|
|
60
|
+
const REGION_BINDING_PREFIX = region_family("binding");
|
|
61
|
+
const WRAPPER_PREFIX = region_family("wrapper");
|
|
62
|
+
const TS_REGISTRY_EXT_RE = /\.(ts|js|mjs)$/;
|
|
63
|
+
const SVELTE_RUNE_MODULE_RE = /\.svelte\.(ts|js)$/;
|
|
64
|
+
const SCRIPT_MODULE_RE = /\.(?:[cm]?[jt]sx?)$/;
|
|
65
|
+
const SOURCE_EXT_RE = /\.(svelte|ts|js|mjs|cjs)$/;
|
|
66
|
+
const SERVER_MODULE_EXT_RE = /\.(server|remote)\.(ts|js|mjs)$/;
|
|
67
|
+
const SERVER_DIR_RE = /\/(src\/lib\/server|server)\//;
|
|
68
|
+
const IMPORT_SPEC_G = /\bfrom\s*['"]([^'"\n]+)['"]|\bimport\s*['"]([^'"\n]+)['"]|\bimport\s*\(\s*['"]([^'"\n]+)['"]/g;
|
|
69
|
+
const PAGE_FREE_APP_MODULES = /* @__PURE__ */ new Set(["$app/environment", "$app/paths"]);
|
|
70
|
+
const ASSET_EXTS = "css|scss|sass|less|styl|pcss|postcss|json|svg|png|jpe?g|gif|webp|avif|ico|bmp|woff2?|ttf|otf|eot|txt|wasm|mp4|webm|mp3|wav";
|
|
71
|
+
const ASSET_EXT_RE = new RegExp(`\\.(?:${ASSET_EXTS})$`, "i");
|
|
72
|
+
const PAGE_FREE_UNRESOLVED_RE = new RegExp(`^svelte(?:\\/[\\w/-]+)?$|\\.(?:${ASSET_EXTS})(?:\\?[^/]*)?$`, "i");
|
|
73
|
+
const ISLAND_DEP_EXTS = [
|
|
74
|
+
"",
|
|
75
|
+
".svelte",
|
|
76
|
+
".ts",
|
|
77
|
+
".js",
|
|
78
|
+
".svelte.ts",
|
|
79
|
+
".svelte.js",
|
|
80
|
+
".mjs"
|
|
81
|
+
];
|
|
82
|
+
const MODULE_SPEC_RE = /(?:^|[\n;])\s*(?:import|export)\b[^;'"()]*?from\s*['"]([^'"]+)['"]|(?:^|[\n;])\s*import\s*['"]([^'"]+)['"]/g;
|
|
83
|
+
const KIT_RUNTIME_APP = "/@sveltejs/kit/src/runtime/app/";
|
|
84
|
+
/**
|
|
85
|
+
* The island shim for an `$app/*` import, by specifier or by where Kit's alias sent it: Vite's alias
|
|
86
|
+
* plugin runs before any plugin's resolveId, so an import the transform did not rewrite (a module
|
|
87
|
+
* that joined the island graph late) arrives as `<kit>/src/runtime/app/state`, `…/state/index.js`.
|
|
88
|
+
*/
|
|
89
|
+
function app_shim_for(source, shims) {
|
|
90
|
+
const direct = shims[source];
|
|
91
|
+
if (direct) return direct;
|
|
92
|
+
const at = source.indexOf(KIT_RUNTIME_APP);
|
|
93
|
+
if (at === -1) return null;
|
|
94
|
+
let name = source.slice(at + 31);
|
|
95
|
+
if (name.endsWith("/index.js")) name = name.slice(0, -9);
|
|
96
|
+
else if (name.endsWith(".js")) name = name.slice(0, -3);
|
|
97
|
+
return shims[`$app/${name}`] ?? null;
|
|
98
|
+
}
|
|
99
|
+
function prescan_rel(ctx, full) {
|
|
100
|
+
return (ctx.pkg_identity(full) ?? path.relative(ctx.root, full)).split(path.sep).join("/");
|
|
101
|
+
}
|
|
102
|
+
function scan_kind(name) {
|
|
103
|
+
if (name.endsWith(".svelte")) return "svelte";
|
|
104
|
+
if (SCAN_SCRIPT_RE.test(name) && !name.endsWith(".d.ts")) return "script";
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const SCAN_SCRIPT_RE = /\.(?:ts|js|mjs)$/;
|
|
108
|
+
const REMOTE_FILE_RE = /\.remote\.[jt]s$/;
|
|
109
|
+
const PLUGIN_PACKAGES = { "@ogygia/flags": "flags()" };
|
|
110
|
+
const unlisted_said = say();
|
|
111
|
+
function extract_module_specs(src) {
|
|
112
|
+
return [...src.matchAll(MODULE_SPEC_RE)].map((m) => m[1] ?? m[2]);
|
|
113
|
+
}
|
|
114
|
+
const warned_undeclared = cache({
|
|
115
|
+
name: "warned undeclared package marks",
|
|
116
|
+
max: 1e4
|
|
117
|
+
});
|
|
118
|
+
function warn_undeclared_pkg_marks(id) {
|
|
119
|
+
if (warned_undeclared.has(id)) return;
|
|
120
|
+
warned_undeclared.set(id, true);
|
|
121
|
+
warn("package_marks_undeclared", { file: id });
|
|
122
|
+
}
|
|
123
|
+
var Compiler = class Compiler {
|
|
124
|
+
profiler;
|
|
125
|
+
/** The build under way (see `Build`). */
|
|
126
|
+
#build;
|
|
127
|
+
/** The build's program: registry, graph and the scan's facts. */
|
|
128
|
+
get program() {
|
|
129
|
+
return this.#build.program;
|
|
130
|
+
}
|
|
131
|
+
get transform_cache() {
|
|
132
|
+
return this.#build.transform_cache;
|
|
133
|
+
}
|
|
134
|
+
/** Every `import.meta.og.$` hoist collected across the build (tag → factory source). Filled by
|
|
135
|
+
* `macros()`; drained by the adapter's fn-manifest emit (dev load leg, renderChunk, writeBundle). */
|
|
136
|
+
get dollar_hoists() {
|
|
137
|
+
return this.#build.dollar_hoists;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Open leg `name` (the bundler environment a build hook runs in; `server` when its output runs in
|
|
141
|
+
* Node). A leg that already ran in this build begins the next one (watch, a second `build()` in
|
|
142
|
+
* one process): everything the last build learned is dropped. Dev is one build for the session.
|
|
143
|
+
* True when this leg begins a build, so the caller runs its once-per-build work; Kit's route
|
|
144
|
+
* answers are read afresh from there.
|
|
145
|
+
*/
|
|
146
|
+
start_leg(name, server) {
|
|
147
|
+
if (this.#build.legs.has(name) && this.#ctx.is_build) this.#build = new_build(this.#build.program.fresh());
|
|
148
|
+
const build = this.#build;
|
|
149
|
+
if (!build.legs.has(name)) build.legs.set(name, new_leg(name, server));
|
|
150
|
+
if (build.begun) return false;
|
|
151
|
+
build.begun = true;
|
|
152
|
+
this.#ctx.routes.db.reread();
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The leg a hook runs in: its environment's, else (a hook the bundler calls without one) the one
|
|
157
|
+
* leg open now. Refused when that is not one leg (`build_leg_unclear`): two legs open at once
|
|
158
|
+
* cannot be told apart. Dev opens an environment's leg on its first use.
|
|
159
|
+
*/
|
|
160
|
+
leg(env) {
|
|
161
|
+
const legs = this.#build.legs;
|
|
162
|
+
if (env) {
|
|
163
|
+
const leg = legs.get(env.name);
|
|
164
|
+
if (leg) return leg;
|
|
165
|
+
if (!this.#ctx.is_build) {
|
|
166
|
+
const opened = new_leg(env.name, env.server);
|
|
167
|
+
legs.set(env.name, opened);
|
|
168
|
+
return opened;
|
|
169
|
+
}
|
|
170
|
+
throw new OgygiaError("build_leg_unclear", {
|
|
171
|
+
leg: env.name,
|
|
172
|
+
open: 0
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
const open = [...legs.values()].filter((l) => l.life.now.kind === "open");
|
|
176
|
+
if (open.length === 1) return open[0];
|
|
177
|
+
throw new OgygiaError("build_leg_unclear", {
|
|
178
|
+
leg: "",
|
|
179
|
+
open: open.length
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/** Leg `name` of this build, if it started (a reader that may run outside any leg). */
|
|
183
|
+
find_leg(name) {
|
|
184
|
+
return this.#build.legs.get(name);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* A leg ends (its bundle is written): `env`'s, else (a hook the bundler calls without one) the one
|
|
188
|
+
* leg open now. With two open (a dev server closing: its legs live for the session) there is no
|
|
189
|
+
* one leg to end, and none ends. Ending a leg that already ended does nothing (closeBundle may run
|
|
190
|
+
* again).
|
|
191
|
+
*/
|
|
192
|
+
end_leg(env) {
|
|
193
|
+
const legs = this.#build.legs;
|
|
194
|
+
const open = [...legs.values()].filter((l) => l.life.now.kind === "open");
|
|
195
|
+
let leg = env !== null ? legs.get(env) : void 0;
|
|
196
|
+
if (env === null && open.length === 1) leg = open[0];
|
|
197
|
+
if (leg?.life.now.kind === "open") leg.life.go("closed");
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* DEV, after each transform: the virtual modules whose last load read something (the registry,
|
|
201
|
+
* the marks, a fold over the files' scan facts) that has since changed, for the adapter to
|
|
202
|
+
* invalidate. One rule for every reader: the server manifest emitted while a host's rows were
|
|
203
|
+
* dropped for its edit (every hole answered 403 until a restart), the runtime entry chosen before
|
|
204
|
+
* a page's first `idle` region (it never woke: test/dev-regions-reload.test.ts), and the wire
|
|
205
|
+
* loaders, Kit's codecs and the router CSS roots read before a file's facts changed
|
|
206
|
+
* (test/dev-scan-facts.test.ts). A registry module a load answered null while no host held it is
|
|
207
|
+
* named once a host registers it.
|
|
208
|
+
*/
|
|
209
|
+
moved() {
|
|
210
|
+
const out = this.#virtuals.moved();
|
|
211
|
+
for (const id of this.#unanswered) if (this.program.registry.has(id)) {
|
|
212
|
+
this.#unanswered.delete(id);
|
|
213
|
+
out.push(id);
|
|
214
|
+
}
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
/** Register a transform's regions; in dev, note whether that moved what `regions` readers read. */
|
|
218
|
+
#register(result, host) {
|
|
219
|
+
if (!this.#ctx.is_dev) return this.program.register(result, host);
|
|
220
|
+
const before = this.#regions_print(host);
|
|
221
|
+
this.program.register(result, host);
|
|
222
|
+
if (this.#regions_print(host) !== before) this.#virtuals.move("regions");
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* One file's scan facts: what the prescan reads of every file, and the dev transform reads again of
|
|
226
|
+
* the file it transforms (a file added or edited while dev runs). Replaces the file's old facts
|
|
227
|
+
* (`src` null: a deleted file has none). The marks only grow: a feature too many is safe.
|
|
228
|
+
*/
|
|
229
|
+
#scan_facts(full, src, kind) {
|
|
230
|
+
const ctx = this.#ctx;
|
|
231
|
+
const { runtime_marks, scan } = this.program;
|
|
232
|
+
const dev = ctx.is_dev;
|
|
233
|
+
const marks_before = dev ? JSON.stringify(runtime_marks) : "";
|
|
234
|
+
let specs = [];
|
|
235
|
+
if (src === null) scan.set(full, null);
|
|
236
|
+
else {
|
|
237
|
+
const remote = kind === "script" && REMOTE_FILE_RE.test(full);
|
|
238
|
+
specs = extract_module_specs(src);
|
|
239
|
+
const page_importers = ctx.page_importers;
|
|
240
|
+
const reach = own_reach(src, full, kind);
|
|
241
|
+
const facts = {
|
|
242
|
+
crosses_wire: remote || reaches_wire(reach),
|
|
243
|
+
transportable: kind === "svelte" ? svelteModuleHasTransportable(src, full) : moduleHasTransportable(src, full),
|
|
244
|
+
specs,
|
|
245
|
+
router: page_importers.length > 0 && specs.some((s) => page_importers.includes(s)) || ctx.page_files.includes(full)
|
|
246
|
+
};
|
|
247
|
+
scan.set(full, facts);
|
|
248
|
+
if (!runtime_marks.context && reaches_context(reach)) runtime_marks.context = true;
|
|
249
|
+
if (remote) runtime_marks.remoteSeeds = true;
|
|
250
|
+
if (facts.transportable) runtime_marks.wire = true;
|
|
251
|
+
}
|
|
252
|
+
if (dev && JSON.stringify(runtime_marks) !== marks_before) this.#virtuals.move("regions");
|
|
253
|
+
return specs;
|
|
254
|
+
}
|
|
255
|
+
/** How the prescan's walk reads `id`: the app's `src/` and the declared package surfaces, minus
|
|
256
|
+
* `node_modules` and generated island dirs beneath them. Null: the walk never reaches it. */
|
|
257
|
+
#scans(id) {
|
|
258
|
+
const ctx = this.#ctx;
|
|
259
|
+
const kind = scan_kind(id);
|
|
260
|
+
if (!kind || !path.isAbsolute(id)) return null;
|
|
261
|
+
const posix_id = id.split(path.sep).join("/");
|
|
262
|
+
const src_dir = `${path.join(ctx.root, "src").split(path.sep).join("/")}/`;
|
|
263
|
+
let rest;
|
|
264
|
+
if (posix_id.startsWith(src_dir)) rest = posix_id.slice(src_dir.length);
|
|
265
|
+
else if (ctx.in_declared_pkg(posix_id)) {
|
|
266
|
+
const dir = ctx.pkg_scan.flatMap((p) => p.dirs).find((d) => posix_id.startsWith(`${d}/`));
|
|
267
|
+
rest = dir === void 0 ? "" : posix_id.slice(dir.length + 1);
|
|
268
|
+
} else return null;
|
|
269
|
+
const segments = rest.split("/").slice(0, -1);
|
|
270
|
+
return segments.includes("node_modules") || segments.includes(".ogygia") ? null : kind;
|
|
271
|
+
}
|
|
272
|
+
/** The marks and one host's rows, as text (dev only: the change check above). */
|
|
273
|
+
#regions_print(host) {
|
|
274
|
+
const { registry, host_index, runtime_marks } = this.program;
|
|
275
|
+
const rows = [...host_index.get(host_key(host))?.vpaths ?? []].sort().map((vpath) => {
|
|
276
|
+
const e = registry.get(vpath);
|
|
277
|
+
return [
|
|
278
|
+
vpath,
|
|
279
|
+
e?.hostPath,
|
|
280
|
+
e?.server,
|
|
281
|
+
e?.source,
|
|
282
|
+
e?.ssrSource,
|
|
283
|
+
e?.clientSource
|
|
284
|
+
];
|
|
285
|
+
});
|
|
286
|
+
return JSON.stringify([runtime_marks, rows]);
|
|
287
|
+
}
|
|
288
|
+
#ctx;
|
|
289
|
+
/** The resolved compile context (the bundler's resolved config, read once it is resolved). */
|
|
290
|
+
get ctx() {
|
|
291
|
+
return this.#ctx;
|
|
292
|
+
}
|
|
293
|
+
get #virtuals() {
|
|
294
|
+
return this.#build.virtuals;
|
|
295
|
+
}
|
|
296
|
+
/** The app's Kit routes directory (a virtual module that reads it reloads on a route change). */
|
|
297
|
+
routes_dir() {
|
|
298
|
+
return this.#ctx.kit_dirs.routes_dir;
|
|
299
|
+
}
|
|
300
|
+
/** The plugins listed beside `ogygia()`. */
|
|
301
|
+
plugins() {
|
|
302
|
+
const ctx = this.#ctx;
|
|
303
|
+
return {
|
|
304
|
+
server: ctx.server_plugins,
|
|
305
|
+
client: ctx.client_plugins,
|
|
306
|
+
route_config: ctx.route_config
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/** The modules of one leg's built output that its realms may not hold (./virtual/resolver.ts). */
|
|
310
|
+
misplaced_modules(module_ids, ssr) {
|
|
311
|
+
return this.#virtuals.misplaced(module_ids, {
|
|
312
|
+
ssr,
|
|
313
|
+
dev: false
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
/** A module's named imports of a realm module, per entry (./virtual/resolver.ts). */
|
|
317
|
+
split_realm_imports(code) {
|
|
318
|
+
return this.#virtuals.split_realm_imports(code);
|
|
319
|
+
}
|
|
320
|
+
/** A dev change to a part of the session: the resolved ids of the virtual modules whose last load
|
|
321
|
+
* read it (or anything else that has moved), for the caller to invalidate. */
|
|
322
|
+
changed(part) {
|
|
323
|
+
this.#virtuals.move(part);
|
|
324
|
+
return this.#virtuals.moved();
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* DEV: a file was added, changed or removed. What the route answers read of it is read again
|
|
328
|
+
* (`Routes.touch`); when none of that changed, nothing is invalidated. Else the ids to invalidate
|
|
329
|
+
* are the virtual modules that read the routes AND every module compiled for a csr world that is
|
|
330
|
+
* no longer its own: a host compiled for csr=true has its marks stripped, so a page that became
|
|
331
|
+
* csr=false kept no regions until a restart (test/dev-csr-change.test.ts). Its old rows go now;
|
|
332
|
+
* its next transform registers anew.
|
|
333
|
+
*/
|
|
334
|
+
routes_changed(file, event) {
|
|
335
|
+
if (!this.#ctx.routes.touch(file, event)) return [];
|
|
336
|
+
const out = new Set(this.changed("routes"));
|
|
337
|
+
const invalidate = (id) => out.add(id);
|
|
338
|
+
for (const [k, w] of this.#worlds) {
|
|
339
|
+
if (this.#csr_world(w.id, w.ssr, w.link).key === w.key) continue;
|
|
340
|
+
this.#worlds.delete(k);
|
|
341
|
+
if (this.is_registered_host(w.id)) this.invalidate_for_file(w.id, { invalidate });
|
|
342
|
+
out.add(w.id);
|
|
343
|
+
}
|
|
344
|
+
return [...out];
|
|
345
|
+
}
|
|
346
|
+
/** DEV: each module's csr world as last compiled, by leg and id (`routes_changed`). */
|
|
347
|
+
#worlds = /* @__PURE__ */ new Map();
|
|
348
|
+
/**
|
|
349
|
+
* The csr world a module is compiled for, on one leg: whether it links the real region modules
|
|
350
|
+
* (`link_virtual`), its route's csr (`route_csr`), and both as a cache key.
|
|
351
|
+
*
|
|
352
|
+
* A csr=false CLIENT host does not link the real wrappers (or the hydrate entries they pull in):
|
|
353
|
+
* Kit still emits its page node, and sharing that module with the page graph makes Rolldown emit
|
|
354
|
+
* thin `og-region.*` facades. SSR links them for the HTML, and a csr=true client links them so Kit
|
|
355
|
+
* hydrates the regions as plain components. A csr=false LAYOUT links them too when the app has a
|
|
356
|
+
* csr=true route: Kit hydrates that layout under a csr=true child page.
|
|
357
|
+
*
|
|
358
|
+
* `route_csr`: true for a csr=true route host (its marks are stripped so Kit compiles the
|
|
359
|
+
* components inline), false for a csr=false one, undefined for a module that is not a route host
|
|
360
|
+
* (its csr is the page that renders it, read at run time by `documentIsCsrTrue`).
|
|
361
|
+
*/
|
|
362
|
+
#csr_world(id, ssr, link_override) {
|
|
363
|
+
const ctx = this.#ctx;
|
|
364
|
+
const routesDir = ctx.kit_dirs.routes_dir;
|
|
365
|
+
const is_layout_host = is_route_component(path.basename(id), "layout");
|
|
366
|
+
const link_virtual = link_override !== void 0 ? link_override : ssr || !routeCsrIsFalse(ctx.routes, id, routesDir) || is_layout_host && hasAnyCsrTrueRoute(ctx.routes, routesDir);
|
|
367
|
+
let route_csr;
|
|
368
|
+
let csr_key = "n";
|
|
369
|
+
if (routeCsrIsTrue(ctx.routes, id, routesDir)) {
|
|
370
|
+
route_csr = true;
|
|
371
|
+
csr_key = "t";
|
|
372
|
+
} else if (routeCsrIsFalse(ctx.routes, id, routesDir)) {
|
|
373
|
+
route_csr = false;
|
|
374
|
+
csr_key = "f";
|
|
375
|
+
}
|
|
376
|
+
const key = `${link_virtual ? "1" : "0"}\0${csr_key}`;
|
|
377
|
+
return {
|
|
378
|
+
link_virtual,
|
|
379
|
+
route_csr,
|
|
380
|
+
key
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
/** A compile session, made once the bundler has resolved the build (`ctx`): nothing runs before
|
|
384
|
+
* its context exists. */
|
|
385
|
+
constructor(program, profiler, ctx) {
|
|
386
|
+
this.#build = new_build(program);
|
|
387
|
+
this.profiler = profiler;
|
|
388
|
+
this.#ctx = ctx;
|
|
389
|
+
}
|
|
390
|
+
/** A compiler with context `ctx` that carries on this one's build (its program, legs and caches):
|
|
391
|
+
* the next environment of a builder that shares one plugin across them. */
|
|
392
|
+
with_ctx(ctx) {
|
|
393
|
+
const next = new Compiler(this.program, this.profiler, ctx);
|
|
394
|
+
next.#build = this.#build;
|
|
395
|
+
return next;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Devtools: the `island id → component name` map, read at call time off the live registry (so a
|
|
399
|
+
* dev-server middleware serves a COMPLETE, current map — no stale virtual-module snapshot). Keys
|
|
400
|
+
* are the island id (`<hash>` in `ogygia:region/entry/<hash>.js`); values the component's
|
|
401
|
+
* basename. A held/generated island with no source file is skipped (the tab keeps its short hash).
|
|
402
|
+
*/
|
|
403
|
+
region_names() {
|
|
404
|
+
const names = {};
|
|
405
|
+
for (const [iid, vpath] of this.program.by_id) {
|
|
406
|
+
const cp = this.program.registry.get(vpath)?.componentPath;
|
|
407
|
+
if (!cp) continue;
|
|
408
|
+
const base = (cp.split("?")[0].split("#")[0].split("/").pop() || "").replace(COMPONENT_EXT_RE, "");
|
|
409
|
+
if (base && base !== iid) names[iid] = base;
|
|
410
|
+
}
|
|
411
|
+
return names;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Each module that marks region imports (a host, by its absolute path), with the module ids its
|
|
415
|
+
* regions are built from: their components and the modules minted for them. Read at call time
|
|
416
|
+
* off the live registry, like {@link region_names}.
|
|
417
|
+
*/
|
|
418
|
+
region_hosts() {
|
|
419
|
+
const { host_index, registry } = this.program;
|
|
420
|
+
const hosts = /* @__PURE__ */ new Map();
|
|
421
|
+
for (const [host, entry] of host_index) {
|
|
422
|
+
const ids = /* @__PURE__ */ new Set();
|
|
423
|
+
for (const vpath of entry.vpaths) {
|
|
424
|
+
ids.add(vpath);
|
|
425
|
+
const component = registry.get(vpath)?.componentPath;
|
|
426
|
+
if (component) ids.add(strip_id(component));
|
|
427
|
+
}
|
|
428
|
+
if (ids.size > 0) hosts.set(host, ids);
|
|
429
|
+
}
|
|
430
|
+
return hosts;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Run the module-macro passes (`wire`/`$`/`source`/`store`/auto-brand, then the plugins' macros)
|
|
434
|
+
* over one module — the leg that must land before the island transform / svelte compile /
|
|
435
|
+
* ts-region minting sees it. `source` is the CURRENT text (a plugin's pre-transform may already have
|
|
436
|
+
* edited it). Returns `{ code, touched, maps }`, one map per pass that changed the text.
|
|
437
|
+
*/
|
|
438
|
+
macros(source, id, watch) {
|
|
439
|
+
const ctx = this.#ctx;
|
|
440
|
+
return run_module_macros(source, id, {
|
|
441
|
+
root: ctx.root,
|
|
442
|
+
alias: ctx.resolve_alias,
|
|
443
|
+
pkgRoot: ctx.pkg_root,
|
|
444
|
+
dollarHoists: this.dollar_hoists,
|
|
445
|
+
macros: ctx.macros,
|
|
446
|
+
ownSource: (file) => ctx.is_own_source(file),
|
|
447
|
+
watch
|
|
448
|
+
}, this.profiler);
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Transform a content (`.svx`/`.md`) island source the markdown preprocessor hands back — always
|
|
452
|
+
* wrapper-linked (`linkVirtual: true`), because a preprocessor output is shared across the ssr/client
|
|
453
|
+
* legs and can't take the csr=false stub split; content files aren't routes, so they'd get wrappers
|
|
454
|
+
* anyway. Registers the descriptors and returns the rewritten code, or `null` when it has no islands.
|
|
455
|
+
* This is the transform the adapter installs on the content-island bridge.
|
|
456
|
+
*/
|
|
457
|
+
transform_content_island(source, filename) {
|
|
458
|
+
const result = this.transform(source, filename, {
|
|
459
|
+
ssr: false,
|
|
460
|
+
linkVirtual: true
|
|
461
|
+
});
|
|
462
|
+
if (!result || !result.islands?.length) return null;
|
|
463
|
+
this.#register(result, filename);
|
|
464
|
+
return result.code;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* The REAL source file a module derives from. A real file is its own origin. A generated entry
|
|
468
|
+
* (a portable-snippet synth, re-processed under its `ogygia:region/entry/<iid>.svelte` id)
|
|
469
|
+
* resolves through the registry's `hostPath` — transitively, so an entry minted while re-processing
|
|
470
|
+
* another entry still lands on the file the outermost slice was cut from. This is the ONE rule
|
|
471
|
+
* `resolve_id` already applies to an entry's plain imports; threading it into the transform keeps
|
|
472
|
+
* a re-minted marked import (whose resolved path is BAKED into a region module's source, bypassing
|
|
473
|
+
* resolveId) on the same base. Normalized like `transform_module`'s gate (`strip_id`, `/@id/`).
|
|
474
|
+
*/
|
|
475
|
+
#origin_of(id) {
|
|
476
|
+
const { registry } = this.program;
|
|
477
|
+
const bare = (s) => {
|
|
478
|
+
const n = strip_id(s);
|
|
479
|
+
return n.startsWith("/@id/") ? n.slice(5) : n;
|
|
480
|
+
};
|
|
481
|
+
let cur = bare(id);
|
|
482
|
+
const seen = /* @__PURE__ */ new Set([cur]);
|
|
483
|
+
for (;;) {
|
|
484
|
+
const host = registry.get(cur)?.hostPath;
|
|
485
|
+
if (!host) break;
|
|
486
|
+
const next = bare(host);
|
|
487
|
+
if (seen.has(next)) break;
|
|
488
|
+
seen.add(next);
|
|
489
|
+
cur = next;
|
|
490
|
+
}
|
|
491
|
+
return cur;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Lower one file and register nothing: the caller registers the returned descriptors into the
|
|
495
|
+
* `Program`. Memoized per id, leg and csr world, and only while the source is the same.
|
|
496
|
+
*/
|
|
497
|
+
transform(source, id, opts = {}) {
|
|
498
|
+
const ctx = this.#ctx;
|
|
499
|
+
const { prof, P, outHash } = this.profiler;
|
|
500
|
+
const ssr = opts.ssr !== false;
|
|
501
|
+
const { link_virtual, route_csr, key } = this.#csr_world(id, ssr, opts.linkVirtual);
|
|
502
|
+
if (ctx.is_dev) this.#worlds.set(`${ssr ? "s" : "c"}\0${id}`, {
|
|
503
|
+
id,
|
|
504
|
+
ssr,
|
|
505
|
+
link: opts.linkVirtual,
|
|
506
|
+
key
|
|
507
|
+
});
|
|
508
|
+
const cache_key = `${id}\0${ssr ? "s" : "c"}\0${key}`;
|
|
509
|
+
const hit = this.transform_cache.get(cache_key);
|
|
510
|
+
if (hit && hit.code === source) {
|
|
511
|
+
if (P) prof.transformHit++;
|
|
512
|
+
return hit.result;
|
|
513
|
+
}
|
|
514
|
+
const th0 = P ? performance.now() : 0;
|
|
515
|
+
const result = transformHost(source, id, {
|
|
516
|
+
root: ctx.root,
|
|
517
|
+
libDir: ctx.libDir,
|
|
518
|
+
readFile: (abs) => ctx.read_file(abs),
|
|
519
|
+
dev: ctx.is_dev,
|
|
520
|
+
virtualPathFor: (_hostId, iid) => ctx.island_virtual_id(iid),
|
|
521
|
+
wrapperPathFor: (_hostId, iid) => wrapperVirtualId(iid),
|
|
522
|
+
devUrlFor: (virtualPath) => ctx.dev_url_for(virtualPath),
|
|
523
|
+
originOf: (host) => this.#origin_of(host),
|
|
524
|
+
appDir: ctx.app_dir,
|
|
525
|
+
visibleMargin: ctx.visibleMargin,
|
|
526
|
+
presets: ctx.presets,
|
|
527
|
+
importKeys: ctx.import_keys,
|
|
528
|
+
idSalt: ctx.id_salt,
|
|
529
|
+
pkg_identity: (abs) => ctx.pkg_identity(abs),
|
|
530
|
+
alias: ctx.app_spec.alias,
|
|
531
|
+
stat: ctx.app_spec.stat,
|
|
532
|
+
linkVirtualIsland: link_virtual,
|
|
533
|
+
clientBindingStub: CLIENT_BINDING_STUB,
|
|
534
|
+
routeCsr: route_csr,
|
|
535
|
+
ssr
|
|
536
|
+
});
|
|
537
|
+
if (P) {
|
|
538
|
+
prof.transformMs += performance.now() - th0;
|
|
539
|
+
prof.transformN++;
|
|
540
|
+
outHash.set(cache_key, fnv1a32(JSON.stringify(result?.code ?? result)));
|
|
541
|
+
}
|
|
542
|
+
this.transform_cache.set(cache_key, {
|
|
543
|
+
code: source,
|
|
544
|
+
result
|
|
545
|
+
});
|
|
546
|
+
return result;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Mint the `.ts` / `.js` regions in one module — `with { wake: … }` load/remote imports become
|
|
550
|
+
* island descriptors. The ts-region half of the front-end, sharing the driver's resolved context
|
|
551
|
+
* (so both the prescan and the transform hook mint identically). Not memoized — the caller gates it
|
|
552
|
+
* on the id + marker; the returned descriptors are the caller's to `register`.
|
|
553
|
+
*/
|
|
554
|
+
ts_regions(source, id) {
|
|
555
|
+
const ctx = this.#ctx;
|
|
556
|
+
return transformTsRegions(source, id, {
|
|
557
|
+
root: ctx.root,
|
|
558
|
+
libDir: ctx.libDir,
|
|
559
|
+
dev: ctx.is_dev,
|
|
560
|
+
virtualPathFor: (_hostId, iid) => ctx.island_virtual_id(iid),
|
|
561
|
+
devUrlFor: (virtualPath) => ctx.dev_url_for(virtualPath),
|
|
562
|
+
appDir: ctx.app_dir,
|
|
563
|
+
importKeys: ctx.import_keys,
|
|
564
|
+
idSalt: ctx.id_salt,
|
|
565
|
+
pkg_identity: (abs) => ctx.pkg_identity(abs),
|
|
566
|
+
alias: ctx.app_spec.alias,
|
|
567
|
+
stat: ctx.app_spec.stat
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Discover every island up front — walk `src/`, transform each `.svelte` host and mint each
|
|
572
|
+
* `.ts`/`.js` region, register the descriptors, then complete `island_graph` TRANSITIVELY and
|
|
573
|
+
* finalize the runtime capability marks (so the sticky runtime entry bundles only what the app
|
|
574
|
+
* uses, and its immutable chunk name busts on a feature-set change). Once per build, so the
|
|
575
|
+
* adapter can call it from any hook. Populates the `Program`; the fs walk is the only side effect.
|
|
576
|
+
*/
|
|
577
|
+
prescan() {
|
|
578
|
+
return this.#build.scan ??= this.#scan();
|
|
579
|
+
}
|
|
580
|
+
#scan() {
|
|
581
|
+
const ctx = this.#ctx;
|
|
582
|
+
const { prof, P } = this.profiler;
|
|
583
|
+
const program = this.program;
|
|
584
|
+
const { registry, island_graph, runtime_marks } = program;
|
|
585
|
+
const root = ctx.root;
|
|
586
|
+
const src_dir = path.join(root, "src");
|
|
587
|
+
clean_stale_ogygia_dirs(src_dir);
|
|
588
|
+
const unlisted = /* @__PURE__ */ new Map();
|
|
589
|
+
const read_for_plugins = (full, src, specs) => {
|
|
590
|
+
for (const hook of ctx.prescans) if (specs.some((s) => hook.imports.includes(s))) hook.module({
|
|
591
|
+
file: full,
|
|
592
|
+
rel: prescan_rel(ctx, full),
|
|
593
|
+
code: src
|
|
594
|
+
});
|
|
595
|
+
for (const s of specs) if (Object.hasOwn(PLUGIN_PACKAGES, s) && !ctx.plugins.includes(s) && !unlisted.has(s)) unlisted.set(s, prescan_rel(ctx, full));
|
|
596
|
+
};
|
|
597
|
+
const say_one_off_keys = (full, src, kind) => {
|
|
598
|
+
if (!src.includes("Symbol(") || !reaches_context(own_reach(src, full, kind))) return;
|
|
599
|
+
for (const key of context_keys(src, kind).one_off) warn("region_context_key_one_off", {
|
|
600
|
+
file: path.relative(root, full),
|
|
601
|
+
key
|
|
602
|
+
});
|
|
603
|
+
};
|
|
604
|
+
const scan_file = (full, name) => {
|
|
605
|
+
const kind = scan_kind(name);
|
|
606
|
+
if (!kind) return;
|
|
607
|
+
const src = ctx.read_file(full);
|
|
608
|
+
if (src == null) return;
|
|
609
|
+
say_one_off_keys(full, src, kind);
|
|
610
|
+
read_for_plugins(full, src, this.#scan_facts(full, src, kind));
|
|
611
|
+
if (kind === "svelte") {
|
|
612
|
+
const result = this.transform(src, full);
|
|
613
|
+
if (result) program.register(result, full);
|
|
614
|
+
} else {
|
|
615
|
+
const result = this.ts_regions(src, full);
|
|
616
|
+
if (result) program.register(result, full);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
const walk = (dir) => {
|
|
620
|
+
const entries = ctx.fs.list(dir);
|
|
621
|
+
if (entries === null) return;
|
|
622
|
+
for (const entry of entries) {
|
|
623
|
+
const full = path.join(dir, entry.name);
|
|
624
|
+
if (entry.kind === "dir") {
|
|
625
|
+
if (entry.name === "node_modules" || entry.name === ".ogygia") continue;
|
|
626
|
+
walk(full);
|
|
627
|
+
} else scan_file(full, entry.name);
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
{
|
|
631
|
+
const __ps = P ? performance.now() : 0;
|
|
632
|
+
walk(src_dir);
|
|
633
|
+
for (const p of ctx.pkg_scan) {
|
|
634
|
+
for (const d of p.dirs) walk(d);
|
|
635
|
+
for (const f of p.files) scan_file(f, f.slice(f.lastIndexOf("/") + 1));
|
|
636
|
+
}
|
|
637
|
+
for (const f of ctx.page_files) {
|
|
638
|
+
if (program.scan.has(f)) continue;
|
|
639
|
+
const src = ctx.read_file(f);
|
|
640
|
+
program.scan.set(f, {
|
|
641
|
+
crosses_wire: false,
|
|
642
|
+
transportable: false,
|
|
643
|
+
specs: src == null ? [] : extract_module_specs(src),
|
|
644
|
+
router: true
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
if (P) prof.prescanMs += performance.now() - __ps;
|
|
648
|
+
}
|
|
649
|
+
for (const [pkg, file] of unlisted) unlisted_said.once(pkg, () => warn("plugin_not_listed", {
|
|
650
|
+
package: pkg,
|
|
651
|
+
plugin: PLUGIN_PACKAGES[pkg],
|
|
652
|
+
file
|
|
653
|
+
}));
|
|
654
|
+
{
|
|
655
|
+
const __ws = P ? performance.now() : 0;
|
|
656
|
+
for (const entry of registry.values()) if (entry.componentPath) this.mark_island_closure(entry.componentPath);
|
|
657
|
+
if (P) prof.prescanMs += performance.now() - __ws;
|
|
658
|
+
}
|
|
659
|
+
if (!runtime_marks.context) {
|
|
660
|
+
const reads = [];
|
|
661
|
+
const island_set = /* @__PURE__ */ new Set();
|
|
662
|
+
for (const file of island_graph) {
|
|
663
|
+
if (!file.endsWith(".svelte") && !SCRIPT_MODULE_RE.test(file)) continue;
|
|
664
|
+
const src = ctx.read_file(file);
|
|
665
|
+
if (src == null) continue;
|
|
666
|
+
const { reads: r, sets } = context_keys(src, file.endsWith(".svelte") ? "svelte" : "script");
|
|
667
|
+
for (const k of sets) island_set.add(k);
|
|
668
|
+
if (r.length) reads.push({
|
|
669
|
+
file,
|
|
670
|
+
keys: r
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
for (const { file, keys } of reads) for (const key of keys) {
|
|
674
|
+
if (island_set.has(key)) continue;
|
|
675
|
+
warn("island_context_unprovided", {
|
|
676
|
+
file: path.relative(root, file),
|
|
677
|
+
key: key_label(key_of(key))
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
runtime_marks.foreign = ctx.foreign_hydrate;
|
|
682
|
+
runtime_marks.page = program.island_reads_page || runtime_marks.foreign || ctx.client_plugins.length > 0;
|
|
683
|
+
runtime_marks.complete = true;
|
|
684
|
+
return { feature_hash: createHash("sha256").update(resolveFeatures(runtime_marks).join(",")).digest("hex").slice(0, 8) };
|
|
685
|
+
}
|
|
686
|
+
/** The scan's feature hash; empty before the scan ran. */
|
|
687
|
+
get #feature_hash() {
|
|
688
|
+
return this.#build.scan?.feature_hash ?? "";
|
|
689
|
+
}
|
|
690
|
+
/** DEV: modules `mark_island_closure` marked for the first time AFTER prescan — an island a later
|
|
691
|
+
* transform registered (a file added while the server runs). Each may already sit in the dev
|
|
692
|
+
* server's module graph, transformed with Kit's real `$app/*` for a non-island importer; the
|
|
693
|
+
* plugin drains this list and drops those cached transforms so the next load re-resolves them. */
|
|
694
|
+
#closure_added = [];
|
|
695
|
+
#mark_registered_closures(result) {
|
|
696
|
+
if (!this.#ctx.is_dev) return;
|
|
697
|
+
for (const isl of result.islands ?? []) if (isl.componentPath) this.#closure_added.push(...this.mark_island_closure(isl.componentPath));
|
|
698
|
+
}
|
|
699
|
+
/** DEV: take the modules newly marked as island code since the last drain (see above). */
|
|
700
|
+
drain_closure_marks() {
|
|
701
|
+
const out = this.#closure_added;
|
|
702
|
+
this.#closure_added = [];
|
|
703
|
+
return out;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Mark `componentAbs` and everything it imports through relative paths and the app's aliases as
|
|
707
|
+
* island code, before the bundler resolves any of it; a bare package specifier stops the walk.
|
|
708
|
+
* Returns the modules marked for the first time by this call.
|
|
709
|
+
*/
|
|
710
|
+
mark_island_closure(componentAbs) {
|
|
711
|
+
const ctx = this.#ctx;
|
|
712
|
+
const { island_graph } = this.program;
|
|
713
|
+
const spec_ctx = ctx.app_spec;
|
|
714
|
+
const added = [];
|
|
715
|
+
const resolve_dep = (spec, importerAbs) => {
|
|
716
|
+
const base = resolve_app_spec(spec, importerAbs, spec_ctx);
|
|
717
|
+
if (!base) return null;
|
|
718
|
+
for (const ext of ISLAND_DEP_EXTS) if (ctx.fs.stat(base + ext) === "file") return base + ext;
|
|
719
|
+
for (const ext of ISLAND_DEP_EXTS.slice(1)) {
|
|
720
|
+
const idx = path.join(base, `index${ext}`);
|
|
721
|
+
if (ctx.fs.stat(idx) === "file") return idx;
|
|
722
|
+
}
|
|
723
|
+
return null;
|
|
724
|
+
};
|
|
725
|
+
const walk = (abs) => {
|
|
726
|
+
const norm = strip_id(abs);
|
|
727
|
+
const seen = this.#build.island_closure_seen;
|
|
728
|
+
if (seen.has(norm)) return;
|
|
729
|
+
seen.add(norm);
|
|
730
|
+
if (!island_graph.has(norm)) {
|
|
731
|
+
island_graph.add(norm);
|
|
732
|
+
added.push(norm);
|
|
733
|
+
}
|
|
734
|
+
if (!SOURCE_EXT_RE.test(norm)) {
|
|
735
|
+
if (!ASSET_EXT_RE.test(norm)) this.program.island_reads_page = true;
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
const src = ctx.read_file(norm);
|
|
739
|
+
if (src == null) return;
|
|
740
|
+
for (const m of src.matchAll(IMPORT_SPEC_G)) {
|
|
741
|
+
const spec = m[1] || m[2] || m[3];
|
|
742
|
+
if (!spec || spec[0] === "\0") continue;
|
|
743
|
+
if (spec.startsWith("$app/")) {
|
|
744
|
+
if (!PAGE_FREE_APP_MODULES.has(spec)) this.program.island_reads_page = true;
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
if (spec.startsWith("$env/") || is_generated_specifier(spec)) continue;
|
|
748
|
+
const dep = resolve_dep(spec, norm);
|
|
749
|
+
if (dep) walk(dep);
|
|
750
|
+
else if (!PAGE_FREE_UNRESOLVED_RE.test(spec)) this.program.island_reads_page = true;
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
walk(componentAbs);
|
|
754
|
+
return added;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Scan ENTRIES for Vite's dep optimizer: every hydrate island's component file and the host file
|
|
758
|
+
* that places it — real, absolute, on-disk source paths. Under `csr = false` Kit ships no client
|
|
759
|
+
* entry and registers only `routes/**\/+*` as scan entries, so Vite's scanner reaches an island
|
|
760
|
+
* only when a route file imports it statically. An island behind a block registry, an
|
|
761
|
+
* `import.meta.og.regions()` glob or a `.remote.ts` mint is never crawled: its client deps are
|
|
762
|
+
* discovered LAZILY on its first wake, and every discovery re-optimizes, rotates the optimizer's
|
|
763
|
+
* browserHash and full-reloads — on a large app a reload storm that never settles. The adapter
|
|
764
|
+
* appends these to `optimizeDeps.entries` (dev) so Vite's OWN scanner crawls them at startup with
|
|
765
|
+
* the full plugin pipeline: its resolver, every plugin's `resolveId` (a `?client` import resolves
|
|
766
|
+
* through vite-plugin-iso-import), a linked workspace package followed as SOURCE and never
|
|
767
|
+
* pre-bundled, the app's `exclude` honoured.
|
|
768
|
+
*
|
|
769
|
+
* Deliberately NOT a self-computed `optimizeDeps.include` list. A resolver that is not Vite's
|
|
770
|
+
* mis-classifies something Vite knows — a plugin query, a workspace link, an `exports` map — and
|
|
771
|
+
* a wrong `include` hands rolldown an id it cannot load: `UNLOADABLE_DEPENDENCY`, a dead dev
|
|
772
|
+
* server (two field-reported regressions). An entry can only ever ADD a crawl root; what the
|
|
773
|
+
* crawl finds is Vite's call. A `defer` island renders on the server (its closure is not client
|
|
774
|
+
* code) and a lake ships no client JS, so neither is an entry; the host file covers a
|
|
775
|
+
* portable-snippet synth, which has no component file of its own. Needs `prescan()`; deduped,
|
|
776
|
+
* sorted, existing source files only.
|
|
777
|
+
*/
|
|
778
|
+
island_scan_entries() {
|
|
779
|
+
const { registry } = this.program;
|
|
780
|
+
const out = /* @__PURE__ */ new Set();
|
|
781
|
+
const add = (p) => {
|
|
782
|
+
if (!p) return;
|
|
783
|
+
const abs = strip_id(p);
|
|
784
|
+
if (!SOURCE_EXT_RE.test(abs)) return;
|
|
785
|
+
if (this.#ctx.fs.stat(abs) === "file") out.add(abs);
|
|
786
|
+
};
|
|
787
|
+
for (const entry of registry.values()) {
|
|
788
|
+
if (entry.role !== "entry" || entry.server) continue;
|
|
789
|
+
add(entry.componentPath);
|
|
790
|
+
add(entry.hostPath);
|
|
791
|
+
}
|
|
792
|
+
return [...out].sort();
|
|
793
|
+
}
|
|
794
|
+
/** The feature-selected runtime chunk name (immutable-cached). Needs prescan to have run for a
|
|
795
|
+
* non-empty feature hash; both build legs prescan the same source → the same name. */
|
|
796
|
+
runtime_chunk_filename() {
|
|
797
|
+
return this.#ctx.runtime_chunk_filename(this.#feature_hash);
|
|
798
|
+
}
|
|
799
|
+
/** Public URL of the runtime chunk (asset prefix + filename — honors a non-root base / assets CDN). */
|
|
800
|
+
runtime_chunk_url() {
|
|
801
|
+
return this.#ctx.runtime_chunk_url(this.#feature_hash);
|
|
802
|
+
}
|
|
803
|
+
/** The server-router component roots (link/router-css.ts). Build: prescan is complete before any
|
|
804
|
+
* consumer runs — memoized for the build. Dev: modules appear lazily (HMR), recompute per call. */
|
|
805
|
+
router_css_roots() {
|
|
806
|
+
const ctx = this.#ctx;
|
|
807
|
+
const build = this.#build;
|
|
808
|
+
if (ctx.is_build && build.router_css_roots) return build.router_css_roots;
|
|
809
|
+
const roots = router_css_roots(this.program.router_modules, this.program.module_specs, ctx.app_spec, (p) => ctx.fs.stat(p) === "file");
|
|
810
|
+
if (ctx.is_build) build.router_css_roots = roots;
|
|
811
|
+
return roots;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Server-only islands — `render: 'deferred'` with no client chunk — and the component file each
|
|
815
|
+
* renders. Nothing on any page links such a component's CSS (Kit collects stylesheets from the
|
|
816
|
+
* client graph; this subtree is never in it), so the client leg compiles each one's whole tree
|
|
817
|
+
* CSS into a dedicated asset the hole response links (vite/index.ts, `region_css_links`).
|
|
818
|
+
* Sorted for determinism; a component shared by several ids is emitted once (by `abs`).
|
|
819
|
+
*/
|
|
820
|
+
server_island_css_roots() {
|
|
821
|
+
const out = [];
|
|
822
|
+
for (const [iid, vpath] of this.program.by_id) {
|
|
823
|
+
const entry = this.program.registry.get(vpath);
|
|
824
|
+
if (!entry?.server || !entry.componentPath) continue;
|
|
825
|
+
if (this.program.region_kinds.get(iid) === "hydrate") continue;
|
|
826
|
+
out.push({
|
|
827
|
+
iid,
|
|
828
|
+
abs: host_key(entry.componentPath)
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
return out.sort((a, b) => by_code_unit(a.iid, b.iid));
|
|
832
|
+
}
|
|
833
|
+
/** The public URL key a server island's CSS is handed off under (matches `island_url[id]`). */
|
|
834
|
+
island_public_url(iid) {
|
|
835
|
+
return this.#ctx.island_public_url(iid);
|
|
836
|
+
}
|
|
837
|
+
/** Whether the program holds any hydrate region, wherever it is placed (a Kit page or not). */
|
|
838
|
+
has_hydrate_regions() {
|
|
839
|
+
for (const kind of this.program.region_kinds.values()) if (kind === "hydrate") return true;
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
/** The server leg's real module graph, for the client-leg handoff (link/emit-gate.ts). */
|
|
843
|
+
ssr_transformed_hosts() {
|
|
844
|
+
return [...this.program.ssr_transformed].sort();
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Client leg: the runtime chunk + one deterministic chunk per deduped hydrate region. `loaded` —
|
|
848
|
+
* the server leg's transformed-module set (the handoff the plugin reads) — gates the emit to
|
|
849
|
+
* islands whose HOST the server bundle actually contains; `null` (no handoff: standalone, or a
|
|
850
|
+
* client-only build) keeps every prescanned island, as before. Returns how many were skipped.
|
|
851
|
+
*/
|
|
852
|
+
emit_build_chunks(leg, emitFile, { emitRuntime, loaded = null }) {
|
|
853
|
+
if (emitRuntime) {
|
|
854
|
+
const feat = this.#ctx.runtime_features(this.#feature_hash);
|
|
855
|
+
leg.runtime_entry_ref = emitFile({
|
|
856
|
+
type: "chunk",
|
|
857
|
+
id: V_RUNTIME_ENTRY,
|
|
858
|
+
name: RUNTIME_ENTRY_NAME + (feat ? `-${feat}` : "")
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
const { region_kinds, by_id, registry } = this.program;
|
|
862
|
+
let skipped = 0;
|
|
863
|
+
for (const [rid, kind] of region_kinds) {
|
|
864
|
+
if (kind !== "hydrate") continue;
|
|
865
|
+
const virtualPath = by_id.get(rid);
|
|
866
|
+
if (!virtualPath) continue;
|
|
867
|
+
if (leg.island_entry_refs.has(rid)) continue;
|
|
868
|
+
if (!island_host_loaded(registry.get(virtualPath)?.hostPath, loaded)) {
|
|
869
|
+
skipped++;
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
this.emit_island_entry(leg, emitFile, rid, virtualPath);
|
|
873
|
+
}
|
|
874
|
+
return skipped;
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* At the bundle's end (the names are final): each entry's IDENTITY → its LOCATION. `islands` maps
|
|
878
|
+
* an island entry's hashed file to its identity (the collector keys every map by identity);
|
|
879
|
+
* `locations` is what the handoff carries to the server (`entries`): identity → served path.
|
|
880
|
+
* `get_file_name` is the bundler's `this.getFileName`.
|
|
881
|
+
*/
|
|
882
|
+
entry_locations(leg, get_file_name) {
|
|
883
|
+
const islands = /* @__PURE__ */ new Map();
|
|
884
|
+
const locations = {};
|
|
885
|
+
const served = (file) => file.startsWith("/") ? file : `/${file}`;
|
|
886
|
+
const refs = [...leg.island_entry_refs].sort(by_key);
|
|
887
|
+
for (const [rid, ref] of refs) {
|
|
888
|
+
const file = get_file_name(ref);
|
|
889
|
+
const identity = this.island_public_url(rid);
|
|
890
|
+
islands.set(file, identity);
|
|
891
|
+
locations[identity] = served(file);
|
|
892
|
+
}
|
|
893
|
+
let runtime = null;
|
|
894
|
+
let runtime_file = null;
|
|
895
|
+
if (leg.runtime_entry_ref) {
|
|
896
|
+
runtime_file = get_file_name(leg.runtime_entry_ref);
|
|
897
|
+
runtime = this.runtime_chunk_url();
|
|
898
|
+
locations[runtime] = served(runtime_file);
|
|
899
|
+
}
|
|
900
|
+
return {
|
|
901
|
+
islands,
|
|
902
|
+
runtime,
|
|
903
|
+
runtime_file,
|
|
904
|
+
locations
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* A server region this registration added after the leg wrote `server-regions` (its host was
|
|
909
|
+
* reached late: outside the start-up scan, #1420): its loader is its own chunk, emitted now and
|
|
910
|
+
* named in that module at renderChunk (link/relocations.ts). Once per region per leg.
|
|
911
|
+
*/
|
|
912
|
+
#emit_late_server_regions(leg, emitFile, result) {
|
|
913
|
+
const written = this.program.server_regions_written;
|
|
914
|
+
if (written === null) return;
|
|
915
|
+
for (const isl of result.islands ?? []) {
|
|
916
|
+
if (!isl.server || !isl.virtualPath || written.has(isl.id)) continue;
|
|
917
|
+
if (leg.late_server_regions.has(isl.id)) continue;
|
|
918
|
+
leg.late_server_regions.set(isl.id, emitFile({
|
|
919
|
+
type: "chunk",
|
|
920
|
+
id: isl.virtualPath,
|
|
921
|
+
name: LATE_SERVER_REGION_NAME
|
|
922
|
+
}));
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
/** Emit one hydrate region's entry chunk into `leg`, by name: the bundler content-hashes it. */
|
|
926
|
+
emit_island_entry(leg, emitFile, rid, virtualPath) {
|
|
927
|
+
leg.island_entry_refs.set(rid, emitFile({
|
|
928
|
+
type: "chunk",
|
|
929
|
+
id: virtualPath,
|
|
930
|
+
name: ISLAND_ENTRY_NAME_PREFIX + rid
|
|
931
|
+
}));
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* The output file pattern for one of OUR entries (by the chunk name `emit_island_entry` / the
|
|
935
|
+
* runtime emit gave it), else null (the app's own naming applies). Readable and content-hashed:
|
|
936
|
+
* `<appDir>/immutable/og-region.<iid>.<hash>.js`, `…/og-runtime-<features>.<hash>.js` — the hash is the
|
|
937
|
+
* cache law, the name is for people (a network tab, a CDN rule, a profile). It never equals a
|
|
938
|
+
* stable name, which has no hash segment.
|
|
939
|
+
*/
|
|
940
|
+
entry_file_pattern(chunk_name) {
|
|
941
|
+
if (!chunk_name) return null;
|
|
942
|
+
if (!(chunk_name.startsWith(ISLAND_ENTRY_NAME_PREFIX) || chunk_name === RUNTIME_ENTRY_NAME || chunk_name.startsWith(`${RUNTIME_ENTRY_NAME}-`))) return null;
|
|
943
|
+
return `${this.#ctx.app_dir}/immutable/[name].[hash].js`;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* The build's location maps (link/location-map.ts), for the bundle's end (the names are final):
|
|
947
|
+
* every island entry's identity → its hashed file, content-hashed and at the one fixed name.
|
|
948
|
+
* `get_file_name` is the bundler's `this.getFileName`. Empty with no island.
|
|
949
|
+
*/
|
|
950
|
+
location_maps(leg, get_file_name) {
|
|
951
|
+
const ctx = this.#ctx;
|
|
952
|
+
const pairs = [];
|
|
953
|
+
for (const [rid, ref] of leg.island_entry_refs) pairs.push([ctx.island_chunk_filename(rid), get_file_name(ref)]);
|
|
954
|
+
const files = location_map_files(ctx.app_dir, pairs, (source) => createHash("sha256").update(source).digest("hex").slice(0, 12));
|
|
955
|
+
leg.location_map_url = files.length ? `/${files[0].fileName}` : null;
|
|
956
|
+
return files;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Emit one ogygia VIRTUAL module's source: the config/capability virtuals (secret / sign / rate-limit
|
|
960
|
+
* / router / session / ttl / manifests / runtime entry+url / transport / dev-hmr / request-event /
|
|
961
|
+
* region-endpoint), and the registered island/region sources (with the client leg's `$app/*`-shim +
|
|
962
|
+
* lake-placeholder rewrites). Returns the source string, or `null` if `id` is not an ogygia virtual —
|
|
963
|
+
* the adapter owns only the FOUC-css virtuals (they carry a Vite `moduleType`) and the Vite build
|
|
964
|
+
* value threaded in here (the `universalHooks` path).
|
|
965
|
+
*/
|
|
966
|
+
emit(id, leg) {
|
|
967
|
+
const ctx = this.#ctx;
|
|
968
|
+
const program = this.program;
|
|
969
|
+
const { ssr } = leg;
|
|
970
|
+
const registry_client = registry_client_path(id);
|
|
971
|
+
if (registry_client) return this.#registry_client_emit(registry_client);
|
|
972
|
+
const declared = this.#virtuals.load(id, this, leg);
|
|
973
|
+
if (declared !== null) {
|
|
974
|
+
if (typeof declared === "string" && this.#virtuals.side_effect_free(id)) return {
|
|
975
|
+
code: declared,
|
|
976
|
+
moduleSideEffects: false
|
|
977
|
+
};
|
|
978
|
+
return declared;
|
|
979
|
+
}
|
|
980
|
+
const srcEntry = program.registry.get(id);
|
|
981
|
+
if (srcEntry && srcEntry.role === "region") return ssr ? srcEntry.ssrSource : srcEntry.clientSource;
|
|
982
|
+
if (srcEntry) {
|
|
983
|
+
let src = !ssr && srcEntry.clientSource ? srcEntry.clientSource : srcEntry.source;
|
|
984
|
+
const foreign = src.indexOf(FOREIGN_HYDRATE_MARK);
|
|
985
|
+
if (foreign !== -1 && (ssr || !ctx.foreign_hydrate)) src = src.slice(0, foreign);
|
|
986
|
+
if (!ssr) {
|
|
987
|
+
src = src.replace(APP_SHIM_IMPORT, (_m, _q, name) => JSON.stringify(ctx.app_shims[`$app/${name}`]));
|
|
988
|
+
for (const local of srcEntry.lakes ?? []) src = rewrite_lake_import_to_placeholder(src, local, ctx.client_binding_stub_file);
|
|
989
|
+
}
|
|
990
|
+
return src;
|
|
991
|
+
}
|
|
992
|
+
if (ctx.is_dev && this.#virtuals.claims(id)) this.#unanswered.add(id);
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
/** DEV: the registry's modules a load answered null for while no host held them (`moved`). */
|
|
996
|
+
#unanswered = /* @__PURE__ */ new Set();
|
|
997
|
+
/**
|
|
998
|
+
* Resolve an ogygia-owned import id: the virtual-module vocabulary (config/manifest virtuals + FOUC
|
|
999
|
+
* graph + client-binding stub), and the island CLIENT graph — `$app/*` shims for island importers,
|
|
1000
|
+
* virtual island/wrapper ids, and relative imports of a generated island module resolved against its
|
|
1001
|
+
* host (marking each resolved dep into `island_graph` so its own `$app/*` stays shimmed). `resolve` is
|
|
1002
|
+
* the bundler's own resolver (Vite `this.resolve`), threaded in so the driver stays bundler-agnostic.
|
|
1003
|
+
* Returns a resolved id / result, or `null` to defer to the bundler. The adapter handles the few
|
|
1004
|
+
* package/Kit-specific ids first (ogygia injected imports, Kit's remote runtime, the kit-wire path).
|
|
1005
|
+
*/
|
|
1006
|
+
async resolve_id(source, importer, { ssr, resolve }) {
|
|
1007
|
+
const ctx = this.#ctx;
|
|
1008
|
+
const { registry, island_graph } = this.program;
|
|
1009
|
+
const declared = this.#virtuals.resolve(source, {
|
|
1010
|
+
ssr,
|
|
1011
|
+
dev: ctx.is_dev
|
|
1012
|
+
});
|
|
1013
|
+
if (declared) return declared;
|
|
1014
|
+
if (source === CLIENT_BINDING_STUB) return ctx.client_binding_stub_file;
|
|
1015
|
+
if (!ssr && ctx.is_build && importer && (source.startsWith(REGION_BINDING_PREFIX) || source.startsWith(WRAPPER_PREFIX)) && this.#links_client_stub(importer)) return ctx.client_binding_stub_file;
|
|
1016
|
+
if (source.startsWith(FOUC_CSS_PREFIX) || source.startsWith(FOUC_SCOPED_PREFIX)) return RESOLVED(source);
|
|
1017
|
+
const registry_stub = await this.#registry_stub_for(source, importer, {
|
|
1018
|
+
ssr,
|
|
1019
|
+
resolve
|
|
1020
|
+
});
|
|
1021
|
+
if (registry_stub) return registry_stub;
|
|
1022
|
+
const importer_id = importer ? strip_id(importer) : void 0;
|
|
1023
|
+
const from_island = importer_id && (registry.has(importer_id) || island_graph.has(importer_id));
|
|
1024
|
+
if (!ssr && from_island) {
|
|
1025
|
+
const shim = app_shim_for(source, ctx.app_shims);
|
|
1026
|
+
if (shim) return shim;
|
|
1027
|
+
}
|
|
1028
|
+
if (is_island_path(source)) {
|
|
1029
|
+
let candidate = source.split("?")[0];
|
|
1030
|
+
if (candidate.startsWith("/@id/")) candidate = candidate.slice(5);
|
|
1031
|
+
if (candidate.startsWith("/@fs/")) candidate = candidate.slice(4);
|
|
1032
|
+
if (registry.has(candidate)) {
|
|
1033
|
+
island_graph.add(candidate);
|
|
1034
|
+
return candidate;
|
|
1035
|
+
}
|
|
1036
|
+
const abs = path.isAbsolute(candidate) ? candidate : path.join(ctx.root, candidate.replace(LEADING_SLASH, ""));
|
|
1037
|
+
if (registry.has(abs)) {
|
|
1038
|
+
island_graph.add(abs);
|
|
1039
|
+
return abs;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (importer_id && registry.has(importer_id) && !is_island_path(source)) {
|
|
1043
|
+
const host = registry.get(importer_id).hostPath ?? "";
|
|
1044
|
+
const resolved = await resolve(source, host, { skipSelf: true });
|
|
1045
|
+
if (resolved?.id) island_graph.add(strip_id(resolved.id));
|
|
1046
|
+
if (!resolved && !source.startsWith(".") && !source.startsWith("\0") && !is_generated_specifier(source) && !path.isAbsolute(source)) throw new OgygiaError("island_import_unresolved", {
|
|
1047
|
+
specifier: source,
|
|
1048
|
+
host: path.relative(ctx.root, host)
|
|
1049
|
+
});
|
|
1050
|
+
return resolved;
|
|
1051
|
+
}
|
|
1052
|
+
if (!ssr && importer_id && island_graph.has(importer_id) && !is_island_path(source)) {
|
|
1053
|
+
const resolved = await resolve(source, importer, { skipSelf: true });
|
|
1054
|
+
if (resolved?.id) island_graph.add(strip_id(resolved.id));
|
|
1055
|
+
return resolved;
|
|
1056
|
+
}
|
|
1057
|
+
return null;
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* The client-leg registry decision for one import edge (see link/registry-stub.ts). Fires only on
|
|
1061
|
+
* the client leg of a build, for an importer that is either a csr=false ROUTE host (`+page`/
|
|
1062
|
+
* `+layout` `.svelte`/`.ts`/`.js` — the page node's own files, whose client JS never runs) or a
|
|
1063
|
+
* module already in that variant world (its id carries the variant query), and only when the
|
|
1064
|
+
* resolved target is a local `.ts`/`.js` module that IS a region registry or REACHES one through
|
|
1065
|
+
* static script imports. The variant world is contagious along script edges only: a registry
|
|
1066
|
+
* behind a plain helper (`+page.svelte` → `$lib/factory.ts` → `registry.ts`) gets the same
|
|
1067
|
+
* treatment as a direct import, while modules that reach no registry stay shared (no copies).
|
|
1068
|
+
* `.svelte` edges never fork (forking a component's id breaks its scoped CSS). Returns the
|
|
1069
|
+
* variant id, or `null` to let resolution continue.
|
|
1070
|
+
*/
|
|
1071
|
+
async #registry_stub_for(source, importer, { ssr, resolve }) {
|
|
1072
|
+
const ctx = this.#ctx;
|
|
1073
|
+
if (ssr || ctx.is_dev || !ctx.is_build || !importer) return null;
|
|
1074
|
+
if (source.startsWith("\0") || is_generated_specifier(source) || source.startsWith("$app/")) return null;
|
|
1075
|
+
if (registry_client_path(importer) == null && !this.#is_csr_false_route_host(importer)) return null;
|
|
1076
|
+
const target = await this.#resolve_local_script(source, importer, resolve);
|
|
1077
|
+
if (!target) return null;
|
|
1078
|
+
this.prescan();
|
|
1079
|
+
if (!await this.#reaches_registry(target, resolve)) return null;
|
|
1080
|
+
return registry_client_id(target);
|
|
1081
|
+
}
|
|
1082
|
+
/** A route COMPONENT whose client leg links the binding stub — `transform`'s `link_virtual` rule,
|
|
1083
|
+
* for a host that could not apply it itself: csr=false, and not a layout of an app with a
|
|
1084
|
+
* csr=true route (Kit can hydrate that layout: a csr=true child page, or an error render). */
|
|
1085
|
+
#links_client_stub(importer) {
|
|
1086
|
+
const importer_abs = strip_id(importer);
|
|
1087
|
+
const { routes } = this.#ctx;
|
|
1088
|
+
const routes_dir = this.#ctx.kit_dirs.routes_dir;
|
|
1089
|
+
if (!importer_abs.startsWith(routes_dir + path.sep)) return false;
|
|
1090
|
+
const base = path.basename(importer_abs);
|
|
1091
|
+
if (is_route_component(base, "layout")) return routeCsrIsFalse(routes, importer_abs, routes_dir) && !hasAnyCsrTrueRoute(routes, routes_dir);
|
|
1092
|
+
return is_route_component(base, "page") && routeCsrIsFalse(routes, importer_abs, routes_dir);
|
|
1093
|
+
}
|
|
1094
|
+
/** A csr=false route host file: a page or layout component, or its option module. */
|
|
1095
|
+
#is_csr_false_route_host(importer) {
|
|
1096
|
+
const importer_abs = strip_id(importer);
|
|
1097
|
+
const { routes } = this.#ctx;
|
|
1098
|
+
const routes_dir = this.#ctx.kit_dirs.routes_dir;
|
|
1099
|
+
if (!importer_abs.startsWith(routes_dir + path.sep)) return false;
|
|
1100
|
+
const base = path.basename(importer_abs);
|
|
1101
|
+
if (is_route_component(base, "page") || is_route_component(base, "layout")) return routeCsrIsFalse(routes, importer_abs, routes_dir);
|
|
1102
|
+
const m = ROUTE_HOST_FILE_RE.exec(base);
|
|
1103
|
+
if (!m) return false;
|
|
1104
|
+
return routeCsrIsFalse(routes, path.join(importer_abs, "..", `+${m[1]}.svelte`), routes_dir);
|
|
1105
|
+
}
|
|
1106
|
+
/** `source` resolved from `importer` to a local `.ts`/`.js` file on disk, or `null` (virtuals,
|
|
1107
|
+
* components, assets, unresolvable). Package files count only when the prescan registered them
|
|
1108
|
+
* as region hosts (an `ogygia.files` package registry) — package internals are never walked. */
|
|
1109
|
+
async #resolve_local_script(source, importer, resolve) {
|
|
1110
|
+
const memo_key = `${strip_id(importer)}\n${source}`;
|
|
1111
|
+
const memos = this.#build.resolve_memo;
|
|
1112
|
+
const memo = memos.get(memo_key);
|
|
1113
|
+
if (memo !== void 0) return memo;
|
|
1114
|
+
const target = await this.#resolve_local_script_uncached(source, importer, resolve);
|
|
1115
|
+
memos.set(memo_key, target);
|
|
1116
|
+
return target;
|
|
1117
|
+
}
|
|
1118
|
+
async #resolve_local_script_uncached(source, importer, resolve) {
|
|
1119
|
+
let resolved = null;
|
|
1120
|
+
try {
|
|
1121
|
+
resolved = await resolve(source, importer, { skipSelf: true });
|
|
1122
|
+
} catch {
|
|
1123
|
+
return null;
|
|
1124
|
+
}
|
|
1125
|
+
if (!resolved?.id || resolved.id.startsWith("\0")) return null;
|
|
1126
|
+
const target = strip_id(resolved.id);
|
|
1127
|
+
if (!TS_REGISTRY_EXT_RE.test(target) || this.#ctx.fs.stat(target) === null) return null;
|
|
1128
|
+
const posix = target.split(path.sep).join("/");
|
|
1129
|
+
if (SERVER_MODULE_EXT_RE.test(posix) || SERVER_DIR_RE.test(posix)) return null;
|
|
1130
|
+
if (SVELTE_RUNE_MODULE_RE.test(posix)) return null;
|
|
1131
|
+
return target;
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Whether `file` is a region registry or reaches one through static script imports (`.svelte`
|
|
1135
|
+
* and package-internal edges are not walked). Every module is read, parsed and walked AT MOST
|
|
1136
|
+
* ONCE per build: a shared helper reached from thousands of import edges answers from the memo.
|
|
1137
|
+
*
|
|
1138
|
+
* Cycles are why that needs care. A NEGATIVE computed while the walk was inside a cycle may
|
|
1139
|
+
* depend on a file still open above it (that file can still turn out to reach a registry), so it
|
|
1140
|
+
* is not final yet. Tarjan's strongly-connected-components bookkeeping decides exactly when it
|
|
1141
|
+
* is: each open file gets its depth on the walk, every step reports the shallowest open file its
|
|
1142
|
+
* subtree looped back to (`low`), and when a file finishes with `low >= depth` nothing below it
|
|
1143
|
+
* depends on anything above it — the file and every file still parked on the component stack
|
|
1144
|
+
* above it form one finished component, all with the same answer. A positive is always final.
|
|
1145
|
+
* (Keeping only top-level negatives instead, as this did first, re-walked every shared module
|
|
1146
|
+
* once per path to it — a large app's build never finished.)
|
|
1147
|
+
*/
|
|
1148
|
+
async #reaches_registry(file, resolve) {
|
|
1149
|
+
return (await this.#reach(file, resolve, /* @__PURE__ */ new Map(), [])).reaches;
|
|
1150
|
+
}
|
|
1151
|
+
async #reach(file, resolve, open, component) {
|
|
1152
|
+
const key = host_key(file);
|
|
1153
|
+
const reach_memo = this.#build.reach_memo;
|
|
1154
|
+
const memo = reach_memo.get(key);
|
|
1155
|
+
if (memo !== void 0) return {
|
|
1156
|
+
reaches: memo,
|
|
1157
|
+
low: Infinity
|
|
1158
|
+
};
|
|
1159
|
+
if (this.program.host_index.has(key)) {
|
|
1160
|
+
reach_memo.set(key, true);
|
|
1161
|
+
return {
|
|
1162
|
+
reaches: true,
|
|
1163
|
+
low: Infinity
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
const open_depth = open.get(key);
|
|
1167
|
+
if (open_depth !== void 0) return {
|
|
1168
|
+
reaches: false,
|
|
1169
|
+
low: open_depth
|
|
1170
|
+
};
|
|
1171
|
+
if (file.includes("/node_modules/")) return {
|
|
1172
|
+
reaches: false,
|
|
1173
|
+
low: Infinity
|
|
1174
|
+
};
|
|
1175
|
+
const depth = open.size;
|
|
1176
|
+
open.set(key, depth);
|
|
1177
|
+
const parked = component.length;
|
|
1178
|
+
component.push(key);
|
|
1179
|
+
let reaches = false;
|
|
1180
|
+
let low = Infinity;
|
|
1181
|
+
for (const spec of this.#script_specs(key, file)) {
|
|
1182
|
+
const target = await this.#resolve_local_script(spec, file, resolve);
|
|
1183
|
+
if (!target) continue;
|
|
1184
|
+
const step = await this.#reach(target, resolve, open, component);
|
|
1185
|
+
if (step.low < low) low = step.low;
|
|
1186
|
+
if (step.reaches) {
|
|
1187
|
+
reaches = true;
|
|
1188
|
+
break;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
open.delete(key);
|
|
1192
|
+
if (reaches) {
|
|
1193
|
+
reach_memo.set(key, true);
|
|
1194
|
+
component.length = parked + 1;
|
|
1195
|
+
component.pop();
|
|
1196
|
+
return {
|
|
1197
|
+
reaches: true,
|
|
1198
|
+
low: Infinity
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
if (low >= depth) {
|
|
1202
|
+
for (let i = parked; i < component.length; i++) reach_memo.set(component[i], false);
|
|
1203
|
+
component.length = parked;
|
|
1204
|
+
return {
|
|
1205
|
+
reaches: false,
|
|
1206
|
+
low: Infinity
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1209
|
+
return {
|
|
1210
|
+
reaches: false,
|
|
1211
|
+
low
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
/** A module's static script specifiers, read and parsed once per build. */
|
|
1215
|
+
#script_specs(key, file) {
|
|
1216
|
+
const memos = this.#build.specs_memo;
|
|
1217
|
+
let specs = memos.get(key);
|
|
1218
|
+
if (specs === void 0) {
|
|
1219
|
+
const src = this.#ctx.read_file(file);
|
|
1220
|
+
specs = src == null ? [] : static_script_specs(src, file) ?? [];
|
|
1221
|
+
memos.set(key, specs);
|
|
1222
|
+
}
|
|
1223
|
+
return specs;
|
|
1224
|
+
}
|
|
1225
|
+
/** The client-leg registry source (link/registry-stub.ts): marks blanked, plain imports kept. A
|
|
1226
|
+
* registry that does not parse falls back to the names-only stub. */
|
|
1227
|
+
#registry_client_emit(file) {
|
|
1228
|
+
const ctx = this.#ctx;
|
|
1229
|
+
const src = ctx.read_file(file);
|
|
1230
|
+
if (src == null) return null;
|
|
1231
|
+
const keys = ctx.import_keys;
|
|
1232
|
+
const region_keys = /* @__PURE__ */ new Set([
|
|
1233
|
+
keys.wake,
|
|
1234
|
+
keys.render,
|
|
1235
|
+
keys.preset,
|
|
1236
|
+
keys.region
|
|
1237
|
+
]);
|
|
1238
|
+
return registry_client_source(src, file, region_keys) ?? registry_stub_source([...export_names(src)]);
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* The per-file transform pass: content-preset tagging ▸ `import.meta.og.*` macros ▸ the host-island
|
|
1242
|
+
* transform (`.svelte`) ▸ ts/js region minting (`.ts/.js`) ▸ the client `$app/*` shim. Registers the
|
|
1243
|
+
* discovered descriptors into the `Program`, and (client build only) emits the deterministic chunk for
|
|
1244
|
+
* any hydrate island a library component declares that the prescan couldn't see — via the `emitFile`
|
|
1245
|
+
* callback (the one Vite primitive threaded in), into `leg` (the leg the transform runs in).
|
|
1246
|
+
* Returns the Vite transform result, or `null` if the module was untouched. `prescan()` runs first
|
|
1247
|
+
* so `island_graph` is complete before any module lowers.
|
|
1248
|
+
*/
|
|
1249
|
+
async transform_module(code, id, { leg, emitFile, watch }) {
|
|
1250
|
+
const ctx = this.#ctx;
|
|
1251
|
+
const ssr = leg.server;
|
|
1252
|
+
const program = this.program;
|
|
1253
|
+
const { registry, island_graph } = program;
|
|
1254
|
+
const root = ctx.root;
|
|
1255
|
+
code = strip_bom(code);
|
|
1256
|
+
this.prescan();
|
|
1257
|
+
if (registry_client_path(id) != null) return null;
|
|
1258
|
+
const id_n = strip_id(id);
|
|
1259
|
+
if (ssr && ctx.is_build) program.ssr_transformed.add(host_key(id_n));
|
|
1260
|
+
if (ctx.is_dev && is_script_request(id)) {
|
|
1261
|
+
const kind = this.#scans(id_n);
|
|
1262
|
+
if (kind) this.#scan_facts(path.normalize(id_n), code, kind);
|
|
1263
|
+
}
|
|
1264
|
+
if (ctx.is_build && ctx.page_reads) ctx.page_reads.module(id.split("?")[0].split("\\").join("/"), code);
|
|
1265
|
+
let out = code;
|
|
1266
|
+
let touched = false;
|
|
1267
|
+
const chain = new MapChain();
|
|
1268
|
+
const edit = (edits) => {
|
|
1269
|
+
const before = out;
|
|
1270
|
+
out = splice_text(before, edits);
|
|
1271
|
+
chain.step(() => splice_map(before, edits, id_n));
|
|
1272
|
+
touched = true;
|
|
1273
|
+
};
|
|
1274
|
+
const macroed = await this.macros(out, id_n, watch);
|
|
1275
|
+
if (macroed.touched) {
|
|
1276
|
+
out = macroed.code;
|
|
1277
|
+
chain.steps(macroed.maps);
|
|
1278
|
+
touched = true;
|
|
1279
|
+
}
|
|
1280
|
+
const in_node_modules = id_n.includes("/node_modules/");
|
|
1281
|
+
const bare_v = id_n.startsWith("/@id/") ? id_n.slice(5) : id_n;
|
|
1282
|
+
const portable_entry = id_n.endsWith(".svelte") && is_island_path(bare_v) && registry.get(bare_v)?.portable === true;
|
|
1283
|
+
if (id_n.endsWith(".svelte") && is_script_request(id) && (!is_island_path(bare_v) || portable_entry) && (!in_node_modules || ctx.in_declared_pkg(bare_v) || ctx.has_island_hint(code))) {
|
|
1284
|
+
const result = this.transform(out, id_n, { ssr });
|
|
1285
|
+
if (result) {
|
|
1286
|
+
this.#register(result, id_n);
|
|
1287
|
+
this.#mark_registered_closures(result);
|
|
1288
|
+
out = result.code;
|
|
1289
|
+
chain.step(result_map(result));
|
|
1290
|
+
touched = true;
|
|
1291
|
+
if (ctx.is_build && !ssr) for (const isl of result.islands ?? []) {
|
|
1292
|
+
if ((isl.kind ?? (isl.server ? "defer" : "hydrate")) !== "hydrate" || !isl.virtualPath || leg.island_entry_refs.has(isl.id)) continue;
|
|
1293
|
+
this.emit_island_entry(leg, emitFile, isl.id, isl.virtualPath);
|
|
1294
|
+
}
|
|
1295
|
+
if (ctx.is_build && ssr) this.#emit_late_server_regions(leg, emitFile, result);
|
|
1296
|
+
}
|
|
1297
|
+
if (!id_n.startsWith(ctx.pkg_root)) {
|
|
1298
|
+
const registration = svelte_module_registration(out, id_n, root);
|
|
1299
|
+
if (registration !== null) edit([registration]);
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
const nm_ts = id_n.endsWith(".ts") || id_n.endsWith(".js") || id_n.endsWith(".mjs") ? id_n.includes("/node_modules/") : null;
|
|
1303
|
+
if (nm_ts === true && !id_n.startsWith(ctx.pkg_root) && !ctx.in_declared_pkg(id_n) && ctx.has_island_hint(out) && ctx.has_marked_import(out, id_n)) warn_undeclared_pkg_marks(id_n);
|
|
1304
|
+
if (nm_ts !== null && (nm_ts === false || ctx.in_declared_pkg(id_n)) && !is_island_path(id_n)) {
|
|
1305
|
+
const result = this.ts_regions(out, id_n);
|
|
1306
|
+
if (result) {
|
|
1307
|
+
this.#register(result, id_n);
|
|
1308
|
+
this.#mark_registered_closures(result);
|
|
1309
|
+
if (ctx.is_build && ssr) this.#emit_late_server_regions(leg, emitFile, result);
|
|
1310
|
+
out = result.code;
|
|
1311
|
+
chain.step(result_map(result));
|
|
1312
|
+
touched = true;
|
|
1313
|
+
}
|
|
1314
|
+
if (!id_n.startsWith(ctx.pkg_root)) {
|
|
1315
|
+
const registered = appendTransportRegistrations(out, id_n, root);
|
|
1316
|
+
if (registered !== null) edit([{
|
|
1317
|
+
start: out.length,
|
|
1318
|
+
end: out.length,
|
|
1319
|
+
text: registered.slice(out.length)
|
|
1320
|
+
}]);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
if (!ssr && island_graph.has(id_n) && (id_n.endsWith(".svelte") || SCRIPT_MODULE_RE.test(id_n))) {
|
|
1324
|
+
const shims = [...out.matchAll(APP_SHIM_IMPORT)].map((m) => ({
|
|
1325
|
+
start: m.index,
|
|
1326
|
+
end: m.index + m[0].length,
|
|
1327
|
+
text: JSON.stringify(ctx.app_shims[`$app/${m[2]}`])
|
|
1328
|
+
}));
|
|
1329
|
+
if (shims.length) edit(shims);
|
|
1330
|
+
}
|
|
1331
|
+
if (ssr && !id.includes("?") && id_n.endsWith(".svelte") && !is_island_path(bare_v) && (!in_node_modules || ctx.in_declared_pkg(id_n))) {
|
|
1332
|
+
const stamps = opaque_stamp_edits(out, id_n);
|
|
1333
|
+
if (stamps.length) edit(stamps);
|
|
1334
|
+
}
|
|
1335
|
+
return touched ? {
|
|
1336
|
+
code: out,
|
|
1337
|
+
map: chain.result(id_n)
|
|
1338
|
+
} : null;
|
|
1339
|
+
}
|
|
1340
|
+
/** The fn-manifest for the build handoff (tag → factory source), sorted by tag. */
|
|
1341
|
+
fn_manifest() {
|
|
1342
|
+
return Object.fromEntries(fn_manifest_entries(this.dollar_hoists));
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* A finished chunk with its relocation tokens replaced from the final records (every transform has
|
|
1346
|
+
* run by renderChunk, and the graph is complete), each patch counted on the leg
|
|
1347
|
+
* (link/relocations.ts). `null` when the chunk carries none.
|
|
1348
|
+
*/
|
|
1349
|
+
relocate(code, leg, bundle) {
|
|
1350
|
+
const ctx = this.#ctx;
|
|
1351
|
+
const out = relocate(code, relocations_of(leg.server), leg.relocated, {
|
|
1352
|
+
program: this.program,
|
|
1353
|
+
public_url: (iid) => ctx.island_public_url(iid),
|
|
1354
|
+
late_server_regions: leg.late_server_regions,
|
|
1355
|
+
chunk_file: bundle.chunk_file,
|
|
1356
|
+
file_name: bundle.file_name,
|
|
1357
|
+
facade_file: bundle.facade_file,
|
|
1358
|
+
graph: bundle.graph,
|
|
1359
|
+
module_ids: bundle.module_ids,
|
|
1360
|
+
page_reads: ctx.page_reads
|
|
1361
|
+
});
|
|
1362
|
+
if (out === null) return null;
|
|
1363
|
+
const { s, mapped } = out;
|
|
1364
|
+
return {
|
|
1365
|
+
code: s.toString(),
|
|
1366
|
+
map: mapped ? s.generateMap({ hires: true }) : null
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
/** True when `file` is a registered island HOST (a component that declares islands). */
|
|
1370
|
+
is_registered_host(file) {
|
|
1371
|
+
const { host_index, registry } = this.program;
|
|
1372
|
+
return host_index.has(host_key(file)) || [...registry.values()].some((e) => same_module_path(e.hostPath, file));
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Drop the cached virtual island modules + the registry rows for `file` — call when a HOST changes
|
|
1376
|
+
* (an import-target rename keeps the same island id) or an ENTRY component is deleted (NOT on ordinary
|
|
1377
|
+
* entry-component content edits — those are soft HMR). Mutates the Program; `invalidate` is the
|
|
1378
|
+
* bundler's module-invalidation (Vite's moduleGraph), threaded in. Returns whether anything changed.
|
|
1379
|
+
*/
|
|
1380
|
+
invalidate_for_file(file, { deleted = false, invalidate }) {
|
|
1381
|
+
const { registry, host_index } = this.program;
|
|
1382
|
+
const affected = /* @__PURE__ */ new Set();
|
|
1383
|
+
if (this.is_registered_host(file)) {
|
|
1384
|
+
for (const vpath of island_vpaths_affected_by_file(file, registry.entries())) affected.add(vpath);
|
|
1385
|
+
const prev = host_index.get(host_key(file));
|
|
1386
|
+
if (prev) for (const vpath of prev.vpaths) affected.add(vpath);
|
|
1387
|
+
this.program.unregister_host(file);
|
|
1388
|
+
}
|
|
1389
|
+
if (deleted) {
|
|
1390
|
+
const kind = this.#scans(file);
|
|
1391
|
+
if (kind) this.#scan_facts(path.normalize(file), null, kind);
|
|
1392
|
+
for (const id of this.moved()) invalidate(id);
|
|
1393
|
+
for (const vpath of this.program.drop_component(file)) affected.add(vpath);
|
|
1394
|
+
}
|
|
1395
|
+
if (affected.size === 0) return false;
|
|
1396
|
+
for (const vpath of affected) invalidate(vpath);
|
|
1397
|
+
for (const id of this.changed("regions")) invalidate(id);
|
|
1398
|
+
return true;
|
|
1399
|
+
}
|
|
1400
|
+
};
|
|
1401
|
+
export { Compiler, app_shim_for };
|