@barefootjs/hono 0.30.6 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,11 +31,10 @@ export interface HonoAdapterOptions {
31
31
  */
32
32
  clientJsFilename?: string;
33
33
  /**
34
- * Display name surfaced through `JsxAdapter.name` read by `bf build`
35
- * for its `Adapter: …` banner. Defaults to `'hono'`. CSR-mode callers
36
- * (`@barefootjs/client/build`) pass `'csr'` so the banner reflects the
37
- * mode the user picked at scaffold time instead of leaking the
38
- * fact that CSR currently reuses HonoAdapter under the hood.
34
+ * Display name surfaced through `JsxAdapter.name`. Defaults to `'hono'`.
35
+ * (CSR mode no longer reuses `HonoAdapter` under the hood — see
36
+ * `@barefootjs/client/csr-adapter`'s own in-package `CSRAdapter` so
37
+ * this option has no CSR-specific caller today.)
39
38
  */
40
39
  name?: string;
41
40
  }
@@ -43,7 +42,6 @@ export declare class HonoAdapter extends JsxAdapter implements IRNodeEmitter<Hon
43
42
  name: string;
44
43
  extension: string;
45
44
  clientShimSource: string;
46
- importMapInjection: 'component';
47
45
  acceptsTemplateCall: () => boolean;
48
46
  protected jsxConfig: JsxAdapterConfig;
49
47
  private options;
@@ -61,8 +59,47 @@ export declare class HonoAdapter extends JsxAdapter implements IRNodeEmitter<Hon
61
59
  private rewriteRelativeImport?;
62
60
  /** Stack of loop keys for generating data-key / data-key-1 attributes on loop items */
63
61
  private loopKeyStack;
62
+ /**
63
+ * Per-call `AdapterGenerateOptions.scriptAssets`, stashed for the
64
+ * duration of one `generate()` call (same lifecycle as
65
+ * `rewriteRelativeImport`) so `generateImports`/`generateComponent`/
66
+ * `renderIfStatement` can all see it without threading it through every
67
+ * method signature. `undefined` means "the caller didn't resolve
68
+ * scriptAssets", so no script-registration codegen is emitted; `[]`
69
+ * means "resolved, and empty" (a server-only file, or a client file
70
+ * whose bundle isn't in the manifest yet); a non-empty array means
71
+ * "bake exactly these URLs in". See `AdapterGenerateOptions.
72
+ * scriptAssets`'s docstring for the full precedence contract this
73
+ * mirrors from `GoTemplateAdapter`.
74
+ */
75
+ private scriptAssets?;
76
+ /**
77
+ * Per-call `AdapterGenerateOptions.preloadAssets`, same stash-for-the-
78
+ * duration-of-one-`generate()`-call lifecycle as `scriptAssets`. Only
79
+ * consulted when `hasScriptAssets()` is also true — see
80
+ * `AdapterGenerateOptions.preloadAssets`'s docstring: preloads are only
81
+ * meaningful alongside a non-empty `scriptAssets`.
82
+ */
83
+ private preloadAssets?;
64
84
  constructor(options?: HonoAdapterOptions);
65
85
  generate(ir: ComponentIR, options?: AdapterGenerateOptions): AdapterOutput;
86
+ /**
87
+ * True when `options.scriptAssets` was resolved AND non-empty for this
88
+ * `generate()` call — the single guard `generateImports`/
89
+ * `generateComponent`/`renderIfStatement` all consult before emitting
90
+ * script-registration codegen. See `scriptAssets`'s field docstring for
91
+ * why `undefined` and `[]` are both "no" here.
92
+ */
93
+ private hasScriptAssets;
94
+ /**
95
+ * True when `options.preloadAssets` was resolved AND non-empty for this
96
+ * `generate()` call, AND `hasScriptAssets()` also holds — see
97
+ * `AdapterGenerateOptions.preloadAssets`'s docstring: preloads are only
98
+ * meaningful alongside a non-empty `scriptAssets`. Consulted by
99
+ * `generateImports`/`generateComponent`/`renderIfStatement` alongside
100
+ * `hasScriptAssets()` before emitting preload-registration codegen.
101
+ */
102
+ private hasPreloadAssets;
66
103
  private generateModuleLevelContextBindings;
67
104
  private generateImports;
68
105
  generateTypes(ir: ComponentIR, componentBody?: string): string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"hono-adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/hono-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KA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E,GAAG,MAAM,CAkE5F;IAEQ,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAgB1C;IAED,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,CAAC,EAAE;QAAE,uBAAuB,CAAC,EAAE,OAAO,CAAC;QAAC,cAAc,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAkDhH;IAED,OAAO,CAAC,cAAc;IAQtB;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAY5B;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAsBlC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAiBpC;IAED,OAAO,CAAC,gBAAgB;IAiCxB,OAAO,CAAC,oBAAoB;IAyB5B,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,0BAA0B;CAwBnC;AAGD,eAAO,MAAM,WAAW,aAAoB,CAAA"}
@@ -187323,7 +187323,6 @@ class HonoAdapter extends JsxAdapter {
187323
187323
  name = "hono";
187324
187324
  extension = ".tsx";
187325
187325
  clientShimSource = "@barefootjs/hono/client-shim";
187326
- importMapInjection = "component";
187327
187326
  acceptsTemplateCall = () => true;
187328
187327
  jsxConfig = { preserveTypes: true };
187329
187328
  options;
@@ -187332,6 +187331,8 @@ class HonoAdapter extends JsxAdapter {
187332
187331
  currentComponentHasProps = false;
187333
187332
  rewriteRelativeImport;
187334
187333
  loopKeyStack = [];
187334
+ scriptAssets;
187335
+ preloadAssets;
187335
187336
  constructor(options = {}) {
187336
187337
  super();
187337
187338
  this.options = {
@@ -187346,6 +187347,13 @@ class HonoAdapter extends JsxAdapter {
187346
187347
  this.componentName = ir.metadata.componentName;
187347
187348
  this.isClientComponent = ir.metadata.isClientComponent;
187348
187349
  this.rewriteRelativeImport = options?.rewriteRelativeImport;
187350
+ if (options?.skipScriptRegistration) {
187351
+ this.scriptAssets = undefined;
187352
+ this.preloadAssets = undefined;
187353
+ } else {
187354
+ this.scriptAssets = options?.scriptAssets;
187355
+ this.preloadAssets = options?.preloadAssets;
187356
+ }
187349
187357
  const component = this.generateComponent(ir);
187350
187358
  const types2 = this.generateTypes(ir, component);
187351
187359
  const componentCode = [types2, component].filter(Boolean).join(`
@@ -187371,8 +187379,16 @@ export default ${this.componentName}` : "";
187371
187379
  extension: this.extension
187372
187380
  };
187373
187381
  this.rewriteRelativeImport = undefined;
187382
+ this.scriptAssets = undefined;
187383
+ this.preloadAssets = undefined;
187374
187384
  return result;
187375
187385
  }
187386
+ hasScriptAssets() {
187387
+ return !!this.scriptAssets && this.scriptAssets.length > 0;
187388
+ }
187389
+ hasPreloadAssets() {
187390
+ return this.hasScriptAssets() && !!this.preloadAssets && this.preloadAssets.length > 0;
187391
+ }
187376
187392
  generateModuleLevelContextBindings(ir) {
187377
187393
  const lines = [];
187378
187394
  for (const c of ir.metadata.localConstants) {
@@ -187402,6 +187418,10 @@ export default ${this.componentName}` : "";
187402
187418
  if (utilImports.length > 0) {
187403
187419
  lines.push(`import { ${utilImports.join(", ")} } from '@barefootjs/hono/utils'`);
187404
187420
  }
187421
+ if (this.hasScriptAssets()) {
187422
+ const names = this.hasPreloadAssets() ? ["registerComponentScripts", "registerComponentPreloads", "wrapWithInlineScripts"] : ["registerComponentScripts", "wrapWithInlineScripts"];
187423
+ lines.push(`import { ${names.join(", ")} } from '@barefootjs/hono/scripts'`);
187424
+ }
187405
187425
  if (componentCode.includes("<__BfSuspense")) {
187406
187426
  lines.push(`import { Suspense as __BfSuspense } from 'hono/jsx/streaming'`);
187407
187427
  }
@@ -187574,6 +187594,12 @@ export default ${this.componentName}` : "";
187574
187594
  const lines = [];
187575
187595
  const exportPrefix = ir.metadata.isExported === false ? "" : "export ";
187576
187596
  lines.push(`${exportPrefix}function ${name}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
187597
+ if (this.hasPreloadAssets()) {
187598
+ lines.push(` const __bfInlinePreloads = registerComponentPreloads(${JSON.stringify(this.preloadAssets)})`);
187599
+ }
187600
+ if (this.hasScriptAssets()) {
187601
+ lines.push(` const __bfInlineScripts = registerComponentScripts(${JSON.stringify(this.scriptAssets)})`);
187602
+ }
187577
187603
  if (propsExtraction) {
187578
187604
  lines.push(propsExtraction);
187579
187605
  }
@@ -187605,9 +187631,15 @@ export default ${this.componentName}` : "";
187605
187631
  return lines.join(`
187606
187632
  `);
187607
187633
  }
187608
- lines.push(` return (`);
187609
- lines.push(` ${jsxBody}`);
187610
- lines.push(` )`);
187634
+ if (this.hasScriptAssets()) {
187635
+ lines.push(` return wrapWithInlineScripts((`);
187636
+ lines.push(` ${jsxBody}`);
187637
+ lines.push(this.hasPreloadAssets() ? ` ), __bfInlineScripts, __bfInlinePreloads)` : ` ), __bfInlineScripts)`);
187638
+ } else {
187639
+ lines.push(` return (`);
187640
+ lines.push(` ${jsxBody}`);
187641
+ lines.push(` )`);
187642
+ }
187611
187643
  lines.push(`}`);
187612
187644
  return lines.join(`
187613
187645
  `);
@@ -187817,10 +187849,14 @@ export default ${this.componentName}` : "";
187817
187849
  lines.push(` const ${v.name} = ${init}`);
187818
187850
  }
187819
187851
  const consequent = this.renderNode(ifStmt.consequent, ctx);
187852
+ const wrap = this.hasScriptAssets();
187853
+ const wrapPreload = this.hasPreloadAssets();
187854
+ const openReturn = wrap ? " return wrapWithInlineScripts((" : " return (";
187855
+ const closeReturn = wrap ? wrapPreload ? " ), __bfInlineScripts, __bfInlinePreloads)" : " ), __bfInlineScripts)" : " )";
187820
187856
  lines.unshift(` if (${ifStmt.condition}) {`);
187821
- lines.push(` return (`);
187857
+ lines.push(openReturn);
187822
187858
  lines.push(` ${consequent}`);
187823
- lines.push(` )`);
187859
+ lines.push(closeReturn);
187824
187860
  lines.push(` }`);
187825
187861
  if (ifStmt.alternate) {
187826
187862
  if (ifStmt.alternate.type === "if-statement") {
@@ -187828,9 +187864,9 @@ export default ${this.componentName}` : "";
187828
187864
  lines.push(elseIfCode.replace(/^\s*if/, " else if"));
187829
187865
  } else {
187830
187866
  const alternate = this.renderNode(ifStmt.alternate, ctx);
187831
- lines.push(` return (`);
187867
+ lines.push(wrap ? " return wrapWithInlineScripts((" : " return (");
187832
187868
  lines.push(` ${alternate}`);
187833
- lines.push(` )`);
187869
+ lines.push(wrap ? wrapPreload ? " ), __bfInlineScripts, __bfInlinePreloads)" : " ), __bfInlineScripts)" : " )");
187834
187870
  }
187835
187871
  } else {
187836
187872
  lines.push(` return null`);
package/dist/app.d.ts CHANGED
@@ -9,10 +9,9 @@
9
9
  *
10
10
  * Two pieces:
11
11
  *
12
- * - **JSX components** (`<BfImportMap />`, `<BfScripts />`,
13
- * `<BfDevReload />`) — return raw HTML the caller composes inside
14
- * the Layout passed to Hono's `jsxRenderer`. All URL/data inputs
15
- * are required props.
12
+ * - **JSX components** (`<BfScripts />`, `<BfDevReload />`) — return
13
+ * raw HTML the caller composes inside the Layout passed to Hono's
14
+ * `jsxRenderer`. All URL/data inputs are required props.
16
15
  *
17
16
  * - **Middleware** (`barefootDevReload`) — registers the SSE endpoint
18
17
  * paired with `<BfDevReload />`. Both `endpoint` and `enabled` are
@@ -27,13 +26,12 @@
27
26
  */
28
27
  import type { MiddlewareHandler } from 'hono';
29
28
  import type { HtmlEscapedString } from 'hono/utils/html';
30
- import { type ImportMapManifest } from '@barefootjs/jsx/import-map';
31
29
  import './search-params-ssr.ts';
32
30
  /**
33
- * Build manifest shape produced by `bf build`. Each compiled
34
- * component is keyed by its manifest name; `__barefoot__` is the
35
- * runtime entry. `clientJs` is a path under `dist/`, e.g.
36
- * `"components/Counter.client.js"`.
31
+ * Build manifest shape read by `manifestToScriptUrls` (and `BfScripts`
32
+ * below) to emit per-component `<script>` tags. Each compiled component
33
+ * is keyed by its manifest name; `__barefoot__` is the runtime entry.
34
+ * `clientJs` is a path under `dist/`, e.g. `"components/Counter.client.js"`.
37
35
  *
38
36
  * `stubDeps` lists the manifest keys of every `'use client'` sibling
39
37
  * this bundle reaches via a stub rewrite (i.e. via an imperative
@@ -46,8 +44,7 @@ import './search-params-ssr.ts';
46
44
  * `ui/button/index.tsx`), not the runtime registry name passed to
47
45
  * `createComponent(...)` (e.g. `"Button"`). For top-level
48
46
  * single-component files the two coincide; for nested layouts they
49
- * differ. `build.ts` does the path → manifest-key conversion before
50
- * writing this field.
47
+ * differ.
51
48
  */
52
49
  export interface BarefootBuildManifest {
53
50
  __barefoot__?: {
@@ -65,47 +62,6 @@ export interface BarefootBuildManifest {
65
62
  */
66
63
  export declare function manifestToScriptUrls(manifest: BarefootBuildManifest, base: string): string[];
67
64
  export declare function relPathFromComponentsBase(p: string): string;
68
- export interface BfImportMapProps {
69
- /** Base URL where the runtime + component bundles are served. */
70
- base: string;
71
- /**
72
- * Contents of `barefoot-externals.json` (import it and pass it
73
- * through). Its `importmap.imports` are merged on top of the
74
- * built-in `@barefootjs/client*` mappings so islands importing
75
- * configured externals (e.g. `zod`, `@barefootjs/form`) resolve in
76
- * the browser. When omitted, only the `@barefootjs/client*`
77
- * mappings are emitted — the pre-#1639 behavior.
78
- *
79
- * Typed with the shared {@link ImportMapManifest} from `@barefootjs/jsx`,
80
- * so the component and the `bf build` snippet path describe the manifest
81
- * with one type.
82
- */
83
- externals?: ImportMapManifest;
84
- /**
85
- * Whether to also emit `<link rel="modulepreload">` for the
86
- * manifest's `preloads`. Defaults to `true`; set `false` to emit
87
- * the importmap only.
88
- */
89
- preload?: boolean;
90
- }
91
- /**
92
- * Emits the `<script type="importmap">` that maps the bare
93
- * `@barefootjs/client` / `@barefootjs/client/runtime` specifiers to
94
- * the runtime bundle, plus any externals from `barefoot-externals.json`
95
- * passed via the `externals` prop. Also emits `<link rel="modulepreload">`
96
- * for the manifest's `preloads` unless `preload` is `false`. Place in
97
- * `<head>`.
98
- *
99
- * The merge of the `@barefootjs/client*` defaults (synthesized from `base`
100
- * for prop-less / hand-written manifests) is Hono-specific; the actual HTML
101
- * rendering — importmap JSON escaping, `<link rel="modulepreload">`
102
- * emission with `crossorigin` (#1648) — is delegated to the shared
103
- * `renderImportMapHtml` so this path can never drift from the static
104
- * `barefoot-importmap.html` snippet `bf build` emits for template-string
105
- * adapters (#1644). Imported from the `@barefootjs/jsx/import-map` subpath,
106
- * a zero-dependency module, to keep this runtime file free of the compiler.
107
- */
108
- export declare function BfImportMap(props: BfImportMapProps): HtmlEscapedString | Promise<HtmlEscapedString>;
109
65
  export interface BfScriptsProps {
110
66
  /** Base URL where the runtime + component bundles are served. */
111
67
  base: string;
@@ -117,9 +73,9 @@ export interface BfScriptsProps {
117
73
  * manifest, runtime first. Place at the end of `<body>`.
118
74
  *
119
75
  * Logs a one-time warning when the manifest is empty — a strong
120
- * signal the user is running the server before `bf build` has
121
- * produced anything, which would otherwise present as a silent
122
- * "page renders but nothing is interactive."
76
+ * signal the user is running the server before a build has produced
77
+ * anything, which would otherwise present as a silent "page renders
78
+ * but nothing is interactive."
123
79
  */
124
80
  export declare function BfScripts(props: BfScriptsProps): HtmlEscapedString | Promise<HtmlEscapedString>;
125
81
  export interface BfDevReloadProps {
package/dist/app.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAE7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAIxD,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAIxF,OAAO,wBAAwB,CAAA;AAM/B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,qBAAqB;IACpC,YAAY,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACpC,CAAC,aAAa,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,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AAiB,CAAC,IAAI,EAAE,wBAAwB,GAAG,iBAAiB,CAanF"}
package/dist/app.js CHANGED
@@ -135,7 +135,6 @@ data: ${BOOT_ID}
135
135
  // src/app.ts
136
136
  import { html, raw } from "hono/html";
137
137
  import { useRequestContext as useRequestContext2 } from "hono/jsx-renderer";
138
- import { renderImportMapHtml } from "@barefootjs/jsx/import-map";
139
138
 
140
139
  // src/search-params-ssr.ts
141
140
  import { useRequestContext } from "hono/jsx-renderer";
@@ -175,22 +174,12 @@ function manifestToScriptUrls(manifest, base) {
175
174
  function relPathFromComponentsBase(p) {
176
175
  return p.startsWith("components/") ? p.slice("components/".length) : p;
177
176
  }
178
- function BfImportMap(props) {
179
- const base = props.base.replace(/\/$/, "");
180
- const imports = {
181
- "@barefootjs/client": `${base}/barefoot.js`,
182
- "@barefootjs/client/runtime": `${base}/barefoot.js`,
183
- ...props.externals?.importmap?.imports ?? {}
184
- };
185
- const preloads = props.preload === false ? [] : props.externals?.preloads ?? [];
186
- return html`${raw(renderImportMapHtml({ importmap: { imports }, preloads }))}`;
187
- }
188
177
  var __bfEmptyManifestWarned = false;
189
178
  function BfScripts(props) {
190
179
  const urls = manifestToScriptUrls(props.manifest, props.base);
191
180
  if (urls.length === 0 && !__bfEmptyManifestWarned) {
192
181
  __bfEmptyManifestWarned = true;
193
- console.warn("[barefootjs] BfScripts: manifest is empty — no <script> tags emitted. " + "Run `bf build` to compile components and rebuild the manifest.");
182
+ console.warn("[barefootjs] BfScripts: manifest is empty — no <script> tags emitted. " + "Run `vite build` to compile components and rebuild the manifest.");
194
183
  }
195
184
  const tags = urls.map((src) => `<script type="module" src="${src}"></script>`).join("");
196
185
  return html`${raw(tags)}`;
@@ -227,6 +216,5 @@ export {
227
216
  manifestToScriptUrls,
228
217
  barefootDevReload,
229
218
  BfScripts,
230
- BfImportMap,
231
219
  BfDevReload
232
220
  };
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  export { HonoAdapter, honoAdapter } from './adapter/index.ts';
7
7
  export type { HonoAdapterOptions } from './adapter/index.ts';
8
8
  export { conformancePins } from './conformance-pins.ts';
9
- export type { CollectedScript } from './scripts.tsx';
9
+ export type { CollectedScript, CollectedPreload } from './scripts.tsx';
10
10
  export type { CollectedPortal } from './portals.tsx';
11
11
  export type { PortalProps } from './portal-ssr.tsx';
12
12
  export type { BfAsyncProps } from './async.tsx';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC7D,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAIvD,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAIpD,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AACpD,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAInD,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI/C,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC7D,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAIvD,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAItE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AACpD,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAInD,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI/C,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA"}
package/dist/index.js CHANGED
@@ -187323,7 +187323,6 @@ class HonoAdapter extends JsxAdapter {
187323
187323
  name = "hono";
187324
187324
  extension = ".tsx";
187325
187325
  clientShimSource = "@barefootjs/hono/client-shim";
187326
- importMapInjection = "component";
187327
187326
  acceptsTemplateCall = () => true;
187328
187327
  jsxConfig = { preserveTypes: true };
187329
187328
  options;
@@ -187332,6 +187331,8 @@ class HonoAdapter extends JsxAdapter {
187332
187331
  currentComponentHasProps = false;
187333
187332
  rewriteRelativeImport;
187334
187333
  loopKeyStack = [];
187334
+ scriptAssets;
187335
+ preloadAssets;
187335
187336
  constructor(options = {}) {
187336
187337
  super();
187337
187338
  this.options = {
@@ -187346,6 +187347,13 @@ class HonoAdapter extends JsxAdapter {
187346
187347
  this.componentName = ir.metadata.componentName;
187347
187348
  this.isClientComponent = ir.metadata.isClientComponent;
187348
187349
  this.rewriteRelativeImport = options?.rewriteRelativeImport;
187350
+ if (options?.skipScriptRegistration) {
187351
+ this.scriptAssets = undefined;
187352
+ this.preloadAssets = undefined;
187353
+ } else {
187354
+ this.scriptAssets = options?.scriptAssets;
187355
+ this.preloadAssets = options?.preloadAssets;
187356
+ }
187349
187357
  const component = this.generateComponent(ir);
187350
187358
  const types2 = this.generateTypes(ir, component);
187351
187359
  const componentCode = [types2, component].filter(Boolean).join(`
@@ -187371,8 +187379,16 @@ export default ${this.componentName}` : "";
187371
187379
  extension: this.extension
187372
187380
  };
187373
187381
  this.rewriteRelativeImport = undefined;
187382
+ this.scriptAssets = undefined;
187383
+ this.preloadAssets = undefined;
187374
187384
  return result;
187375
187385
  }
187386
+ hasScriptAssets() {
187387
+ return !!this.scriptAssets && this.scriptAssets.length > 0;
187388
+ }
187389
+ hasPreloadAssets() {
187390
+ return this.hasScriptAssets() && !!this.preloadAssets && this.preloadAssets.length > 0;
187391
+ }
187376
187392
  generateModuleLevelContextBindings(ir) {
187377
187393
  const lines = [];
187378
187394
  for (const c of ir.metadata.localConstants) {
@@ -187402,6 +187418,10 @@ export default ${this.componentName}` : "";
187402
187418
  if (utilImports.length > 0) {
187403
187419
  lines.push(`import { ${utilImports.join(", ")} } from '@barefootjs/hono/utils'`);
187404
187420
  }
187421
+ if (this.hasScriptAssets()) {
187422
+ const names = this.hasPreloadAssets() ? ["registerComponentScripts", "registerComponentPreloads", "wrapWithInlineScripts"] : ["registerComponentScripts", "wrapWithInlineScripts"];
187423
+ lines.push(`import { ${names.join(", ")} } from '@barefootjs/hono/scripts'`);
187424
+ }
187405
187425
  if (componentCode.includes("<__BfSuspense")) {
187406
187426
  lines.push(`import { Suspense as __BfSuspense } from 'hono/jsx/streaming'`);
187407
187427
  }
@@ -187574,6 +187594,12 @@ export default ${this.componentName}` : "";
187574
187594
  const lines = [];
187575
187595
  const exportPrefix = ir.metadata.isExported === false ? "" : "export ";
187576
187596
  lines.push(`${exportPrefix}function ${name}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
187597
+ if (this.hasPreloadAssets()) {
187598
+ lines.push(` const __bfInlinePreloads = registerComponentPreloads(${JSON.stringify(this.preloadAssets)})`);
187599
+ }
187600
+ if (this.hasScriptAssets()) {
187601
+ lines.push(` const __bfInlineScripts = registerComponentScripts(${JSON.stringify(this.scriptAssets)})`);
187602
+ }
187577
187603
  if (propsExtraction) {
187578
187604
  lines.push(propsExtraction);
187579
187605
  }
@@ -187605,9 +187631,15 @@ export default ${this.componentName}` : "";
187605
187631
  return lines.join(`
187606
187632
  `);
187607
187633
  }
187608
- lines.push(` return (`);
187609
- lines.push(` ${jsxBody}`);
187610
- lines.push(` )`);
187634
+ if (this.hasScriptAssets()) {
187635
+ lines.push(` return wrapWithInlineScripts((`);
187636
+ lines.push(` ${jsxBody}`);
187637
+ lines.push(this.hasPreloadAssets() ? ` ), __bfInlineScripts, __bfInlinePreloads)` : ` ), __bfInlineScripts)`);
187638
+ } else {
187639
+ lines.push(` return (`);
187640
+ lines.push(` ${jsxBody}`);
187641
+ lines.push(` )`);
187642
+ }
187611
187643
  lines.push(`}`);
187612
187644
  return lines.join(`
187613
187645
  `);
@@ -187817,10 +187849,14 @@ export default ${this.componentName}` : "";
187817
187849
  lines.push(` const ${v.name} = ${init}`);
187818
187850
  }
187819
187851
  const consequent = this.renderNode(ifStmt.consequent, ctx);
187852
+ const wrap = this.hasScriptAssets();
187853
+ const wrapPreload = this.hasPreloadAssets();
187854
+ const openReturn = wrap ? " return wrapWithInlineScripts((" : " return (";
187855
+ const closeReturn = wrap ? wrapPreload ? " ), __bfInlineScripts, __bfInlinePreloads)" : " ), __bfInlineScripts)" : " )";
187820
187856
  lines.unshift(` if (${ifStmt.condition}) {`);
187821
- lines.push(` return (`);
187857
+ lines.push(openReturn);
187822
187858
  lines.push(` ${consequent}`);
187823
- lines.push(` )`);
187859
+ lines.push(closeReturn);
187824
187860
  lines.push(` }`);
187825
187861
  if (ifStmt.alternate) {
187826
187862
  if (ifStmt.alternate.type === "if-statement") {
@@ -187828,9 +187864,9 @@ export default ${this.componentName}` : "";
187828
187864
  lines.push(elseIfCode.replace(/^\s*if/, " else if"));
187829
187865
  } else {
187830
187866
  const alternate = this.renderNode(ifStmt.alternate, ctx);
187831
- lines.push(` return (`);
187867
+ lines.push(wrap ? " return wrapWithInlineScripts((" : " return (");
187832
187868
  lines.push(` ${alternate}`);
187833
- lines.push(` )`);
187869
+ lines.push(wrap ? wrapPreload ? " ), __bfInlineScripts, __bfInlinePreloads)" : " ), __bfInlineScripts)" : " )");
187834
187870
  }
187835
187871
  } else {
187836
187872
  lines.push(` return null`);
package/dist/preload.d.ts CHANGED
@@ -9,6 +9,12 @@ export interface ManifestEntry {
9
9
  type: string;
10
10
  optional: boolean;
11
11
  }>;
12
+ /**
13
+ * Dependency component names for recursive preloading.
14
+ * Note: no current producer (neither legacy site build nor @barefootjs/vite)
15
+ * emits this field, so dependency recursion only activates for
16
+ * hand-authored manifests. Kept for API compatibility.
17
+ */
12
18
  dependencies?: string[];
13
19
  }
14
20
  /**
@@ -50,7 +56,10 @@ export interface BfPreloadProps {
50
56
  * by all BarefootJS components.
51
57
  *
52
58
  * When manifest and components props are provided, automatically
53
- * preloads the full dependency chain for those components.
59
+ * preloads the full dependency chain for those components. The `components`
60
+ * array entries must match manifest keys exactly — for the legacy site
61
+ * build, use path-qualified keys like `ui/button`, not component names.
62
+ * A mismatched key is silently skipped.
54
63
  */
55
64
  export declare function BfPreload({ staticPath, scripts, includeRuntime, manifest, components }?: BfPreloadProps): import("hono/jsx/jsx-dev-runtime").JSX.Element;
56
65
  //# sourceMappingURL=preload.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"preload.d.ts","sourceRoot":"","sources":["../src/preload.tsx"],"names":[],"mappings":"AAmCA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;IAChE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;AAEpD,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAElB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IAExB;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;IAEnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CACtB;AAwCD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,EACxB,UAAsB,EACtB,OAAY,EACZ,cAAqB,EACrB,QAAQ,EACR,UAAe,EAChB,GAAE,cAAmB,kDA6BrB"}
1
+ {"version":3,"file":"preload.d.ts","sourceRoot":"","sources":["../src/preload.tsx"],"names":[],"mappings":"AAmCA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;IAChE;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;AAEpD,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAElB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IAExB;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;IAEnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CACtB;AA4CD;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,EACxB,UAAsB,EACtB,OAAY,EACZ,cAAqB,EACrB,QAAQ,EACR,UAAe,EAChB,GAAE,cAAmB,kDA6BrB"}
package/dist/render.d.ts CHANGED
@@ -15,7 +15,7 @@
15
15
  * `<Suspense>` boundaries flush out-of-order.
16
16
  *
17
17
  * Both accept a `hono/jsx` node (typically a full page including the
18
- * layout shell, `<BfImportMap>`, and `<BfScripts>`).
18
+ * layout shell and `<BfScripts>`).
19
19
  */
20
20
  /**
21
21
  * Render a hono/jsx node to a complete HTML string.
package/dist/scripts.d.ts CHANGED
@@ -2,6 +2,9 @@ import { type BarefootBuildManifest } from './app.ts';
2
2
  export type CollectedScript = {
3
3
  src: string;
4
4
  };
5
+ export type CollectedPreload = {
6
+ href: string;
7
+ };
5
8
  export interface BfScriptsProps {
6
9
  /**
7
10
  * Build manifest from `dist/components/manifest.json`. When supplied
@@ -49,6 +52,79 @@ export interface BfScriptsProps {
49
52
  * collecting them here.
50
53
  */
51
54
  export declare function BfScripts(props?: BfScriptsProps): import("hono/jsx/jsx-dev-runtime").JSX.Element | null;
55
+ /**
56
+ * Register `urls` (a component's resolved script URLs for THIS render) into
57
+ * the same request-context collector `BfScripts` reads, and return the
58
+ * subset that must be rendered INLINE right here instead — see
59
+ * `BfScripts`'s docstring on `bfScriptsRendered` (a component rendering
60
+ * after `<BfScripts />` has already run, e.g. inside a Suspense boundary,
61
+ * can't rely on the end-of-body collector; its scripts have to ship inline
62
+ * at the point of render for streaming to deliver them at all).
63
+ *
64
+ * `HonoAdapter.generate()` calls this directly from CODEGEN — one call per
65
+ * rendered component, with `urls` baked in as
66
+ * `AdapterGenerateOptions.scriptAssets` (the Vite plugin's already-resolved,
67
+ * manifest-hashed or dev-origin URL list). Two properties follow from that:
68
+ *
69
+ * - No separate `barefoot.js` runtime registration: `scriptAssets` under
70
+ * Vite is just the component's own bundled entry (see
71
+ * `@barefootjs/vite`'s `resolveScriptAssets` docstring) — the
72
+ * `@barefootjs/client` runtime arrives as a shared ESM chunk that entry
73
+ * imports, which the browser follows on its own with no extra
74
+ * `<script src>` needed. Go's `.Scripts.Register` calls (generated by
75
+ * `GoTemplateAdapter`) make exactly the same simplification for the same
76
+ * reason.
77
+ * - Dedup keys on the URL itself (there is no separate `componentId` to key
78
+ * by): rendering the SAME component N times (e.g. inside a `.map()`) or
79
+ * two different components that happen to share a chunk both correctly
80
+ * collapse to one `<script>` tag.
81
+ *
82
+ * Swallows a missing request context (no `jsxRenderer` in the render path),
83
+ * returning `[]` — SSR still renders, just without hydration scripts.
84
+ */
85
+ export declare function registerComponentScripts(urls: string[]): string[];
86
+ /**
87
+ * Register `urls` (a component's resolved TRANSITIVE-chunk preload URLs for
88
+ * THIS render, per `AdapterGenerateOptions.preloadAssets`) into the same
89
+ * request-context collector `BfScripts` reads, and return the subset that
90
+ * must be rendered INLINE right here instead — same
91
+ * already-rendered-`<BfScripts />` escape hatch as `registerComponentScripts`
92
+ * (see that function's docstring), and the same reasons apply: a component
93
+ * whose SSR happens inside a Suspense boundary that renders after
94
+ * `<BfScripts />` has already flushed can't rely on the end-of-body
95
+ * collector.
96
+ *
97
+ * Kept as a SEPARATE collector (`bfCollectedPreloads` / `bfOutputPreloads`)
98
+ * from `registerComponentScripts`'s `bfCollectedScripts` /
99
+ * `bfOutputScripts` — a preload URL and a script URL are never the same
100
+ * concern (preloads are the entry's TRANSITIVE deps, never the entry
101
+ * itself — see `AdapterGenerateOptions.preloadAssets`), so there is no
102
+ * cross-dedup to do between the two sets; keeping them separate avoids
103
+ * conflating "this was preloaded" with "this was registered as a script".
104
+ *
105
+ * Dedup keys on the URL itself, same as `registerComponentScripts`:
106
+ * rendering the SAME component N times (e.g. inside a `.map()`), or two
107
+ * different components that happen to share a transitive chunk, both
108
+ * correctly collapse to one `<link rel="modulepreload">` tag.
109
+ *
110
+ * Swallows a missing request context, returning `[]` — SSR still renders,
111
+ * just without preload hints.
112
+ */
113
+ export declare function registerComponentPreloads(urls: string[]): string[];
114
+ /**
115
+ * Wrap `jsx` with a leading `<link rel="modulepreload">` per entry in
116
+ * `inlinePreloads` and a trailing `<script type="module">` per entry in
117
+ * `inlineScripts` (the return values of `registerComponentPreloads` and
118
+ * `registerComponentScripts` respectively) — a single shared function
119
+ * every generated component imports, rather than per-file duplicated
120
+ * inline-asset logic. Returns `jsx` unchanged when both are empty (the
121
+ * common case: collected, not inline).
122
+ *
123
+ * `inlinePreloads` defaults to `[]` so existing generated call sites that
124
+ * only ever pass `inlineScripts` (a component with `scriptAssets` but no
125
+ * `preloadAssets`) keep compiling and behaving exactly as before.
126
+ */
127
+ export declare function wrapWithInlineScripts(jsx: unknown, inlineScripts: string[], inlinePreloads?: string[]): unknown;
52
128
  /**
53
129
  * Walk stub-rewrite edges from each manifest entry in `roots`,
54
130
  * returning the script URLs for every transitively reachable
@@ -1 +1 @@
1
- {"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../src/scripts.tsx"],"names":[],"mappings":"AA0CA,OAAO,EAA6B,KAAK,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAEhF,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,qBAAqB,CAAA;IAChC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,KAAK,GAAE,cAAmB,yDAgEnD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,qBAAqB,EAC/B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EACvB,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,GACpB,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CA0B9B"}
1
+ {"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../src/scripts.tsx"],"names":[],"mappings":"AA0CA,OAAO,EAA6B,KAAK,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAEhF,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,qBA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