@ogygia/compiler 0.14.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/dist/ctx.d.ts CHANGED
@@ -3,7 +3,7 @@ import { KitDirs, Routes } from "./kit.js";
3
3
  import { ClientRealmFile, ServerRealm } from "./link/caps.js";
4
4
  import { AliasEntry, PluginMacro } from "./macros/pipeline.js";
5
5
  import { AppSpecCtx } from "./app-spec.js";
6
- import { PreprocessCss } from "./fouc-css.js";
6
+ import { ComponentCss } from "./fouc-css.js";
7
7
  import { ImportKeys } from "./region/transform.js";
8
8
  /** The part of a seed-shaping plugin the compiler calls (the whole of it: vite/plugin-api.ts
9
9
  * `PageReads`): each module the transform reads, and each module's answer when chunks are finished. */
@@ -87,9 +87,9 @@ export interface CompileCtxInit {
87
87
  import_keys: ImportKeys;
88
88
  /** Resolved Vite aliases (an island's closure walk; every plugin macro gets them). */
89
89
  resolve_alias: readonly AliasEntry[];
90
- /** The plugin's preprocessor for a component's CSS (fouc-css.ts `scoped_component_css`). Absent:
91
- * a host with no bundler, which compiles the source as it is. */
92
- preprocess_css?: PreprocessCss;
90
+ /** How the app compiles a component's CSS (fouc-css.ts `scoped_component_css`). Absent: a host
91
+ * with no bundler, which compiles the source as it is. */
92
+ component_css?: ComponentCss;
93
93
  /** The plugins' `import.meta.og.*` macros (`b.macro`), in plugin order. Optional (default none). */
94
94
  macros?: readonly PluginMacro[];
95
95
  /** The plugin that reads which `page.data` keys a module reads (`b.pageReads`), handed each
@@ -165,7 +165,7 @@ export declare class CompileCtx {
165
165
  readonly resolve_alias: readonly AliasEntry[];
166
166
  /** What an app import specifier is resolved against (app-spec.ts): the root, `$lib`, the aliases. */
167
167
  get app_spec(): AppSpecCtx;
168
- readonly preprocess_css: PreprocessCss | undefined;
168
+ readonly component_css: ComponentCss | undefined;
169
169
  readonly macros: readonly PluginMacro[];
170
170
  readonly page_reads: PageReadsSink | null;
171
171
  readonly prescans: readonly PrescanHook[];
package/dist/ctx.js CHANGED
@@ -41,7 +41,7 @@ var CompileCtx = class {
41
41
  stat: (abs) => this.fs.stat(abs)
42
42
  };
43
43
  }
44
- preprocess_css;
44
+ component_css;
45
45
  macros;
46
46
  page_reads;
47
47
  prescans;
@@ -94,7 +94,7 @@ var CompileCtx = class {
94
94
  this.presets = init.presets;
95
95
  this.import_keys = init.import_keys;
96
96
  this.resolve_alias = init.resolve_alias;
97
- this.preprocess_css = init.preprocess_css;
97
+ this.component_css = init.component_css;
98
98
  this.macros = init.macros ?? [];
99
99
  this.page_reads = init.page_reads ?? null;
100
100
  this.prescans = init.prescans ?? [];
package/dist/driver.d.ts CHANGED
@@ -294,13 +294,15 @@ export declare class Compiler implements CoreApp {
294
294
  * Returns a resolved id / result, or `null` to defer to the bundler. The adapter handles the few
295
295
  * package/Kit-specific ids first (ogygia injected imports, Kit's remote runtime, the kit-wire path).
296
296
  */
297
- resolve_id(source: string, importer: string | undefined, { ssr, resolve }: {
297
+ resolve_id(source: string, importer: string | undefined, { ssr, resolve, importers_of }: {
298
298
  ssr: boolean;
299
299
  resolve: (source: string, importer: string, opts: {
300
300
  skipSelf: boolean;
301
301
  }) => Promise<{
302
302
  id: string;
303
303
  } | null>;
304
+ /** the bundler's module graph: who imported a module, for a refusal's import chain */
305
+ importers_of?: (id: string) => readonly string[] | undefined;
304
306
  }): Promise<string | {
305
307
  id: string;
306
308
  } | null>;
package/dist/driver.js CHANGED
@@ -14,7 +14,7 @@ import { own_reach, reaches_context, reaches_wire } from "./link/own-reach.js";
14
14
  import { router_css_roots } from "./link/router-css.js";
15
15
  import { relocate, relocations_of } from "./link/relocations.js";
16
16
  import { island_vpaths_affected_by_file, same_module_path } from "./dev/hmr.js";
17
- import { VirtualTable } from "./virtual/resolver.js";
17
+ import { VirtualTable, import_chain } from "./virtual/resolver.js";
18
18
  import { CORE_VALUE_NAMES } from "./virtual/value-names.js";
19
19
  import { CORE_PARTS, CORE_VIRTUALS, core_path } from "./virtual/core.js";
20
20
  import { host_key, strip_id } from "./program.js";
@@ -1003,12 +1003,13 @@ var Compiler = class Compiler {
1003
1003
  * Returns a resolved id / result, or `null` to defer to the bundler. The adapter handles the few
1004
1004
  * package/Kit-specific ids first (ogygia injected imports, Kit's remote runtime, the kit-wire path).
1005
1005
  */
1006
- async resolve_id(source, importer, { ssr, resolve }) {
1006
+ async resolve_id(source, importer, { ssr, resolve, importers_of }) {
1007
1007
  const ctx = this.#ctx;
1008
1008
  const { registry, island_graph } = this.program;
1009
1009
  const declared = this.#virtuals.resolve(source, {
1010
1010
  ssr,
1011
- dev: ctx.is_dev
1011
+ dev: ctx.is_dev,
1012
+ via: () => importer ? import_chain(importer, importers_of ?? (() => []), ctx.root) : ""
1012
1013
  });
1013
1014
  if (declared) return declared;
1014
1015
  if (source === CLIENT_BINDING_STUB) return ctx.client_binding_stub_file;
@@ -1,5 +1,6 @@
1
1
  import { ExportIndex } from "./exports/index.js";
2
2
  import { AppAlias } from "./app-spec.js";
3
+ import { CompileOptions } from "svelte/compiler";
3
4
  export declare const FOUC_CSS_PREFIX: string;
4
5
  export declare const FOUC_SCOPED_PREFIX: string;
5
6
  /** @param relPosix */
@@ -69,16 +70,22 @@ export declare function collectFoucCssReachable(entryAbs: string, opts: CssReach
69
70
  kind: "scoped" | "css";
70
71
  abs: string;
71
72
  }>>;
72
- /** The plugin's preprocessor for a component's CSS: `<style lang="scss|sass">` to CSS, TypeScript
73
- * stripped from its script (vite/style-preprocess.ts). */
74
- export type PreprocessCss = (source: string, abs: string) => Promise<string>;
73
+ /** How the app compiles a component, as its CSS needs it. */
74
+ export interface ComponentCss {
75
+ /** `<style lang="scss|sass">` to CSS, TypeScript stripped from its script
76
+ * (vite/style-preprocess.ts). */
77
+ preprocess(source: string, abs: string): Promise<string>;
78
+ /** The Svelte options the component's own compile uses (vite/svelte-options.ts), so the scope
79
+ * class matches its markup (test/region-css-svelte-options.test.ts). */
80
+ options(abs: string, source: string): Promise<CompileOptions>;
81
+ }
75
82
  /**
76
83
  * A component's scoped CSS, one rule for every leg (dev router CSS, the build's tree CSS, the fouc
77
- * module): preprocessed by `preprocess`, then compiled with its script
78
- * (test/router-css-dev-preprocess.test.ts). With no preprocessor (a host with no bundler), the
79
- * source as it is.
84
+ * module): preprocessed, then compiled with its script and the app's Svelte options
85
+ * (test/router-css-dev-preprocess.test.ts). With no `css` (a host with no bundler), the source as
86
+ * it is.
80
87
  */
81
- export declare function scoped_component_css(abs: string, source: string, preprocess: PreprocessCss | undefined): Promise<string>;
88
+ export declare function scoped_component_css(abs: string, source: string, css: ComponentCss | undefined): Promise<string>;
82
89
  /**
83
90
  * Compile scoped CSS for a `.svelte` file (filename must match SSR for hash stability).
84
91
  * @param abs
@@ -91,6 +98,9 @@ export declare function compileFoucScopedCss(abs: string, source: string, opts?:
91
98
  * the SSR'd markup carries. Without it (a source that may still carry TypeScript), the
92
99
  * source is tried whole first (Svelte reads `lang="ts"` itself), then script-stripped. */
93
100
  keepScript?: boolean;
101
+ /** The app's Svelte options (`ComponentCss.options`); this compile sets only what makes it
102
+ * a CSS compile. */
103
+ options?: CompileOptions;
94
104
  }): string;
95
105
  /** @param source */
96
106
  export declare function svelteHasStyle(source: string): boolean;
package/dist/fouc-css.js CHANGED
@@ -190,12 +190,17 @@ async function collectFoucCssReachable(entryAbs, opts) {
190
190
  }
191
191
  /**
192
192
  * A component's scoped CSS, one rule for every leg (dev router CSS, the build's tree CSS, the fouc
193
- * module): preprocessed by `preprocess`, then compiled with its script
194
- * (test/router-css-dev-preprocess.test.ts). With no preprocessor (a host with no bundler), the
195
- * source as it is.
193
+ * module): preprocessed, then compiled with its script and the app's Svelte options
194
+ * (test/router-css-dev-preprocess.test.ts). With no `css` (a host with no bundler), the source as
195
+ * it is.
196
196
  */
197
- async function scoped_component_css(abs, source, preprocess) {
198
- return preprocess ? compileFoucScopedCss(abs, await preprocess(source, abs), { keepScript: true }) : compileFoucScopedCss(abs, source);
197
+ async function scoped_component_css(abs, source, css) {
198
+ if (!css) return compileFoucScopedCss(abs, source);
199
+ const preprocessed = await css.preprocess(source, abs);
200
+ return compileFoucScopedCss(abs, preprocessed, {
201
+ keepScript: true,
202
+ options: await css.options(abs, preprocessed)
203
+ });
199
204
  }
200
205
  /**
201
206
  * Compile scoped CSS for a `.svelte` file (filename must match SSR for hash stability).
@@ -207,11 +212,16 @@ function compileFoucScopedCss(abs, source, opts = {}) {
207
212
  let err;
208
213
  for (const input of inputs) try {
209
214
  return compile(input, {
215
+ ...opts.options,
210
216
  filename: abs,
211
217
  generate: "client",
212
218
  css: "external",
219
+ hmr: false,
213
220
  discloseVersion: false,
214
- experimental: { async: true }
221
+ experimental: {
222
+ ...opts.options?.experimental,
223
+ async: true
224
+ }
215
225
  }).css?.code ?? "";
216
226
  } catch (e) {
217
227
  err ??= e;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { CLIENT_BINDING_STUB, DEFAULT_IMPORT_KEYS, ISLAND_DIR, ImportKeys, PRESET_KEYS, STABLE_NAME_DIR, import_keys_hint, is_island_path, islandChunkFileName, islandId, islandPublicUrl, normalize_hydrate_value, normalize_import_keys, normalize_region_value, transformHost, transformTsRegions } from "./region/transform.js";
2
2
  import { AstNode, parse_module } from "./parse/oxc.js";
3
3
  import { parse_roots } from "./parse/roots.js";
4
- import { CssReachOptions, FOUC_CSS_PREFIX, FOUC_SCOPED_PREFIX, PreprocessCss, WalkResolve, buildFoucCssModuleSource, collectFoucCssReachable, compileFoucScopedCss, foucCssVirtualId, foucRelFromId, foucScopedVirtualId, isFoucCssId, isFoucScopedId, listStaticImports, scoped_component_css, svelteHasStyle, through_caller } from "./fouc-css.js";
4
+ import { ComponentCss, CssReachOptions, FOUC_CSS_PREFIX, FOUC_SCOPED_PREFIX, WalkResolve, buildFoucCssModuleSource, collectFoucCssReachable, compileFoucScopedCss, foucCssVirtualId, foucRelFromId, foucScopedVirtualId, isFoucCssId, isFoucScopedId, listStaticImports, scoped_component_css, svelteHasStyle, through_caller } from "./fouc-css.js";
5
5
  import { collectCaptureInfo, collectFreeIdentifiers, collectSnippetNames, collect_pattern_names, free_references, scope_bindings } from "./free-vars.js";
6
6
  import { regionId, regionIdentity, strategyKey } from "./region/identity.js";
7
7
  import { Compiler, Profiler } from "./driver.js";
@@ -20,4 +20,4 @@ import { JsRegion, OgCall, find_og_calls, is_js_module, og_js_regions, split_fir
20
20
  import { og_member } from "./macros/wire.js";
21
21
  import { BuildCache, __set_build_cache_root, configure_build_cache } from "./build-cache.js";
22
22
  import { OWN_FILE_RE, content_css_key, dedent } from "@ogygia/core/contract";
23
- export { type AstNode, BUILD_ERRORS, BUILD_WARNINGS, BuildCache, CLIENT_BINDING_STUB, type Change, CompileCtx, type CompileCtxInit, Compiler, CssReachOptions, DEFAULT_IMPORT_KEYS, ExportIndex, type ExportMap, FOUC_CSS_PREFIX, FOUC_SCOPED_PREFIX, type Fs, type FsEntry, ISLAND_DIR, type ImportDecl, ImportKeys, type ImportSpec, type JsRegion, type Leaf, type MemoryFs, OGYGIA_SCHEME, OWN_FILE_RE, type OgCall, PRESET_KEYS, PROFILER_MAPS_GZ_PREFIX, PROFILER_MAPS_PLACEHOLDER, type Policy, PreprocessCss, type Profiler, Program, REGION_FAMILY, RESOLVED, STABLE_NAME_DIR, Shapes, V_RUNTIME_ENTRY, V_SERVER_MANIFEST, V_SERVER_REGIONS, V_TRANSPORT, V_TRANSPORTABLES, WalkResolve, __set_build_cache_root, analyze_imports, blank_styles, buildFoucCssModuleSource, collectCaptureInfo, collectFoucCssReachable, collectFreeIdentifiers, collectSnippetNames, collect_pattern_names, compileFoucScopedCss, configure_build_cache, content_css_key, dedent, find_og_calls, foucCssVirtualId, foucRelFromId, foucScopedVirtualId, free_references, host_key, import_keys_hint, isFoucCssId, isFoucScopedId, is_island_path, is_js_module, is_script_request, islandChunkFileName, islandId, islandPublicUrl, islandVirtualId, lazyEntryVirtualId, listStaticImports, memory_fs, node_fs, normalize_hydrate_value, normalize_import_keys, normalize_region_value, og_js_regions, og_member, parse_module, parse_roots, regionBindingVirtualId, regionId, regionIdentity, region_family, scope_bindings, scoped_component_css, split_first_string, strategyKey, strip_id, svelteHasStyle, through_caller, transformHost, transformTsRegions, wrapperVirtualId };
23
+ export { type AstNode, BUILD_ERRORS, BUILD_WARNINGS, BuildCache, CLIENT_BINDING_STUB, type Change, CompileCtx, type CompileCtxInit, Compiler, ComponentCss, CssReachOptions, DEFAULT_IMPORT_KEYS, ExportIndex, type ExportMap, FOUC_CSS_PREFIX, FOUC_SCOPED_PREFIX, type Fs, type FsEntry, ISLAND_DIR, type ImportDecl, ImportKeys, type ImportSpec, type JsRegion, type Leaf, type MemoryFs, OGYGIA_SCHEME, OWN_FILE_RE, type OgCall, PRESET_KEYS, PROFILER_MAPS_GZ_PREFIX, PROFILER_MAPS_PLACEHOLDER, type Policy, type Profiler, Program, REGION_FAMILY, RESOLVED, STABLE_NAME_DIR, Shapes, V_RUNTIME_ENTRY, V_SERVER_MANIFEST, V_SERVER_REGIONS, V_TRANSPORT, V_TRANSPORTABLES, WalkResolve, __set_build_cache_root, analyze_imports, blank_styles, buildFoucCssModuleSource, collectCaptureInfo, collectFoucCssReachable, collectFreeIdentifiers, collectSnippetNames, collect_pattern_names, compileFoucScopedCss, configure_build_cache, content_css_key, dedent, find_og_calls, foucCssVirtualId, foucRelFromId, foucScopedVirtualId, free_references, host_key, import_keys_hint, isFoucCssId, isFoucScopedId, is_island_path, is_js_module, is_script_request, islandChunkFileName, islandId, islandPublicUrl, islandVirtualId, lazyEntryVirtualId, listStaticImports, memory_fs, node_fs, normalize_hydrate_value, normalize_import_keys, normalize_region_value, og_js_regions, og_member, parse_module, parse_roots, regionBindingVirtualId, regionId, regionIdentity, region_family, scope_bindings, scoped_component_css, split_first_string, strategyKey, strip_id, svelteHasStyle, through_caller, transformHost, transformTsRegions, wrapperVirtualId };
@@ -53,11 +53,17 @@ const PAGE_DATA_READS = {
53
53
  return !!info && (imports_kit_page(info.importedIds) || imports_kit_page(info.dynamicallyImportedIds));
54
54
  };
55
55
  const ids_by_path = /* @__PURE__ */ new Map();
56
- for (const id of cx.module_ids()) if (!id.startsWith("\0")) ids_by_path.set(clean(id), id);
56
+ for (const id of cx.module_ids()) {
57
+ if (id.startsWith("\0")) continue;
58
+ const c = clean(id);
59
+ const ids = ids_by_path.get(c);
60
+ if (ids) ids.push(id);
61
+ else ids_by_path.set(c, [id]);
62
+ }
57
63
  const proven_clean = /* @__PURE__ */ new Set();
58
- const reads = (root) => {
59
- const seen = /* @__PURE__ */ new Set([root]);
60
- const queue = [root];
64
+ const reads = (roots) => {
65
+ const seen = new Set(roots);
66
+ const queue = [...roots];
61
67
  for (let i = 0; i < queue.length; i++) {
62
68
  const id = queue[i];
63
69
  if (proven_clean.has(id)) continue;
@@ -78,8 +84,8 @@ const PAGE_DATA_READS = {
78
84
  };
79
85
  const out = {};
80
86
  for (const [iid, , reg] of server_regions(cx.program)) {
81
- const root = reg.componentPath ? ids_by_path.get(clean(reg.componentPath)) : void 0;
82
- out[iid] = root === void 0 ? true : reads(root);
87
+ const roots = reg.componentPath ? ids_by_path.get(clean(reg.componentPath)) : void 0;
88
+ out[iid] = roots === void 0 ? true : reads(roots);
83
89
  }
84
90
  const json = JSON.stringify(out);
85
91
  return (quote) => in_literal(json, quote);
@@ -1,4 +1,4 @@
1
- import { PreprocessCss, WalkResolve } from "../fouc-css.js";
1
+ import { ComponentCss, WalkResolve } from "../fouc-css.js";
2
2
  import { AppSpecCtx } from "../app-spec.js";
3
3
  import { ExportIndex } from "../exports/index.js";
4
4
  export declare const ROUTER_CSS_KEY_PREFIX = "rcss:";
@@ -29,8 +29,8 @@ export declare function router_css_module(roots: readonly string[], opts: {
29
29
  lib_dir: string;
30
30
  is_dev: boolean;
31
31
  read_file: (p: string) => string | null;
32
- /** the plugin's CSS preprocessor: dev compiles a component as the build does */
33
- preprocess?: PreprocessCss;
32
+ /** how the app compiles a component's CSS: dev compiles it as the build does */
33
+ css?: ComponentCss;
34
34
  /** the bundler's resolver, for the dev tree-CSS walk (compiler/fouc-css.ts) */
35
35
  resolve?: (spec: string, importer: string) => Promise<string | null>;
36
36
  /** `resolve`'s export index */
@@ -84,7 +84,7 @@ async function router_css_module(roots, opts) {
84
84
  if (e.kind === "scoped") {
85
85
  const source = opts.read_file(e.abs);
86
86
  if (source == null) continue;
87
- const css = await scoped_component_css(e.abs, source, opts.preprocess);
87
+ const css = await scoped_component_css(e.abs, source, opts.css);
88
88
  if (css) entries.push({
89
89
  key: `rcss-dev:${e_rel}`,
90
90
  css
@@ -477,6 +477,7 @@ export declare const BUILD_ERRORS: {
477
477
  id: string;
478
478
  realm: string;
479
479
  leg: string;
480
+ via?: string;
480
481
  }) => string;
481
482
  details: () => string;
482
483
  };
package/dist/messages.js CHANGED
@@ -638,7 +638,7 @@ const BUILD_ERRORS = {
638
638
  `
639
639
  },
640
640
  virtual_wrong_realm: {
641
- text: (a) => `\`${a.id}\` is a ${a.realm} module, and the ${a.leg} build imported it.`,
641
+ text: (a) => `\`${a.id}\` is a ${a.realm} module, and the ${a.leg} build imported it${a.via ? `, through ${a.via}` : ""}.`,
642
642
  details: () => prose`
643
643
  Each of ogygia's modules runs in one realm: \`ogygia:server\` on the server, \`ogygia:boot\`
644
644
  in the browser's runtime, \`ogygia:region\` in both, \`ogygia:dev\` on the dev server only.
@@ -1,9 +1,11 @@
1
1
  import { Edit } from "./splice.js";
2
2
  /**
3
- * `source` with every opaque element stamped, or `null` when there is nothing to stamp (or the file
4
- * does not parse — the real compile reports that). Outermost wins: nothing is stamped inside a stamped
5
- * element (the repair never enters it anyway).
3
+ * `source` with every opaque element stamped, and every element holding an `{@html}` beside other
4
+ * children stamped `data-og-html` with each `{@html}` range marked; or `null` when there is nothing to
5
+ * stamp (or the file does not parse — the real compile reports that). Outermost wins: nothing is
6
+ * stamped inside a stamped element (the repair never enters it anyway).
6
7
  */
7
8
  export declare function stamp_opaque(raw: string, filename: string): string | null;
8
- /** The inserts `stamp_opaque` makes to `source` (no byte-order mark): none when there is nothing to stamp. */
9
+ /** The inserts `stamp_opaque` makes to `source` (no byte-order mark): none when there is nothing to
10
+ * stamp. Server leg only: the client never sees a stamp or a mark. */
9
11
  export declare function opaque_stamp_edits(source: string, filename: string): Edit[];
@@ -1,7 +1,7 @@
1
1
  import { splice_text } from "./splice.js";
2
2
  import { blank_styles } from "./blank-styles.js";
3
3
  import { strip_bom } from "./bom.js";
4
- import { OG_HTML, OG_OPAQUE } from "@ogygia/core/contract";
4
+ import { HTML_RANGE_MARK, OG_HTML, OG_OPAQUE } from "@ogygia/core/contract";
5
5
  import { parse } from "svelte/compiler";
6
6
  // src/ownership-stamps.ts
7
7
  const MAY_STAMP_RE = /\{@html|bind:(?:innerHTML|textContent|innerText)|<[a-z][\w.]*-[\w-]*[\s/>]|\sis=/;
@@ -33,12 +33,22 @@ function is_custom_element(el) {
33
33
  return String(el.name).includes("-") || (el.attributes ?? []).some((a) => a.type === "Attribute" && a.name === "is");
34
34
  }
35
35
  function opaque(el) {
36
- if ((el.attributes ?? []).some((a) => a.type === "Attribute" && a.name === OG_OPAQUE)) return false;
36
+ if (has_attribute(el, OG_OPAQUE)) return false;
37
37
  const kids = (el.fragment?.nodes ?? []).filter((n) => !is_blank(n));
38
38
  if (kids.length === 1 && kids[0].type === "HtmlTag") return true;
39
39
  if ((el.attributes ?? []).some((a) => a.type === "BindDirective" && WHOLESALE_BINDS.has(a.name))) return true;
40
40
  return is_custom_element(el) && all_static(el.fragment?.nodes ?? []);
41
41
  }
42
+ function has_attribute(el, name) {
43
+ return (el.attributes ?? []).some((a) => a.type === "Attribute" && a.name === name);
44
+ }
45
+ const insert = (pos, text) => ({
46
+ start: pos,
47
+ end: pos,
48
+ text
49
+ });
50
+ const RANGE_OPEN = `((s) => s && '<!--${HTML_RANGE_MARK}-->' + s)(String((`;
51
+ const RANGE_CLOSE = `) ?? ''))`;
42
52
  const CHILD_KEYS = [
43
53
  "fragment",
44
54
  "consequent",
@@ -50,16 +60,18 @@ const CHILD_KEYS = [
50
60
  "fallback"
51
61
  ];
52
62
  /**
53
- * `source` with every opaque element stamped, or `null` when there is nothing to stamp (or the file
54
- * does not parse — the real compile reports that). Outermost wins: nothing is stamped inside a stamped
55
- * element (the repair never enters it anyway).
63
+ * `source` with every opaque element stamped, and every element holding an `{@html}` beside other
64
+ * children stamped `data-og-html` with each `{@html}` range marked; or `null` when there is nothing to
65
+ * stamp (or the file does not parse — the real compile reports that). Outermost wins: nothing is
66
+ * stamped inside a stamped element (the repair never enters it anyway).
56
67
  */
57
68
  function stamp_opaque(raw, filename) {
58
69
  const source = strip_bom(raw);
59
70
  const edits = opaque_stamp_edits(source, filename);
60
71
  return edits.length ? splice_text(source, edits) : null;
61
72
  }
62
- /** The inserts `stamp_opaque` makes to `source` (no byte-order mark): none when there is nothing to stamp. */
73
+ /** The inserts `stamp_opaque` makes to `source` (no byte-order mark): none when there is nothing to
74
+ * stamp. Server leg only: the client never sees a stamp or a mark. */
63
75
  function opaque_stamp_edits(source, filename) {
64
76
  if (!MAY_STAMP_RE.test(source)) return [];
65
77
  let ast;
@@ -71,20 +83,23 @@ function opaque_stamp_edits(source, filename) {
71
83
  } catch {
72
84
  return [];
73
85
  }
74
- const at = [];
86
+ const edits = [];
75
87
  const visit = (nodes) => {
76
88
  for (const n of nodes ?? []) {
77
89
  if (n.type === "RegularElement" && opaque(n)) {
78
- at.push({
79
- pos: n.start + 1 + String(n.name).length,
80
- attr: OG_OPAQUE
81
- });
90
+ edits.push(insert(n.start + 1 + String(n.name).length, ` ${OG_OPAQUE}`));
82
91
  continue;
83
92
  }
84
- if (n.type === "RegularElement" && (n.fragment?.nodes ?? []).some((c) => c.type === "HtmlTag") && !(n.attributes ?? []).some((a) => a.type === "Attribute" && (a.name === OG_HTML || a.name === OG_OPAQUE))) at.push({
85
- pos: n.start + 1 + String(n.name).length,
86
- attr: OG_HTML
87
- });
93
+ if (n.type === "RegularElement" && !has_attribute(n, OG_OPAQUE)) {
94
+ const html_tags = (n.fragment?.nodes ?? []).filter((c) => c.type === "HtmlTag");
95
+ if (html_tags.length) {
96
+ if (!has_attribute(n, OG_HTML)) edits.push(insert(n.start + 1 + String(n.name).length, ` ${OG_HTML}`));
97
+ for (const h of html_tags) {
98
+ edits.push(insert(h.expression.start, RANGE_OPEN));
99
+ edits.push(insert(h.expression.end, RANGE_CLOSE));
100
+ }
101
+ }
102
+ }
88
103
  for (const k of CHILD_KEYS) {
89
104
  const child = n[k];
90
105
  if (child && Array.isArray(child.nodes)) visit(child.nodes);
@@ -92,10 +107,6 @@ function opaque_stamp_edits(source, filename) {
92
107
  }
93
108
  };
94
109
  visit(ast.fragment?.nodes);
95
- return at.map(({ pos, attr }) => ({
96
- start: pos,
97
- end: pos,
98
- text: ` ${attr}`
99
- }));
110
+ return edits;
100
111
  }
101
112
  export { opaque_stamp_edits, stamp_opaque };
@@ -220,7 +220,7 @@ const router_css = virtual.family({
220
220
  root: app.ctx.root,
221
221
  lib_dir: app.ctx.libDir,
222
222
  is_dev: app.ctx.is_dev,
223
- preprocess: app.ctx.preprocess_css,
223
+ css: app.ctx.component_css,
224
224
  read_file: (p) => app.ctx.read_file(p),
225
225
  resolve: leg.resolve,
226
226
  exports: leg.exports
@@ -6,7 +6,13 @@ import { Queries } from "../queries.js";
6
6
  export interface Env {
7
7
  ssr: boolean;
8
8
  dev: boolean;
9
+ /** the import chain that reached the module ({@link import_chain}), named when it is refused */
10
+ via?: () => string;
9
11
  }
12
+ /** The files that imported `start`, nearest first, each the first importer not yet named, back to
13
+ * one nothing imports (or a cycle): `` `a.ts` ← `b.svelte` ``, relative to `root`. Virtual ids are
14
+ * passed through, never named. */
15
+ export declare function import_chain(start: string, importers_of: (id: string) => readonly string[] | undefined, root: string): string;
10
16
  /** The realms each leg may import: the server leg server and region, the browser leg boot and
11
17
  * region; dev only on the dev server. */
12
18
  export declare function realm_allowed(realm: Realm, env: Env): boolean;
@@ -3,9 +3,23 @@ import { OGYGIA_SCHEME } from "./specifier.js";
3
3
  import { RESOLVED } from "../ids.js";
4
4
  import { realm_exports, specifier_of, value_names, write_value } from "./table.js";
5
5
  import { input } from "../queries.js";
6
+ import path from "node:path";
6
7
  // src/virtual/resolver.ts
7
8
  const PART = input("session part", (part) => part, () => 0);
8
9
  const REALM_NAMED_IMPORT_G = /\b(import|export)\s*\{([^}]*)\}\s*from\s*(['"])ogygia:(server|boot|region|dev)\3;?/g;
10
+ /** The files that imported `start`, nearest first, each the first importer not yet named, back to
11
+ * one nothing imports (or a cycle): `` `a.ts` ← `b.svelte` ``, relative to `root`. Virtual ids are
12
+ * passed through, never named. */
13
+ function import_chain(start, importers_of, root) {
14
+ const seen = /* @__PURE__ */ new Set();
15
+ const named = [];
16
+ for (let id = start; id !== void 0 && !seen.has(id);) {
17
+ seen.add(id);
18
+ if (!id.startsWith("\0")) named.push(`\`${path.relative(root, id.split("?")[0])}\``);
19
+ id = importers_of(id)?.find((importer) => !seen.has(importer));
20
+ }
21
+ return named.join(" ← ");
22
+ }
9
23
  /** The realms each leg may import: the server leg server and region, the browser leg boot and
10
24
  * region; dev only on the dev server. */
11
25
  function realm_allowed(realm, env) {
@@ -17,7 +31,8 @@ function check_realm(id, realm, env) {
17
31
  if (!realm_allowed(realm, env)) throw new OgygiaError("virtual_wrong_realm", {
18
32
  id,
19
33
  realm,
20
- leg: env.ssr ? "server" : "browser"
34
+ leg: env.ssr ? "server" : "browser",
35
+ via: env.via?.()
21
36
  });
22
37
  }
23
38
  /** Is this specifier (or resolved id) in ogygia's virtual namespace? */
@@ -126,7 +141,8 @@ var VirtualTable = class {
126
141
  load(id, app, leg) {
127
142
  const browser = {
128
143
  ssr: false,
129
- dev: true
144
+ dev: true,
145
+ via: leg.via
130
146
  };
131
147
  const [wrong] = leg.ssr ? [] : this.misplaced([id], browser);
132
148
  if (wrong) check_realm(id, wrong[1], browser);
@@ -246,4 +262,4 @@ function tracked(app, parts, cx) {
246
262
  return typeof v === "function" ? v.bind(target) : v;
247
263
  } });
248
264
  }
249
- export { VirtualTable, is_virtual_specifier, realm_allowed };
265
+ export { VirtualTable, import_chain, is_virtual_specifier, realm_allowed };
@@ -25,6 +25,8 @@ export interface Leg {
25
25
  exports?: ExportIndex<WalkResolve>;
26
26
  /** Kit 3's own codec module (`#app/internal/transport`), when the app's Kit has one */
27
27
  kitCodec?: string | null;
28
+ /** the import chain that reached the module being loaded (resolver.ts `import_chain`) */
29
+ via?: () => string;
28
30
  }
29
31
  type Source = string | Promise<string>;
30
32
  interface Base {
@@ -27,17 +27,21 @@ import { Program, strip_id } from "../program.js";
27
27
  import { Compiler } from "../driver.js";
28
28
  import { compiler_of, configured, new_session, resolve } from "./session.js";
29
29
  import { core_defines } from "../virtual/core.js";
30
+ import { import_chain } from "../virtual/resolver.js";
30
31
  import { CompileCtx } from "../ctx.js";
31
32
  import { discover_package_files } from "./package-files.js";
32
33
  import { async_twin_redirect, svelte_async_enabled } from "./late-island.js";
34
+ import { app_compile_options, svelte_compile } from "./svelte-options.js";
33
35
  import { KIT_REMOTE_CLIENT, KIT_REMOTE_STATE, RUNTIME_HASH, scan_entry_pattern } from "./paths.js";
34
36
  import { SVELTE_DEV_ISLAND_ENTRIES } from "./svelte-entries.js";
35
37
  import { OgygiaError, line, warn } from "../messages.js";
38
+ import { RouteWatch } from "./route-watch.js";
36
39
  import path from "node:path";
37
- 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, 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";
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";
38
41
  import fs from "node:fs";
39
42
  import MagicString from "magic-string";
40
43
  import crypto from "node:crypto";
44
+ import { scope } from "@ogygia/machine";
41
45
  import { isMainThread } from "node:worker_threads";
42
46
  import { loadEnv } from "vite";
43
47
  // src/vite/index.ts
@@ -103,7 +107,11 @@ function ogygia(options = {}) {
103
107
  let devtools_lazy = false;
104
108
  const build_secret = crypto.randomBytes(32).toString("hex");
105
109
  let id_salt = "";
106
- const preprocess_css = (source, abs) => preprocess_component_for_css(source, abs, root);
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
+ };
107
115
  const tree_css_walk = (ctx) => {
108
116
  const { compiled_css } = leg_of(ctx);
109
117
  const walk_resolve = bundler_resolve(ctx);
@@ -124,7 +132,7 @@ function ogygia(options = {}) {
124
132
  if (css === void 0) {
125
133
  const src = readFile(e.abs);
126
134
  css = null;
127
- if (src != null && e.kind === "scoped") css = await scoped_component_css(e.abs, src, preprocess_css);
135
+ if (src != null && e.kind === "scoped") css = await scoped_component_css(e.abs, src, component_css);
128
136
  else if (src != null && CSS_EXT_RE.test(e.abs)) css = src;
129
137
  compiled_css.set(e.abs, css);
130
138
  }
@@ -159,6 +167,7 @@ function ogygia(options = {}) {
159
167
  let client_hooks = null;
160
168
  let kit_transport_init = null;
161
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);
162
171
  const readFile = (abs) => {
163
172
  try {
164
173
  return fs.readFileSync(abs, "utf-8");
@@ -259,6 +268,12 @@ function ogygia(options = {}) {
259
268
  const mod = server.moduleGraph.getModuleById(id);
260
269
  if (mod) server.moduleGraph.invalidateModule(mod);
261
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
+ });
262
277
  const invalidate_islands_for_file = (file, { deleted = false, server = vite_server } = {}) => {
263
278
  if (!server) return false;
264
279
  return compiler_of(session, "invalidate").invalidate_for_file(file, {
@@ -348,7 +363,8 @@ function ogygia(options = {}) {
348
363
  inline_style_threshold: 0
349
364
  };
350
365
  base = config.base || "";
351
- svelte_async = svelte_async_enabled(config.plugins);
366
+ svelte = svelte_compile(config.plugins);
367
+ svelte_async = svelte_async_enabled(svelte);
352
368
  if (config.command === "serve") {
353
369
  const own = (config.optimizeDeps?.include ?? []).filter((d) => is_own_specifier(d));
354
370
  if (own.length) config.logger.warn(line("optimize_deps_includes_ogygia", {
@@ -414,7 +430,7 @@ function ogygia(options = {}) {
414
430
  presets,
415
431
  import_keys,
416
432
  resolve_alias,
417
- preprocess_css,
433
+ component_css,
418
434
  macros,
419
435
  page_reads,
420
436
  prescans,
@@ -529,12 +545,8 @@ function ogygia(options = {}) {
529
545
  }
530
546
  },
531
547
  watchChange(id, change) {
532
- const compiler = compiler_of(session, "watchChange");
533
548
  shapes.invalidate(id, change.event);
534
- if (is_dev) {
535
- const ids = compiler.routes_changed(id, change.event);
536
- if (vite_server) for (const mid of ids) invalidate_module_id(vite_server, mid);
537
- }
549
+ if (is_dev) route_watch.heard(id, change.event);
538
550
  if (!is_dev || change.event !== "delete" || !vite_server) return;
539
551
  if (!invalidate_islands_for_file(id, {
540
552
  deleted: true,
@@ -617,9 +629,9 @@ function ogygia(options = {}) {
617
629
  if (awaiting) return awaiting;
618
630
  }
619
631
  const ssr = leg_of(this).server;
620
- if (!ssr && source === "__sveltekit/remote") {
632
+ if (!ssr && (source === "__sveltekit/remote" || names_kit_remote(source, importer))) {
621
633
  if (!kit_remote_index) throw new OgygiaError("kit_remote_src_missing");
622
- return kit_remote_index;
634
+ return importer !== void 0 && real_posix(importer) === real_posix(QUERY_MAKERS) ? kit_remote_index : QUERY_MAKERS;
623
635
  }
624
636
  if (!ssr && importer && importer.includes("/remote-functions/")) {
625
637
  if (KIT_REMOTE_CLIENT.test(source)) return STUB_CLIENT;
@@ -630,7 +642,8 @@ function ogygia(options = {}) {
630
642
  if (!ssr && source === "$app/paths/internal/client") return STUB_PATHS;
631
643
  return compiler_of(session, "resolveId").resolve_id(source, importer, {
632
644
  ssr,
633
- resolve: (s, i, o) => this.resolve(s, i, o)
645
+ resolve: (s, i, o) => this.resolve(s, i, o),
646
+ importers_of: (id) => this.getModuleInfo(id)?.importers
634
647
  });
635
648
  },
636
649
  async load(id) {
@@ -670,7 +683,7 @@ function ogygia(options = {}) {
670
683
  };
671
684
  }
672
685
  return {
673
- code: await scoped_component_css(abs, source, preprocess_css),
686
+ code: await scoped_component_css(abs, source, component_css),
674
687
  moduleType: "css"
675
688
  };
676
689
  }
@@ -679,7 +692,8 @@ function ogygia(options = {}) {
679
692
  universalHooks: universal_hooks,
680
693
  resolve: bundler_resolve(this),
681
694
  exports: css_walk_index(this.environment.name),
682
- kitCodec: kit_transport_init
695
+ kitCodec: kit_transport_init,
696
+ via: () => import_chain(id, (m) => this.getModuleInfo(m)?.importers, root)
683
697
  });
684
698
  },
685
699
  async transform(code, id) {
@@ -773,6 +787,7 @@ function ogygia(options = {}) {
773
787
  } catch {}
774
788
  },
775
789
  closeBundle() {
790
+ if (is_dev) dev_owner.close();
776
791
  compiler_of(session, "closeBundle").end_leg(env_of(this)?.name ?? null);
777
792
  },
778
793
  async writeBundle(_options, bundle) {
@@ -786,7 +801,8 @@ function ogygia(options = {}) {
786
801
  if (wrong) this.error(new OgygiaError("virtual_wrong_realm", {
787
802
  id: wrong[0].replace("\0", ""),
788
803
  realm: wrong[1],
789
- leg: server_leg ? "server" : "browser"
804
+ leg: server_leg ? "server" : "browser",
805
+ via: import_chain(wrong[0], (m) => this.getModuleInfo(m)?.importers, root)
790
806
  }));
791
807
  }
792
808
  if (!is_build || server_leg) return;
@@ -1,11 +1,8 @@
1
+ import { SvelteCompile } from "./svelte-options.js";
1
2
  /** Region's twin imports: the file it imports → its awaiting twin (beside it). */
2
3
  export declare const ASYNC_TWINS: Readonly<Record<string, string>>;
3
- /** Does the app compile with Svelte's async mode? Read off vite-plugin-svelte's resolved options (its
4
- * config plugin publishes them as `api.options`, resolved before any plugin's own configResolved). */
5
- export declare function svelte_async_enabled(plugins: readonly {
6
- name?: string;
7
- api?: unknown;
8
- }[] | undefined): boolean;
4
+ /** Does the app compile with Svelte's async mode? */
5
+ export declare function svelte_async_enabled(svelte: SvelteCompile | null): boolean;
9
6
  /** The awaiting twin a Region twin import resolves to in an app with async mode on (beside Region,
10
7
  * whichever copy imported it), or null for any other import. */
11
8
  export declare function async_twin_redirect(source: string, importer: string | undefined, region_modules: ReadonlySet<string>): string | null;
@@ -4,10 +4,9 @@ const ASYNC_TWINS = {
4
4
  "./LateIsland.svelte": "LateIslandAwait.svelte",
5
5
  "./PromiseRegion.svelte": "PromiseRegionAwait.svelte"
6
6
  };
7
- /** Does the app compile with Svelte's async mode? Read off vite-plugin-svelte's resolved options (its
8
- * config plugin publishes them as `api.options`, resolved before any plugin's own configResolved). */
9
- function svelte_async_enabled(plugins) {
10
- return (plugins?.find((p) => p.name === "vite-plugin-svelte:config")?.api)?.options?.compilerOptions?.experimental?.async === true;
7
+ /** Does the app compile with Svelte's async mode? */
8
+ function svelte_async_enabled(svelte) {
9
+ return svelte?.compilerOptions?.experimental?.async === true;
11
10
  }
12
11
  /** The awaiting twin a Region twin import resolves to in an app with async mode on (beside Region,
13
12
  * whichever copy imported it), or null for any other import. */
@@ -5,6 +5,8 @@
5
5
  export declare function scan_entry_pattern(file: string, own_root?: string): string | null;
6
6
  export declare const KIT_REMOTE_CLIENT: RegExp;
7
7
  export declare const KIT_REMOTE_STATE: RegExp;
8
+ /** The end of every path to Kit's client remote functions (`remote-functions/index.js`). */
9
+ export declare const KIT_REMOTE_INDEX_TAIL = "/client/remote-functions/index.js";
8
10
  /** What the runtime chunk is made from: the compiler's runtime entry, core's named inputs, and every
9
11
  * `.js` file in `runtime_dir` (none when it is not built yet). */
10
12
  export declare function runtime_inputs(runtime_dir?: string): string[];
@@ -15,6 +15,8 @@ function scan_entry_pattern(file, own_root = CORE_ROOT_ID) {
15
15
  }
16
16
  const KIT_REMOTE_CLIENT = /(^|\/)client\.js$/;
17
17
  const KIT_REMOTE_STATE = /state\.svelte\.js$/;
18
+ /** The end of every path to Kit's client remote functions (`remote-functions/index.js`). */
19
+ const KIT_REMOTE_INDEX_TAIL = "/client/remote-functions/index.js";
18
20
  /** What the runtime chunk is made from: the compiler's runtime entry, core's named inputs, and every
19
21
  * `.js` file in `runtime_dir` (none when it is not built yet). */
20
22
  function runtime_inputs(runtime_dir = RUNTIME_DIR) {
@@ -34,4 +36,4 @@ function content_hash(files) {
34
36
  }
35
37
  /** The runtime chunk's source-content hash (the immutable-filename base; feature hash rides on top). */
36
38
  const RUNTIME_HASH = content_hash(runtime_inputs());
37
- export { KIT_REMOTE_CLIENT, KIT_REMOTE_STATE, RUNTIME_HASH, content_hash, runtime_inputs, scan_entry_pattern };
39
+ export { KIT_REMOTE_CLIENT, KIT_REMOTE_INDEX_TAIL, KIT_REMOTE_STATE, RUNTIME_HASH, content_hash, runtime_inputs, scan_entry_pattern };
@@ -0,0 +1,15 @@
1
+ import { FileEvent } from "../kit.js";
2
+ import { Scope } from "@ogygia/machine";
3
+ /**
4
+ * DEV: what each watched file event changed in the route answers, read when the event comes and
5
+ * once more after the watcher's quiet window, while `owner` is open. A save that truncates the file
6
+ * and then writes it is reported at the truncate, so its first read can be a write in progress.
7
+ * When the second read finds a change, the event the watcher dropped is `replay`ed, so the dev
8
+ * server updates what it ran from the file as it does for any event.
9
+ */
10
+ export declare class RouteWatch {
11
+ #private;
12
+ constructor(owner: Scope, changed: (file: string, event: FileEvent) => readonly string[], invalidate: (id: string) => void, replay: (file: string) => void);
13
+ /** The watcher reported `event` at `file`. */
14
+ heard(file: string, event: FileEvent): void;
15
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * DEV: what each watched file event changed in the route answers, read when the event comes and
3
+ * once more after the watcher's quiet window, while `owner` is open. A save that truncates the file
4
+ * and then writes it is reported at the truncate, so its first read can be a write in progress.
5
+ * When the second read finds a change, the event the watcher dropped is `replay`ed, so the dev
6
+ * server updates what it ran from the file as it does for any event.
7
+ */
8
+ var RouteWatch = class {
9
+ #owner;
10
+ #changed;
11
+ #invalidate;
12
+ #replay;
13
+ constructor(owner, changed, invalidate, replay) {
14
+ this.#owner = owner;
15
+ this.#changed = changed;
16
+ this.#invalidate = invalidate;
17
+ this.#replay = replay;
18
+ }
19
+ /** The watcher reported `event` at `file`. */
20
+ heard(file, event) {
21
+ this.#read(file, event);
22
+ if (event !== "delete") this.#owner.timeout(() => {
23
+ if (this.#read(file, "update")) this.#replay(file);
24
+ }, 100);
25
+ }
26
+ #read(file, event) {
27
+ const ids = this.#changed(file, event);
28
+ for (const id of ids) this.#invalidate(id);
29
+ return ids.length > 0;
30
+ }
31
+ };
32
+ export { RouteWatch };
@@ -0,0 +1,20 @@
1
+ import { CompileOptions } from "svelte/compiler";
2
+ /** The parts of vite-plugin-svelte's resolved options that decide how it compiles a component. */
3
+ export interface SvelteCompile {
4
+ readonly compilerOptions?: CompileOptions;
5
+ dynamicCompileOptions?(data: {
6
+ filename: string;
7
+ code: string;
8
+ compileOptions: CompileOptions;
9
+ }): Promise<Partial<CompileOptions> | void> | Partial<CompileOptions> | void;
10
+ }
11
+ /** The app's Svelte compile, read off vite-plugin-svelte's resolved options (its config plugin
12
+ * publishes them as `api.options`, resolved before any plugin's own configResolved); null when
13
+ * the app lists no vite-plugin-svelte. */
14
+ export declare function svelte_compile(plugins: readonly {
15
+ name?: string;
16
+ api?: unknown;
17
+ }[] | undefined): SvelteCompile | null;
18
+ /** The options vite-plugin-svelte compiles `filename` with: the app's `compilerOptions`, then that
19
+ * file's `dynamicCompileOptions`. */
20
+ export declare function app_compile_options(svelte: SvelteCompile | null, filename: string, code: string): Promise<CompileOptions>;
@@ -0,0 +1,22 @@
1
+ // src/vite/svelte-options.ts
2
+ /** The app's Svelte compile, read off vite-plugin-svelte's resolved options (its config plugin
3
+ * publishes them as `api.options`, resolved before any plugin's own configResolved); null when
4
+ * the app lists no vite-plugin-svelte. */
5
+ function svelte_compile(plugins) {
6
+ return (plugins?.find((p) => p.name === "vite-plugin-svelte:config")?.api)?.options ?? null;
7
+ }
8
+ /** The options vite-plugin-svelte compiles `filename` with: the app's `compilerOptions`, then that
9
+ * file's `dynamicCompileOptions`. */
10
+ async function app_compile_options(svelte, filename, code) {
11
+ const base = { ...svelte?.compilerOptions };
12
+ const dynamic = await svelte?.dynamicCompileOptions?.({
13
+ filename,
14
+ code,
15
+ compileOptions: base
16
+ });
17
+ return dynamic ? {
18
+ ...base,
19
+ ...dynamic
20
+ } : base;
21
+ }
22
+ export { app_compile_options, svelte_compile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ogygia/compiler",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "The compiler of ogygia (SSR islands for SvelteKit): the region transform, the build's link step and the Vite plugin",
5
5
  "keywords": [
6
6
  "compiler",
@@ -53,7 +53,7 @@
53
53
  "devDependencies": {
54
54
  "@jridgewell/trace-mapping": "^0.3.31",
55
55
  "@ogygia/config": "0.0.0",
56
- "@ogygia/core": "0.14.0",
56
+ "@ogygia/core": "0.14.1",
57
57
  "@sveltejs/kit": "^2.70.2",
58
58
  "@sveltejs/vite-plugin-svelte": "^7.2.0",
59
59
  "@types/node": "^26.1.2",
@@ -68,7 +68,7 @@
68
68
  "vitest": "^4.1.12"
69
69
  },
70
70
  "peerDependencies": {
71
- "@ogygia/core": "^0.14.0",
71
+ "@ogygia/core": "^0.14.1",
72
72
  "@sveltejs/kit": ">=2.70.2 <4",
73
73
  "rolldown": ">=1.0.0",
74
74
  "svelte": "^5.56.8",