@ogygia/compiler 0.0.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +62 -1
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/app-spec.d.ts +18 -0
- package/dist/app-spec.js +22 -0
- package/dist/blank-styles.d.ts +1 -0
- package/dist/blank-styles.js +24 -0
- package/dist/bom.d.ts +2 -0
- package/dist/bom.js +7 -0
- package/dist/build-cache.d.ts +13 -0
- package/dist/build-cache.js +65 -0
- package/dist/ctx.d.ts +238 -0
- package/dist/ctx.js +221 -0
- package/dist/dev/css-scope.d.ts +16 -0
- package/dist/dev/css-scope.js +32 -0
- package/dist/dev/dev-hmr.d.ts +24 -0
- package/dist/dev/dev-hmr.js +51 -0
- package/dist/dev/hmr.d.ts +34 -0
- package/dist/dev/hmr.js +52 -0
- package/dist/driver.d.ts +351 -0
- package/dist/driver.js +1402 -0
- package/dist/exports/index.d.ts +77 -0
- package/dist/exports/index.js +349 -0
- package/dist/exports/parse.d.ts +65 -0
- package/dist/exports/parse.js +251 -0
- package/dist/fouc-css.d.ts +112 -0
- package/dist/fouc-css.js +314 -0
- package/dist/free-vars.d.ts +32 -0
- package/dist/free-vars.js +454 -0
- package/dist/fs.d.ts +31 -0
- package/dist/fs.js +82 -0
- package/dist/ids.d.ts +49 -0
- package/dist/ids.js +52 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +23 -0
- package/dist/kit.d.ts +204 -0
- package/dist/kit.js +554 -0
- package/dist/leg.d.ts +34 -0
- package/dist/leg.js +26 -0
- package/dist/link/analyses.d.ts +26 -0
- package/dist/link/analyses.js +237 -0
- package/dist/link/build-output.d.ts +47 -0
- package/dist/link/build-output.js +168 -0
- package/dist/link/caps.d.ts +32 -0
- package/dist/link/caps.js +39 -0
- package/dist/link/context-detect.d.ts +28 -0
- package/dist/link/context-detect.js +143 -0
- package/dist/link/emit-gate.d.ts +43 -0
- package/dist/link/emit-gate.js +55 -0
- package/dist/link/file-token.d.ts +11 -0
- package/dist/link/file-token.js +15 -0
- package/dist/link/island-deps.d.ts +183 -0
- package/dist/link/island-deps.js +802 -0
- package/dist/link/location-map.d.ts +24 -0
- package/dist/link/location-map.js +51 -0
- package/dist/link/own-reach.d.ts +15 -0
- package/dist/link/own-reach.js +188 -0
- package/dist/link/registry-stub.d.ts +50 -0
- package/dist/link/registry-stub.js +163 -0
- package/dist/link/relocations.d.ts +79 -0
- package/dist/link/relocations.js +204 -0
- package/dist/link/router-css.d.ts +38 -0
- package/dist/link/router-css.js +124 -0
- package/dist/link/runtime-entry.d.ts +103 -0
- package/dist/link/runtime-entry.js +183 -0
- package/dist/link/server-manifest.d.ts +25 -0
- package/dist/link/server-manifest.js +102 -0
- package/dist/link/transport.d.ts +42 -0
- package/dist/link/transport.js +91 -0
- package/dist/macros/dollar.d.ts +24 -0
- package/dist/macros/dollar.js +397 -0
- package/dist/macros/pipeline.d.ts +50 -0
- package/dist/macros/pipeline.js +133 -0
- package/dist/macros/source.d.ts +9 -0
- package/dist/macros/source.js +115 -0
- package/dist/macros/store.d.ts +22 -0
- package/dist/macros/store.js +217 -0
- package/dist/macros/wire.d.ts +17 -0
- package/dist/macros/wire.js +116 -0
- package/dist/map-chain.d.ts +18 -0
- package/dist/map-chain.js +42 -0
- package/dist/messages.d.ts +673 -0
- package/dist/messages.js +938 -0
- package/dist/ownership-stamps.d.ts +11 -0
- package/dist/ownership-stamps.js +112 -0
- package/dist/parse/oxc.d.ts +36 -0
- package/dist/parse/oxc.js +35 -0
- package/dist/parse/roots.d.ts +4 -0
- package/dist/parse/roots.js +27 -0
- package/dist/parse/scan.d.ts +65 -0
- package/dist/parse/scan.js +297 -0
- package/dist/parse/svelte-ast.d.ts +7 -0
- package/dist/parse/svelte-ast.js +99 -0
- package/dist/program.d.ts +140 -0
- package/dist/program.js +304 -0
- package/dist/queries.d.ts +105 -0
- package/dist/queries.js +326 -0
- package/dist/region/emit.d.ts +168 -0
- package/dist/region/emit.js +292 -0
- package/dist/region/identity.d.ts +32 -0
- package/dist/region/identity.js +46 -0
- package/dist/region/ir.d.ts +56 -0
- package/dist/region/ir.js +0 -0
- package/dist/region/marked-imports.d.ts +27 -0
- package/dist/region/marked-imports.js +265 -0
- package/dist/region/transform.d.ts +189 -0
- package/dist/region/transform.js +1565 -0
- package/dist/scan-facts.d.ts +36 -0
- package/dist/scan-facts.js +54 -0
- package/dist/script-request.d.ts +1 -0
- package/dist/script-request.js +33 -0
- package/dist/splice.d.ts +11 -0
- package/dist/splice.js +33 -0
- package/dist/transportables.d.ts +23 -0
- package/dist/transportables.js +144 -0
- package/dist/virtual/core.d.ts +158 -0
- package/dist/virtual/core.js +588 -0
- package/dist/virtual/resolver.d.ts +62 -0
- package/dist/virtual/resolver.js +265 -0
- package/dist/virtual/specifier.d.ts +10 -0
- package/dist/virtual/specifier.js +6 -0
- package/dist/virtual/table.d.ts +120 -0
- package/dist/virtual/table.js +54 -0
- package/dist/virtual/types.d.ts +17 -0
- package/dist/virtual/types.js +100 -0
- package/dist/virtual/value-names.d.ts +2 -0
- package/dist/virtual/value-names.js +18 -0
- package/dist/vite/definers.d.ts +16 -0
- package/dist/vite/definers.js +69 -0
- package/dist/vite/dev-maps.d.ts +34 -0
- package/dist/vite/dev-maps.js +91 -0
- package/dist/vite/index.d.ts +21 -0
- package/dist/vite/index.js +890 -0
- package/dist/vite/kit-dirs.d.ts +6 -0
- package/dist/vite/kit-dirs.js +53 -0
- package/dist/vite/late-island.d.ts +8 -0
- package/dist/vite/late-island.js +18 -0
- package/dist/vite/lazy-files.d.ts +2 -0
- package/dist/vite/lazy-files.js +72 -0
- package/dist/vite/options.d.ts +195 -0
- package/dist/vite/options.js +72 -0
- package/dist/vite/package-files.d.ts +3 -0
- package/dist/vite/package-files.js +88 -0
- package/dist/vite/paths.d.ts +16 -0
- package/dist/vite/paths.js +39 -0
- package/dist/vite/plugin-api.d.ts +316 -0
- package/dist/vite/plugin-api.js +328 -0
- package/dist/vite/route-watch.d.ts +15 -0
- package/dist/vite/route-watch.js +32 -0
- package/dist/vite/session.d.ts +28 -0
- package/dist/vite/session.js +43 -0
- package/dist/vite/sourcemaps.d.ts +19 -0
- package/dist/vite/sourcemaps.js +75 -0
- package/dist/vite/style-preprocess.d.ts +2 -0
- package/dist/vite/style-preprocess.js +84 -0
- package/dist/vite/svelte-entries.d.ts +4 -0
- package/dist/vite/svelte-entries.js +10 -0
- package/dist/vite/svelte-options.d.ts +20 -0
- package/dist/vite/svelte-options.js +22 -0
- package/package.json +87 -12
package/dist/ctx.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { strip_bom } from "./bom.js";
|
|
2
|
+
import { node_fs } from "./fs.js";
|
|
3
|
+
import { default_kit_dirs, route_reader } from "./kit.js";
|
|
4
|
+
import { islandVirtualId, wrapperVirtualId } from "./ids.js";
|
|
5
|
+
import { parse_module } from "./parse/oxc.js";
|
|
6
|
+
import { STABLE_NAME_DIR, islandChunkFileName, islandPublicUrl } from "./region/transform.js";
|
|
7
|
+
// src/ctx.ts
|
|
8
|
+
const BACKSLASH_SEP = /\\/;
|
|
9
|
+
const NEVER_MATCH_RE = /$^/;
|
|
10
|
+
var CompileCtx = class {
|
|
11
|
+
/** Every read of the app's files goes through here (./fs.ts). */
|
|
12
|
+
fs;
|
|
13
|
+
/** Kit's route worlds and route config, read through `fs` (one cache set per file system). */
|
|
14
|
+
routes;
|
|
15
|
+
root;
|
|
16
|
+
/** The app's Kit dirs (`kit.files.routes`, `kit.outDir`). */
|
|
17
|
+
kit_dirs;
|
|
18
|
+
base;
|
|
19
|
+
app_dir;
|
|
20
|
+
libDir;
|
|
21
|
+
pkg_scan;
|
|
22
|
+
page_importers;
|
|
23
|
+
page_files;
|
|
24
|
+
measure;
|
|
25
|
+
server_plugins;
|
|
26
|
+
client_plugins;
|
|
27
|
+
route_config;
|
|
28
|
+
foreign_hydrate;
|
|
29
|
+
is_dev;
|
|
30
|
+
id_salt;
|
|
31
|
+
visibleMargin;
|
|
32
|
+
presets;
|
|
33
|
+
import_keys;
|
|
34
|
+
resolve_alias;
|
|
35
|
+
/** What an app import specifier is resolved against (app-spec.ts): the root, `$lib`, the aliases. */
|
|
36
|
+
get app_spec() {
|
|
37
|
+
return {
|
|
38
|
+
root: this.root,
|
|
39
|
+
libDir: this.libDir,
|
|
40
|
+
alias: this.resolve_alias,
|
|
41
|
+
stat: (abs) => this.fs.stat(abs)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
component_css;
|
|
45
|
+
macros;
|
|
46
|
+
page_reads;
|
|
47
|
+
prescans;
|
|
48
|
+
plugins;
|
|
49
|
+
pkg_root;
|
|
50
|
+
build_secret;
|
|
51
|
+
rate_limit;
|
|
52
|
+
session_cookie;
|
|
53
|
+
region_ttl;
|
|
54
|
+
renew_window;
|
|
55
|
+
router_enabled;
|
|
56
|
+
router_view_transitions;
|
|
57
|
+
client_hooks;
|
|
58
|
+
runtime_dir;
|
|
59
|
+
runtime_hash;
|
|
60
|
+
kit_wire_path;
|
|
61
|
+
client_binding_stub_file;
|
|
62
|
+
app_shims;
|
|
63
|
+
is_build;
|
|
64
|
+
devtools;
|
|
65
|
+
/** `with { … }` hint matcher — a node_modules `.svelte` is only transformed when it carries one
|
|
66
|
+
* (so a library can declare its own islands). Built once from the resolved import keys. */
|
|
67
|
+
#island_hint_re;
|
|
68
|
+
/** The resolved import-attribute keys that make a mark (`wake`, `render`, …). */
|
|
69
|
+
#mark_keys;
|
|
70
|
+
/** Declared package files (exact) + dirs (prefix) — the transform-gate membership index. */
|
|
71
|
+
#pkg_files;
|
|
72
|
+
#pkg_dirs;
|
|
73
|
+
/** Package roots, longest first, for stable-identity mapping (root → published name). */
|
|
74
|
+
#pkg_roots;
|
|
75
|
+
constructor(init) {
|
|
76
|
+
this.fs = init.fs ?? node_fs;
|
|
77
|
+
this.routes = route_reader(this.fs);
|
|
78
|
+
this.root = init.root;
|
|
79
|
+
this.kit_dirs = init.kit_dirs ?? default_kit_dirs(init.root);
|
|
80
|
+
this.base = init.base;
|
|
81
|
+
this.app_dir = init.app_dir;
|
|
82
|
+
this.libDir = init.libDir;
|
|
83
|
+
this.pkg_scan = init.pkg_scan ?? [];
|
|
84
|
+
this.page_importers = init.page_importers ?? [];
|
|
85
|
+
this.page_files = init.page_files ?? [];
|
|
86
|
+
this.measure = init.measure;
|
|
87
|
+
this.server_plugins = init.server_plugins ?? [];
|
|
88
|
+
this.client_plugins = init.client_plugins ?? [];
|
|
89
|
+
this.route_config = init.route_config ?? [];
|
|
90
|
+
this.foreign_hydrate = init.foreign_hydrate ?? false;
|
|
91
|
+
this.is_dev = init.is_dev;
|
|
92
|
+
this.id_salt = init.id_salt;
|
|
93
|
+
this.visibleMargin = init.visibleMargin;
|
|
94
|
+
this.presets = init.presets;
|
|
95
|
+
this.import_keys = init.import_keys;
|
|
96
|
+
this.resolve_alias = init.resolve_alias;
|
|
97
|
+
this.component_css = init.component_css;
|
|
98
|
+
this.macros = init.macros ?? [];
|
|
99
|
+
this.page_reads = init.page_reads ?? null;
|
|
100
|
+
this.prescans = init.prescans ?? [];
|
|
101
|
+
this.plugins = init.plugins ?? [];
|
|
102
|
+
this.pkg_root = init.pkg_root;
|
|
103
|
+
this.build_secret = init.build_secret;
|
|
104
|
+
this.rate_limit = init.rate_limit;
|
|
105
|
+
this.session_cookie = init.session_cookie;
|
|
106
|
+
this.region_ttl = init.region_ttl;
|
|
107
|
+
this.renew_window = init.renew_window;
|
|
108
|
+
this.router_enabled = init.router_enabled;
|
|
109
|
+
this.router_view_transitions = init.router_view_transitions;
|
|
110
|
+
this.client_hooks = init.client_hooks ?? null;
|
|
111
|
+
this.runtime_dir = init.runtime_dir;
|
|
112
|
+
this.runtime_hash = init.runtime_hash;
|
|
113
|
+
this.kit_wire_path = init.kit_wire_path ?? null;
|
|
114
|
+
this.client_binding_stub_file = init.client_binding_stub_file;
|
|
115
|
+
this.app_shims = init.app_shims;
|
|
116
|
+
this.is_build = init.is_build;
|
|
117
|
+
this.devtools = init.devtools;
|
|
118
|
+
const hint_keys = Object.values(init.import_keys).filter((v) => typeof v === "string");
|
|
119
|
+
this.#island_hint_re = hint_keys.length ? new RegExp(`\\bwith\\s*\\{[^}]*\\b(?:${hint_keys.join("|")})\\b`) : NEVER_MATCH_RE;
|
|
120
|
+
this.#mark_keys = new Set(hint_keys);
|
|
121
|
+
this.#pkg_files = new Set(this.pkg_scan.flatMap((p) => p.files));
|
|
122
|
+
this.#pkg_dirs = this.pkg_scan.flatMap((p) => p.dirs);
|
|
123
|
+
this.#pkg_roots = this.pkg_scan.map((p) => ({
|
|
124
|
+
root: p.root,
|
|
125
|
+
name: p.name
|
|
126
|
+
})).sort((a, b) => b.root.length - a.root.length);
|
|
127
|
+
}
|
|
128
|
+
/** True when `code` carries an ogygia `with { … }` island hint (gates node_modules `.svelte`). */
|
|
129
|
+
has_island_hint(code) {
|
|
130
|
+
return this.#island_hint_re.test(code);
|
|
131
|
+
}
|
|
132
|
+
/** True when a JS module has a real `import … with { <mark key>: … }` declaration. The hint
|
|
133
|
+
* above is a text sniff, so it also matches a comment, a string or generated code that merely
|
|
134
|
+
* mentions `with { wake }`; this parses. A module that does not parse counts as marked, so a
|
|
135
|
+
* warning that depends on it errs toward speaking. */
|
|
136
|
+
has_marked_import(code, id) {
|
|
137
|
+
const { program, ok } = parse_module(code, id);
|
|
138
|
+
if (!ok || !program) return true;
|
|
139
|
+
for (const node of program.body) {
|
|
140
|
+
if (node.type !== "ImportDeclaration") continue;
|
|
141
|
+
for (const attr of node.attributes ?? []) {
|
|
142
|
+
const key = attr.key?.type === "Identifier" ? attr.key.name : attr.key?.value;
|
|
143
|
+
if (typeof key === "string" && this.#mark_keys.has(key)) return true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
/** True when `id` is inside a dependency's DECLARED `ogygia.files` surface — those files are
|
|
149
|
+
* prescanned + transformed exactly like app source (the node_modules gates lift for them). */
|
|
150
|
+
in_declared_pkg(id) {
|
|
151
|
+
if (this.#pkg_files.size === 0 && this.#pkg_dirs.length === 0) return false;
|
|
152
|
+
const p = id.split(BACKSLASH_SEP).join("/");
|
|
153
|
+
if (this.#pkg_files.has(p)) return true;
|
|
154
|
+
for (const dir of this.#pkg_dirs) if (p.startsWith(`${dir}/`)) return true;
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
/** True for the app's own source (anything not installed: the app, its workspace packages,
|
|
158
|
+
* virtual modules) and for a dependency's declared `ogygia.files`. */
|
|
159
|
+
is_own_source(id) {
|
|
160
|
+
const p = id.split(BACKSLASH_SEP).join("/");
|
|
161
|
+
return !p.includes("/node_modules/") || this.in_declared_pkg(p);
|
|
162
|
+
}
|
|
163
|
+
/** Install-independent region identity for a file under a declared package: `<name>/<rel>`.
|
|
164
|
+
* Store paths carry version + peer-resolution hashes (`node_modules/.pnpm/pkg@1.2.3(...)`),
|
|
165
|
+
* so a root-relative identity would change per install/machine and prod HTML would stop
|
|
166
|
+
* matching its chunks. Returns `null` for anything not under a declared package root. */
|
|
167
|
+
pkg_identity(abs) {
|
|
168
|
+
if (this.#pkg_roots.length === 0) return null;
|
|
169
|
+
const p = abs.split(BACKSLASH_SEP).join("/");
|
|
170
|
+
for (const { root, name } of this.#pkg_roots) if (p.startsWith(`${root}/`)) return name + p.slice(root.length);
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
/** The runtime's feature set, as a name segment: the prescan's feature hash, and a trailing `h` when
|
|
174
|
+
* the app has `hooks.client.ts` (the runtime entry then dynamic-imports it). Empty until prescan
|
|
175
|
+
* runs. Both the stable name and the content-hashed file carry it, so a name says which runtime. */
|
|
176
|
+
runtime_features(program_feature_hash) {
|
|
177
|
+
return `${program_feature_hash}${this.client_hooks ? "h" : ""}`;
|
|
178
|
+
}
|
|
179
|
+
/** The runtime's STABLE name (`RUNTIME_HASH` ⊕ its features): its identity — the key the handoff
|
|
180
|
+
* maps to the content-hashed file the page loads (a name, not a file). Computed here
|
|
181
|
+
* (not the caller) so both build legs name it identically. `program_feature_hash` is the scan's
|
|
182
|
+
* `Scan.feature_hash`, threaded in by the caller so this stays a pure naming function. */
|
|
183
|
+
runtime_chunk_filename(program_feature_hash) {
|
|
184
|
+
const feat = this.runtime_features(program_feature_hash);
|
|
185
|
+
return `${this.app_dir}/${STABLE_NAME_DIR}/og-runtime.${this.runtime_hash}${feat ? `-${feat}` : ""}.js`;
|
|
186
|
+
}
|
|
187
|
+
/** App-internal URL of the runtime chunk (leading slash + appDir; NO base). SSR bakes it as the
|
|
188
|
+
* `<script src>`, then `asset()` prepends base / the assets CDN at render time. */
|
|
189
|
+
runtime_chunk_url(program_feature_hash) {
|
|
190
|
+
return `/${this.runtime_chunk_filename(program_feature_hash)}`;
|
|
191
|
+
}
|
|
192
|
+
/** Output filename for a hydrate island chunk (under the app dir; an on-disk build path). */
|
|
193
|
+
island_chunk_filename(iid) {
|
|
194
|
+
return islandChunkFileName(iid, this.app_dir);
|
|
195
|
+
}
|
|
196
|
+
/** App-internal URL of a hydrate island chunk (leading slash + appDir; NO base — `asset()` adds it). */
|
|
197
|
+
island_public_url(iid) {
|
|
198
|
+
return islandPublicUrl(iid, this.app_dir);
|
|
199
|
+
}
|
|
200
|
+
/** Read a file as UTF-8, or `null` if it can't be read (the transform tolerates missing deps). */
|
|
201
|
+
read_file(abs) {
|
|
202
|
+
const text = this.fs.read(abs);
|
|
203
|
+
return text === null ? null : strip_bom(text);
|
|
204
|
+
}
|
|
205
|
+
/** Virtual island ENTRY module id for an island id. */
|
|
206
|
+
island_virtual_id(iid) {
|
|
207
|
+
return islandVirtualId(iid);
|
|
208
|
+
}
|
|
209
|
+
/** Virtual wrapper `.svelte` module id for an island id. */
|
|
210
|
+
wrapper_virtual_id(iid) {
|
|
211
|
+
return wrapperVirtualId(iid);
|
|
212
|
+
}
|
|
213
|
+
/** Dev URL for a dynamic `import(entry)` of a virtual island module. Base-LESS, exactly like the
|
|
214
|
+
* prod island/runtime URLs and the dev runtime URL: `Region.svelte` runs it through Kit's `asset()`
|
|
215
|
+
* at SSR, which is the sole base authority. Baking `base` here would double it (Vite dev serves
|
|
216
|
+
* `/@id/…` UNDER base, and `asset()` already adds that prefix). */
|
|
217
|
+
dev_url_for(virtualPath) {
|
|
218
|
+
return `/@id/${virtualPath}`;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
export { CompileCtx };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Structural shape of a Vite dev module-graph node (the two fields the owner walk reads). */
|
|
2
|
+
export type DevGraphModule = {
|
|
3
|
+
file?: string | null;
|
|
4
|
+
importers?: Iterable<DevGraphModule>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Which top-level route scopes can reach `abs_file` — walked UP the dev module graph until route
|
|
8
|
+
* files are hit. A scope is a route file's first path segment under `src/routes` (`'(docs)'`,
|
|
9
|
+
* `'playground'`, `''` for a root-level route file). `[]` = no route owner found; the client treats
|
|
10
|
+
* that as shared and joins anywhere (the safe default for exotic graphs).
|
|
11
|
+
*
|
|
12
|
+
* @internal Exported for unit tests.
|
|
13
|
+
*/
|
|
14
|
+
export declare function derive_css_scope_owners(abs_file: string, routes_dir_of_app: string, graphs: Array<{
|
|
15
|
+
getModulesByFile?: (f: string) => Set<DevGraphModule> | undefined;
|
|
16
|
+
} | undefined | null>): string[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
// src/dev/css-scope.ts
|
|
3
|
+
/**
|
|
4
|
+
* Which top-level route scopes can reach `abs_file` — walked UP the dev module graph until route
|
|
5
|
+
* files are hit. A scope is a route file's first path segment under `src/routes` (`'(docs)'`,
|
|
6
|
+
* `'playground'`, `''` for a root-level route file). `[]` = no route owner found; the client treats
|
|
7
|
+
* that as shared and joins anywhere (the safe default for exotic graphs).
|
|
8
|
+
*
|
|
9
|
+
* @internal Exported for unit tests.
|
|
10
|
+
*/
|
|
11
|
+
function derive_css_scope_owners(abs_file, routes_dir_of_app, graphs) {
|
|
12
|
+
const routes_dir = routes_dir_of_app + path.sep;
|
|
13
|
+
const owners = /* @__PURE__ */ new Set();
|
|
14
|
+
const seen = /* @__PURE__ */ new Set();
|
|
15
|
+
const stack = [];
|
|
16
|
+
for (const g of graphs) for (const m of g?.getModulesByFile?.(abs_file) ?? []) stack.push(m);
|
|
17
|
+
let steps = 0;
|
|
18
|
+
while (stack.length && steps++ < 5e3) {
|
|
19
|
+
const mod = stack.pop();
|
|
20
|
+
if (seen.has(mod)) continue;
|
|
21
|
+
seen.add(mod);
|
|
22
|
+
const f = mod.file ? path.normalize(mod.file) : null;
|
|
23
|
+
if (f && f.startsWith(routes_dir)) {
|
|
24
|
+
const seg = f.slice(routes_dir.length).split(path.sep)[0] ?? "";
|
|
25
|
+
owners.add(seg.includes(".") ? "" : seg);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
for (const imp of mod.importers ?? []) stack.push(imp);
|
|
29
|
+
}
|
|
30
|
+
return [...owners].sort();
|
|
31
|
+
}
|
|
32
|
+
export { derive_css_scope_owners };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client bridge source for `ogygia:dev/hmr` (vite serve only): a LAZY map of app CSS under
|
|
3
|
+
* `/src`, joined per-file when the plugin broadcasts a scoped `ogygia:css` event — plus full-reload
|
|
4
|
+
* on `vite:error`.
|
|
5
|
+
*
|
|
6
|
+
* LAZY is load-bearing. The bridge used to join every `/src` stylesheet EAGERLY, which painted the
|
|
7
|
+
* whole app's CSS onto every page — invisible while one app owned one look, but the moment two
|
|
8
|
+
* sub-apps share one project (the `(docs)` / `playground` split), each page wore the other's skin
|
|
9
|
+
* in dev while prod (Kit's per-route CSS) stayed clean. Now a page boots with exactly its SSR CSS,
|
|
10
|
+
* and joins a stylesheet only when it changes AND this page's route scope owns it (the
|
|
11
|
+
* `ogygia-dev-scope` meta the handle stamps vs. the owners the plugin derives from the module
|
|
12
|
+
* graph). Once joined, later edits soft-apply through Vite's normal CSS HMR.
|
|
13
|
+
*
|
|
14
|
+
* Do **not** strip Kit’s `<style data-sveltekit>` FOUC bag. Under `csr = false` that bag is
|
|
15
|
+
* how page + component CSS is delivered (no client module graph for route shells). Removing
|
|
16
|
+
* it blanks the page; a MutationObserver would also delete FOUC styles the SPA router merges
|
|
17
|
+
* in on navigation.
|
|
18
|
+
*
|
|
19
|
+
* Its `hot.on` listeners are its module run's, and need no scope: Vite drops a replaced module's
|
|
20
|
+
* `hot.on` listeners itself (the client's `ctxToListenersMap`), and a full reload ends the page.
|
|
21
|
+
*
|
|
22
|
+
* @internal Emitted by the plugin; exported for unit tests.
|
|
23
|
+
*/
|
|
24
|
+
export declare function dev_hmr_client_source(): string;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { dedent } from "@ogygia/core/contract";
|
|
2
|
+
// src/dev/dev-hmr.ts
|
|
3
|
+
/**
|
|
4
|
+
* Client bridge source for `ogygia:dev/hmr` (vite serve only): a LAZY map of app CSS under
|
|
5
|
+
* `/src`, joined per-file when the plugin broadcasts a scoped `ogygia:css` event — plus full-reload
|
|
6
|
+
* on `vite:error`.
|
|
7
|
+
*
|
|
8
|
+
* LAZY is load-bearing. The bridge used to join every `/src` stylesheet EAGERLY, which painted the
|
|
9
|
+
* whole app's CSS onto every page — invisible while one app owned one look, but the moment two
|
|
10
|
+
* sub-apps share one project (the `(docs)` / `playground` split), each page wore the other's skin
|
|
11
|
+
* in dev while prod (Kit's per-route CSS) stayed clean. Now a page boots with exactly its SSR CSS,
|
|
12
|
+
* and joins a stylesheet only when it changes AND this page's route scope owns it (the
|
|
13
|
+
* `ogygia-dev-scope` meta the handle stamps vs. the owners the plugin derives from the module
|
|
14
|
+
* graph). Once joined, later edits soft-apply through Vite's normal CSS HMR.
|
|
15
|
+
*
|
|
16
|
+
* Do **not** strip Kit’s `<style data-sveltekit>` FOUC bag. Under `csr = false` that bag is
|
|
17
|
+
* how page + component CSS is delivered (no client module graph for route shells). Removing
|
|
18
|
+
* it blanks the page; a MutationObserver would also delete FOUC styles the SPA router merges
|
|
19
|
+
* in on navigation.
|
|
20
|
+
*
|
|
21
|
+
* Its `hot.on` listeners are its module run's, and need no scope: Vite drops a replaced module's
|
|
22
|
+
* `hot.on` listeners itself (the client's `ctxToListenersMap`), and a full reload ends the page.
|
|
23
|
+
*
|
|
24
|
+
* @internal Emitted by the plugin; exported for unit tests.
|
|
25
|
+
*/
|
|
26
|
+
function dev_hmr_client_source() {
|
|
27
|
+
return `${dedent`
|
|
28
|
+
import "/@vite/client";
|
|
29
|
+
const css_modules = import.meta.glob("/src/**/*.{css,scss,sass,less,styl}", { eager: false });
|
|
30
|
+
const scope_meta = document.querySelector('meta[name="ogygia-dev-scope"]');
|
|
31
|
+
const scope = scope_meta ? scope_meta.getAttribute("content") || "" : "";
|
|
32
|
+
// Soft path: scoped join on first change, then Vite CSS HMR (injected after FOUC; later rules win).
|
|
33
|
+
// Hard path: anything Vite can't apply.
|
|
34
|
+
function ogygia_full_reload() {
|
|
35
|
+
location.reload();
|
|
36
|
+
}
|
|
37
|
+
if (import.meta.hot) {
|
|
38
|
+
import.meta.hot.accept();
|
|
39
|
+
import.meta.hot.on("vite:error", ogygia_full_reload);
|
|
40
|
+
import.meta.hot.on("ogygia:css", (d) => {
|
|
41
|
+
const p = d && d.path;
|
|
42
|
+
if (!p || !css_modules[p]) return;
|
|
43
|
+
const owners = (d && d.owners) || [];
|
|
44
|
+
// Join only what this page's sub-app owns; ownerless css (shared / undeterminable) joins anywhere.
|
|
45
|
+
if (owners.length && owners.indexOf(scope) === -1) return;
|
|
46
|
+
css_modules[p]();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
`}\n`;
|
|
50
|
+
}
|
|
51
|
+
export { dev_hmr_client_source };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host route shells (`+page` / `+layout` / …) never join the browser module graph under
|
|
3
|
+
* `csr=false`, so Vite's fine-grained HMR for them has no client importer. Force a full reload.
|
|
4
|
+
* Standalone CSS is soft-updated via `ogygia:dev/hmr` (Vite inject after Kit FOUC).
|
|
5
|
+
* If that soft path fails, the client bridge listens for `vite:error` and reloads the document.
|
|
6
|
+
*
|
|
7
|
+
* @internal HMR policy helper (also covered by unit tests).
|
|
8
|
+
*/
|
|
9
|
+
export declare function needs_csr_false_full_reload(file: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Island entry `.svelte` files (the `import X from '…' with { hydrate }`) sit behind a virtual
|
|
12
|
+
* wrapper; Svelte soft HMR through that edge is unreliable. Shared `.ts` deps still soft-update.
|
|
13
|
+
*
|
|
14
|
+
* @internal HMR policy helper (also covered by unit tests).
|
|
15
|
+
*/
|
|
16
|
+
export declare function needs_island_entry_full_reload(file: string, entries: Iterable<{
|
|
17
|
+
componentPath?: string | null;
|
|
18
|
+
}>): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Absolute path equality with querystrings stripped (host vs component vs Vite watch paths).
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare function same_module_path(a: string | null | undefined, b: string | null | undefined): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Virtual island ids whose generated source must be dropped when `file` changes or is deleted.
|
|
26
|
+
* Island ids are `hash(componentPath\\0strategyKey)` — renaming a host route keeps the same id, so
|
|
27
|
+
* Vite's moduleGraph must be invalidated or it keeps serving the old import.
|
|
28
|
+
*
|
|
29
|
+
* @internal HMR invalidation helper (also covered by unit tests).
|
|
30
|
+
*/
|
|
31
|
+
export declare function island_vpaths_affected_by_file(file: string, entries: Iterable<[string, {
|
|
32
|
+
hostPath?: string | null;
|
|
33
|
+
componentPath?: string | null;
|
|
34
|
+
}]>): string[];
|
package/dist/dev/hmr.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
// src/dev/hmr.ts
|
|
3
|
+
const BACKSLASH = /\\/g;
|
|
4
|
+
const STYLE_EXT = /\.(css|scss|sass|less|styl)(?:$|\?)/i;
|
|
5
|
+
const KIT_ROUTE_FILE = /(?:^|\/)\+(?:page|layout|error|server|hooks)(?:\.|$)/;
|
|
6
|
+
/**
|
|
7
|
+
* Host route shells (`+page` / `+layout` / …) never join the browser module graph under
|
|
8
|
+
* `csr=false`, so Vite's fine-grained HMR for them has no client importer. Force a full reload.
|
|
9
|
+
* Standalone CSS is soft-updated via `ogygia:dev/hmr` (Vite inject after Kit FOUC).
|
|
10
|
+
* If that soft path fails, the client bridge listens for `vite:error` and reloads the document.
|
|
11
|
+
*
|
|
12
|
+
* @internal HMR policy helper (also covered by unit tests).
|
|
13
|
+
*/
|
|
14
|
+
function needs_csr_false_full_reload(file) {
|
|
15
|
+
const norm = file.replace(BACKSLASH, "/");
|
|
16
|
+
if (STYLE_EXT.test(norm)) return false;
|
|
17
|
+
return KIT_ROUTE_FILE.test(norm);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Island entry `.svelte` files (the `import X from '…' with { hydrate }`) sit behind a virtual
|
|
21
|
+
* wrapper; Svelte soft HMR through that edge is unreliable. Shared `.ts` deps still soft-update.
|
|
22
|
+
*
|
|
23
|
+
* @internal HMR policy helper (also covered by unit tests).
|
|
24
|
+
*/
|
|
25
|
+
function needs_island_entry_full_reload(file, entries) {
|
|
26
|
+
const bare = file.split("?")[0];
|
|
27
|
+
if (!bare.endsWith(".svelte")) return false;
|
|
28
|
+
if (STYLE_EXT.test(bare.replace(BACKSLASH, "/"))) return false;
|
|
29
|
+
for (const entry of entries) if (same_module_path(entry.componentPath, file)) return true;
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Absolute path equality with querystrings stripped (host vs component vs Vite watch paths).
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
function same_module_path(a, b) {
|
|
37
|
+
if (!a || !b) return false;
|
|
38
|
+
return path.resolve(a.split("?")[0]) === path.resolve(b.split("?")[0]);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Virtual island ids whose generated source must be dropped when `file` changes or is deleted.
|
|
42
|
+
* Island ids are `hash(componentPath\\0strategyKey)` — renaming a host route keeps the same id, so
|
|
43
|
+
* Vite's moduleGraph must be invalidated or it keeps serving the old import.
|
|
44
|
+
*
|
|
45
|
+
* @internal HMR invalidation helper (also covered by unit tests).
|
|
46
|
+
*/
|
|
47
|
+
function island_vpaths_affected_by_file(file, entries) {
|
|
48
|
+
const out = [];
|
|
49
|
+
for (const [vpath, entry] of entries) if (same_module_path(entry.hostPath, file) || same_module_path(entry.componentPath, file)) out.push(vpath);
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
export { island_vpaths_affected_by_file, needs_csr_false_full_reload, needs_island_entry_full_reload, same_module_path };
|