@barefootjs/hono 0.31.0 → 0.31.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/scripts.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JSX } from 'hono/jsx/jsx-runtime';
|
|
1
2
|
import { type BarefootBuildManifest } from './app.ts';
|
|
2
3
|
export type CollectedScript = {
|
|
3
4
|
src: string;
|
|
@@ -51,7 +52,7 @@ export interface BfScriptsProps {
|
|
|
51
52
|
* will check this flag and output their scripts inline instead of
|
|
52
53
|
* collecting them here.
|
|
53
54
|
*/
|
|
54
|
-
export declare function BfScripts(props?: BfScriptsProps):
|
|
55
|
+
export declare function BfScripts(props?: BfScriptsProps): JSX.Element | null;
|
|
55
56
|
/**
|
|
56
57
|
* Register `urls` (a component's resolved script URLs for THIS render) into
|
|
57
58
|
* the same request-context collector `BfScripts` reads, and return the
|
|
@@ -124,7 +125,7 @@ export declare function registerComponentPreloads(urls: string[]): string[];
|
|
|
124
125
|
* only ever pass `inlineScripts` (a component with `scriptAssets` but no
|
|
125
126
|
* `preloadAssets`) keep compiling and behaving exactly as before.
|
|
126
127
|
*/
|
|
127
|
-
export declare function wrapWithInlineScripts(jsx: unknown, inlineScripts: string[], inlinePreloads?: string[]):
|
|
128
|
+
export declare function wrapWithInlineScripts(jsx: unknown, inlineScripts: string[], inlinePreloads?: string[]): JSX.Element;
|
|
128
129
|
/**
|
|
129
130
|
* Walk stub-rewrite edges from each manifest entry in `roots`,
|
|
130
131
|
* returning the script URLs for every transitively reachable
|
package/dist/scripts.d.ts.map
CHANGED
|
@@ -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,C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E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,EAAE,cAAc,GAAE,MAAM,EAAO,GAAG,GAAG,CAAC,OAAO,CASvH;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/hono",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.1",
|
|
4
4
|
"description": "Hono integration for BarefootJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
124
|
"@barefootjs/adapter-tests": "0.1.0",
|
|
125
|
-
"@barefootjs/vite": "0.31.
|
|
125
|
+
"@barefootjs/vite": "0.31.1",
|
|
126
126
|
"@types/jsdom": "^27.0.0",
|
|
127
127
|
"hono": "^4.6.0",
|
|
128
128
|
"jsdom": "^27.3.0",
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression for piconic-ai/barefootjs#2559: type-check a CONSUMER program
|
|
3
|
+
* that imports a compiled template — the coverage gap that let
|
|
4
|
+
* `wrapWithInlineScripts`'s `unknown` return ship. Every generated
|
|
5
|
+
* component returns that call as its body, so an `unknown` return made
|
|
6
|
+
* every island fail TS2786 ("cannot be used as a JSX component") in any
|
|
7
|
+
* type-checking consumer (hit by sora's 0.26.2 → 0.31.0 migration), while
|
|
8
|
+
* nothing in-repo ever ran tsc over a program shaped like a consumer app.
|
|
9
|
+
*
|
|
10
|
+
* The test compiles a real `'use client'` component with a non-empty
|
|
11
|
+
* `scriptAssets` (so the emitted template wraps its return in
|
|
12
|
+
* `wrapWithInlineScripts`), writes it plus a scaffold-shaped `server.tsx`
|
|
13
|
+
* that renders the island, and type-checks the pair with the scaffold's
|
|
14
|
+
* own options (`strict`, `jsxImportSource: '@barefootjs/hono/jsx'`).
|
|
15
|
+
*/
|
|
16
|
+
import { describe, expect, test } from 'bun:test'
|
|
17
|
+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
18
|
+
import { join, resolve } from 'node:path'
|
|
19
|
+
import ts from 'typescript'
|
|
20
|
+
import { compileJSX } from '@barefootjs/jsx'
|
|
21
|
+
import { HonoAdapter } from '../adapter/index.ts'
|
|
22
|
+
|
|
23
|
+
const HERE = resolve(import.meta.dir)
|
|
24
|
+
|
|
25
|
+
const COMPONENT_SOURCE = `"use client"
|
|
26
|
+
|
|
27
|
+
import { createSignal } from '@barefootjs/client'
|
|
28
|
+
|
|
29
|
+
export function Counter() {
|
|
30
|
+
const [count, setCount] = createSignal(0)
|
|
31
|
+
return <button onClick={() => setCount(count() + 1)}>{count()}</button>
|
|
32
|
+
}
|
|
33
|
+
`
|
|
34
|
+
|
|
35
|
+
const SERVER_SOURCE = `import { Counter } from './components/Counter.tsx'
|
|
36
|
+
|
|
37
|
+
export function Page() {
|
|
38
|
+
return (
|
|
39
|
+
<div>
|
|
40
|
+
<Counter />
|
|
41
|
+
</div>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
`
|
|
45
|
+
|
|
46
|
+
describe('consumer program type-check (#2559)', () => {
|
|
47
|
+
test('a compiled template used as a JSX component type-checks clean', () => {
|
|
48
|
+
const result = compileJSX(COMPONENT_SOURCE, '/virtual/Counter.tsx', {
|
|
49
|
+
adapter: new HonoAdapter(),
|
|
50
|
+
// Non-empty so the emitted template's component body returns
|
|
51
|
+
// wrapWithInlineScripts(...) — the #2559 shape.
|
|
52
|
+
scriptAssets: ['/static/components/assets/Counter.js'],
|
|
53
|
+
})
|
|
54
|
+
expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
|
|
55
|
+
const template = result.files.find(f => f.type === 'markedTemplate')?.content
|
|
56
|
+
expect(template).toContain('wrapWithInlineScripts(')
|
|
57
|
+
|
|
58
|
+
// Inside the package so module resolution reaches the workspace's
|
|
59
|
+
// node_modules (hono, @barefootjs/*) exactly like a scaffolded app's.
|
|
60
|
+
const tmp = mkdtempSync(join(HERE, '.consumer-typecheck-'))
|
|
61
|
+
try {
|
|
62
|
+
mkdirSync(join(tmp, 'components'), { recursive: true })
|
|
63
|
+
writeFileSync(join(tmp, 'components', 'Counter.tsx'), template!)
|
|
64
|
+
writeFileSync(join(tmp, 'server.tsx'), SERVER_SOURCE)
|
|
65
|
+
|
|
66
|
+
const program = ts.createProgram(
|
|
67
|
+
[join(tmp, 'server.tsx')],
|
|
68
|
+
{
|
|
69
|
+
strict: true,
|
|
70
|
+
noEmit: true,
|
|
71
|
+
target: ts.ScriptTarget.ESNext,
|
|
72
|
+
module: ts.ModuleKind.ESNext,
|
|
73
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
74
|
+
jsx: ts.JsxEmit.ReactJSX,
|
|
75
|
+
jsxImportSource: '@barefootjs/hono/jsx',
|
|
76
|
+
lib: ['lib.esnext.d.ts', 'lib.dom.d.ts'],
|
|
77
|
+
allowImportingTsExtensions: true,
|
|
78
|
+
// Consumer apps skipLibCheck too; TS2786 fires in OUR files
|
|
79
|
+
// regardless, which is exactly what this test pins.
|
|
80
|
+
skipLibCheck: true,
|
|
81
|
+
},
|
|
82
|
+
)
|
|
83
|
+
const diagnostics = ts.getPreEmitDiagnostics(program).map(d => ({
|
|
84
|
+
code: d.code,
|
|
85
|
+
file: d.file?.fileName ?? '',
|
|
86
|
+
message: ts.flattenDiagnosticMessageText(d.messageText, ' '),
|
|
87
|
+
}))
|
|
88
|
+
|
|
89
|
+
// TS2786 = "'X' cannot be used as a JSX component." — the #2559
|
|
90
|
+
// failure. Assert none anywhere in the consumer program.
|
|
91
|
+
expect(diagnostics.filter(d => d.code === 2786)).toEqual([])
|
|
92
|
+
} finally {
|
|
93
|
+
rmSync(tmp, { recursive: true, force: true })
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
})
|
package/src/scripts.tsx
CHANGED
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
|
|
41
41
|
import { useRequestContext } from 'hono/jsx-renderer'
|
|
42
42
|
import { Fragment } from 'hono/jsx'
|
|
43
|
+
import type { JSX } from 'hono/jsx/jsx-runtime'
|
|
43
44
|
import { relPathFromComponentsBase, type BarefootBuildManifest } from './app.ts'
|
|
44
45
|
|
|
45
46
|
export type CollectedScript = {
|
|
@@ -284,8 +285,8 @@ export function registerComponentPreloads(urls: string[]): string[] {
|
|
|
284
285
|
* only ever pass `inlineScripts` (a component with `scriptAssets` but no
|
|
285
286
|
* `preloadAssets`) keep compiling and behaving exactly as before.
|
|
286
287
|
*/
|
|
287
|
-
export function wrapWithInlineScripts(jsx: unknown, inlineScripts: string[], inlinePreloads: string[] = []) {
|
|
288
|
-
if (inlineScripts.length === 0 && inlinePreloads.length === 0) return jsx
|
|
288
|
+
export function wrapWithInlineScripts(jsx: unknown, inlineScripts: string[], inlinePreloads: string[] = []): JSX.Element {
|
|
289
|
+
if (inlineScripts.length === 0 && inlinePreloads.length === 0) return jsx as JSX.Element
|
|
289
290
|
return (
|
|
290
291
|
<Fragment>
|
|
291
292
|
{inlinePreloads.map(href => <link rel="modulepreload" crossorigin="" href={href} />)}
|