brustjs 0.1.61-alpha → 0.1.63-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brustjs",
3
- "version": "0.1.61-alpha",
3
+ "version": "0.1.63-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": {
@@ -41,12 +41,12 @@
41
41
  "typescript": "^6.0.3"
42
42
  },
43
43
  "optionalDependencies": {
44
- "brustjs-darwin-x64": "0.1.61-alpha",
45
- "brustjs-darwin-arm64": "0.1.61-alpha",
46
- "brustjs-linux-x64-gnu": "0.1.61-alpha",
47
- "brustjs-linux-arm64-gnu": "0.1.61-alpha",
48
- "brustjs-linux-x64-musl": "0.1.61-alpha",
49
- "brustjs-linux-arm64-musl": "0.1.61-alpha"
44
+ "brustjs-darwin-x64": "0.1.63-alpha",
45
+ "brustjs-darwin-arm64": "0.1.63-alpha",
46
+ "brustjs-linux-x64-gnu": "0.1.63-alpha",
47
+ "brustjs-linux-arm64-gnu": "0.1.63-alpha",
48
+ "brustjs-linux-x64-musl": "0.1.63-alpha",
49
+ "brustjs-linux-arm64-musl": "0.1.63-alpha"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "react": "^19.2.6",
@@ -1,12 +1,29 @@
1
1
  import { createHash } from 'node:crypto'
2
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
2
+ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
3
3
  import { createRequire } from 'node:module'
4
4
  import { dirname, relative, resolve } from 'node:path'
5
5
  import { buildDevClientTag } from '../dev/client.ts'
6
6
  import { insertGeneratorMeta, insertShellMeta, resolveGenerator } from '../generator.ts'
7
7
  import { islandChunkBasename } from '../islands/chunk-id.ts'
8
+ import { emitBehaviorSsrModule } from '../islands/behavior-ssr-loader.ts'
8
9
  import { DIRECTIVES_BOOTSTRAP, ISLANDS_IMPORTMAP_AND_BOOTSTRAP } from '../islands/importmap.ts'
9
10
 
11
+ const NATIVE_INLINE_FALLBACK_WARNING = /^native component "([^"\r\n]+)" not inlined: ([\s\S]+)$/
12
+
13
+ export function formatCompilerWarning(warning: string): string {
14
+ const match = NATIVE_INLINE_FALLBACK_WARNING.exec(warning)
15
+ if (!match) return `brust: ${warning}`
16
+
17
+ const [, component, reason] = match
18
+ return [
19
+ `brust: warning — native component "${component}" was not inlined`,
20
+ ` reason: ${reason}`,
21
+ ' impact: rendered through React SSR; React hooks and event handlers are not hydrated automatically on a native route',
22
+ ` interactive fix: use <Island component={${component}} props={...} />`,
23
+ ` zero-JS fix: rewrite ${component} using native-compatible JSX`,
24
+ ].join('\n')
25
+ }
26
+
10
27
  /** Gather transitive component sources starting from a page source file.
11
28
  *
12
29
  * BFS/DFS over local imports reachable from `pageSourcePath`:
@@ -391,6 +408,7 @@ interface RawComponentEntry {
391
408
  factoryExpr: string
392
409
  referencedComponents: string[]
393
410
  usesIsland: boolean
411
+ behaviorModules: RawBehaviorModule[]
394
412
  /** ISR cache fields (present only on components with an `isr` attr). Declared
395
413
  * so the `{ ...entry }` / `{ ...e }` enrich spreads below are type-complete —
396
414
  * they MUST survive into the enriched `<Name>.components.json`, or runtime ISR
@@ -400,10 +418,58 @@ interface RawComponentEntry {
400
418
  revalidate?: number
401
419
  }
402
420
 
421
+ interface RawBehaviorModule {
422
+ component: string
423
+ directiveName: string
424
+ source: string
425
+ }
426
+
427
+ interface EnrichedBehaviorModule extends RawBehaviorModule {
428
+ moduleId: string
429
+ sourcePath: string
430
+ }
431
+
403
432
  /** Enriched component entry written to `<Name>.components.json`. */
404
433
  interface EnrichedComponentEntry extends RawComponentEntry {
405
434
  /** Absolute path to the component's source file (resolved from page imports). */
406
435
  sourcePath: string
436
+ behaviorModules: EnrichedBehaviorModule[]
437
+ }
438
+
439
+ function behaviorArtifactPrefix(routeName: string): string {
440
+ const routeScope = createHash('sha256').update(routeName).digest('hex').slice(0, 16)
441
+ return `__brust_behavior_${routeScope}_`
442
+ }
443
+
444
+ function behaviorModuleId(
445
+ routeName: string,
446
+ sourcePath: string,
447
+ directiveName: string,
448
+ source: string,
449
+ ): string {
450
+ return createHash('sha256')
451
+ .update(`${routeName}\0${sourcePath}\0${directiveName}\0${source}`)
452
+ .digest('hex')
453
+ }
454
+
455
+ function behaviorArtifactPaths(jinjaPath: string, routeName: string): string[] {
456
+ const jinjaDir = dirname(jinjaPath)
457
+ const prefix = behaviorArtifactPrefix(routeName)
458
+ if (!existsSync(jinjaDir)) return []
459
+ return readdirSync(jinjaDir)
460
+ .filter((name) => name.startsWith(prefix) && name.endsWith('.tsx'))
461
+ .map((name) => resolve(jinjaDir, name))
462
+ }
463
+
464
+ /** Remove every server-only SSR-component sidecar owned by one route. The
465
+ * route hash in behavior filenames prevents cleanup from touching another
466
+ * route's generated module, even when both render the same component. */
467
+ export function cleanupComponentArtifacts(jinjaPath: string, routeName: string): void {
468
+ rmSync(jinjaPath.replace(/\.jinja$/, '.components.json'), { force: true })
469
+ rmSync(jinjaPath.replace(/\.jinja$/, '.factory.ts'), { force: true })
470
+ for (const generatedPath of behaviorArtifactPaths(jinjaPath, routeName)) {
471
+ rmSync(generatedPath, { force: true })
472
+ }
407
473
  }
408
474
 
409
475
  /** One entry in a `<Name>.islands.json` as emitted by `jsx-rustc` (camelCase,
@@ -454,9 +520,9 @@ export function emitComponentArtifacts(
454
520
  componentsJsonStr: string,
455
521
  pageImports: Map<string, ResolvedImport>,
456
522
  routeName: string,
457
- ): { islandIdsFromComponents: string[] } {
523
+ ): { islandIdsFromComponents: string[]; generatedPaths: string[] } {
458
524
  const raw = JSON.parse(componentsJsonStr) as RawComponentEntry[]
459
- if (raw.length === 0) return { islandIdsFromComponents: [] }
525
+ if (raw.length === 0) return { islandIdsFromComponents: [], generatedPaths: [] }
460
526
 
461
527
  const jinjaDir = dirname(jinjaPath)
462
528
  const projectRoot = process.cwd()
@@ -464,6 +530,67 @@ export function emitComponentArtifacts(
464
530
  // Enrich with the resolved import ref. For local imports `ref.spec` is an
465
531
  // ABSOLUTE path (kept absolute for the readFileSync island scan below); for
466
532
  // bare imports it's the verbatim package specifier.
533
+ const behaviorByComponent = new Map<string, EnrichedBehaviorModule>()
534
+ for (const entry of raw) {
535
+ for (const module of entry.behaviorModules ?? []) {
536
+ const ref = pageImports.get(module.component)
537
+ if (!ref || ref.bare) {
538
+ throw new Error(
539
+ `SSR behavior component "${module.component}" in native route "${routeName}" has no local source import`,
540
+ )
541
+ }
542
+ const sourcePath = relative(projectRoot, ref.spec).replaceAll('\\', '/')
543
+ const moduleId = behaviorModuleId(routeName, sourcePath, module.directiveName, module.source)
544
+ const enrichedModule: EnrichedBehaviorModule = {
545
+ ...module,
546
+ moduleId,
547
+ sourcePath,
548
+ }
549
+ const prior = behaviorByComponent.get(module.component)
550
+ if (
551
+ prior &&
552
+ (prior.moduleId !== enrichedModule.moduleId ||
553
+ prior.directiveName !== enrichedModule.directiveName ||
554
+ prior.sourcePath !== enrichedModule.sourcePath)
555
+ ) {
556
+ throw new Error(
557
+ `SSR behavior component "${module.component}" has conflicting transformed definitions in native route "${routeName}"`,
558
+ )
559
+ }
560
+ behaviorByComponent.set(module.component, enrichedModule)
561
+ }
562
+ }
563
+
564
+ // If an opaque fallback parent imports one of the transformed behavior
565
+ // modules, its original source would otherwise bundle that child's original
566
+ // (unwired) source. Add unchanged passthrough parents until the import graph
567
+ // reaches a fixed point; the loader rewrites their local imports to the
568
+ // generated child artifacts below.
569
+ let addedPassthrough = true
570
+ while (addedPassthrough) {
571
+ addedPassthrough = false
572
+ const generatedSourcePaths = new Set(
573
+ [...behaviorByComponent.values()].map((module) => resolve(projectRoot, module.sourcePath)),
574
+ )
575
+ for (const [component, ref] of pageImports) {
576
+ if (!isComponentIdent(component) || ref.bare || behaviorByComponent.has(component)) continue
577
+ const importsGeneratedModule = [...scanImportRefs(ref.spec).values()].some(
578
+ (dependency) => !dependency.bare && generatedSourcePaths.has(dependency.spec),
579
+ )
580
+ if (!importsGeneratedModule) continue
581
+ const source = readFileSync(ref.spec, 'utf8')
582
+ const sourcePath = relative(projectRoot, ref.spec).replaceAll('\\', '/')
583
+ behaviorByComponent.set(component, {
584
+ component,
585
+ directiveName: '',
586
+ source,
587
+ sourcePath,
588
+ moduleId: behaviorModuleId(routeName, sourcePath, '', source),
589
+ })
590
+ addedPassthrough = true
591
+ }
592
+ }
593
+
467
594
  const enriched: Array<EnrichedComponentEntry & { ref: ResolvedImport }> = raw.map((entry) => {
468
595
  const ref = pageImports.get(entry.component)
469
596
  if (!ref) {
@@ -471,7 +598,14 @@ export function emitComponentArtifacts(
471
598
  `SSR component "${entry.component}" in native route "${routeName}" has no matching import in the page source (expected \`import ${entry.component} from "..."\`)`,
472
599
  )
473
600
  }
474
- return { ...entry, sourcePath: ref.spec, ref }
601
+ return {
602
+ ...entry,
603
+ sourcePath: ref.spec,
604
+ behaviorModules: (entry.behaviorModules ?? []).map(
605
+ (module) => behaviorByComponent.get(module.component)!,
606
+ ),
607
+ ref,
608
+ }
475
609
  })
476
610
 
477
611
  // Write <Name>.components.json. For LOCAL imports sourcePath is PROJECT-RELATIVE
@@ -479,12 +613,70 @@ export function emitComponentArtifacts(
479
613
  // package spec verbatim. (sourcePath is build-time metadata — the factory
480
614
  // import is what's load-bearing at runtime.)
481
615
  const compJsonPath = jinjaPath.replace(/\.jinja$/, '.components.json')
482
- const compJsonEntries = enriched.map(({ ref, ...e }) => ({
616
+ const compJsonEntries = enriched.map(({ ref, behaviorModules: _behaviorModules, ...e }) => ({
483
617
  ...e,
484
618
  sourcePath: ref.bare ? ref.spec : relative(projectRoot, ref.spec).replaceAll('\\', '/'),
485
619
  }))
486
620
  writeFileSync(compJsonPath, JSON.stringify(compJsonEntries))
487
621
 
622
+ const generatedSpecByComponent = new Map<string, string>()
623
+ const generatedPathByComponent = new Map<string, string>()
624
+ const generatedPaths: string[] = []
625
+ const artifactPrefix = behaviorArtifactPrefix(routeName)
626
+ for (const module of behaviorByComponent.values()) {
627
+ const filename = `${artifactPrefix}${module.moduleId}.tsx`
628
+ const outputPath = resolve(jinjaDir, filename)
629
+ generatedSpecByComponent.set(module.component, `./${filename}`)
630
+ generatedPathByComponent.set(module.component, outputPath)
631
+ generatedPaths.push(outputPath)
632
+ }
633
+ const componentBySourcePath = new Map(
634
+ [...behaviorByComponent.values()].map((module) => [
635
+ resolve(projectRoot, module.sourcePath),
636
+ module.component,
637
+ ]),
638
+ )
639
+ const emittedComponents = new Set<string>()
640
+ const emittingComponents = new Set<string>()
641
+ const emitGeneratedModule = (module: EnrichedBehaviorModule): void => {
642
+ if (emittedComponents.has(module.component)) return
643
+ if (!emittingComponents.add(module.component)) {
644
+ throw new Error(
645
+ `SSR behavior modules form an import cycle at "${module.component}" in native route "${routeName}"`,
646
+ )
647
+ }
648
+ const sourcePath = resolve(projectRoot, module.sourcePath)
649
+ for (const dependency of scanImportRefs(sourcePath).values()) {
650
+ if (dependency.bare) continue
651
+ const dependencyComponent = componentBySourcePath.get(dependency.spec)
652
+ if (!dependencyComponent) continue
653
+ emitGeneratedModule(behaviorByComponent.get(dependencyComponent)!)
654
+ }
655
+ const outputPath = generatedPathByComponent.get(module.component)!
656
+ emitBehaviorSsrModule(
657
+ {
658
+ ...module,
659
+ sourcePath,
660
+ dependencies: [...behaviorByComponent.values()]
661
+ .filter((dependency) => dependency.component !== module.component)
662
+ .map((dependency) => ({
663
+ sourcePath: resolve(projectRoot, dependency.sourcePath),
664
+ outputPath: generatedPathByComponent.get(dependency.component)!,
665
+ })),
666
+ },
667
+ outputPath,
668
+ )
669
+ emittingComponents.delete(module.component)
670
+ emittedComponents.add(module.component)
671
+ }
672
+ for (const module of behaviorByComponent.values()) {
673
+ emitGeneratedModule(module)
674
+ }
675
+ const currentGeneratedPaths = new Set(generatedPaths)
676
+ for (const stalePath of behaviorArtifactPaths(jinjaPath, routeName)) {
677
+ if (!currentGeneratedPaths.has(stalePath)) rmSync(stalePath, { force: true })
678
+ }
679
+
488
680
  // Collect import lines. Deduplicate referenced components.
489
681
  const seen = new Set<string>()
490
682
  const importLines: string[] = []
@@ -506,7 +698,12 @@ export function emitComponentArtifacts(
506
698
  seen.add(compName)
507
699
  const ref = pageImports.get(compName)
508
700
  if (!ref) continue
509
- const spec = ref.bare ? ref.spec : toRelativeSpecifier(jinjaDir, ref.spec)
701
+ const generatedSpec = generatedSpecByComponent.get(compName)
702
+ const spec = generatedSpec
703
+ ? generatedSpec
704
+ : ref.bare
705
+ ? ref.spec
706
+ : toRelativeSpecifier(jinjaDir, ref.spec)
510
707
  const specStr = JSON.stringify(spec)
511
708
  if (ref.kind === 'namespace') {
512
709
  importLines.push(`import * as ${compName} from ${specStr}`)
@@ -566,7 +763,7 @@ export function emitComponentArtifacts(
566
763
  }
567
764
  }
568
765
 
569
- return { islandIdsFromComponents }
766
+ return { islandIdsFromComponents, generatedPaths }
570
767
  }
571
768
 
572
769
  export async function emitNativeTemplates(opts: NativeRouteEmitOpts): Promise<NativeEmitStats> {
@@ -755,8 +952,12 @@ export async function emitNativeTemplates(opts: NativeRouteEmitOpts): Promise<Na
755
952
  )
756
953
  }
757
954
 
758
- // Print non-fatal compiler warnings to stderr.
759
- for (const w of compiled.warnings ?? []) process.stderr.write(`brust: ${w}\n`)
955
+ // Print non-fatal compiler warnings to stderr. Native-inline fallbacks get
956
+ // actionable multiline guidance; all other warning strings retain the
957
+ // existing one-line prefix.
958
+ for (const warning of compiled.warnings ?? []) {
959
+ process.stderr.write(`${formatCompilerWarning(warning)}\n`)
960
+ }
760
961
 
761
962
  // SPA navigation extracts the FIRST <main>…</main> block, so a native route
762
963
  // template must hold exactly one <main>. More than one (typically a leaf
@@ -802,11 +1003,14 @@ export async function emitNativeTemplates(opts: NativeRouteEmitOpts): Promise<Na
802
1003
  // SSR component artifacts: .components.json + .factory.ts
803
1004
  const compJsonStr = (compiled as any).componentsJson ?? '[]'
804
1005
  if (compJsonStr !== '[]') {
805
- emitComponentArtifacts(outPath, compJsonStr, mergedImports, name)
1006
+ const { generatedPaths } = emitComponentArtifacts(outPath, compJsonStr, mergedImports, name)
806
1007
  outputs.push(
807
1008
  outPath.replace(/\.jinja$/, '.components.json'),
808
1009
  outPath.replace(/\.jinja$/, '.factory.ts'),
1010
+ ...generatedPaths,
809
1011
  )
1012
+ } else {
1013
+ cleanupComponentArtifacts(outPath, name)
810
1014
  }
811
1015
 
812
1016
  // R14 — memoize only what was hashed AND written by an incremental call;
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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
80
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
96
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
117
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
133
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
150
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
166
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
185
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
201
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
217
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
237
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
253
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
274
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
290
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
308
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
324
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
342
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
358
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
376
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
392
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
410
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
426
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
443
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
459
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
479
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
495
+ if (bindingPackageVersion !== '0.1.63-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.63-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.61-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.61-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
511
+ if (bindingPackageVersion !== '0.1.63-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.63-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
513
  }
514
514
  return binding
515
515
  } catch (e) {
@@ -0,0 +1,71 @@
1
+ import { randomUUID } from 'node:crypto'
2
+ import { rmSync, writeFileSync } from 'node:fs'
3
+ import { dirname, relative, resolve } from 'node:path'
4
+
5
+ export interface BehaviorSsrDependency {
6
+ sourcePath: string
7
+ outputPath: string
8
+ }
9
+
10
+ export interface BehaviorSsrModule {
11
+ component: string
12
+ directiveName: string
13
+ moduleId: string
14
+ source: string
15
+ sourcePath: string
16
+ dependencies?: BehaviorSsrDependency[]
17
+ }
18
+
19
+ function rewriteBehaviorImports(entry: BehaviorSsrModule): string {
20
+ if (!entry.dependencies || entry.dependencies.length === 0) return entry.source
21
+ const dependencyBySource = new Map(
22
+ entry.dependencies.map((dependency) => [resolve(dependency.sourcePath), dependency.outputPath]),
23
+ )
24
+ return entry.source.replace(
25
+ /(\bfrom\s*['"])([^'"]+)(['"])/g,
26
+ (statement, before: string, specifier: string, after: string) => {
27
+ if (!specifier.startsWith('.')) return statement
28
+ const importBase = resolve(dirname(entry.sourcePath), specifier)
29
+ const candidates = [
30
+ importBase,
31
+ `${importBase}.tsx`,
32
+ `${importBase}.ts`,
33
+ resolve(importBase, 'index.tsx'),
34
+ resolve(importBase, 'index.ts'),
35
+ ]
36
+ const dependencyOutput = candidates
37
+ .map((candidate) => dependencyBySource.get(candidate))
38
+ .find((candidate) => candidate !== undefined)
39
+ if (!dependencyOutput) return statement
40
+ const rewritten = relative(dirname(entry.sourcePath), dependencyOutput).replaceAll('\\', '/')
41
+ return `${before}${rewritten.startsWith('.') ? rewritten : `./${rewritten}`}${after}`
42
+ },
43
+ )
44
+ }
45
+
46
+ export function emitBehaviorSsrModule(entry: BehaviorSsrModule, outputPath: string): void {
47
+ const temporaryEntry = `${entry.sourcePath}.brust-behavior-${randomUUID()}.tsx`
48
+ writeFileSync(temporaryEntry, rewriteBehaviorImports(entry))
49
+ try {
50
+ const result = Bun.spawnSync({
51
+ cmd: [
52
+ process.execPath,
53
+ 'build',
54
+ temporaryEntry,
55
+ '--target=bun',
56
+ '--format=esm',
57
+ '--packages=external',
58
+ `--outfile=${outputPath}`,
59
+ ],
60
+ stdout: 'pipe',
61
+ stderr: 'pipe',
62
+ })
63
+ if (result.exitCode !== 0) {
64
+ throw new Error(
65
+ `failed to generate SSR behavior module "${entry.component}" (${entry.moduleId}): ${result.stderr.toString()}`,
66
+ )
67
+ }
68
+ } finally {
69
+ rmSync(temporaryEntry, { force: true })
70
+ }
71
+ }
@@ -16,6 +16,7 @@ import { insertGeneratorMeta, resolveGenerator } from '../generator.ts'
16
16
  import {
17
17
  bakeDirectivesIfUsed,
18
18
  buildChainWrapperSource,
19
+ cleanupComponentArtifacts,
19
20
  countMainTags,
20
21
  emitComponentArtifacts,
21
22
  extractLucideIcons,
@@ -384,6 +385,8 @@ export async function emitMdTemplates(opts: MdEmitOpts): Promise<{
384
385
  const compJsonStr = compiled.componentsJson ?? '[]'
385
386
  if (compJsonStr !== '[]') {
386
387
  emitComponentArtifacts(outPath, compJsonStr, mergedImports, name)
388
+ } else {
389
+ cleanupComponentArtifacts(outPath, name)
387
390
  }
388
391
 
389
392
  // 6. Single idempotent bake pass. Every append below is `includes()`-guarded
@@ -1,3 +1,4 @@
1
+ export declare function formatCompilerWarning(warning: string): string;
1
2
  /** Gather transitive component sources starting from a page source file.
2
3
  *
3
4
  * BFS/DFS over local imports reachable from `pageSourcePath`:
@@ -137,6 +138,10 @@ export interface NativeEmitStats {
137
138
  }
138
139
  /** Clear the incremental memo (test isolation). */
139
140
  export declare function resetNativeEmitMemo(): void;
141
+ /** Remove every server-only SSR-component sidecar owned by one route. The
142
+ * route hash in behavior filenames prevents cleanup from touching another
143
+ * route's generated module, even when both render the same component. */
144
+ export declare function cleanupComponentArtifacts(jinjaPath: string, routeName: string): void;
140
145
  /** Write `<Name>.components.json` and `<Name>.factory.ts` for a native route
141
146
  * that has SSR components. Also scans each SSR component's source for Island
142
147
  * `component={X}` references and returns those identifiers so the build step
@@ -152,6 +157,7 @@ export declare function resetNativeEmitMemo(): void;
152
157
  * can carry layout SSR components and need the same sidecar emission. */
153
158
  export declare function emitComponentArtifacts(jinjaPath: string, componentsJsonStr: string, pageImports: Map<string, ResolvedImport>, routeName: string): {
154
159
  islandIdsFromComponents: string[];
160
+ generatedPaths: string[];
155
161
  };
156
162
  export declare function emitNativeTemplates(opts: NativeRouteEmitOpts): Promise<NativeEmitStats>;
157
163
  /** A resolved import reference, capturing the import FORM so the SSR factory can
@@ -0,0 +1,13 @@
1
+ export interface BehaviorSsrDependency {
2
+ sourcePath: string;
3
+ outputPath: string;
4
+ }
5
+ export interface BehaviorSsrModule {
6
+ component: string;
7
+ directiveName: string;
8
+ moduleId: string;
9
+ source: string;
10
+ sourcePath: string;
11
+ dependencies?: BehaviorSsrDependency[];
12
+ }
13
+ export declare function emitBehaviorSsrModule(entry: BehaviorSsrModule, outputPath: string): void;