@barefootjs/hono 0.30.5 → 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.
package/dist/scripts.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)}`;
@@ -232,6 +221,7 @@ function BfScripts2(props = {}) {
232
221
  const c = useRequestContext3();
233
222
  c.set("bfScriptsRendered", true);
234
223
  const scripts = c.get("bfCollectedScripts") || [];
224
+ const preloads = c.get("bfCollectedPreloads") || [];
235
225
  const outputSet = c.get("bfOutputScripts") || new Set;
236
226
  const { manifest, base, entryRoots } = props;
237
227
  const roots = entryRoots && entryRoots.length > 0 ? new Set([...outputSet, ...entryRoots]) : outputSet;
@@ -249,15 +239,86 @@ function BfScripts2(props = {}) {
249
239
  ...componentScripts.reverse()
250
240
  ];
251
241
  return /* @__PURE__ */ jsxDEV(Fragment, {
252
- children: finalScripts.map(({ src }) => /* @__PURE__ */ jsxDEV("script", {
253
- type: "module",
254
- src
255
- }, undefined, false, undefined, this))
256
- }, undefined, false, undefined, this);
242
+ children: [
243
+ preloads.map(({ href }) => /* @__PURE__ */ jsxDEV("link", {
244
+ rel: "modulepreload",
245
+ crossorigin: "",
246
+ href
247
+ }, undefined, false, undefined, this)),
248
+ finalScripts.map(({ src }) => /* @__PURE__ */ jsxDEV("script", {
249
+ type: "module",
250
+ src
251
+ }, undefined, false, undefined, this))
252
+ ]
253
+ }, undefined, true, undefined, this);
257
254
  } catch {
258
255
  return null;
259
256
  }
260
257
  }
258
+ function registerComponentScripts(urls) {
259
+ try {
260
+ const c = useRequestContext3();
261
+ const scripts = c.get("bfCollectedScripts") || [];
262
+ const outputScripts = c.get("bfOutputScripts") || new Set;
263
+ const rendered = c.get("bfScriptsRendered");
264
+ const inline = [];
265
+ for (const src of urls) {
266
+ if (outputScripts.has(src))
267
+ continue;
268
+ outputScripts.add(src);
269
+ if (rendered)
270
+ inline.push(src);
271
+ else
272
+ scripts.push({ src });
273
+ }
274
+ c.set("bfCollectedScripts", scripts);
275
+ c.set("bfOutputScripts", outputScripts);
276
+ return inline;
277
+ } catch {
278
+ return [];
279
+ }
280
+ }
281
+ function registerComponentPreloads(urls) {
282
+ try {
283
+ const c = useRequestContext3();
284
+ const preloads = c.get("bfCollectedPreloads") || [];
285
+ const outputPreloads = c.get("bfOutputPreloads") || new Set;
286
+ const rendered = c.get("bfScriptsRendered");
287
+ const inline = [];
288
+ for (const href of urls) {
289
+ if (outputPreloads.has(href))
290
+ continue;
291
+ outputPreloads.add(href);
292
+ if (rendered)
293
+ inline.push(href);
294
+ else
295
+ preloads.push({ href });
296
+ }
297
+ c.set("bfCollectedPreloads", preloads);
298
+ c.set("bfOutputPreloads", outputPreloads);
299
+ return inline;
300
+ } catch {
301
+ return [];
302
+ }
303
+ }
304
+ function wrapWithInlineScripts(jsx, inlineScripts, inlinePreloads = []) {
305
+ if (inlineScripts.length === 0 && inlinePreloads.length === 0)
306
+ return jsx;
307
+ return /* @__PURE__ */ jsxDEV(Fragment, {
308
+ children: [
309
+ inlinePreloads.map((href) => /* @__PURE__ */ jsxDEV("link", {
310
+ rel: "modulepreload",
311
+ crossorigin: "",
312
+ href
313
+ }, undefined, false, undefined, this)),
314
+ jsx,
315
+ inlineScripts.map((src) => /* @__PURE__ */ jsxDEV("script", {
316
+ type: "module",
317
+ src
318
+ }, undefined, false, undefined, this))
319
+ ]
320
+ }, undefined, true, undefined, this);
321
+ }
261
322
  function collectStubDepScripts(manifest, base, roots, excluded) {
262
323
  const result = new Map;
263
324
  const prefix = base.endsWith("/") ? base : base + "/";
@@ -286,6 +347,9 @@ function collectStubDepScripts(manifest, base, roots, excluded) {
286
347
  return result;
287
348
  }
288
349
  export {
350
+ wrapWithInlineScripts,
351
+ registerComponentScripts,
352
+ registerComponentPreloads,
289
353
  collectStubDepScripts,
290
354
  BfScripts2 as BfScripts
291
355
  };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { HonoAdapterOptions } from './adapter/index.ts';
3
+ export interface HonoViteOptions {
4
+ /** Source directories to scan for `.tsx` components, relative to the
5
+ * Vite project root (or absolute). */
6
+ components: string[];
7
+ /** Where compiled SSR templates (and `ssrDefaults`) land — relative to
8
+ * the Vite project root (or absolute). This is a backend source
9
+ * directory wrangler/bun's own bundler reads, NOT `build.outDir` (Vite's
10
+ * client-asset output). */
11
+ templates: string;
12
+ /** Adapter-specific options passed to `HonoAdapter` (e.g. `clientJsFilename`). */
13
+ adapterOptions?: HonoAdapterOptions;
14
+ /**
15
+ * Extra, non-component script entries whose Vite-resolved URL (dev:
16
+ * origin-based; production: content-hashed manifest path) should be
17
+ * exposed to the SSR app as a generated `Assets` map — e.g. a
18
+ * hand-written client bootstrap script that isn't a `.tsx` component, so
19
+ * it never goes through core's discovery/`scriptAssets` machinery, but
20
+ * still needs a `<script src="...">` URL only knowable after bundling.
21
+ *
22
+ * Keyed by the identifier the resolved URL should appear under in the
23
+ * generated map; values are entry paths relative to the Vite project
24
+ * root. You must ALSO register the same path as a Rollup entry yourself
25
+ * via stock `build.rollupOptions.input` — this plugin never adds
26
+ * bundling configuration on your behalf; this option only resolves the
27
+ * URL Vite already bundled it to, it doesn't request the bundling.
28
+ */
29
+ assets?: Record<string, string>;
30
+ /** Output path for the generated asset-map TS module, relative to the
31
+ * Vite project root. Default: 'dist/bf-assets.ts'. Ignored when `assets`
32
+ * is empty. */
33
+ assetsOutputFile?: string;
34
+ }
35
+ export declare function barefoot(options: HonoViteOptions): Plugin[];
36
+ export { barefoot as default };
37
+ //# sourceMappingURL=vite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAiDA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAA;AAKjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAE5D,MAAM,WAAW,eAAe;IAC9B;0CACsC;IACtC,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB;;;+BAG2B;IAC3B,SAAS,EAAE,MAAM,CAAA;IACjB,kFAAkF;IAClF,cAAc,CAAC,EAAE,kBAAkB,CAAA;IACnC;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B;;mBAEe;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAoFD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,EAAE,CAoC3D;AAED,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,CAAA"}