@ogygia/core 0.11.0 → 0.11.2

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.
@@ -142,6 +142,11 @@ export declare class CompileCtx {
142
142
  constructor(init: CompileCtxInit);
143
143
  /** True when `code` carries an ogygia `with { … }` island hint (gates node_modules `.svelte`). */
144
144
  has_island_hint(code: string): boolean;
145
+ /** True when a JS module has a real `import … with { <mark key>: … }` declaration. The hint
146
+ * above is a text sniff, so it also matches a comment, a string or generated code that merely
147
+ * mentions `with { wake }`; this parses. A module that does not parse counts as marked, so a
148
+ * warning that depends on it errs toward speaking. */
149
+ has_marked_import(code: string, id: string): boolean;
145
150
  /** True when `id` is inside a dependency's DECLARED `ogygia.files` surface — those files are
146
151
  * prescanned + transformed exactly like app source (the node_modules gates lift for them). */
147
152
  in_declared_pkg(id: string): boolean;
@@ -1,6 +1,7 @@
1
1
  import { fs } from "./host.js";
2
2
  import { strip_bom } from "./bom.js";
3
3
  import { islandVirtualId } from "./ids.js";
4
+ import { parse_module } from "./parse/oxc.js";
4
5
  import { islandChunkFileName, islandPublicUrl, wrapperVirtualId } from "./region/transform.js";
5
6
  // src/compiler/ctx.ts
6
7
  /**
@@ -55,6 +56,8 @@ var CompileCtx = class {
55
56
  /** `with { … }` hint matcher — a node_modules `.svelte` is only transformed when it carries one
56
57
  * (so a library can declare its own islands). Built once from the resolved import keys. */
57
58
  #island_hint_re;
59
+ /** The resolved import-attribute keys that make a mark (`wake`, `render`, …). */
60
+ #mark_keys;
58
61
  /** Declared package files (exact) + dirs (prefix) — the transform-gate membership index. */
59
62
  #pkg_files;
60
63
  #pkg_dirs;
@@ -99,6 +102,7 @@ var CompileCtx = class {
99
102
  this.devtools = init.devtools;
100
103
  const hint_keys = Object.values(init.import_keys).filter((v) => typeof v === "string");
101
104
  this.#island_hint_re = hint_keys.length ? new RegExp(`\\bwith\\s*\\{[^}]*\\b(?:${hint_keys.join("|")})\\b`) : NEVER_MATCH_RE;
105
+ this.#mark_keys = new Set(hint_keys);
102
106
  this.#pkg_files = new Set(this.pkg_scan.flatMap((p) => p.files));
103
107
  this.#pkg_dirs = this.pkg_scan.flatMap((p) => p.dirs);
104
108
  this.#pkg_roots = this.pkg_scan.map((p) => ({
@@ -110,6 +114,22 @@ var CompileCtx = class {
110
114
  has_island_hint(code) {
111
115
  return this.#island_hint_re.test(code);
112
116
  }
117
+ /** True when a JS module has a real `import … with { <mark key>: … }` declaration. The hint
118
+ * above is a text sniff, so it also matches a comment, a string or generated code that merely
119
+ * mentions `with { wake }`; this parses. A module that does not parse counts as marked, so a
120
+ * warning that depends on it errs toward speaking. */
121
+ has_marked_import(code, id) {
122
+ const { program, ok } = parse_module(code, id);
123
+ if (!ok || !program) return true;
124
+ for (const node of program.body) {
125
+ if (node.type !== "ImportDeclaration") continue;
126
+ for (const attr of node.attributes ?? []) {
127
+ const key = attr.key?.type === "Identifier" ? attr.key.name : attr.key?.value;
128
+ if (typeof key === "string" && this.#mark_keys.has(key)) return true;
129
+ }
130
+ }
131
+ return false;
132
+ }
113
133
  /** True when `id` is inside a dependency's DECLARED `ogygia.files` surface — those files are
114
134
  * prescanned + transformed exactly like app source (the node_modules gates lift for them). */
115
135
  in_declared_pkg(id) {
@@ -1199,7 +1199,7 @@ var Compiler = class {
1199
1199
  }
1200
1200
  }
1201
1201
  const nm_ts = id_n.endsWith(".ts") || id_n.endsWith(".js") || id_n.endsWith(".mjs") ? id_n.includes("/node_modules/") : null;
1202
- if (nm_ts === true && !id_n.startsWith(ctx.pkg_root) && !ctx.in_declared_pkg(id_n) && ctx.has_island_hint(out)) warn_undeclared_pkg_marks(id_n);
1202
+ if (nm_ts === true && !id_n.startsWith(ctx.pkg_root) && !ctx.in_declared_pkg(id_n) && ctx.has_island_hint(out) && ctx.has_marked_import(out, id_n)) warn_undeclared_pkg_marks(id_n);
1203
1203
  if (nm_ts !== null && (nm_ts === false || ctx.in_declared_pkg(id_n)) && !is_island_path(id_n)) {
1204
1204
  const result = this.ts_regions(out, id_n);
1205
1205
  if (result) {
package/dist/hooks.js CHANGED
@@ -413,6 +413,14 @@ function has_body_close(carry, chunk) {
413
413
  function csr_page_of(html, body_end, event, bag) {
414
414
  return event?.route?.id != null ? bag?.page?.error != null ? error_route_is_csr_true(event.route.id) : route_is_csr_true(event.route.id) : body_end !== -1 && html_has_kit_bootstrap(html, body_end);
415
415
  }
416
+ /** The drop-in `setContext` page root (`<script data-ogygia-provide-page>`), or '' when the request
417
+ * set nothing an island can read. Drops any non-serializable value (function / store / class
418
+ * instance) instead of crashing. */
419
+ function page_ctx_script(bag) {
420
+ if (!bag?.ctx?.size) return "";
421
+ const payload = serialize_provided_context(bag.ctx);
422
+ return payload ? emit_ogygia_script("ctx", payload, PAGE_CTX_MARKER) : "";
423
+ }
416
424
  /** The restorer, inline (runtime/restore.ts — self-contained, so its source runs as is): restores the
417
425
  * document now, and stays as `__og_restore` / `__og_restore_adopt` for hole answers and router swaps. */
418
426
  const RESTORER_SCRIPT = `<script data-og-restore>(function(){var r=${restore.toString()};window.__og_restore=r;window.__og_restore_adopt=${restore_adopt.toString()};r(document)})()<\/script>`;
@@ -630,9 +638,10 @@ var OgygiaHandle = class {
630
638
  if (head !== null) {
631
639
  head_inject = CSR_META;
632
640
  if (devtools_boot_url && !head.includes("data-ogygia-devtools-boot")) head_inject += `<script type="module" data-ogygia-devtools-boot src="${devtools_boot_url}"><\/script>`;
641
+ if (bag) bag.kit_with_runtime = page_declares_runtime_script(head);
633
642
  }
634
643
  if (head !== null && bag?.transform_head) head_inject = bag.transform_head + head_inject;
635
- const tail = spans.body_end !== -1 && bag ? (bag.transform_body ?? "") + bag.tail.render(null) : "";
644
+ const tail = spans.body_end !== -1 && bag ? (bag.transform_body ?? "") + bag.tail.render(null) + (bag.kit_with_runtime ? page_ctx_script(bag) : "") : "";
636
645
  if (head === null && !tail) return html;
637
646
  const ordered = head === null ? null : runtime_first(head, null);
638
647
  return assemble(html, spans, ordered === head ? null : ordered, head_inject, tail);
@@ -735,13 +744,10 @@ var OgygiaHandle = class {
735
744
  scripts.push(fnm_script);
736
745
  fnm_bytes = fnm_script.length;
737
746
  }
738
- const provided = bag?.ctx;
739
- if (provided?.size) {
740
- const payload = serialize_provided_context(provided);
741
- if (payload) {
742
- scripts.push(emit_ogygia_script("ctx", payload, PAGE_CTX_MARKER));
743
- ctx_bytes = payload.length;
744
- }
747
+ const ctx_script = page_ctx_script(bag);
748
+ if (ctx_script) {
749
+ scripts.push(ctx_script);
750
+ ctx_bytes = ctx_script.length;
745
751
  }
746
752
  this.append_devtools_seed(scripts, bag);
747
753
  const out = assemble(html, spans, head_out, head_inject, scripts.join(""));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ogygia/core",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "The core of ogygia (SSR islands for SvelteKit): apps install `ogygia`, plugins build on this",
5
5
  "homepage": "https://ogygiajs.dev",
6
6
  "bugs": {