@ogygia/compiler 0.0.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +62 -1
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/app-spec.d.ts +18 -0
- package/dist/app-spec.js +22 -0
- package/dist/blank-styles.d.ts +1 -0
- package/dist/blank-styles.js +24 -0
- package/dist/bom.d.ts +2 -0
- package/dist/bom.js +7 -0
- package/dist/build-cache.d.ts +13 -0
- package/dist/build-cache.js +65 -0
- package/dist/ctx.d.ts +238 -0
- package/dist/ctx.js +221 -0
- package/dist/dev/css-scope.d.ts +16 -0
- package/dist/dev/css-scope.js +32 -0
- package/dist/dev/dev-hmr.d.ts +24 -0
- package/dist/dev/dev-hmr.js +51 -0
- package/dist/dev/hmr.d.ts +34 -0
- package/dist/dev/hmr.js +52 -0
- package/dist/driver.d.ts +351 -0
- package/dist/driver.js +1402 -0
- package/dist/exports/index.d.ts +77 -0
- package/dist/exports/index.js +349 -0
- package/dist/exports/parse.d.ts +65 -0
- package/dist/exports/parse.js +251 -0
- package/dist/fouc-css.d.ts +112 -0
- package/dist/fouc-css.js +314 -0
- package/dist/free-vars.d.ts +32 -0
- package/dist/free-vars.js +454 -0
- package/dist/fs.d.ts +31 -0
- package/dist/fs.js +82 -0
- package/dist/ids.d.ts +49 -0
- package/dist/ids.js +52 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +23 -0
- package/dist/kit.d.ts +204 -0
- package/dist/kit.js +554 -0
- package/dist/leg.d.ts +34 -0
- package/dist/leg.js +26 -0
- package/dist/link/analyses.d.ts +26 -0
- package/dist/link/analyses.js +237 -0
- package/dist/link/build-output.d.ts +47 -0
- package/dist/link/build-output.js +168 -0
- package/dist/link/caps.d.ts +32 -0
- package/dist/link/caps.js +39 -0
- package/dist/link/context-detect.d.ts +28 -0
- package/dist/link/context-detect.js +143 -0
- package/dist/link/emit-gate.d.ts +43 -0
- package/dist/link/emit-gate.js +55 -0
- package/dist/link/file-token.d.ts +11 -0
- package/dist/link/file-token.js +15 -0
- package/dist/link/island-deps.d.ts +183 -0
- package/dist/link/island-deps.js +802 -0
- package/dist/link/location-map.d.ts +24 -0
- package/dist/link/location-map.js +51 -0
- package/dist/link/own-reach.d.ts +15 -0
- package/dist/link/own-reach.js +188 -0
- package/dist/link/registry-stub.d.ts +50 -0
- package/dist/link/registry-stub.js +163 -0
- package/dist/link/relocations.d.ts +79 -0
- package/dist/link/relocations.js +204 -0
- package/dist/link/router-css.d.ts +38 -0
- package/dist/link/router-css.js +124 -0
- package/dist/link/runtime-entry.d.ts +103 -0
- package/dist/link/runtime-entry.js +183 -0
- package/dist/link/server-manifest.d.ts +25 -0
- package/dist/link/server-manifest.js +102 -0
- package/dist/link/transport.d.ts +42 -0
- package/dist/link/transport.js +91 -0
- package/dist/macros/dollar.d.ts +24 -0
- package/dist/macros/dollar.js +397 -0
- package/dist/macros/pipeline.d.ts +50 -0
- package/dist/macros/pipeline.js +133 -0
- package/dist/macros/source.d.ts +9 -0
- package/dist/macros/source.js +115 -0
- package/dist/macros/store.d.ts +22 -0
- package/dist/macros/store.js +217 -0
- package/dist/macros/wire.d.ts +17 -0
- package/dist/macros/wire.js +116 -0
- package/dist/map-chain.d.ts +18 -0
- package/dist/map-chain.js +42 -0
- package/dist/messages.d.ts +673 -0
- package/dist/messages.js +938 -0
- package/dist/ownership-stamps.d.ts +11 -0
- package/dist/ownership-stamps.js +112 -0
- package/dist/parse/oxc.d.ts +36 -0
- package/dist/parse/oxc.js +35 -0
- package/dist/parse/roots.d.ts +4 -0
- package/dist/parse/roots.js +27 -0
- package/dist/parse/scan.d.ts +65 -0
- package/dist/parse/scan.js +297 -0
- package/dist/parse/svelte-ast.d.ts +7 -0
- package/dist/parse/svelte-ast.js +99 -0
- package/dist/program.d.ts +140 -0
- package/dist/program.js +304 -0
- package/dist/queries.d.ts +105 -0
- package/dist/queries.js +326 -0
- package/dist/region/emit.d.ts +168 -0
- package/dist/region/emit.js +292 -0
- package/dist/region/identity.d.ts +32 -0
- package/dist/region/identity.js +46 -0
- package/dist/region/ir.d.ts +56 -0
- package/dist/region/ir.js +0 -0
- package/dist/region/marked-imports.d.ts +27 -0
- package/dist/region/marked-imports.js +265 -0
- package/dist/region/transform.d.ts +189 -0
- package/dist/region/transform.js +1565 -0
- package/dist/scan-facts.d.ts +36 -0
- package/dist/scan-facts.js +54 -0
- package/dist/script-request.d.ts +1 -0
- package/dist/script-request.js +33 -0
- package/dist/splice.d.ts +11 -0
- package/dist/splice.js +33 -0
- package/dist/transportables.d.ts +23 -0
- package/dist/transportables.js +144 -0
- package/dist/virtual/core.d.ts +158 -0
- package/dist/virtual/core.js +588 -0
- package/dist/virtual/resolver.d.ts +62 -0
- package/dist/virtual/resolver.js +265 -0
- package/dist/virtual/specifier.d.ts +10 -0
- package/dist/virtual/specifier.js +6 -0
- package/dist/virtual/table.d.ts +120 -0
- package/dist/virtual/table.js +54 -0
- package/dist/virtual/types.d.ts +17 -0
- package/dist/virtual/types.js +100 -0
- package/dist/virtual/value-names.d.ts +2 -0
- package/dist/virtual/value-names.js +18 -0
- package/dist/vite/definers.d.ts +16 -0
- package/dist/vite/definers.js +69 -0
- package/dist/vite/dev-maps.d.ts +34 -0
- package/dist/vite/dev-maps.js +91 -0
- package/dist/vite/index.d.ts +21 -0
- package/dist/vite/index.js +890 -0
- package/dist/vite/kit-dirs.d.ts +6 -0
- package/dist/vite/kit-dirs.js +53 -0
- package/dist/vite/late-island.d.ts +8 -0
- package/dist/vite/late-island.js +18 -0
- package/dist/vite/lazy-files.d.ts +2 -0
- package/dist/vite/lazy-files.js +72 -0
- package/dist/vite/options.d.ts +195 -0
- package/dist/vite/options.js +72 -0
- package/dist/vite/package-files.d.ts +3 -0
- package/dist/vite/package-files.js +88 -0
- package/dist/vite/paths.d.ts +16 -0
- package/dist/vite/paths.js +39 -0
- package/dist/vite/plugin-api.d.ts +316 -0
- package/dist/vite/plugin-api.js +328 -0
- package/dist/vite/route-watch.d.ts +15 -0
- package/dist/vite/route-watch.js +32 -0
- package/dist/vite/session.d.ts +28 -0
- package/dist/vite/session.js +43 -0
- package/dist/vite/sourcemaps.d.ts +19 -0
- package/dist/vite/sourcemaps.js +75 -0
- package/dist/vite/style-preprocess.d.ts +2 -0
- package/dist/vite/style-preprocess.js +84 -0
- package/dist/vite/svelte-entries.d.ts +4 -0
- package/dist/vite/svelte-entries.js +10 -0
- package/dist/vite/svelte-options.d.ts +20 -0
- package/dist/vite/svelte-options.js +22 -0
- package/package.json +87 -12
|
@@ -0,0 +1,890 @@
|
|
|
1
|
+
import { configure_build_cache } from "../build-cache.js";
|
|
2
|
+
import { island_sourcemaps_plugin } from "./sourcemaps.js";
|
|
3
|
+
import { lazy_files } from "./lazy-files.js";
|
|
4
|
+
import { install_dev_client_maps, install_dev_maps, install_dev_page_keys } from "./dev-maps.js";
|
|
5
|
+
import { CLIENT_BINDING_STUB, DEFAULT_IMPORT_KEYS, import_keys_hint, is_island_path, islandChunkFileName, islandId, islandPublicUrl, normalize_import_keys } from "../region/transform.js";
|
|
6
|
+
import { wrapperVirtualId } from "../ids.js";
|
|
7
|
+
import { rewrite_lake_import_to_placeholder } from "../region/emit.js";
|
|
8
|
+
import { regionId, regionIdentity, strategyKey } from "../region/identity.js";
|
|
9
|
+
import { definePlugin, find_plugins, resolve_plugins } from "./plugin-api.js";
|
|
10
|
+
import { definers_plugin } from "./definers.js";
|
|
11
|
+
import { assert_known_options, resolve_options, validate_region_presets } from "./options.js";
|
|
12
|
+
import { clientBuildWillSkip, default_kit_dirs, hasAnyCsrFalseRoute, inject_keep_client_route, keep_client_dir, kit_major, resolve_kit_paths, route_reader } from "../kit.js";
|
|
13
|
+
import { node_fs } from "../fs.js";
|
|
14
|
+
import { load_kit_config } from "./kit-dirs.js";
|
|
15
|
+
import { buildFoucCssModuleSource, collectFoucCssReachable, foucRelFromId, isFoucCssId, isFoucScopedId, scoped_component_css, svelteHasStyle, through_caller } from "../fouc-css.js";
|
|
16
|
+
import { ExportIndex, Shapes } from "../exports/index.js";
|
|
17
|
+
import { strip_bom } from "../bom.js";
|
|
18
|
+
import { preprocess_component_for_css } from "./style-preprocess.js";
|
|
19
|
+
import { needs_csr_false_full_reload, needs_island_entry_full_reload } from "../dev/hmr.js";
|
|
20
|
+
import { derive_css_scope_owners } from "../dev/css-scope.js";
|
|
21
|
+
import { DEV_FN_MANIFEST_KEY, collectIslandDepModulepreloads, collect_inline_css, remote_hash_of, summarize_chunk_contents } from "../link/island-deps.js";
|
|
22
|
+
import { emit_island_deps_handoff, refuse_client_secrets, report_seed_shaping } from "../link/build-output.js";
|
|
23
|
+
import { unpatched } from "../link/relocations.js";
|
|
24
|
+
import { read_server_handoff, server_handoff_json, server_handoff_path } from "../link/emit-gate.js";
|
|
25
|
+
import { router_css_key } from "../link/router-css.js";
|
|
26
|
+
import { Program, strip_id } from "../program.js";
|
|
27
|
+
import { Compiler } from "../driver.js";
|
|
28
|
+
import { compiler_of, configured, new_session, resolve } from "./session.js";
|
|
29
|
+
import { core_defines } from "../virtual/core.js";
|
|
30
|
+
import { import_chain } from "../virtual/resolver.js";
|
|
31
|
+
import { CompileCtx } from "../ctx.js";
|
|
32
|
+
import { discover_package_files } from "./package-files.js";
|
|
33
|
+
import { async_twin_redirect, svelte_async_enabled } from "./late-island.js";
|
|
34
|
+
import { app_compile_options, svelte_compile } from "./svelte-options.js";
|
|
35
|
+
import { KIT_REMOTE_CLIENT, KIT_REMOTE_STATE, RUNTIME_HASH, scan_entry_pattern } from "./paths.js";
|
|
36
|
+
import { SVELTE_DEV_ISLAND_ENTRIES } from "./svelte-entries.js";
|
|
37
|
+
import { OgygiaError, line, warn } from "../messages.js";
|
|
38
|
+
import { RouteWatch } from "./route-watch.js";
|
|
39
|
+
import path from "node:path";
|
|
40
|
+
import { APP_SHIMS, BARREL_LEFT_REASONS, CLIENT_BINDING_STUB_FILE, CORE_ROOT, CORE_ROOT_ID, DEFAULT_REGION_TTL_SEC, MIN_SECRET_BYTES, OGYGIA_INJECTED_FILES, OGYGIA_INJECTED_IMPORTS, OGYGIA_REGION_MODULES, OGYGIA_VERSION, OWN_PACKAGE_NAMES, QUERY_MAKERS, RENEW_WINDOW_SEC, RUNTIME_DIR, STUB_CLIENT, STUB_PATHS, STUB_STATE, content_css_key, dedent, derive_id_salt, is_own_specifier, real_posix, secret_has_min_entropy } from "@ogygia/core/contract";
|
|
41
|
+
import fs from "node:fs";
|
|
42
|
+
import MagicString from "magic-string";
|
|
43
|
+
import crypto from "node:crypto";
|
|
44
|
+
import { scope } from "@ogygia/machine";
|
|
45
|
+
import { isMainThread } from "node:worker_threads";
|
|
46
|
+
import { loadEnv } from "vite";
|
|
47
|
+
// src/vite/index.ts
|
|
48
|
+
const KIT_CLIENT_APP_RE = /\/generated\/(?:build\/|dev\/)?client(-optimized)?\/app\.js$/;
|
|
49
|
+
const KIT_PAGE_THREAD = `\n${dedent`
|
|
50
|
+
import { page as __og_kit_page, navigating as __og_kit_nav } from '$app/state';
|
|
51
|
+
import * as __og_kit_navigation from '$app/navigation';
|
|
52
|
+
globalThis[Symbol.for('ogygia.kit-page')] = { page: __og_kit_page, navigating: __og_kit_nav, navigation: __og_kit_navigation };
|
|
53
|
+
`}\n`;
|
|
54
|
+
const KIT_DISCLOSE_VERSION = `((globalThis.__ogygia ??= {}).v ??= new Set()).add(${JSON.stringify(OGYGIA_VERSION)});\n`;
|
|
55
|
+
const DEV_CSS_FILE_RE = /\.(css|scss|sass|less|styl)$/;
|
|
56
|
+
const BACKSLASH_G = /\\/g;
|
|
57
|
+
const CSS_EXT_RE = /\.css$/;
|
|
58
|
+
const STYLE_BEARING_FILE_RE = /\.(svelte|css|scss|sass|less|styl)$/;
|
|
59
|
+
function bundler_resolve(ctx) {
|
|
60
|
+
return async (spec, importer) => {
|
|
61
|
+
try {
|
|
62
|
+
const r = await ctx.resolve(spec, importer, { skipSelf: true });
|
|
63
|
+
return r && !r.external ? r.id : null;
|
|
64
|
+
} catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Vite plugin: transforms `with { hydrate | defer | preset }` imports into islands,
|
|
71
|
+
* serves virtual island modules, and wires signed region endpoints for deferred HTML.
|
|
72
|
+
*
|
|
73
|
+
* Place **before** `sveltekit()` in `vite.config`.
|
|
74
|
+
*
|
|
75
|
+
* @param options - Plugin configuration. See {@link OgygiaOptions}.
|
|
76
|
+
* @returns Vite plugins (`ogygia` pre + island sourcemap fix post). Vite flattens the array.
|
|
77
|
+
*/
|
|
78
|
+
function ogygia(options = {}) {
|
|
79
|
+
const standalone = options.standalone === true;
|
|
80
|
+
assert_known_options(options);
|
|
81
|
+
const visibleMargin = options.visible?.margin;
|
|
82
|
+
const presets = options.presets || {};
|
|
83
|
+
validate_region_presets(presets);
|
|
84
|
+
let app_plugins = [];
|
|
85
|
+
let server_plugins = [];
|
|
86
|
+
let client_plugins = [];
|
|
87
|
+
let runtime_hooks = [];
|
|
88
|
+
let route_config = [];
|
|
89
|
+
let foreign_hydrate = false;
|
|
90
|
+
let macros = [];
|
|
91
|
+
let page_reads = null;
|
|
92
|
+
let prescans = [];
|
|
93
|
+
let listed_plugins = [];
|
|
94
|
+
let stage_transforms = [];
|
|
95
|
+
let stayed_answers = [];
|
|
96
|
+
let markup = [];
|
|
97
|
+
let definers = [];
|
|
98
|
+
const import_keys = normalize_import_keys(options.importKeys);
|
|
99
|
+
let measure = false;
|
|
100
|
+
const pkg_scan = [];
|
|
101
|
+
const plugin_file_roots = [];
|
|
102
|
+
let declared_scanned = false;
|
|
103
|
+
let page_importers = [];
|
|
104
|
+
let page_files = [];
|
|
105
|
+
const { rate_limit, session_cookie, region_ttl, renew_window, router_enabled, router_view_transitions, continuity_forms, server_delta } = resolve_options(options, DEFAULT_REGION_TTL_SEC, RENEW_WINDOW_SEC);
|
|
106
|
+
let devtools_effective = false;
|
|
107
|
+
let devtools_lazy = false;
|
|
108
|
+
const build_secret = crypto.randomBytes(32).toString("hex");
|
|
109
|
+
let id_salt = "";
|
|
110
|
+
let svelte = null;
|
|
111
|
+
const component_css = {
|
|
112
|
+
preprocess: (source, abs) => preprocess_component_for_css(source, abs, root),
|
|
113
|
+
options: (abs, source) => app_compile_options(svelte, abs, source)
|
|
114
|
+
};
|
|
115
|
+
const tree_css_walk = (ctx) => {
|
|
116
|
+
const { compiled_css } = leg_of(ctx);
|
|
117
|
+
const walk_resolve = bundler_resolve(ctx);
|
|
118
|
+
const exports = css_walk_index(ctx.environment.name);
|
|
119
|
+
return async (abs, opts = {}) => {
|
|
120
|
+
const { own, skip } = opts;
|
|
121
|
+
const parts = [];
|
|
122
|
+
for (const e of await collectFoucCssReachable(abs, {
|
|
123
|
+
root,
|
|
124
|
+
libDir,
|
|
125
|
+
readFile: own == null ? readFile : (p) => p === abs ? own : readFile(p),
|
|
126
|
+
alias: resolve_alias,
|
|
127
|
+
resolve: walk_resolve,
|
|
128
|
+
exports
|
|
129
|
+
})) {
|
|
130
|
+
if (own != null && e.abs === abs || skip?.(e.abs)) continue;
|
|
131
|
+
let css = compiled_css.get(e.abs);
|
|
132
|
+
if (css === void 0) {
|
|
133
|
+
const src = readFile(e.abs);
|
|
134
|
+
css = null;
|
|
135
|
+
if (src != null && e.kind === "scoped") css = await scoped_component_css(e.abs, src, component_css);
|
|
136
|
+
else if (src != null && CSS_EXT_RE.test(e.abs)) css = src;
|
|
137
|
+
compiled_css.set(e.abs, css);
|
|
138
|
+
}
|
|
139
|
+
if (css) parts.push(css);
|
|
140
|
+
}
|
|
141
|
+
return parts.join("\n");
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
let root;
|
|
145
|
+
let kit;
|
|
146
|
+
let base = "";
|
|
147
|
+
let app_dir = "_app";
|
|
148
|
+
let libDir;
|
|
149
|
+
let is_dev = false;
|
|
150
|
+
let svelte_async = false;
|
|
151
|
+
let resolve_alias = [];
|
|
152
|
+
let is_build = false;
|
|
153
|
+
let is_ssr = false;
|
|
154
|
+
const env_of = (ctx) => {
|
|
155
|
+
const env = ctx?.environment;
|
|
156
|
+
if (!env?.name) return null;
|
|
157
|
+
return {
|
|
158
|
+
name: env.name,
|
|
159
|
+
server: env.name === "ssr" || env.config?.consumer === "server"
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
const leg_of = (ctx) => compiler_of(session, "leg").leg(env_of(ctx));
|
|
163
|
+
let vite_server = null;
|
|
164
|
+
let kit_wire_path = null;
|
|
165
|
+
let kit_remote_index = null;
|
|
166
|
+
let universal_hooks = null;
|
|
167
|
+
let client_hooks = null;
|
|
168
|
+
let kit_transport_init = null;
|
|
169
|
+
let keep_client_cleanup_armed = false;
|
|
170
|
+
const names_kit_remote = (source, importer) => kit_remote_index !== null && importer !== void 0 && source.startsWith(".") && source.endsWith("/client/remote-functions/index.js") && real_posix(path.resolve(path.dirname(importer), source)) === real_posix(kit_remote_index);
|
|
171
|
+
const readFile = (abs) => {
|
|
172
|
+
try {
|
|
173
|
+
return fs.readFileSync(abs, "utf-8");
|
|
174
|
+
} catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const shapes = new Shapes((abs) => {
|
|
179
|
+
const code = readFile(abs);
|
|
180
|
+
return code == null ? null : strip_bom(code);
|
|
181
|
+
});
|
|
182
|
+
const transform_indexes = /* @__PURE__ */ new Map();
|
|
183
|
+
const seams = {
|
|
184
|
+
exports: { map(file, spec, policy, t) {
|
|
185
|
+
let index = transform_indexes.get(t.environment);
|
|
186
|
+
if (index === void 0) transform_indexes.set(t.environment, index = new ExportIndex((s, importer, caller) => caller.resolve(s, importer), shapes));
|
|
187
|
+
return index.map(file, spec, policy, t);
|
|
188
|
+
} },
|
|
189
|
+
pinned_imports() {
|
|
190
|
+
const keys = new Set(Object.values(import_keys));
|
|
191
|
+
return (decl) => decl.attribute_keys.some((k) => keys.has(k));
|
|
192
|
+
},
|
|
193
|
+
regions: {
|
|
194
|
+
names: () => compiler_of(session, "regions.names").region_names(),
|
|
195
|
+
hosts: () => compiler_of(session, "regions.hosts").region_hosts(),
|
|
196
|
+
whyStayed: (file, importers) => why_stayed(file, importers)
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const why_stayed = (file, importers) => {
|
|
200
|
+
const ids = [...importers];
|
|
201
|
+
const found = /* @__PURE__ */ new Set();
|
|
202
|
+
for (const answer of stayed_answers) for (const r of answer(file, ids, "client")) found.add(r);
|
|
203
|
+
return BARREL_LEFT_REASONS.filter((r) => found.has(r));
|
|
204
|
+
};
|
|
205
|
+
const stage_host = (stage) => ({
|
|
206
|
+
name: `ogygia:${stage}`,
|
|
207
|
+
enforce: "pre",
|
|
208
|
+
async transform(raw, id) {
|
|
209
|
+
const mine = stage_transforms.filter((s) => s.stage === stage && (s.filter?.(id) ?? true));
|
|
210
|
+
if (mine.length === 0) return null;
|
|
211
|
+
const code = strip_bom(raw);
|
|
212
|
+
const edit = new MagicString(code);
|
|
213
|
+
const t = {
|
|
214
|
+
id,
|
|
215
|
+
code,
|
|
216
|
+
edit,
|
|
217
|
+
environment: this.environment.name,
|
|
218
|
+
resolve: async (spec, importer) => {
|
|
219
|
+
let r;
|
|
220
|
+
try {
|
|
221
|
+
r = await this.resolve(spec, importer, { skipSelf: true });
|
|
222
|
+
} catch {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
return r && !r.external ? r.id.replace(BACKSLASH_G, "/") : null;
|
|
226
|
+
},
|
|
227
|
+
watch: (file) => this.addWatchFile(file)
|
|
228
|
+
};
|
|
229
|
+
for (const s of mine) await s.transform(t);
|
|
230
|
+
return edit.hasChanged() ? {
|
|
231
|
+
code: edit.toString(),
|
|
232
|
+
map: edit.generateMap({ hires: true })
|
|
233
|
+
} : null;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
const css_walk_indexes = /* @__PURE__ */ new Map();
|
|
237
|
+
const css_walk_index = (environment) => {
|
|
238
|
+
let index = css_walk_indexes.get(environment);
|
|
239
|
+
if (index === void 0) css_walk_indexes.set(environment, index = new ExportIndex(through_caller, shapes));
|
|
240
|
+
return index;
|
|
241
|
+
};
|
|
242
|
+
const __prof = {
|
|
243
|
+
transformMs: 0,
|
|
244
|
+
transformN: 0,
|
|
245
|
+
transformHit: 0,
|
|
246
|
+
prescanMs: 0,
|
|
247
|
+
macroMs: 0,
|
|
248
|
+
macroN: 0,
|
|
249
|
+
resolveMs: 0,
|
|
250
|
+
loadMs: 0
|
|
251
|
+
};
|
|
252
|
+
const __P = !!process.env.OGYGIA_PROFILE;
|
|
253
|
+
const __outHash = /* @__PURE__ */ new Map();
|
|
254
|
+
const session = new_session();
|
|
255
|
+
const arm_keep_client_cleanup = (routes_dir) => {
|
|
256
|
+
if (keep_client_cleanup_armed) return;
|
|
257
|
+
keep_client_cleanup_armed = true;
|
|
258
|
+
process.on("exit", () => {
|
|
259
|
+
try {
|
|
260
|
+
fs.rmSync(keep_client_dir(routes_dir), {
|
|
261
|
+
recursive: true,
|
|
262
|
+
force: true
|
|
263
|
+
});
|
|
264
|
+
} catch {}
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
const invalidate_module_id = (server, id) => {
|
|
268
|
+
const mod = server.moduleGraph.getModuleById(id);
|
|
269
|
+
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
270
|
+
};
|
|
271
|
+
const dev_owner = scope();
|
|
272
|
+
const route_watch = new RouteWatch(dev_owner, (file, event) => compiler_of(session, "watchChange").routes_changed(file, event), (id) => {
|
|
273
|
+
if (vite_server) invalidate_module_id(vite_server, id);
|
|
274
|
+
}, (file) => {
|
|
275
|
+
vite_server?.watcher.emit("change", file);
|
|
276
|
+
});
|
|
277
|
+
const invalidate_islands_for_file = (file, { deleted = false, server = vite_server } = {}) => {
|
|
278
|
+
if (!server) return false;
|
|
279
|
+
return compiler_of(session, "invalidate").invalidate_for_file(file, {
|
|
280
|
+
deleted,
|
|
281
|
+
invalidate: (id) => invalidate_module_id(server, id)
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
return [
|
|
285
|
+
stage_host("source"),
|
|
286
|
+
definers_plugin(() => definers),
|
|
287
|
+
{
|
|
288
|
+
name: "ogygia",
|
|
289
|
+
enforce: "pre",
|
|
290
|
+
config: {
|
|
291
|
+
order: "pre",
|
|
292
|
+
async handler(userConfig, env) {
|
|
293
|
+
configured(session);
|
|
294
|
+
kit = await load_kit_config(path.resolve(userConfig.root ?? "."), userConfig.plugins);
|
|
295
|
+
app_plugins = standalone ? [] : await find_plugins(userConfig.plugins);
|
|
296
|
+
const resolved = resolve_plugins(app_plugins, path.resolve(userConfig.root ?? "."), env.command === "serve", (source, filename) => compiler_of(session, "markup").transform_content_island(source, filename), seams);
|
|
297
|
+
stage_transforms = resolved.transforms;
|
|
298
|
+
stayed_answers = resolved.stayed;
|
|
299
|
+
({servers: server_plugins, clients: client_plugins, client_hooks: runtime_hooks, route_config, foreign_hydrate, macros, prescans, markup, definers, page_reads} = resolved);
|
|
300
|
+
listed_plugins = app_plugins.map((p) => p.name);
|
|
301
|
+
measure = resolved.measure;
|
|
302
|
+
devtools_effective = resolved.events !== false;
|
|
303
|
+
devtools_lazy = resolved.events !== false && resolved.events.lazy;
|
|
304
|
+
page_importers = resolved.page_modules.importers;
|
|
305
|
+
page_files = resolved.page_modules.files.map(real_posix);
|
|
306
|
+
for (const p of resolved.files) if (!pkg_scan.some((s) => s.name === p.name)) {
|
|
307
|
+
plugin_file_roots.push(`${real_posix(p.root)}/`);
|
|
308
|
+
pkg_scan.push({
|
|
309
|
+
name: p.name,
|
|
310
|
+
root: real_posix(p.root),
|
|
311
|
+
dirs: p.dirs.map(real_posix),
|
|
312
|
+
files: p.files.map(real_posix)
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
if (env.command === "build" && !standalone && isMainThread) {
|
|
316
|
+
const routes = kit.dirs.routes_dir;
|
|
317
|
+
if (clientBuildWillSkip(route_reader(node_fs), routes)) {
|
|
318
|
+
inject_keep_client_route(routes);
|
|
319
|
+
arm_keep_client_cleanup(routes);
|
|
320
|
+
} else fs.rmSync(keep_client_dir(routes), {
|
|
321
|
+
recursive: true,
|
|
322
|
+
force: true
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
if (!standalone && !declared_scanned) {
|
|
326
|
+
declared_scanned = true;
|
|
327
|
+
for (const p of discover_package_files(path.resolve(userConfig.root ?? "."))) if (!pkg_scan.some((s) => s.name === p.name)) pkg_scan.push(p);
|
|
328
|
+
}
|
|
329
|
+
const declared_pkg_names = [.../* @__PURE__ */ new Set([...pkg_scan.map((p) => p.name), ...app_plugins.map((p) => p.name)])];
|
|
330
|
+
const dev_island_deps = env.command === "serve" ? [...SVELTE_DEV_ISLAND_ENTRIES, "ogygia > @ogygia/core > devalue"] : [];
|
|
331
|
+
return {
|
|
332
|
+
resolve: { dedupe: ["@sveltejs/kit"] },
|
|
333
|
+
ssr: { noExternal: [
|
|
334
|
+
"esm-env",
|
|
335
|
+
...OWN_PACKAGE_NAMES,
|
|
336
|
+
...declared_pkg_names
|
|
337
|
+
] },
|
|
338
|
+
optimizeDeps: {
|
|
339
|
+
exclude: [...OWN_PACKAGE_NAMES, ...declared_pkg_names],
|
|
340
|
+
include: dev_island_deps
|
|
341
|
+
},
|
|
342
|
+
define: core_defines({
|
|
343
|
+
continuity_forms,
|
|
344
|
+
server_delta,
|
|
345
|
+
devtools: devtools_effective,
|
|
346
|
+
devtools_lazy,
|
|
347
|
+
rules: process.env.OGYGIA_RULES === "1",
|
|
348
|
+
client_plugins: client_plugins.length > 0,
|
|
349
|
+
hooks: runtime_hooks,
|
|
350
|
+
kit_major: kit_major(path.resolve(userConfig.root ?? ".")),
|
|
351
|
+
version: OGYGIA_VERSION,
|
|
352
|
+
dev_server: env.command === "serve"
|
|
353
|
+
}),
|
|
354
|
+
server: { fs: { allow: [CORE_ROOT] } },
|
|
355
|
+
build: { rolldownOptions: { preserveEntrySignatures: "exports-only" } }
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
configResolved(config) {
|
|
360
|
+
root = config.root;
|
|
361
|
+
kit ??= {
|
|
362
|
+
dirs: default_kit_dirs(root),
|
|
363
|
+
inline_style_threshold: 0
|
|
364
|
+
};
|
|
365
|
+
base = config.base || "";
|
|
366
|
+
svelte = svelte_compile(config.plugins);
|
|
367
|
+
svelte_async = svelte_async_enabled(svelte);
|
|
368
|
+
if (config.command === "serve") {
|
|
369
|
+
const own = (config.optimizeDeps?.include ?? []).filter((d) => is_own_specifier(d));
|
|
370
|
+
if (own.length) config.logger.warn(line("optimize_deps_includes_ogygia", {
|
|
371
|
+
specifiers: own.join(", "),
|
|
372
|
+
count: own.length
|
|
373
|
+
}));
|
|
374
|
+
}
|
|
375
|
+
const app_dir_define = config.define?.["__SVELTEKIT_APP_DIR__"];
|
|
376
|
+
if (typeof app_dir_define === "string") try {
|
|
377
|
+
const v = JSON.parse(app_dir_define);
|
|
378
|
+
if (typeof v === "string" && v) app_dir = v;
|
|
379
|
+
} catch {}
|
|
380
|
+
const ra = config.resolve?.alias ?? [];
|
|
381
|
+
resolve_alias = Array.isArray(ra) ? ra.map((a) => ({
|
|
382
|
+
find: a.find,
|
|
383
|
+
replacement: a.replacement
|
|
384
|
+
})) : Object.entries(ra).map(([find, replacement]) => ({
|
|
385
|
+
find,
|
|
386
|
+
replacement
|
|
387
|
+
}));
|
|
388
|
+
configure_build_cache(root);
|
|
389
|
+
libDir = path.join(root, "src", "lib");
|
|
390
|
+
is_dev = config.command === "serve";
|
|
391
|
+
is_build = config.command === "build";
|
|
392
|
+
is_ssr = !!config.build?.ssr;
|
|
393
|
+
if (is_dev) fs.rmSync(keep_client_dir(kit.dirs.routes_dir), {
|
|
394
|
+
recursive: true,
|
|
395
|
+
force: true
|
|
396
|
+
});
|
|
397
|
+
if (!process.env.OGYGIA_SECRET?.trim()) {
|
|
398
|
+
let env_dir = root;
|
|
399
|
+
if (config.envDir === false) env_dir = false;
|
|
400
|
+
else if (config.envDir) env_dir = path.resolve(root, config.envDir);
|
|
401
|
+
if (env_dir !== false) {
|
|
402
|
+
const from_file = loadEnv(config.mode, env_dir, "").OGYGIA_SECRET?.trim();
|
|
403
|
+
if (from_file) process.env.OGYGIA_SECRET = from_file;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const env_secret = process.env.OGYGIA_SECRET?.trim() || "";
|
|
407
|
+
if (env_secret) {
|
|
408
|
+
if (is_build && !secret_has_min_entropy(env_secret)) throw new OgygiaError("secret_too_short", { min_bytes: MIN_SECRET_BYTES });
|
|
409
|
+
id_salt = derive_id_salt(env_secret);
|
|
410
|
+
} else id_salt = "";
|
|
411
|
+
({kit_wire_path, kit_remote_index, universal_hooks, client_hooks, kit_transport_init} = resolve_kit_paths(root));
|
|
412
|
+
const compiler = resolve(session, (prev) => {
|
|
413
|
+
const ctx = new CompileCtx({
|
|
414
|
+
root,
|
|
415
|
+
kit_dirs: kit.dirs,
|
|
416
|
+
base,
|
|
417
|
+
app_dir,
|
|
418
|
+
libDir,
|
|
419
|
+
pkg_scan,
|
|
420
|
+
page_importers,
|
|
421
|
+
page_files,
|
|
422
|
+
measure,
|
|
423
|
+
server_plugins,
|
|
424
|
+
client_plugins,
|
|
425
|
+
route_config,
|
|
426
|
+
foreign_hydrate,
|
|
427
|
+
is_dev,
|
|
428
|
+
id_salt,
|
|
429
|
+
visibleMargin,
|
|
430
|
+
presets,
|
|
431
|
+
import_keys,
|
|
432
|
+
resolve_alias,
|
|
433
|
+
component_css,
|
|
434
|
+
macros,
|
|
435
|
+
page_reads,
|
|
436
|
+
prescans,
|
|
437
|
+
plugins: listed_plugins,
|
|
438
|
+
pkg_root: CORE_ROOT_ID,
|
|
439
|
+
build_secret,
|
|
440
|
+
rate_limit,
|
|
441
|
+
session_cookie,
|
|
442
|
+
region_ttl,
|
|
443
|
+
renew_window,
|
|
444
|
+
router_enabled,
|
|
445
|
+
router_view_transitions,
|
|
446
|
+
client_hooks,
|
|
447
|
+
runtime_dir: RUNTIME_DIR,
|
|
448
|
+
runtime_hash: RUNTIME_HASH,
|
|
449
|
+
kit_wire_path,
|
|
450
|
+
client_binding_stub_file: CLIENT_BINDING_STUB_FILE,
|
|
451
|
+
app_shims: APP_SHIMS,
|
|
452
|
+
is_build,
|
|
453
|
+
devtools: devtools_effective
|
|
454
|
+
});
|
|
455
|
+
return prev ? prev.with_ctx(ctx) : new Compiler(new Program({
|
|
456
|
+
forms: continuity_forms,
|
|
457
|
+
router: router_enabled
|
|
458
|
+
}), {
|
|
459
|
+
prof: __prof,
|
|
460
|
+
P: __P,
|
|
461
|
+
outHash: __outHash
|
|
462
|
+
}, ctx);
|
|
463
|
+
});
|
|
464
|
+
if (is_dev) {
|
|
465
|
+
compiler.prescan();
|
|
466
|
+
const opt = config.optimizeDeps ??= {};
|
|
467
|
+
let entries = [];
|
|
468
|
+
if (Array.isArray(opt.entries)) entries = opt.entries;
|
|
469
|
+
else if (opt.entries) entries = [opt.entries];
|
|
470
|
+
opt.entries = entries;
|
|
471
|
+
const have = new Set(entries);
|
|
472
|
+
for (const abs of compiler.island_scan_entries()) {
|
|
473
|
+
const posix = real_posix(abs);
|
|
474
|
+
const pattern = plugin_file_roots.some((r) => posix.startsWith(r)) ? null : scan_entry_pattern(abs);
|
|
475
|
+
if (pattern !== null && !have.has(pattern)) {
|
|
476
|
+
have.add(pattern);
|
|
477
|
+
entries.push(pattern);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
async buildStart() {
|
|
483
|
+
const compiler = compiler_of(session, "buildStart");
|
|
484
|
+
const env = env_of(this) ?? {
|
|
485
|
+
name: is_ssr ? "ssr" : "client",
|
|
486
|
+
server: is_ssr
|
|
487
|
+
};
|
|
488
|
+
const begins = compiler.start_leg(env.name, env.server);
|
|
489
|
+
const leg = compiler.leg(env);
|
|
490
|
+
const server_leg = leg.server;
|
|
491
|
+
if (is_build && server_leg) fs.rmSync(server_handoff_path(kit.dirs.out_dir), { force: true });
|
|
492
|
+
if (begins) {
|
|
493
|
+
compiler.prescan();
|
|
494
|
+
for (const source of markup) await source.scan?.({
|
|
495
|
+
root,
|
|
496
|
+
readFile
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
if (is_build && !server_leg) {
|
|
500
|
+
const emit_runtime = !standalone && (hasAnyCsrFalseRoute(compiler.ctx.routes, kit.dirs.routes_dir) || compiler.has_hydrate_regions());
|
|
501
|
+
const handoff = read_server_handoff(kit.dirs.out_dir);
|
|
502
|
+
const loaded = handoff?.hosts ?? null;
|
|
503
|
+
const server_regions = handoff?.server_regions ?? null;
|
|
504
|
+
const skipped = compiler.emit_build_chunks(leg, (chunk) => this.emitFile(chunk), {
|
|
505
|
+
emitRuntime: emit_runtime,
|
|
506
|
+
loaded
|
|
507
|
+
});
|
|
508
|
+
if (skipped && isMainThread) console.log(line("island_chunks_not_emitted", { count: skipped }));
|
|
509
|
+
const tree_css = tree_css_walk(this);
|
|
510
|
+
for (const abs of compiler.router_css_roots()) {
|
|
511
|
+
const source = await tree_css(abs);
|
|
512
|
+
if (source) leg.router_css_refs.set(router_css_key(root, abs), this.emitFile({
|
|
513
|
+
type: "asset",
|
|
514
|
+
name: "og-rcss.css",
|
|
515
|
+
source
|
|
516
|
+
}));
|
|
517
|
+
}
|
|
518
|
+
const hole_css_by_abs = /* @__PURE__ */ new Map();
|
|
519
|
+
for (const { iid, abs } of server_regions ?? compiler.server_island_css_roots()) {
|
|
520
|
+
let ref = hole_css_by_abs.get(abs);
|
|
521
|
+
if (ref === void 0) {
|
|
522
|
+
const source = await tree_css(abs);
|
|
523
|
+
ref = source ? this.emitFile({
|
|
524
|
+
type: "asset",
|
|
525
|
+
name: "og-hole.css",
|
|
526
|
+
source
|
|
527
|
+
}) : "";
|
|
528
|
+
hole_css_by_abs.set(abs, ref);
|
|
529
|
+
}
|
|
530
|
+
if (ref) leg.hole_css_refs.set(iid, ref);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
configureServer(server) {
|
|
535
|
+
const compiler = compiler_of(session, "configureServer");
|
|
536
|
+
vite_server = server;
|
|
537
|
+
globalThis[Symbol.for(DEV_FN_MANIFEST_KEY)] = () => compiler.fn_manifest();
|
|
538
|
+
if (measure) {
|
|
539
|
+
install_dev_maps(server);
|
|
540
|
+
install_dev_client_maps(server);
|
|
541
|
+
if (page_reads) install_dev_page_keys(server, (iid) => {
|
|
542
|
+
const { registry, by_id } = compiler.program;
|
|
543
|
+
return registry.get(by_id.get(iid) ?? "")?.componentPath;
|
|
544
|
+
}, root, page_reads);
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
watchChange(id, change) {
|
|
548
|
+
shapes.invalidate(id, change.event);
|
|
549
|
+
if (is_dev) route_watch.heard(id, change.event);
|
|
550
|
+
if (!is_dev || change.event !== "delete" || !vite_server) return;
|
|
551
|
+
if (!invalidate_islands_for_file(id, {
|
|
552
|
+
deleted: true,
|
|
553
|
+
server: vite_server
|
|
554
|
+
})) return;
|
|
555
|
+
vite_server.ws.send({
|
|
556
|
+
type: "full-reload",
|
|
557
|
+
path: "*"
|
|
558
|
+
});
|
|
559
|
+
},
|
|
560
|
+
buildEnd() {
|
|
561
|
+
const compiler = compiler_of(session, "buildEnd");
|
|
562
|
+
const server_leg = leg_of(this).server;
|
|
563
|
+
if (is_build && server_leg && !standalone) try {
|
|
564
|
+
const handoff = server_handoff_path(kit.dirs.out_dir);
|
|
565
|
+
fs.mkdirSync(path.dirname(handoff), { recursive: true });
|
|
566
|
+
fs.writeFileSync(handoff, server_handoff_json(compiler.ssr_transformed_hosts(), build_secret, compiler.server_island_css_roots()));
|
|
567
|
+
} catch (e) {
|
|
568
|
+
if (isMainThread) warn("island_handoff_write_failed", e);
|
|
569
|
+
}
|
|
570
|
+
if (__P) {
|
|
571
|
+
const keys = [...__outHash.keys()].sort();
|
|
572
|
+
let d = 2166136261;
|
|
573
|
+
for (const k of keys) {
|
|
574
|
+
d ^= __outHash.get(k);
|
|
575
|
+
d = Math.imul(d, 16777619) >>> 0;
|
|
576
|
+
}
|
|
577
|
+
const summary = JSON.stringify({
|
|
578
|
+
...__prof,
|
|
579
|
+
transformDigest: (d >>> 0).toString(16),
|
|
580
|
+
transformFiles: keys.length
|
|
581
|
+
});
|
|
582
|
+
console.error(`\n[ogygia-prof] ${summary}`);
|
|
583
|
+
}
|
|
584
|
+
},
|
|
585
|
+
handleHotUpdate({ file, server }) {
|
|
586
|
+
const compiler = compiler_of(session, "handleHotUpdate");
|
|
587
|
+
if (!is_dev) return;
|
|
588
|
+
vite_server = server;
|
|
589
|
+
if (STYLE_BEARING_FILE_RE.test(file)) for (const mid of compiler.changed("styles")) invalidate_module_id(server, mid);
|
|
590
|
+
if (DEV_CSS_FILE_RE.test(file) && !file.includes("/node_modules/")) {
|
|
591
|
+
const src_prefix = `${path.join(root, "src")}${path.sep}`;
|
|
592
|
+
if (path.normalize(file).startsWith(src_prefix)) {
|
|
593
|
+
const envs = server.environments;
|
|
594
|
+
const client_graph = envs?.client?.moduleGraph;
|
|
595
|
+
if (!(client_graph?.getModulesByFile?.(file)?.size ?? 0)) {
|
|
596
|
+
const owners = derive_css_scope_owners(file, kit.dirs.routes_dir, [envs?.ssr?.moduleGraph, client_graph]);
|
|
597
|
+
const web_path = `/${path.relative(root, file).split(path.sep).join("/")}`;
|
|
598
|
+
server.ws.send({
|
|
599
|
+
type: "custom",
|
|
600
|
+
event: "ogygia:css",
|
|
601
|
+
data: {
|
|
602
|
+
path: web_path,
|
|
603
|
+
owners
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
return [];
|
|
607
|
+
}
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const deleted = !fs.existsSync(strip_id(file));
|
|
612
|
+
const host_changed = !deleted && compiler.is_registered_host(file);
|
|
613
|
+
const entry_changed = !deleted && needs_island_entry_full_reload(file, compiler.program.registry.values());
|
|
614
|
+
if (host_changed || deleted) invalidate_islands_for_file(file, {
|
|
615
|
+
deleted,
|
|
616
|
+
server
|
|
617
|
+
});
|
|
618
|
+
if (!needs_csr_false_full_reload(file) && !deleted && !host_changed && !entry_changed) return;
|
|
619
|
+
server.ws.send({
|
|
620
|
+
type: "full-reload",
|
|
621
|
+
path: "*"
|
|
622
|
+
});
|
|
623
|
+
return [];
|
|
624
|
+
},
|
|
625
|
+
async resolveId(source, importer) {
|
|
626
|
+
if (OGYGIA_INJECTED_IMPORTS.has(source)) return OGYGIA_INJECTED_FILES[source];
|
|
627
|
+
if (svelte_async) {
|
|
628
|
+
const awaiting = async_twin_redirect(source, importer, OGYGIA_REGION_MODULES);
|
|
629
|
+
if (awaiting) return awaiting;
|
|
630
|
+
}
|
|
631
|
+
const ssr = leg_of(this).server;
|
|
632
|
+
if (!ssr && (source === "__sveltekit/remote" || names_kit_remote(source, importer))) {
|
|
633
|
+
if (!kit_remote_index) throw new OgygiaError("kit_remote_src_missing");
|
|
634
|
+
return importer !== void 0 && real_posix(importer) === real_posix(QUERY_MAKERS) ? kit_remote_index : QUERY_MAKERS;
|
|
635
|
+
}
|
|
636
|
+
if (!ssr && importer && importer.includes("/remote-functions/")) {
|
|
637
|
+
if (KIT_REMOTE_CLIENT.test(source)) return STUB_CLIENT;
|
|
638
|
+
if (KIT_REMOTE_STATE.test(source)) return STUB_STATE;
|
|
639
|
+
if (source === "#app/paths") return STUB_PATHS;
|
|
640
|
+
if (source === "#app/state/client") return STUB_STATE;
|
|
641
|
+
}
|
|
642
|
+
if (!ssr && source === "$app/paths/internal/client") return STUB_PATHS;
|
|
643
|
+
return compiler_of(session, "resolveId").resolve_id(source, importer, {
|
|
644
|
+
ssr,
|
|
645
|
+
resolve: (s, i, o) => this.resolve(s, i, o),
|
|
646
|
+
importers_of: (id) => this.getModuleInfo(id)?.importers
|
|
647
|
+
});
|
|
648
|
+
},
|
|
649
|
+
async load(id) {
|
|
650
|
+
const compiler = compiler_of(session, "load");
|
|
651
|
+
const ssr = leg_of(this).server;
|
|
652
|
+
const fouc_bare = id.startsWith("\0") ? id.slice(1) : id;
|
|
653
|
+
if (isFoucCssId(fouc_bare)) {
|
|
654
|
+
const rel = foucRelFromId(fouc_bare);
|
|
655
|
+
if (!rel) return {
|
|
656
|
+
code: "export {}",
|
|
657
|
+
moduleSideEffects: false
|
|
658
|
+
};
|
|
659
|
+
const abs = path.join(root, rel);
|
|
660
|
+
return {
|
|
661
|
+
code: await buildFoucCssModuleSource(abs, {
|
|
662
|
+
root,
|
|
663
|
+
libDir,
|
|
664
|
+
readFile
|
|
665
|
+
}),
|
|
666
|
+
moduleSideEffects: true
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
if (isFoucScopedId(fouc_bare)) {
|
|
670
|
+
const rel = foucRelFromId(fouc_bare);
|
|
671
|
+
if (!rel) return {
|
|
672
|
+
code: "",
|
|
673
|
+
moduleType: "css"
|
|
674
|
+
};
|
|
675
|
+
const abs = path.join(root, rel);
|
|
676
|
+
let source = "";
|
|
677
|
+
try {
|
|
678
|
+
source = fs.readFileSync(abs, "utf8");
|
|
679
|
+
} catch {
|
|
680
|
+
return {
|
|
681
|
+
code: "",
|
|
682
|
+
moduleType: "css"
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
return {
|
|
686
|
+
code: await scoped_component_css(abs, source, component_css),
|
|
687
|
+
moduleType: "css"
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
return compiler.emit(id, {
|
|
691
|
+
ssr,
|
|
692
|
+
universalHooks: universal_hooks,
|
|
693
|
+
resolve: bundler_resolve(this),
|
|
694
|
+
exports: css_walk_index(this.environment.name),
|
|
695
|
+
kitCodec: kit_transport_init,
|
|
696
|
+
via: () => import_chain(id, (m) => this.getModuleInfo(m)?.importers, root)
|
|
697
|
+
});
|
|
698
|
+
},
|
|
699
|
+
async transform(code, id) {
|
|
700
|
+
const compiler = compiler_of(session, "transform");
|
|
701
|
+
let source = code;
|
|
702
|
+
const leg = leg_of(this);
|
|
703
|
+
if (!leg.server && KIT_CLIENT_APP_RE.test(id)) source += KIT_PAGE_THREAD + KIT_DISCLOSE_VERSION;
|
|
704
|
+
source = compiler.split_realm_imports(source) ?? source;
|
|
705
|
+
const result = await compiler.transform_module(source, id, {
|
|
706
|
+
leg,
|
|
707
|
+
emitFile: (chunk) => this.emitFile(chunk),
|
|
708
|
+
watch: (file) => this.addWatchFile(file)
|
|
709
|
+
});
|
|
710
|
+
if (is_dev && vite_server) for (const mid of compiler.moved()) invalidate_module_id(vite_server, mid);
|
|
711
|
+
if (is_dev && vite_server) for (const marked of compiler.drain_closure_marks()) invalidate_module_id(vite_server, marked);
|
|
712
|
+
if (result) return result;
|
|
713
|
+
return source === code ? null : {
|
|
714
|
+
code: source,
|
|
715
|
+
map: null
|
|
716
|
+
};
|
|
717
|
+
},
|
|
718
|
+
renderChunk(code, chunk, _options, meta) {
|
|
719
|
+
let facades = null;
|
|
720
|
+
return compiler_of(session, "renderChunk").relocate(code, leg_of(this), {
|
|
721
|
+
chunk_file: chunk.fileName,
|
|
722
|
+
file_name: (ref) => this.getFileName(ref),
|
|
723
|
+
facade_file: (id) => {
|
|
724
|
+
if (facades === null) {
|
|
725
|
+
facades = /* @__PURE__ */ new Map();
|
|
726
|
+
for (const c of Object.values(meta.chunks)) if (c.facadeModuleId) facades.set(c.facadeModuleId, c.fileName);
|
|
727
|
+
}
|
|
728
|
+
return facades.get(id);
|
|
729
|
+
},
|
|
730
|
+
graph: (id) => this.getModuleInfo(id),
|
|
731
|
+
module_ids: () => this.getModuleIds()
|
|
732
|
+
});
|
|
733
|
+
},
|
|
734
|
+
outputOptions(output) {
|
|
735
|
+
const compiler = compiler_of(session, "outputOptions");
|
|
736
|
+
if (!is_build || (env_of(this)?.server ?? is_ssr)) return null;
|
|
737
|
+
const ours = (fallback, dflt) => (info) => compiler.entry_file_pattern(info.name) ?? (typeof fallback === "function" ? fallback(info) : fallback ?? dflt);
|
|
738
|
+
return {
|
|
739
|
+
...output,
|
|
740
|
+
entryFileNames: ours(output.entryFileNames, "[name].js"),
|
|
741
|
+
chunkFileNames: ours(output.chunkFileNames, "[name]-[hash].js")
|
|
742
|
+
};
|
|
743
|
+
},
|
|
744
|
+
async generateBundle(_options, bundle) {
|
|
745
|
+
const compiler = compiler_of(session, "generateBundle");
|
|
746
|
+
if (!is_build) return;
|
|
747
|
+
const leg = leg_of(this);
|
|
748
|
+
const chunks = Object.values(bundle).filter((item) => item.type === "chunk");
|
|
749
|
+
for (const r of unpatched(leg.server, chunks)) warn("relocation_unpatched", {
|
|
750
|
+
name: r.name,
|
|
751
|
+
leg: leg.name
|
|
752
|
+
});
|
|
753
|
+
if (leg.server) return;
|
|
754
|
+
for (const file of compiler.location_maps(leg, (ref) => this.getFileName(ref))) this.emitFile({
|
|
755
|
+
type: "asset",
|
|
756
|
+
fileName: file.fileName,
|
|
757
|
+
source: file.source
|
|
758
|
+
});
|
|
759
|
+
const modules = markup.flatMap((m) => m.modules ? [...m.modules] : []);
|
|
760
|
+
if (!modules.length) return;
|
|
761
|
+
const client = /* @__PURE__ */ new Set();
|
|
762
|
+
for (const id of this.getModuleIds()) client.add(path.normalize(id.split("?")[0]));
|
|
763
|
+
const tree_css = tree_css_walk(this);
|
|
764
|
+
const { compile } = await import("svelte/compiler");
|
|
765
|
+
for (const [abs, source] of modules) try {
|
|
766
|
+
let own = "";
|
|
767
|
+
if (svelteHasStyle(source)) {
|
|
768
|
+
const { css } = compile(source, {
|
|
769
|
+
filename: abs,
|
|
770
|
+
css: "external",
|
|
771
|
+
dev: false,
|
|
772
|
+
generate: "client",
|
|
773
|
+
experimental: { async: true }
|
|
774
|
+
});
|
|
775
|
+
own = css?.code ?? "";
|
|
776
|
+
}
|
|
777
|
+
const tree = await tree_css(abs, {
|
|
778
|
+
own: source,
|
|
779
|
+
skip: (p) => client.has(p)
|
|
780
|
+
});
|
|
781
|
+
const css = [own, tree].filter(Boolean).join("\n");
|
|
782
|
+
if (css) leg.content_css_refs.set(content_css_key(abs), this.emitFile({
|
|
783
|
+
type: "asset",
|
|
784
|
+
name: "og-content.css",
|
|
785
|
+
source: css
|
|
786
|
+
}));
|
|
787
|
+
} catch {}
|
|
788
|
+
},
|
|
789
|
+
closeBundle() {
|
|
790
|
+
if (is_dev) dev_owner.close();
|
|
791
|
+
compiler_of(session, "closeBundle").end_leg(env_of(this)?.name ?? null);
|
|
792
|
+
},
|
|
793
|
+
async writeBundle(_options, bundle) {
|
|
794
|
+
const compiler = compiler_of(session, "writeBundle");
|
|
795
|
+
const leg = leg_of(this);
|
|
796
|
+
const server_leg = leg.server;
|
|
797
|
+
if (is_build) {
|
|
798
|
+
const ids = [];
|
|
799
|
+
for (const item of Object.values(bundle)) if (item.type === "chunk") ids.push(...item.moduleIds);
|
|
800
|
+
const [wrong] = compiler.misplaced_modules(ids, server_leg);
|
|
801
|
+
if (wrong) this.error(new OgygiaError("virtual_wrong_realm", {
|
|
802
|
+
id: wrong[0].replace("\0", ""),
|
|
803
|
+
realm: wrong[1],
|
|
804
|
+
leg: server_leg ? "server" : "browser",
|
|
805
|
+
via: import_chain(wrong[0], (m) => this.getModuleInfo(m)?.importers, root)
|
|
806
|
+
}));
|
|
807
|
+
}
|
|
808
|
+
if (!is_build || server_leg) return;
|
|
809
|
+
refuse_client_secrets(bundle, [read_server_handoff(kit.dirs.out_dir)?.build_key ?? build_secret, process.env.OGYGIA_SECRET?.trim() ?? ""]);
|
|
810
|
+
if (isMainThread) for (const hook of prescans) hook.written?.();
|
|
811
|
+
await page_reads?.settle((s, importer) => this.resolve(s, importer));
|
|
812
|
+
const remote_hash = (id) => remote_hash_of(id, process.cwd());
|
|
813
|
+
const entries = compiler.entry_locations(leg, (ref) => this.getFileName(ref));
|
|
814
|
+
const map = collectIslandDepModulepreloads(bundle, [APP_SHIMS["$app/state"], APP_SHIMS["$app/stores"]], remote_hash, page_reads && ((module_id) => page_reads.keys(module_id)), readFile, entries.runtime_file, {
|
|
815
|
+
islands: entries.islands,
|
|
816
|
+
runtime: entries.runtime
|
|
817
|
+
});
|
|
818
|
+
const page_why = page_reads ? report_seed_shaping(map, bundle, (module) => page_reads.why(module), root, (identity) => entries.locations[identity] ?? identity) : {};
|
|
819
|
+
for (const [key, ref] of leg.router_css_refs) try {
|
|
820
|
+
const file = this.getFileName(ref);
|
|
821
|
+
map.css[key] = [file.startsWith("/") ? file : `/${file}`];
|
|
822
|
+
} catch {}
|
|
823
|
+
for (const [iid, ref] of leg.hole_css_refs) try {
|
|
824
|
+
const file = this.getFileName(ref);
|
|
825
|
+
const key = compiler.island_public_url(iid);
|
|
826
|
+
(map.css[key] ??= []).push(file.startsWith("/") ? file : `/${file}`);
|
|
827
|
+
} catch {}
|
|
828
|
+
const content_css = {};
|
|
829
|
+
for (const [key, ref] of leg.content_css_refs) try {
|
|
830
|
+
const file = this.getFileName(ref);
|
|
831
|
+
content_css[key] = [file.startsWith("/") ? file : `/${file}`];
|
|
832
|
+
} catch {}
|
|
833
|
+
const css_inline = collect_inline_css(bundle, [...Object.values(map.css).flat(), ...Object.values(content_css).flat()], kit.inline_style_threshold);
|
|
834
|
+
if (!measure) {
|
|
835
|
+
map.contents = {};
|
|
836
|
+
map.heavy = {};
|
|
837
|
+
map.hazards = {};
|
|
838
|
+
map.dupes = [];
|
|
839
|
+
}
|
|
840
|
+
const barrels = {};
|
|
841
|
+
if (measure) for (const [key, chunk] of Object.entries(bundle)) {
|
|
842
|
+
if (chunk.type !== "chunk") continue;
|
|
843
|
+
const found = [];
|
|
844
|
+
for (const id of chunk.moduleIds ?? []) {
|
|
845
|
+
if (id.startsWith("\0")) continue;
|
|
846
|
+
const q = id.indexOf("?");
|
|
847
|
+
if ((q === -1 ? id : id.slice(0, q)).endsWith(".svelte")) continue;
|
|
848
|
+
const info = this.getModuleInfo(id);
|
|
849
|
+
if (!info) continue;
|
|
850
|
+
const fanout = info.importedIds.filter((d) => !d.startsWith("\0")).length;
|
|
851
|
+
const own = info.code?.length ?? Infinity;
|
|
852
|
+
if (fanout >= 6 && own <= fanout * 160) {
|
|
853
|
+
const name = summarize_chunk_contents([id], 1, 1)[0];
|
|
854
|
+
const why = why_stayed(id, info.importers);
|
|
855
|
+
if (name) found.push(why.length ? {
|
|
856
|
+
name,
|
|
857
|
+
fanout,
|
|
858
|
+
why
|
|
859
|
+
} : {
|
|
860
|
+
name,
|
|
861
|
+
fanout
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
if (found.length) barrels[`/${chunk.fileName || key}`] = found.sort((a, b) => b.fanout - a.fanout).slice(0, 3);
|
|
866
|
+
}
|
|
867
|
+
const json = JSON.stringify({
|
|
868
|
+
...map,
|
|
869
|
+
...measure ? {
|
|
870
|
+
page_why,
|
|
871
|
+
barrels
|
|
872
|
+
} : {},
|
|
873
|
+
content_css,
|
|
874
|
+
css_inline,
|
|
875
|
+
fn_manifest: compiler.fn_manifest(),
|
|
876
|
+
entries: entries.locations,
|
|
877
|
+
locations: leg.location_map_url
|
|
878
|
+
});
|
|
879
|
+
emit_island_deps_handoff(root, json, kit.dirs.out_dir, leg.relocated);
|
|
880
|
+
}
|
|
881
|
+
},
|
|
882
|
+
stage_host("post"),
|
|
883
|
+
island_sourcemaps_plugin({
|
|
884
|
+
program: () => compiler_of(session, "sourcemaps").program,
|
|
885
|
+
is_island_path
|
|
886
|
+
}),
|
|
887
|
+
lazy_files()
|
|
888
|
+
];
|
|
889
|
+
}
|
|
890
|
+
export { CLIENT_BINDING_STUB, DEFAULT_IMPORT_KEYS, definePlugin, import_keys_hint, islandChunkFileName, islandId, islandPublicUrl, normalize_import_keys, ogygia, regionId, regionIdentity, rewrite_lake_import_to_placeholder, strategyKey, wrapperVirtualId };
|