@@ -25,55 +25,63 @@ export async function buildApp(
2525 const baseDir = config . environments . client . build . outDir ;
2626 const base = normalizeBase ( config . base ) ;
2727
28- const { entries, deferRegistry } = await entry . build ( ) ;
29-
30- // Validate all entry paths
31- const paths : string [ ] = [ ] ;
32- for ( const result of entries ) {
33- const error = validateEntryPath ( result . path ) ;
34- if ( error ) {
35- throw new Error ( error ) ;
28+ async function doBuild ( ) {
29+ const { entries, deferRegistry } = await entry . build ( ) ;
30+
31+ // Validate all entry paths
32+ const paths : string [ ] = [ ] ;
33+ for ( const result of entries ) {
34+ const error = validateEntryPath ( result . path ) ;
35+ if ( error ) {
36+ throw new Error ( error ) ;
37+ }
38+ paths . push ( result . path ) ;
39+ }
40+ const dupError = checkDuplicatePaths ( paths ) ;
41+ if ( dupError ) {
42+ throw new Error ( dupError ) ;
3643 }
37- paths . push ( result . path ) ;
38- }
39- const dupError = checkDuplicatePaths ( paths ) ;
40- if ( dupError ) {
41- throw new Error ( dupError ) ;
42- }
43-
44- // Process all deferred components once across all entries.
45- // We pass a dummy empty stream since we handle per-entry RSC payloads separately.
46- const dummyStream = new ReadableStream < Uint8Array > ( {
47- start ( controller ) {
48- controller . close ( ) ;
49- } ,
50- } ) ;
51- const { components, idMapping } = await processRscComponents (
52- deferRegistry . loadAll ( ) ,
53- dummyStream ,
54- options . rscPayloadDir ,
55- context ,
56- ) ;
5744
58- // Write each entry's HTML and RSC payload
59- for ( const result of entries ) {
60- await buildSingleEntry (
61- result ,
62- idMapping ,
63- baseDir ,
64- base ,
45+ // Process all deferred components once across all entries.
46+ // We pass a dummy empty stream since we handle per-entry RSC payloads separately.
47+ const dummyStream = new ReadableStream < Uint8Array > ( {
48+ start ( controller ) {
49+ controller . close ( ) ;
50+ } ,
51+ } ) ;
52+ const { components, idMapping } = await processRscComponents (
53+ deferRegistry . loadAll ( ) ,
54+ dummyStream ,
6555 options . rscPayloadDir ,
6656 context ,
6757 ) ;
58+
59+ // Write each entry's HTML and RSC payload
60+ for ( const result of entries ) {
61+ await buildSingleEntry (
62+ result ,
63+ idMapping ,
64+ baseDir ,
65+ base ,
66+ options . rscPayloadDir ,
67+ context ,
68+ ) ;
69+ }
70+
71+ // Write all deferred component payloads
72+ for ( const { finalId, finalContent, name } of components ) {
73+ const filePath = path . join (
74+ baseDir ,
75+ getModulePathFor ( finalId ) . replace ( / ^ \/ / , "" ) ,
76+ ) ;
77+ await writeFileNormal ( filePath , finalContent , context , name ) ;
78+ }
6879 }
6980
70- // Write all deferred component payloads
71- for ( const { finalId, finalContent, name } of components ) {
72- const filePath = path . join (
73- baseDir ,
74- getModulePathFor ( finalId ) . replace ( / ^ \/ / , "" ) ,
75- ) ;
76- await writeFileNormal ( filePath , finalContent , context , name ) ;
81+ if ( entry . buildEntry ) {
82+ await entry . buildEntry ( { build : doBuild , outDir : baseDir } ) ;
83+ } else {
84+ await doBuild ( ) ;
7785 }
7886}
7987
0 commit comments