brustjs 0.1.36-alpha → 0.1.37-alpha
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/example/pokedex/app.css +11 -0
- package/example/pokedex/components/AppLayout.tsx +3 -1
- package/example/pokedex/components/TeamBuilder.module.css +47 -0
- package/example/pokedex/components/TeamBuilder.tsx +11 -2
- package/example/pokedex/components/ThemeToggle.tsx +7 -5
- package/example/pokedex/lib/loaders.ts +26 -11
- package/example/pokedex/lib/types.ts +1 -0
- package/example/pokedex/pages/TypeChart.tsx +17 -13
- package/package.json +7 -7
- package/runtime/cli/build.ts +65 -35
- package/runtime/cli/templates/minimal/package.json.tmpl +1 -0
- package/runtime/cli/templates.ts +1 -0
- package/runtime/css/component-build.ts +13 -5
- package/runtime/css/route-deps.ts +26 -11
- package/runtime/css-modules.d.ts +17 -0
- package/runtime/index.js +52 -52
- package/runtime/index.ts +38 -12
- package/runtime/islands/bootstrap.ts +16 -1
- package/runtime/islands/build.ts +46 -5
- package/runtime/routes.ts +16 -0
package/example/pokedex/app.css
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
@import "tailwindcss";
|
|
2
2
|
@source "./**/*.{tsx,ts}";
|
|
3
3
|
@custom-variant dark (&:where([data-mode="dark"], [data-mode="dark"] *));
|
|
4
|
+
|
|
5
|
+
/* Theme-toggle icons: hide the wrong icon at SSR time via the server-rendered
|
|
6
|
+
<html data-mode> ancestor, so there's no flash before x-show hydrates. After
|
|
7
|
+
mount, x-show sets inline display (which wins over these stylesheet rules). */
|
|
8
|
+
[data-mode="light"] .theme-icon-dark { display: none; }
|
|
9
|
+
[data-mode="dark"] .theme-icon-light { display: none; }
|
|
10
|
+
|
|
4
11
|
@theme {
|
|
5
12
|
--color-brand-50: oklch(0.97 0.02 264);
|
|
6
13
|
--color-brand-500: oklch(0.55 0.20 264);
|
|
7
14
|
--color-brand-600: oklch(0.49 0.20 264);
|
|
8
15
|
--color-brand-700: oklch(0.43 0.19 264);
|
|
9
16
|
}
|
|
17
|
+
|
|
18
|
+
button {
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
}
|
|
@@ -21,10 +21,12 @@ export default function AppLayout({
|
|
|
21
21
|
title,
|
|
22
22
|
teamProps,
|
|
23
23
|
mode,
|
|
24
|
+
themeLabel,
|
|
24
25
|
}: {
|
|
25
26
|
title: string
|
|
26
27
|
teamProps: { teamInitial: TeamMember[] }
|
|
27
28
|
mode: 'dark' | 'light'
|
|
29
|
+
themeLabel: string
|
|
28
30
|
}) {
|
|
29
31
|
return (
|
|
30
32
|
<BrustPage
|
|
@@ -48,7 +50,7 @@ export default function AppLayout({
|
|
|
48
50
|
<NavLink native href="/pokedex" label="Pokédex" />
|
|
49
51
|
<NavLink native href="/type-chart" label="Type chart" />
|
|
50
52
|
<div className="ml-auto flex items-center gap-2">
|
|
51
|
-
<ThemeToggle native />
|
|
53
|
+
<ThemeToggle native themeLabel={themeLabel} />
|
|
52
54
|
{/* Team dock opens via the TeamBuilder island's own floating trigger
|
|
53
55
|
(the island owns its open state). A navbar button here would be a
|
|
54
56
|
dead affordance — cross-chunk toggle wiring is out of scope. */}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* CSS Modules use-case (dogfood).
|
|
2
|
+
*
|
|
3
|
+
* brust runs every co-located `.module.css` through Lightning CSS at build:
|
|
4
|
+
* class + @keyframes names are scoped to `<name>_<hash>` and emitted as a
|
|
5
|
+
* per-component chunk under `dist/css/components/<sha8>.css`. The chunk is
|
|
6
|
+
* linked into the page <head> via the component-CSS manifest (route → chunks),
|
|
7
|
+
* and `import styles from './TeamBuilder.module.css'` resolves to the
|
|
8
|
+
* original→hashed name map through brust's Bun.plugin — so `styles.panel`
|
|
9
|
+
* is the scoped class string at runtime.
|
|
10
|
+
*
|
|
11
|
+
* This is for things Tailwind utilities express awkwardly: keyframe entrance
|
|
12
|
+
* animations + pseudo-elements, scoped to this island. Plain CSS only — the
|
|
13
|
+
* component-CSS pass runs without Tailwind, so no `@apply` here. */
|
|
14
|
+
|
|
15
|
+
/* Roster panel: rise + fade in when the dock opens. */
|
|
16
|
+
.panel {
|
|
17
|
+
animation: rise 0.18s ease-out;
|
|
18
|
+
transform-origin: bottom right;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@keyframes rise {
|
|
22
|
+
from {
|
|
23
|
+
opacity: 0;
|
|
24
|
+
transform: translateY(0.5rem) scale(0.98);
|
|
25
|
+
}
|
|
26
|
+
to {
|
|
27
|
+
opacity: 1;
|
|
28
|
+
transform: translateY(0) scale(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Count badge on the floating trigger: a quick pop on (re)mount. */
|
|
33
|
+
.badge {
|
|
34
|
+
animation: pop 0.22s ease-out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@keyframes pop {
|
|
38
|
+
0% {
|
|
39
|
+
transform: scale(0.6);
|
|
40
|
+
}
|
|
41
|
+
60% {
|
|
42
|
+
transform: scale(1.15);
|
|
43
|
+
}
|
|
44
|
+
100% {
|
|
45
|
+
transform: scale(1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -10,6 +10,10 @@ import { client, useStore } from 'brustjs/client'
|
|
|
10
10
|
import type { Actions } from '../actions'
|
|
11
11
|
import type { TeamMember } from '../lib/types'
|
|
12
12
|
import { teamStore } from '../stores/team'
|
|
13
|
+
// CSS Modules: scoped class + keyframe names; resolves to the hashed-name map
|
|
14
|
+
// via brust's Bun.plugin. The chunk is linked per-route from the component-CSS
|
|
15
|
+
// manifest (see routes.tsx for the route→chunk linking note).
|
|
16
|
+
import styles from './TeamBuilder.module.css'
|
|
13
17
|
|
|
14
18
|
const api = client<Actions>()
|
|
15
19
|
const MAX = 6
|
|
@@ -47,7 +51,9 @@ export default function TeamBuilder({ teamInitial }: { teamInitial: TeamMember[]
|
|
|
47
51
|
return (
|
|
48
52
|
<div className="fixed bottom-5 right-5 z-[200]">
|
|
49
53
|
{open && (
|
|
50
|
-
<div
|
|
54
|
+
<div
|
|
55
|
+
className={`mb-3 w-80 overflow-hidden rounded-xl border border-slate-200 bg-white shadow-2xl dark:border-slate-700 dark:bg-slate-900 ${styles.panel}`}
|
|
56
|
+
>
|
|
51
57
|
<div className="h-1 bg-brand-500" />
|
|
52
58
|
<div className="flex items-center gap-2 border-b border-slate-100 px-4 py-3 dark:border-slate-800">
|
|
53
59
|
<Users size={16} className="text-brand-500" />
|
|
@@ -132,7 +138,10 @@ export default function TeamBuilder({ teamInitial }: { teamInitial: TeamMember[]
|
|
|
132
138
|
>
|
|
133
139
|
<Users size={16} />
|
|
134
140
|
My team
|
|
135
|
-
<span
|
|
141
|
+
<span
|
|
142
|
+
key={team.length}
|
|
143
|
+
className={`rounded-full bg-white/25 px-2 py-0.5 text-xs font-extrabold ${styles.badge}`}
|
|
144
|
+
>
|
|
136
145
|
{team.length}
|
|
137
146
|
</span>
|
|
138
147
|
</button>
|
|
@@ -40,8 +40,10 @@ export const behavior = () => {
|
|
|
40
40
|
|
|
41
41
|
// default → jinja (server). The x-* directives are static string attributes the
|
|
42
42
|
// native compiler passes straight through; the directive runtime binds them to
|
|
43
|
-
// the behavior instance on the client.
|
|
44
|
-
|
|
43
|
+
// the behavior instance on the client. `themeLabel` is server-stamped (the
|
|
44
|
+
// inverse of the active mode) so the x-text placeholder already shows the right
|
|
45
|
+
// word — no Dark→Light flash before the behavior hydrates.
|
|
46
|
+
export default function ThemeToggle({ themeLabel }: { themeLabel: string }) {
|
|
45
47
|
return (
|
|
46
48
|
<button
|
|
47
49
|
type="button"
|
|
@@ -49,13 +51,13 @@ export default function ThemeToggle() {
|
|
|
49
51
|
aria-label="Toggle theme"
|
|
50
52
|
className="inline-flex items-center gap-1.5 rounded-lg border border-slate-200 px-3 py-1.5 text-sm font-medium text-slate-700 transition-colors hover:bg-slate-100 dark:border-slate-700 dark:text-slate-200 dark:hover:bg-slate-800"
|
|
51
53
|
>
|
|
52
|
-
<span x-show="isDark" className="inline-flex">
|
|
54
|
+
<span x-show="isDark" className="theme-icon-dark inline-flex">
|
|
53
55
|
<Sun size={16} />
|
|
54
56
|
</span>
|
|
55
|
-
<span x-show="isLight" className="inline-flex">
|
|
57
|
+
<span x-show="isLight" className="theme-icon-light inline-flex">
|
|
56
58
|
<Moon size={16} />
|
|
57
59
|
</span>
|
|
58
|
-
<span x-text="label">
|
|
60
|
+
<span x-text="label">{themeLabel}</span>
|
|
59
61
|
</button>
|
|
60
62
|
)
|
|
61
63
|
}
|
|
@@ -50,12 +50,17 @@ interface LoaderCtx {
|
|
|
50
50
|
req: BrustRequest
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const chrome = (req: BrustRequest, title: string, crumb: string) =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
const chrome = (req: BrustRequest, title: string, crumb: string) => {
|
|
54
|
+
const mode = (req.cookies.mode === 'light' ? 'light' : 'dark') as 'light' | 'dark'
|
|
55
|
+
return {
|
|
56
|
+
title,
|
|
57
|
+
crumb,
|
|
58
|
+
mode,
|
|
59
|
+
// The toggle button shows what it switches TO — the inverse of the active mode.
|
|
60
|
+
themeLabel: mode === 'dark' ? 'Light' : 'Dark',
|
|
61
|
+
teamProps: { teamInitial: teamStore.list() },
|
|
62
|
+
}
|
|
63
|
+
}
|
|
59
64
|
|
|
60
65
|
export async function homeLoader({ req }: LoaderCtx): Promise<HomeData> {
|
|
61
66
|
const featured = FEATURED.map((p) => ({
|
|
@@ -251,15 +256,25 @@ const SHORT: Record<string, string> = {
|
|
|
251
256
|
// Effectiveness → static Tailwind utility class string. These are literals in a
|
|
252
257
|
// .ts file scanned by `@source`, so the scanner sees every class. The header /
|
|
253
258
|
// row-head / corner / data cells share a base sizing class.
|
|
259
|
+
// Effectiveness → static Tailwind utility class string. Every cell gets a solid
|
|
260
|
+
// fill so the `gap-px` over a slate gridline background reads as a continuous
|
|
261
|
+
// grid (the old design left 1× cells transparent → black voids you couldn't
|
|
262
|
+
// trace). `hover:` lifts a cell with an inset brand ring to pinpoint a matchup.
|
|
254
263
|
const CELL_BASE =
|
|
255
|
-
'flex items-center justify-center text-xs font-
|
|
264
|
+
'flex items-center justify-center text-xs font-bold tabular-nums aspect-square transition-colors hover:relative hover:z-10 hover:ring-2 hover:ring-inset hover:ring-brand-500'
|
|
256
265
|
const HEAD_BASE =
|
|
257
266
|
'flex items-center justify-center text-[10px] font-bold uppercase tracking-tight text-white aspect-square'
|
|
267
|
+
// Fill hierarchy so the grid reads as FULL (every cell visibly distinct from
|
|
268
|
+
// the slate gridline showing through `gap-px`):
|
|
269
|
+
// light: card white < gridline slate-200, normal slate-50, 0 slate-800
|
|
270
|
+
// dark: card slate-900 < gridline slate-700, normal slate-800, 0 slate-950
|
|
271
|
+
// (normal must NOT equal the card colour or cells vanish; 0 must differ from
|
|
272
|
+
// normal or "no effect" looks like a blank.)
|
|
258
273
|
const CELL_CLASS: Record<string, string> = {
|
|
259
|
-
super: `${CELL_BASE} bg-
|
|
260
|
-
weak: `${CELL_BASE} bg-
|
|
261
|
-
none: `${CELL_BASE} bg-slate-800
|
|
262
|
-
normal: `${CELL_BASE} text-slate-300 dark:text-slate-600`,
|
|
274
|
+
super: `${CELL_BASE} bg-emerald-500 text-white`,
|
|
275
|
+
weak: `${CELL_BASE} bg-rose-400 text-white dark:bg-rose-500`,
|
|
276
|
+
none: `${CELL_BASE} bg-slate-800 text-slate-100 dark:bg-slate-950 dark:text-slate-400`,
|
|
277
|
+
normal: `${CELL_BASE} bg-slate-50 text-slate-300 dark:bg-slate-800 dark:text-slate-600`,
|
|
263
278
|
}
|
|
264
279
|
|
|
265
280
|
export async function typeChartLoader({ req }: LoaderCtx): Promise<TypeChartData> {
|
|
@@ -23,6 +23,7 @@ export interface ChromeData {
|
|
|
23
23
|
title: string // dynamic <title> + nav header, via AppLayout's <BrustPage title={title}>
|
|
24
24
|
crumb: string // topbar breadcrumb leaf label
|
|
25
25
|
mode: 'dark' | 'light' // theme, read from the `mode` cookie → <html data-mode={mode}>
|
|
26
|
+
themeLabel: string // server-stamped toggle label ("Light"/"Dark"), the inverse of mode — SSR placeholder for ThemeToggle's x-text so it doesn't flash
|
|
26
27
|
teamProps: { teamInitial: TeamMember[] } // floating team-dock island initial state
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -14,39 +14,43 @@ import type { TypeChartData } from '../lib/types'
|
|
|
14
14
|
export default function TypeChart({ rows }: TypeChartData) {
|
|
15
15
|
return (
|
|
16
16
|
<section className="py-2">
|
|
17
|
-
<div className="mb-
|
|
17
|
+
<div className="mb-6">
|
|
18
18
|
<h1 className="text-3xl font-extrabold tracking-tight text-slate-900 dark:text-white">
|
|
19
19
|
Type chart
|
|
20
20
|
</h1>
|
|
21
|
-
<p className="mt-2 max-w-2xl text-slate-500 dark:text-slate-400">
|
|
22
|
-
Damage relations —
|
|
23
|
-
(native:true · no React runtime in the payload).
|
|
21
|
+
<p className="mt-2 max-w-2xl text-sm leading-relaxed text-slate-500 dark:text-slate-400">
|
|
22
|
+
Damage relations — read a row (attacker) across to a column (defender). Rendered
|
|
23
|
+
server-side in Rust from jinja (native:true · no React runtime in the payload).
|
|
24
24
|
</p>
|
|
25
25
|
</div>
|
|
26
26
|
|
|
27
|
-
<div className="mb-
|
|
28
|
-
<span className="inline-flex items-center gap-1
|
|
29
|
-
<span className="flex h-5 w-5 items-center justify-center rounded bg-
|
|
27
|
+
<div className="mb-5 flex flex-wrap items-center gap-2.5 text-sm">
|
|
28
|
+
<span className="inline-flex items-center gap-2 rounded-full border border-slate-200 bg-white px-3 py-1 text-slate-600 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300">
|
|
29
|
+
<span className="flex h-5 w-5 items-center justify-center rounded bg-emerald-500 text-xs font-bold text-white">
|
|
30
30
|
2
|
|
31
31
|
</span>
|
|
32
32
|
super effective
|
|
33
33
|
</span>
|
|
34
|
-
<span className="inline-flex items-center gap-1
|
|
35
|
-
<span className="flex h-5 w-5 items-center justify-center rounded bg-
|
|
34
|
+
<span className="inline-flex items-center gap-2 rounded-full border border-slate-200 bg-white px-3 py-1 text-slate-600 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300">
|
|
35
|
+
<span className="flex h-5 w-5 items-center justify-center rounded bg-rose-400 text-xs font-bold text-white dark:bg-rose-500">
|
|
36
36
|
½
|
|
37
37
|
</span>
|
|
38
38
|
not very effective
|
|
39
39
|
</span>
|
|
40
|
-
<span className="inline-flex items-center gap-1
|
|
41
|
-
<span className="flex h-5 w-5 items-center justify-center rounded bg-slate-800
|
|
40
|
+
<span className="inline-flex items-center gap-2 rounded-full border border-slate-200 bg-white px-3 py-1 text-slate-600 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300">
|
|
41
|
+
<span className="flex h-5 w-5 items-center justify-center rounded bg-slate-800 text-xs font-bold text-slate-100 dark:bg-slate-950 dark:text-slate-400">
|
|
42
42
|
0
|
|
43
43
|
</span>
|
|
44
44
|
no effect
|
|
45
45
|
</span>
|
|
46
|
+
<span className="inline-flex items-center gap-2 rounded-full border border-slate-200 bg-white px-3 py-1 text-slate-600 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300">
|
|
47
|
+
<span className="h-5 w-5 rounded bg-slate-50 ring-1 ring-slate-200 dark:bg-slate-800 dark:ring-slate-700" />
|
|
48
|
+
normal (1×)
|
|
49
|
+
</span>
|
|
46
50
|
</div>
|
|
47
51
|
|
|
48
|
-
<div className="overflow-x-auto rounded-2xl border border-slate-200 bg-white p-
|
|
49
|
-
<div className="grid w-
|
|
52
|
+
<div className="overflow-x-auto rounded-2xl border border-slate-200 bg-white p-3 shadow-sm dark:border-slate-800 dark:bg-slate-900">
|
|
53
|
+
<div className="grid w-full grid-cols-[2.75rem_repeat(18,minmax(1.75rem,1fr))] gap-px overflow-hidden rounded-xl bg-slate-200 dark:bg-slate-700">
|
|
50
54
|
{rows.map((r) => (
|
|
51
55
|
<div key={r.id} className="contents">
|
|
52
56
|
{r.cells.map((c) => (
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brustjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.37-alpha",
|
|
4
4
|
"description": "Bun + Rust SSR framework — React on the server, Rust everywhere else (napi cdylib + per-worker SharedArrayBuffer).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"typescript": "^6.0.3"
|
|
41
41
|
},
|
|
42
42
|
"optionalDependencies": {
|
|
43
|
-
"brustjs-darwin-x64": "0.1.
|
|
44
|
-
"brustjs-darwin-arm64": "0.1.
|
|
45
|
-
"brustjs-linux-x64-gnu": "0.1.
|
|
46
|
-
"brustjs-linux-arm64-gnu": "0.1.
|
|
47
|
-
"brustjs-linux-x64-musl": "0.1.
|
|
48
|
-
"brustjs-linux-arm64-musl": "0.1.
|
|
43
|
+
"brustjs-darwin-x64": "0.1.37-alpha",
|
|
44
|
+
"brustjs-darwin-arm64": "0.1.37-alpha",
|
|
45
|
+
"brustjs-linux-x64-gnu": "0.1.37-alpha",
|
|
46
|
+
"brustjs-linux-arm64-gnu": "0.1.37-alpha",
|
|
47
|
+
"brustjs-linux-x64-musl": "0.1.37-alpha",
|
|
48
|
+
"brustjs-linux-arm64-musl": "0.1.37-alpha"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"react": "^19.2.6",
|
package/runtime/cli/build.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync } from 'node:fs'
|
|
|
2
2
|
import { copyFile, cp, mkdir, readdir, rm } from 'node:fs/promises'
|
|
3
3
|
import { createRequire } from 'node:module'
|
|
4
4
|
import path, { isAbsolute, resolve } from 'node:path'
|
|
5
|
+
import type { BunPlugin } from 'bun'
|
|
5
6
|
import { emitNativeTemplates } from './native-routes-emit.ts'
|
|
6
7
|
import { nativeShimPlugin } from './native-shim-plugin.ts'
|
|
7
8
|
|
|
@@ -223,6 +224,60 @@ export async function runBuild(args: string[]): Promise<void> {
|
|
|
223
224
|
// (S4). Computed once here and reused below.
|
|
224
225
|
const routesFile = path.join(entryDir, 'routes.tsx')
|
|
225
226
|
|
|
227
|
+
// 2.7. Component CSS — Lightning CSS + CSS Modules. MUST run BEFORE the island
|
|
228
|
+
// and directive bundles: those Bun.build passes bundle components that may
|
|
229
|
+
// `import styles from './X.module.css'`, and the cssLoaderPlugin registered
|
|
230
|
+
// here (from the freshly built manifest) resolves that import to the scoped
|
|
231
|
+
// name map. Without the plugin Bun treats the .module.css as an asset and
|
|
232
|
+
// collides on the output filename (e.g. X.module.css + X.tsx → both X.js).
|
|
233
|
+
// Mirrors brust.run's ordering (plugin registered before buildIslands).
|
|
234
|
+
// Captured here and passed explicitly to buildIslands below (global
|
|
235
|
+
// Bun.plugin() does NOT reach Bun.build).
|
|
236
|
+
const cssBuildPlugins: BunPlugin[] = []
|
|
237
|
+
{
|
|
238
|
+
const { scanCssImports } = await import('../css/scan-imports.ts')
|
|
239
|
+
const scan = await scanCssImports(entryDir)
|
|
240
|
+
if (scan.size > 0) {
|
|
241
|
+
const { buildComponentCss } = await import('../css/component-build.ts')
|
|
242
|
+
const { cssLoaderPlugin } = await import('../css/component-loader.ts')
|
|
243
|
+
let routeForCss: { fullPath: string; componentSources: string[] }[] = []
|
|
244
|
+
if (existsSync(routesFile)) {
|
|
245
|
+
try {
|
|
246
|
+
const { scanImports } = await import('./native-routes-emit.ts')
|
|
247
|
+
const { routes } = await import(routesFile)
|
|
248
|
+
// component name → source file (default imports in routes.tsx).
|
|
249
|
+
const idents = scanImports(routesFile)
|
|
250
|
+
routeForCss = (routes as any[]).map((r) => ({
|
|
251
|
+
fullPath: r.fullPath,
|
|
252
|
+
// Resolve each component in the route's chain (layout → leaf) to its
|
|
253
|
+
// source; computeRouteChunks BFS-walks each subtree for CSS deps.
|
|
254
|
+
componentSources: ((r.chain ?? []) as { Component?: { name?: string } }[])
|
|
255
|
+
.map((node) => node?.Component?.name)
|
|
256
|
+
.map((name) => (name ? idents.get(name) : undefined))
|
|
257
|
+
.filter((p): p is string => typeof p === 'string'),
|
|
258
|
+
}))
|
|
259
|
+
} catch {
|
|
260
|
+
/* if routes import fails, skip — manifest still emits modules */
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const cssOutDir = path.join(outDir, 'css')
|
|
264
|
+
const manifest = await buildComponentCss({
|
|
265
|
+
scanRoot: entryDir,
|
|
266
|
+
outDir: cssOutDir,
|
|
267
|
+
tailwindCompile: null,
|
|
268
|
+
routes: routeForCss,
|
|
269
|
+
})
|
|
270
|
+
const plugin = cssLoaderPlugin(manifest)
|
|
271
|
+
Bun.plugin(plugin) // runtime/SSR resolution of .module.css in the worker isolate
|
|
272
|
+
cssBuildPlugins.push(plugin) // explicit Bun.build resolution for island bundling
|
|
273
|
+
console.log(
|
|
274
|
+
`[brust build] css-mod: ${Object.keys(manifest.modules).length} chunk(s) → ${cssOutDir}/components/`,
|
|
275
|
+
)
|
|
276
|
+
} else {
|
|
277
|
+
console.log(`[brust build] css-mod: skipped (no component CSS imports)`)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
226
281
|
// 3. Build islands (if any <Island> usage is found in the routes graph).
|
|
227
282
|
const { scanIslandChunks, buildIslands } = await import('../islands/build.ts')
|
|
228
283
|
const islandMap = existsSync(routesFile)
|
|
@@ -230,7 +285,10 @@ export async function runBuild(args: string[]): Promise<void> {
|
|
|
230
285
|
: new Map<string, string>()
|
|
231
286
|
if (islandMap.size > 0) {
|
|
232
287
|
const islandsOutDir = path.join(outDir, 'islands')
|
|
233
|
-
const result = await buildIslands(islandMap, {
|
|
288
|
+
const result = await buildIslands(islandMap, {
|
|
289
|
+
outDir: islandsOutDir,
|
|
290
|
+
plugins: cssBuildPlugins,
|
|
291
|
+
})
|
|
234
292
|
console.log(`[brust build] islands: ${result.islandCount} chunk(s) → ${islandsOutDir}`)
|
|
235
293
|
|
|
236
294
|
// Mirror into cwd/.brust/islands so the NON-prebuilt source runtime
|
|
@@ -361,39 +419,8 @@ export async function runBuild(args: string[]): Promise<void> {
|
|
|
361
419
|
console.log(`[brust build] css: skipped (no app.css)`)
|
|
362
420
|
}
|
|
363
421
|
|
|
364
|
-
//
|
|
365
|
-
|
|
366
|
-
const { scanCssImports } = await import('../css/scan-imports.ts')
|
|
367
|
-
const scan = await scanCssImports(entryDir)
|
|
368
|
-
if (scan.size > 0) {
|
|
369
|
-
const { buildComponentCss } = await import('../css/component-build.ts')
|
|
370
|
-
const routesFile = path.join(entryDir, 'routes.tsx')
|
|
371
|
-
let routeForCss: { fullPath: string; componentSource: string }[] = []
|
|
372
|
-
if (existsSync(routesFile)) {
|
|
373
|
-
try {
|
|
374
|
-
const { routes } = await import(routesFile)
|
|
375
|
-
routeForCss = (routes as any[]).map((r) => ({
|
|
376
|
-
fullPath: r.fullPath,
|
|
377
|
-
componentSource: routesFile,
|
|
378
|
-
}))
|
|
379
|
-
} catch {
|
|
380
|
-
/* if routes import fails, skip — manifest still emits modules */
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
const cssOutDir = path.join(outDir, 'css')
|
|
384
|
-
const manifest = await buildComponentCss({
|
|
385
|
-
scanRoot: entryDir,
|
|
386
|
-
outDir: cssOutDir,
|
|
387
|
-
tailwindCompile: null,
|
|
388
|
-
routes: routeForCss,
|
|
389
|
-
})
|
|
390
|
-
console.log(
|
|
391
|
-
`[brust build] css-mod: ${Object.keys(manifest.modules).length} chunk(s) → ${cssOutDir}/components/`,
|
|
392
|
-
)
|
|
393
|
-
} else {
|
|
394
|
-
console.log(`[brust build] css-mod: skipped (no component CSS imports)`)
|
|
395
|
-
}
|
|
396
|
-
}
|
|
422
|
+
// (Component CSS — Lightning CSS + CSS Modules — moved up to section 2.7 so the
|
|
423
|
+
// cssLoaderPlugin is registered before the island/directive bundles.)
|
|
397
424
|
|
|
398
425
|
// Static public assets: copy <project>/public → <dist>/public so a deployed
|
|
399
426
|
// dist is self-contained. No .brust mirror — the source/dev runtime reads
|
|
@@ -436,7 +463,10 @@ export async function runBuild(args: string[]): Promise<void> {
|
|
|
436
463
|
// point at non-existent files. Whitespace + syntax minification still apply.
|
|
437
464
|
minify: { whitespace: true, syntax: true, identifiers: false },
|
|
438
465
|
banner,
|
|
439
|
-
|
|
466
|
+
// cssBuildPlugins resolves any `.module.css` reached from the entry graph
|
|
467
|
+
// (e.g. routes.tsx → a component's CSS module) to the scoped name map, so
|
|
468
|
+
// Bun doesn't emit the CSS as an asset and collide on the bundle name.
|
|
469
|
+
plugins: [nativeShimPlugin(REPO_ROOT), ...cssBuildPlugins],
|
|
440
470
|
})
|
|
441
471
|
|
|
442
472
|
if (!result.success) {
|
package/runtime/cli/templates.ts
CHANGED
|
@@ -60,7 +60,14 @@ export async function buildComponentCss(
|
|
|
60
60
|
lines.push(` readonly ${k}: string`)
|
|
61
61
|
}
|
|
62
62
|
lines.push('}', 'export default styles', '')
|
|
63
|
-
|
|
63
|
+
// Emit the per-module .d.ts into the BUILD output (under outDir/types,
|
|
64
|
+
// mirroring the source layout) instead of next to the source .module.css —
|
|
65
|
+
// generated artifacts belong in .brust/dist, not the project tree. Import
|
|
66
|
+
// resolution uses the framework-shipped ambient `*.module.css` declaration
|
|
67
|
+
// (runtime/css-modules.d.ts); these precise files are an inspectable record.
|
|
68
|
+
const dtsPath = path.join(opts.outDir, 'types', `${rel}.d.ts`)
|
|
69
|
+
await mkdir(path.dirname(dtsPath), { recursive: true })
|
|
70
|
+
await writeFile(dtsPath, lines.join('\n'), 'utf-8')
|
|
64
71
|
}
|
|
65
72
|
}
|
|
66
73
|
|
|
@@ -70,9 +77,10 @@ export async function buildComponentCss(
|
|
|
70
77
|
const routeChunks = computeRouteChunks(opts.routes, scan, lookup)
|
|
71
78
|
|
|
72
79
|
const manifest: ComponentCssManifest = { version: 1, modules, routeChunks }
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
)
|
|
80
|
+
// opts.outDir is already the css dir (chunks land in opts.outDir/components,
|
|
81
|
+
// served at /_brust/css/components/). The manifest sits beside it at
|
|
82
|
+
// opts.outDir/component-manifest.json — where both readers look
|
|
83
|
+
// (dist/css/component-manifest.json and .brust/css/component-manifest.json).
|
|
84
|
+
await writeComponentCssManifest(path.join(opts.outDir, 'component-manifest.json'), manifest)
|
|
77
85
|
return manifest
|
|
78
86
|
}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { scanImports } from '../cli/native-routes-emit.ts'
|
|
1
3
|
import type { CssDep } from './scan-imports.ts'
|
|
2
4
|
|
|
3
5
|
export interface RouteForCss {
|
|
4
6
|
/** Route.fullPath (e.g. '/' or '/blog/{slug}'). */
|
|
5
7
|
fullPath: string
|
|
6
|
-
/** Absolute
|
|
7
|
-
|
|
8
|
+
/** Absolute source files of the route's component CHAIN (root layout → leaf).
|
|
9
|
+
* computeRouteChunks walks the local import graph from each and unions the
|
|
10
|
+
* CSS deps it finds — so a layout's co-located `.module.css` links to every
|
|
11
|
+
* route under it, and a leaf's links only to that route. */
|
|
12
|
+
componentSources: string[]
|
|
8
13
|
}
|
|
9
14
|
|
|
10
15
|
/** Build the route → CSS chunk hrefs map.
|
|
11
16
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
+
* For each route, BFS the LOCAL import graph rooted at the route's component
|
|
18
|
+
* chain (via {@link scanImports}, same default-import walk islands use) and
|
|
19
|
+
* collect the CSS deps of every reachable file. This means a `.module.css`
|
|
20
|
+
* co-located with the component that imports it is enough — no need to also
|
|
21
|
+
* import it in routes.tsx. Chunks are deduplicated and sorted per route. */
|
|
17
22
|
export function computeRouteChunks(
|
|
18
23
|
routes: RouteForCss[],
|
|
19
24
|
scan: Map<string, CssDep[]>,
|
|
@@ -21,11 +26,21 @@ export function computeRouteChunks(
|
|
|
21
26
|
): Record<string, string[]> {
|
|
22
27
|
const out: Record<string, string[]> = {}
|
|
23
28
|
for (const r of routes) {
|
|
24
|
-
const deps = scan.get(r.componentSource) ?? []
|
|
25
29
|
const chunks = new Set<string>()
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
const seen = new Set<string>()
|
|
31
|
+
const queue = [...r.componentSources]
|
|
32
|
+
while (queue.length > 0) {
|
|
33
|
+
const file = queue.shift()!
|
|
34
|
+
if (seen.has(file) || !existsSync(file)) continue
|
|
35
|
+
seen.add(file)
|
|
36
|
+
for (const d of scan.get(file) ?? []) {
|
|
37
|
+
const mod = modules[d.path]
|
|
38
|
+
if (mod) chunks.add(mod.chunk)
|
|
39
|
+
}
|
|
40
|
+
// Follow this file's local (relative) default imports transitively.
|
|
41
|
+
for (const dep of scanImports(file).values()) {
|
|
42
|
+
if (!seen.has(dep)) queue.push(dep)
|
|
43
|
+
}
|
|
29
44
|
}
|
|
30
45
|
out[r.fullPath] = Array.from(chunks).sort()
|
|
31
46
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Ambient declarations for component CSS imports, so `import styles from
|
|
2
|
+
// './X.module.css'` and side-effect `import './globals.css'` typecheck without a
|
|
3
|
+
// generated per-file .d.ts in the source tree. The precise key map is resolved
|
|
4
|
+
// at runtime by brust's Bun.plugin (built from the component-CSS manifest); the
|
|
5
|
+
// per-module precise .d.ts is emitted into the build output (<outDir>/types) for
|
|
6
|
+
// reference, not for resolution. This file is a global script (no import/export),
|
|
7
|
+
// so the declarations apply across the program.
|
|
8
|
+
|
|
9
|
+
declare module '*.module.css' {
|
|
10
|
+
const classes: { readonly [key: string]: string }
|
|
11
|
+
export default classes
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.css' {
|
|
15
|
+
const css: string
|
|
16
|
+
export default css
|
|
17
|
+
}
|
package/runtime/index.js
CHANGED
|
@@ -77,8 +77,8 @@ function requireNative() {
|
|
|
77
77
|
try {
|
|
78
78
|
const binding = require('brustjs-android-arm64')
|
|
79
79
|
const bindingPackageVersion = require('brustjs-android-arm64/package.json').version
|
|
80
|
-
if (bindingPackageVersion !== '0.1.
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
80
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
81
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
82
82
|
}
|
|
83
83
|
return binding
|
|
84
84
|
} catch (e) {
|
|
@@ -93,8 +93,8 @@ function requireNative() {
|
|
|
93
93
|
try {
|
|
94
94
|
const binding = require('brustjs-android-arm-eabi')
|
|
95
95
|
const bindingPackageVersion = require('brustjs-android-arm-eabi/package.json').version
|
|
96
|
-
if (bindingPackageVersion !== '0.1.
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
96
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
97
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
98
98
|
}
|
|
99
99
|
return binding
|
|
100
100
|
} catch (e) {
|
|
@@ -114,8 +114,8 @@ function requireNative() {
|
|
|
114
114
|
try {
|
|
115
115
|
const binding = require('brustjs-win32-x64-gnu')
|
|
116
116
|
const bindingPackageVersion = require('brustjs-win32-x64-gnu/package.json').version
|
|
117
|
-
if (bindingPackageVersion !== '0.1.
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
117
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
118
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
119
|
}
|
|
120
120
|
return binding
|
|
121
121
|
} catch (e) {
|
|
@@ -130,8 +130,8 @@ function requireNative() {
|
|
|
130
130
|
try {
|
|
131
131
|
const binding = require('brustjs-win32-x64-msvc')
|
|
132
132
|
const bindingPackageVersion = require('brustjs-win32-x64-msvc/package.json').version
|
|
133
|
-
if (bindingPackageVersion !== '0.1.
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
133
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
134
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
135
135
|
}
|
|
136
136
|
return binding
|
|
137
137
|
} catch (e) {
|
|
@@ -147,8 +147,8 @@ function requireNative() {
|
|
|
147
147
|
try {
|
|
148
148
|
const binding = require('brustjs-win32-ia32-msvc')
|
|
149
149
|
const bindingPackageVersion = require('brustjs-win32-ia32-msvc/package.json').version
|
|
150
|
-
if (bindingPackageVersion !== '0.1.
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
150
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
152
|
}
|
|
153
153
|
return binding
|
|
154
154
|
} catch (e) {
|
|
@@ -163,8 +163,8 @@ function requireNative() {
|
|
|
163
163
|
try {
|
|
164
164
|
const binding = require('brustjs-win32-arm64-msvc')
|
|
165
165
|
const bindingPackageVersion = require('brustjs-win32-arm64-msvc/package.json').version
|
|
166
|
-
if (bindingPackageVersion !== '0.1.
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
166
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
167
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
168
168
|
}
|
|
169
169
|
return binding
|
|
170
170
|
} catch (e) {
|
|
@@ -182,8 +182,8 @@ function requireNative() {
|
|
|
182
182
|
try {
|
|
183
183
|
const binding = require('brustjs-darwin-universal')
|
|
184
184
|
const bindingPackageVersion = require('brustjs-darwin-universal/package.json').version
|
|
185
|
-
if (bindingPackageVersion !== '0.1.
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
185
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
186
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
187
187
|
}
|
|
188
188
|
return binding
|
|
189
189
|
} catch (e) {
|
|
@@ -198,8 +198,8 @@ function requireNative() {
|
|
|
198
198
|
try {
|
|
199
199
|
const binding = require('brustjs-darwin-x64')
|
|
200
200
|
const bindingPackageVersion = require('brustjs-darwin-x64/package.json').version
|
|
201
|
-
if (bindingPackageVersion !== '0.1.
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
201
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
202
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
203
203
|
}
|
|
204
204
|
return binding
|
|
205
205
|
} catch (e) {
|
|
@@ -214,8 +214,8 @@ function requireNative() {
|
|
|
214
214
|
try {
|
|
215
215
|
const binding = require('brustjs-darwin-arm64')
|
|
216
216
|
const bindingPackageVersion = require('brustjs-darwin-arm64/package.json').version
|
|
217
|
-
if (bindingPackageVersion !== '0.1.
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
217
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
219
219
|
}
|
|
220
220
|
return binding
|
|
221
221
|
} catch (e) {
|
|
@@ -234,8 +234,8 @@ function requireNative() {
|
|
|
234
234
|
try {
|
|
235
235
|
const binding = require('brustjs-freebsd-x64')
|
|
236
236
|
const bindingPackageVersion = require('brustjs-freebsd-x64/package.json').version
|
|
237
|
-
if (bindingPackageVersion !== '0.1.
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
237
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
239
|
}
|
|
240
240
|
return binding
|
|
241
241
|
} catch (e) {
|
|
@@ -250,8 +250,8 @@ function requireNative() {
|
|
|
250
250
|
try {
|
|
251
251
|
const binding = require('brustjs-freebsd-arm64')
|
|
252
252
|
const bindingPackageVersion = require('brustjs-freebsd-arm64/package.json').version
|
|
253
|
-
if (bindingPackageVersion !== '0.1.
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
253
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
254
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
255
255
|
}
|
|
256
256
|
return binding
|
|
257
257
|
} catch (e) {
|
|
@@ -271,8 +271,8 @@ function requireNative() {
|
|
|
271
271
|
try {
|
|
272
272
|
const binding = require('brustjs-linux-x64-musl')
|
|
273
273
|
const bindingPackageVersion = require('brustjs-linux-x64-musl/package.json').version
|
|
274
|
-
if (bindingPackageVersion !== '0.1.
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
274
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
275
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
276
276
|
}
|
|
277
277
|
return binding
|
|
278
278
|
} catch (e) {
|
|
@@ -287,8 +287,8 @@ function requireNative() {
|
|
|
287
287
|
try {
|
|
288
288
|
const binding = require('brustjs-linux-x64-gnu')
|
|
289
289
|
const bindingPackageVersion = require('brustjs-linux-x64-gnu/package.json').version
|
|
290
|
-
if (bindingPackageVersion !== '0.1.
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
290
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
291
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
292
292
|
}
|
|
293
293
|
return binding
|
|
294
294
|
} catch (e) {
|
|
@@ -305,8 +305,8 @@ function requireNative() {
|
|
|
305
305
|
try {
|
|
306
306
|
const binding = require('brustjs-linux-arm64-musl')
|
|
307
307
|
const bindingPackageVersion = require('brustjs-linux-arm64-musl/package.json').version
|
|
308
|
-
if (bindingPackageVersion !== '0.1.
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
308
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
309
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
310
310
|
}
|
|
311
311
|
return binding
|
|
312
312
|
} catch (e) {
|
|
@@ -321,8 +321,8 @@ function requireNative() {
|
|
|
321
321
|
try {
|
|
322
322
|
const binding = require('brustjs-linux-arm64-gnu')
|
|
323
323
|
const bindingPackageVersion = require('brustjs-linux-arm64-gnu/package.json').version
|
|
324
|
-
if (bindingPackageVersion !== '0.1.
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
324
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
325
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
326
326
|
}
|
|
327
327
|
return binding
|
|
328
328
|
} catch (e) {
|
|
@@ -339,8 +339,8 @@ function requireNative() {
|
|
|
339
339
|
try {
|
|
340
340
|
const binding = require('brustjs-linux-arm-musleabihf')
|
|
341
341
|
const bindingPackageVersion = require('brustjs-linux-arm-musleabihf/package.json').version
|
|
342
|
-
if (bindingPackageVersion !== '0.1.
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
342
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
343
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
344
344
|
}
|
|
345
345
|
return binding
|
|
346
346
|
} catch (e) {
|
|
@@ -355,8 +355,8 @@ function requireNative() {
|
|
|
355
355
|
try {
|
|
356
356
|
const binding = require('brustjs-linux-arm-gnueabihf')
|
|
357
357
|
const bindingPackageVersion = require('brustjs-linux-arm-gnueabihf/package.json').version
|
|
358
|
-
if (bindingPackageVersion !== '0.1.
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
358
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
359
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
360
360
|
}
|
|
361
361
|
return binding
|
|
362
362
|
} catch (e) {
|
|
@@ -373,8 +373,8 @@ function requireNative() {
|
|
|
373
373
|
try {
|
|
374
374
|
const binding = require('brustjs-linux-loong64-musl')
|
|
375
375
|
const bindingPackageVersion = require('brustjs-linux-loong64-musl/package.json').version
|
|
376
|
-
if (bindingPackageVersion !== '0.1.
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
376
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
377
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
378
378
|
}
|
|
379
379
|
return binding
|
|
380
380
|
} catch (e) {
|
|
@@ -389,8 +389,8 @@ function requireNative() {
|
|
|
389
389
|
try {
|
|
390
390
|
const binding = require('brustjs-linux-loong64-gnu')
|
|
391
391
|
const bindingPackageVersion = require('brustjs-linux-loong64-gnu/package.json').version
|
|
392
|
-
if (bindingPackageVersion !== '0.1.
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
392
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
393
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
394
394
|
}
|
|
395
395
|
return binding
|
|
396
396
|
} catch (e) {
|
|
@@ -407,8 +407,8 @@ function requireNative() {
|
|
|
407
407
|
try {
|
|
408
408
|
const binding = require('brustjs-linux-riscv64-musl')
|
|
409
409
|
const bindingPackageVersion = require('brustjs-linux-riscv64-musl/package.json').version
|
|
410
|
-
if (bindingPackageVersion !== '0.1.
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
410
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
412
|
}
|
|
413
413
|
return binding
|
|
414
414
|
} catch (e) {
|
|
@@ -423,8 +423,8 @@ function requireNative() {
|
|
|
423
423
|
try {
|
|
424
424
|
const binding = require('brustjs-linux-riscv64-gnu')
|
|
425
425
|
const bindingPackageVersion = require('brustjs-linux-riscv64-gnu/package.json').version
|
|
426
|
-
if (bindingPackageVersion !== '0.1.
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
426
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
427
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
428
428
|
}
|
|
429
429
|
return binding
|
|
430
430
|
} catch (e) {
|
|
@@ -440,8 +440,8 @@ function requireNative() {
|
|
|
440
440
|
try {
|
|
441
441
|
const binding = require('brustjs-linux-ppc64-gnu')
|
|
442
442
|
const bindingPackageVersion = require('brustjs-linux-ppc64-gnu/package.json').version
|
|
443
|
-
if (bindingPackageVersion !== '0.1.
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
443
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
445
|
}
|
|
446
446
|
return binding
|
|
447
447
|
} catch (e) {
|
|
@@ -456,8 +456,8 @@ function requireNative() {
|
|
|
456
456
|
try {
|
|
457
457
|
const binding = require('brustjs-linux-s390x-gnu')
|
|
458
458
|
const bindingPackageVersion = require('brustjs-linux-s390x-gnu/package.json').version
|
|
459
|
-
if (bindingPackageVersion !== '0.1.
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
459
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
461
|
}
|
|
462
462
|
return binding
|
|
463
463
|
} catch (e) {
|
|
@@ -476,8 +476,8 @@ function requireNative() {
|
|
|
476
476
|
try {
|
|
477
477
|
const binding = require('brustjs-openharmony-arm64')
|
|
478
478
|
const bindingPackageVersion = require('brustjs-openharmony-arm64/package.json').version
|
|
479
|
-
if (bindingPackageVersion !== '0.1.
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
479
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
481
|
}
|
|
482
482
|
return binding
|
|
483
483
|
} catch (e) {
|
|
@@ -492,8 +492,8 @@ function requireNative() {
|
|
|
492
492
|
try {
|
|
493
493
|
const binding = require('brustjs-openharmony-x64')
|
|
494
494
|
const bindingPackageVersion = require('brustjs-openharmony-x64/package.json').version
|
|
495
|
-
if (bindingPackageVersion !== '0.1.
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
495
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
497
|
}
|
|
498
498
|
return binding
|
|
499
499
|
} catch (e) {
|
|
@@ -508,8 +508,8 @@ function requireNative() {
|
|
|
508
508
|
try {
|
|
509
509
|
const binding = require('brustjs-openharmony-arm')
|
|
510
510
|
const bindingPackageVersion = require('brustjs-openharmony-arm/package.json').version
|
|
511
|
-
if (bindingPackageVersion !== '0.1.
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
511
|
+
if (bindingPackageVersion !== '0.1.37-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
512
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.37-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
513
|
}
|
|
514
514
|
return binding
|
|
515
515
|
} catch (e) {
|
package/runtime/index.ts
CHANGED
|
@@ -372,11 +372,13 @@ export const brust = {
|
|
|
372
372
|
console.log(`[brust] main: spawning ${workers} worker threads`)
|
|
373
373
|
if (cacheMaxEntries !== undefined) this.configureCache({ maxEntries: cacheMaxEntries })
|
|
374
374
|
|
|
375
|
-
// Component CSS pipeline.
|
|
376
|
-
//
|
|
377
|
-
//
|
|
378
|
-
//
|
|
379
|
-
// (
|
|
375
|
+
// Component CSS pipeline. Build the manifest + capture the loader plugin
|
|
376
|
+
// BEFORE buildIslands and pass it EXPLICITLY below (global Bun.plugin()
|
|
377
|
+
// does NOT reach Bun.build) — otherwise Bun's default loader emits
|
|
378
|
+
// .module.css as a separate asset and collides when an island and its
|
|
379
|
+
// module share a basename (Counter.tsx + Counter.module.css → both
|
|
380
|
+
// want to emit Counter.js).
|
|
381
|
+
const cssBuildPlugins: import('bun').BunPlugin[] = []
|
|
380
382
|
{
|
|
381
383
|
const { readComponentCssManifest } = await import('./css/manifest.ts')
|
|
382
384
|
const { cssLoaderPlugin } = await import('./css/component-loader.ts')
|
|
@@ -390,9 +392,19 @@ export const brust = {
|
|
|
390
392
|
const scan = await scanCssImports(scanRoot)
|
|
391
393
|
if (scan.size > 0) {
|
|
392
394
|
const { buildComponentCss } = await import('./css/component-build.ts')
|
|
395
|
+
const { scanImports } = await import('./cli/native-routes-emit.ts')
|
|
396
|
+
const routesFile = path.join(scanRoot, 'routes.tsx')
|
|
397
|
+
const idents = existsSync(routesFile)
|
|
398
|
+
? scanImports(routesFile)
|
|
399
|
+
: new Map<string, string>()
|
|
393
400
|
const routeForCss = opts.routes.map((r) => ({
|
|
394
401
|
fullPath: r.fullPath,
|
|
395
|
-
|
|
402
|
+
// Resolve the route's component chain (layout → leaf) to source
|
|
403
|
+
// files; computeRouteChunks BFS-walks each subtree for CSS deps.
|
|
404
|
+
componentSources: r.chain
|
|
405
|
+
.map((node) => (node as { Component?: { name?: string } }).Component?.name)
|
|
406
|
+
.map((name) => (name ? idents.get(name) : undefined))
|
|
407
|
+
.filter((p): p is string => typeof p === 'string'),
|
|
396
408
|
}))
|
|
397
409
|
const cssOutDir = path.join(process.cwd(), '.brust', 'css')
|
|
398
410
|
manifest = await buildComponentCss({
|
|
@@ -408,7 +420,9 @@ export const brust = {
|
|
|
408
420
|
}
|
|
409
421
|
|
|
410
422
|
if (manifest) {
|
|
411
|
-
|
|
423
|
+
const plugin = cssLoaderPlugin(manifest)
|
|
424
|
+
Bun.plugin(plugin) // runtime/SSR resolution of .module.css in the worker isolate
|
|
425
|
+
cssBuildPlugins.push(plugin) // explicit resolution for island Bun.build
|
|
412
426
|
for (const [routePath, hrefs] of Object.entries(manifest.routeChunks)) {
|
|
413
427
|
configureCssHrefsForRoute(routePath, hrefs)
|
|
414
428
|
}
|
|
@@ -429,7 +443,7 @@ export const brust = {
|
|
|
429
443
|
const islandMap = scanIslandChunks(routesPath)
|
|
430
444
|
let islandsDir: string | undefined
|
|
431
445
|
if (islandMap.size > 0) {
|
|
432
|
-
const islands = await build(islandMap)
|
|
446
|
+
const islands = await build(islandMap, { plugins: cssBuildPlugins })
|
|
433
447
|
islandsDir = islands.outDir
|
|
434
448
|
console.log(`[brust] main: built ${islands.islandCount} island chunk(s)`)
|
|
435
449
|
}
|
|
@@ -640,9 +654,17 @@ export const brust = {
|
|
|
640
654
|
if (scan.size === 0) return
|
|
641
655
|
const { buildComponentCss } = await import('./css/component-build.ts')
|
|
642
656
|
const { cssLoaderPlugin } = await import('./css/component-loader.ts')
|
|
657
|
+
const { scanImports } = await import('./cli/native-routes-emit.ts')
|
|
658
|
+
const routesFile = pathModule.join(scanRoot, 'routes.tsx')
|
|
659
|
+
const idents = existsSync(routesFile)
|
|
660
|
+
? scanImports(routesFile)
|
|
661
|
+
: new Map<string, string>()
|
|
643
662
|
const routeForCss = opts.routes.map((r) => ({
|
|
644
663
|
fullPath: r.fullPath,
|
|
645
|
-
|
|
664
|
+
componentSources: r.chain
|
|
665
|
+
.map((node) => (node as { Component?: { name?: string } }).Component?.name)
|
|
666
|
+
.map((name) => (name ? idents.get(name) : undefined))
|
|
667
|
+
.filter((p): p is string => typeof p === 'string'),
|
|
646
668
|
}))
|
|
647
669
|
const cssOutDir = pathModule.join(process.cwd(), '.brust', 'css')
|
|
648
670
|
const manifest = await buildComponentCss({
|
|
@@ -744,9 +766,10 @@ export const brust = {
|
|
|
744
766
|
}
|
|
745
767
|
|
|
746
768
|
// Worker: register the component CSS Bun.plugin so .module.css imports
|
|
747
|
-
// resolve to the same hash map main saw
|
|
748
|
-
//
|
|
749
|
-
//
|
|
769
|
+
// resolve to the same hash map main saw, AND seed the per-route CSS hrefs.
|
|
770
|
+
// The streaming renderer (render/stream.ts) runs HERE in the worker and
|
|
771
|
+
// reads getCssHrefsForRoute to inject the <link> before </head> — so the
|
|
772
|
+
// route→chunk map must be configured in the worker, not just on main.
|
|
750
773
|
{
|
|
751
774
|
const { readComponentCssManifest } = await import('./css/manifest.ts')
|
|
752
775
|
const { cssLoaderPlugin } = await import('./css/component-loader.ts')
|
|
@@ -756,6 +779,9 @@ export const brust = {
|
|
|
756
779
|
const manifest = await readComponentCssManifest(manifestPath)
|
|
757
780
|
if (manifest) {
|
|
758
781
|
Bun.plugin(cssLoaderPlugin(manifest))
|
|
782
|
+
for (const [routePath, hrefs] of Object.entries(manifest.routeChunks)) {
|
|
783
|
+
configureCssHrefsForRoute(routePath, hrefs)
|
|
784
|
+
}
|
|
759
785
|
}
|
|
760
786
|
}
|
|
761
787
|
|
|
@@ -84,6 +84,20 @@ function registerTrigger(el: HTMLElement, trigger: Trigger, fire: () => void): v
|
|
|
84
84
|
// Exported for unit testing — the public entry is hydrateMarkersIn, but the
|
|
85
85
|
// createRoot/hydrateRoot auto-detect branch is cleanest to assert by driving
|
|
86
86
|
// hydrateOne directly (the `load` trigger fires it as a detached microtask).
|
|
87
|
+
// id → content-addressed chunk URL, emitted by buildIslands as _islands.js.
|
|
88
|
+
// Loaded once (memoized). On any failure the map is empty and resolution falls
|
|
89
|
+
// back to the legacy `/_brust/islands/<id>.js` URL, so an older build still works.
|
|
90
|
+
let chunkMapPromise: Promise<Record<string, string>> | null = null
|
|
91
|
+
function islandChunkMap(): Promise<Record<string, string>> {
|
|
92
|
+
if (!chunkMapPromise) {
|
|
93
|
+
const url = '/_brust/islands/_islands.js' // variable specifier → runtime import, not bundled
|
|
94
|
+
chunkMapPromise = import(url)
|
|
95
|
+
.then((m) => (m.default ?? {}) as Record<string, string>)
|
|
96
|
+
.catch(() => ({}))
|
|
97
|
+
}
|
|
98
|
+
return chunkMapPromise
|
|
99
|
+
}
|
|
100
|
+
|
|
87
101
|
export async function hydrateOne(el: HTMLElement): Promise<void> {
|
|
88
102
|
const id = el.getAttribute('data-brust-island')
|
|
89
103
|
if (!id) return
|
|
@@ -96,7 +110,8 @@ export async function hydrateOne(el: HTMLElement): Promise<void> {
|
|
|
96
110
|
return
|
|
97
111
|
}
|
|
98
112
|
try {
|
|
99
|
-
const
|
|
113
|
+
const url = (await islandChunkMap())[id] ?? `/_brust/islands/${id}.js`
|
|
114
|
+
const mod = await import(url)
|
|
100
115
|
const Component = (mod.default ?? mod) as React.ComponentType<Record<string, unknown>>
|
|
101
116
|
if (typeof Component !== 'function') {
|
|
102
117
|
console.error(`[brust] island "${id}": chunk has no default-exported component`)
|
package/runtime/islands/build.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
1
2
|
import { readFileSync } from 'node:fs'
|
|
2
|
-
import { mkdir, rm } from 'node:fs/promises'
|
|
3
|
-
import { isAbsolute, resolve } from 'node:path'
|
|
3
|
+
import { mkdir, rm, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { isAbsolute, relative, resolve } from 'node:path'
|
|
5
|
+
import type { BunPlugin } from 'bun'
|
|
4
6
|
import { scanImports } from '../cli/native-routes-emit.ts'
|
|
5
7
|
|
|
6
8
|
export interface IslandsBuildResult {
|
|
@@ -8,11 +10,20 @@ export interface IslandsBuildResult {
|
|
|
8
10
|
outDir: string
|
|
9
11
|
/** Number of island chunks emitted (excludes runtime + bootstrap). */
|
|
10
12
|
islandCount: number
|
|
13
|
+
/** id → content-addressed chunk URL (`/_brust/islands/<id>_<hash>.js`). Also
|
|
14
|
+
* written to `_islands.js` for the client bootstrap to resolve at runtime. */
|
|
15
|
+
chunks: Record<string, string>
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
export interface BuildIslandsOptions {
|
|
14
19
|
/** Override the output directory. Default: `<cwd>/.brust/islands`. */
|
|
15
20
|
outDir?: string
|
|
21
|
+
/** Build plugins passed straight to `Bun.build` for the per-island chunks.
|
|
22
|
+
* Needed for the component-CSS loader: global `Bun.plugin()` registrations do
|
|
23
|
+
* NOT apply to `Bun.build`, so an island that `import`s a `.module.css` must
|
|
24
|
+
* get the resolver here or Bun emits the CSS as a separate asset and collides
|
|
25
|
+
* on the output filename (X.module.css + X.tsx → both X.js). */
|
|
26
|
+
plugins?: BunPlugin[]
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
/** Scan a routes entry file for `<Island component={X} />` usage and derive the
|
|
@@ -27,6 +38,16 @@ export interface BuildIslandsOptions {
|
|
|
27
38
|
* 4. Dedup islands that reuse the same component+path; throw on two different
|
|
28
39
|
* files whose island components share a name (ids must be app-unique).
|
|
29
40
|
*/
|
|
41
|
+
/** Content-addressed island chunk basename = `<Name>_<8hex(sha256 cwd-relative
|
|
42
|
+
* source path)>`. Stable + app-unique (mirrors the directive chunk scheme) so
|
|
43
|
+
* the URL is content-busting-stable; the bootstrap resolves the plain marker id
|
|
44
|
+
* to this via the `_islands.js` map. */
|
|
45
|
+
export function islandChunkBasename(name: string, absSourcePath: string): string {
|
|
46
|
+
const rel = relative(process.cwd(), absSourcePath).replaceAll('\\', '/')
|
|
47
|
+
const hash = createHash('sha256').update(rel).digest('hex').slice(0, 8)
|
|
48
|
+
return `${name}_${hash}`
|
|
49
|
+
}
|
|
50
|
+
|
|
30
51
|
export function scanIslandChunks(routesEntryFile: string): Map<string, string> {
|
|
31
52
|
const chunks = new Map<string, string>()
|
|
32
53
|
const visited = new Set<string>()
|
|
@@ -109,8 +130,15 @@ export async function buildIslands(
|
|
|
109
130
|
// 2. react-dom/client (react external; consumes _react.js via importmap).
|
|
110
131
|
await buildOne([`${entriesDir}/react-dom.ts`], outDir, '_react-dom.js', ['react'])
|
|
111
132
|
|
|
112
|
-
// 3. Per-island chunks (all 3 runtime specifiers external).
|
|
133
|
+
// 3. Per-island chunks (all 3 runtime specifiers external). Island sources may
|
|
134
|
+
// `import styles from './X.module.css'`, so the component-CSS plugins resolve
|
|
135
|
+
// those imports to the scoped name map (otherwise Bun emits the CSS as an asset).
|
|
113
136
|
const externals = ['react', 'react/jsx-runtime', 'react-dom/client']
|
|
137
|
+
const plugins = options.plugins ?? []
|
|
138
|
+
// id (plain Component name) → content-addressed chunk URL. The chunk filename
|
|
139
|
+
// is `<Name>_<hash>.js`; the data-brust-island marker stays the plain name, so
|
|
140
|
+
// the bootstrap resolves it to the hashed chunk via the `_islands.js` map below.
|
|
141
|
+
const chunks: Record<string, string> = {}
|
|
114
142
|
let count = 0
|
|
115
143
|
for (const [id, entry] of islands) {
|
|
116
144
|
if (!isValidIslandId(id)) {
|
|
@@ -119,15 +147,26 @@ export async function buildIslands(
|
|
|
119
147
|
`allowed: [A-Za-z0-9_-]+ (matches the server's filename safety check)`,
|
|
120
148
|
)
|
|
121
149
|
}
|
|
122
|
-
|
|
150
|
+
const file = `${islandChunkBasename(id, entry)}.js`
|
|
151
|
+
await buildOne([entry], outDir, file, externals, plugins)
|
|
152
|
+
chunks[id] = `/_brust/islands/${file}`
|
|
123
153
|
count++
|
|
124
154
|
}
|
|
125
155
|
|
|
156
|
+
// id → chunk URL map, served at /_brust/islands/_islands.js. The bootstrap
|
|
157
|
+
// loads it once and resolves a marker's plain id to its hashed chunk (with a
|
|
158
|
+
// legacy `/_brust/islands/<id>.js` fallback). ESM default export.
|
|
159
|
+
await writeFile(
|
|
160
|
+
resolve(outDir, '_islands.js'),
|
|
161
|
+
`export default ${JSON.stringify(chunks)}\n`,
|
|
162
|
+
'utf-8',
|
|
163
|
+
)
|
|
164
|
+
|
|
126
165
|
// 4. Bootstrap (react + react-dom/client external; uses importmap).
|
|
127
166
|
const bootstrapSrc = resolve(import.meta.dir, 'bootstrap.ts')
|
|
128
167
|
await buildOne([bootstrapSrc], outDir, '_bootstrap.js', externals)
|
|
129
168
|
|
|
130
|
-
return { outDir, islandCount: count }
|
|
169
|
+
return { outDir, islandCount: count, chunks }
|
|
131
170
|
}
|
|
132
171
|
|
|
133
172
|
async function buildOne(
|
|
@@ -135,6 +174,7 @@ async function buildOne(
|
|
|
135
174
|
outdir: string,
|
|
136
175
|
naming: string,
|
|
137
176
|
external: string[],
|
|
177
|
+
plugins: BunPlugin[] = [],
|
|
138
178
|
): Promise<void> {
|
|
139
179
|
const result = await Bun.build({
|
|
140
180
|
entrypoints,
|
|
@@ -144,6 +184,7 @@ async function buildOne(
|
|
|
144
184
|
target: 'browser',
|
|
145
185
|
external,
|
|
146
186
|
minify: true,
|
|
187
|
+
plugins,
|
|
147
188
|
define: {
|
|
148
189
|
'process.env.NODE_ENV': '"production"',
|
|
149
190
|
},
|
package/runtime/routes.ts
CHANGED
|
@@ -12,6 +12,7 @@ import * as native from './index.js'
|
|
|
12
12
|
import { renderBranchStreaming } from './render/stream.ts'
|
|
13
13
|
import { runInStoreContext, collectSnapshot } from './store/server-context.ts'
|
|
14
14
|
import { buildStoreScripts } from './render/inject-store.ts'
|
|
15
|
+
import { getCssHrefsForRoute } from './css.ts'
|
|
15
16
|
import { runInRequestCache } from './loader-cache.ts'
|
|
16
17
|
import { runInRequestScope, __scope } from './request-context.ts'
|
|
17
18
|
import {
|
|
@@ -816,6 +817,21 @@ export function makeRenderer(
|
|
|
816
817
|
)
|
|
817
818
|
}
|
|
818
819
|
;(data as Record<string, unknown>).__brust_store__ = buildStoreScripts(storeSnapshot)
|
|
820
|
+
// Component-CSS SSR. Fill the framework-owned
|
|
821
|
+
// `{{ __brust_component_css__ | safe }}` head slot with the route's
|
|
822
|
+
// component-CSS chunk <link>s (from the component-CSS manifest, seeded
|
|
823
|
+
// per-route in the worker). Empty string when the route imports no
|
|
824
|
+
// .module.css / co-located .css, so the slot always resolves.
|
|
825
|
+
if (process.env.BRUST_DEV === '1' && '__brust_component_css__' in data) {
|
|
826
|
+
console.warn(
|
|
827
|
+
`[brust] native loader for "${flat.nativeTemplate}" returned a reserved "__brust_component_css__" key — overwritten by the component-CSS links`,
|
|
828
|
+
)
|
|
829
|
+
}
|
|
830
|
+
;(data as Record<string, unknown>).__brust_component_css__ = getCssHrefsForRoute(
|
|
831
|
+
flat.fullPath,
|
|
832
|
+
)
|
|
833
|
+
.map((href) => `<link rel="stylesheet" href="${href}"/>`)
|
|
834
|
+
.join('')
|
|
819
835
|
}
|
|
820
836
|
const json = JSON.stringify(data)
|
|
821
837
|
// napiRenderJinja has no headers param — any Set-Cookie staged by a
|