@@ -31,6 +31,11 @@ const define = {
3131 'process.env.DISABLE_MUTATION_RECOVERY' : 'true' ,
3232} ;
3333
34+ const testingDefine = {
35+ ...define ,
36+ TESTING : 'true' ,
37+ } ;
38+
3439// Vite config helper functions
3540async function getPackageJSON ( ) {
3641 const content = await readFile ( resolve ( 'package.json' ) , 'utf-8' ) ;
@@ -53,10 +58,14 @@ function extractOutPath(path: string): string | undefined {
5358function extractEntries (
5459 entries : Record < string , unknown > ,
5560 getEntryName : ( key : string , outPath : string ) => string ,
61+ excludeKeys : Set < string > = new Set ( ) ,
5662) : Record < string , string > {
5763 const entryPoints : Record < string , string > = { } ;
5864
5965 for ( const [ key , value ] of Object . entries ( entries ) ) {
66+ if ( excludeKeys . has ( key ) ) {
67+ continue ;
68+ }
6069 const path =
6170 typeof value === 'string' ? value : ( value as { default ?: string } ) . default ;
6271
@@ -94,18 +103,37 @@ function getWorkerEntryPoints(): Record<string, string> {
94103 return entryPoints ;
95104}
96105
106+ // Entry points that need TESTING=true
107+ const testingExports = new Set ( [ './testing' ] ) ;
108+
97109async function getAllEntryPoints ( ) : Promise < Record < string , string > > {
98110 const packageJSON = await getPackageJSON ( ) ;
99111
100112 return {
101- ...extractEntries ( packageJSON . exports ?? { } , ( key , outPath ) =>
102- key === '.' ? 'zero/src/zero' : outPath ,
113+ ...extractEntries (
114+ packageJSON . exports ?? { } ,
115+ ( key , outPath ) => ( key === '.' ? 'zero/src/zero' : outPath ) ,
116+ testingExports ,
103117 ) ,
104118 ...extractEntries ( packageJSON . bin ?? { } , ( _ , outPath ) => outPath ) ,
105119 ...getWorkerEntryPoints ( ) ,
106120 } ;
107121}
108122
123+ async function getTestingEntryPoints ( ) : Promise < Record < string , string > > {
124+ const packageJSON = await getPackageJSON ( ) ;
125+
126+ return extractEntries (
127+ packageJSON . exports ?? { } ,
128+ ( key , outPath ) => ( key === '.' ? 'zero/src/zero' : outPath ) ,
129+ new Set (
130+ Object . keys ( packageJSON . exports ?? { } ) . filter (
131+ k => ! testingExports . has ( k ) ,
132+ ) ,
133+ ) ,
134+ ) ;
135+ }
136+
109137const baseConfig : InlineConfig = {
110138 configFile : false ,
111139 logLevel : 'warn' ,
@@ -143,6 +171,28 @@ async function getViteConfig(): Promise<InlineConfig> {
143171 } ;
144172}
145173
174+ async function getTestingViteConfig ( ) : Promise < InlineConfig > {
175+ return {
176+ ...baseConfig ,
177+ define : testingDefine ,
178+ build : {
179+ ...baseConfig . build ,
180+ rollupOptions : {
181+ external,
182+ input : await getTestingEntryPoints ( ) ,
183+ output : {
184+ format : 'es' ,
185+ entryFileNames : '[name].js' ,
186+ chunkFileNames : 'chunks/[name]-[hash].js' ,
187+ // Don't preserve modules for testing - bundle dependencies so they
188+ // get the TESTING=true define
189+ preserveModules : false ,
190+ } ,
191+ } ,
192+ } ,
193+ } ;
194+ }
195+
146196// Bundle size dashboard config: single entry, no code splitting, minified
147197// Uses esbuild's dropLabels to strip BUNDLE_SIZE labeled code blocks
148198const bundleSizeConfig : InlineConfig = {
@@ -233,8 +283,11 @@ async function build() {
233283 // Watch mode: run vite and tsc in watch mode
234284 const viteConfig = await getViteConfig ( ) ;
235285 viteConfig . build = { ...viteConfig . build , watch : { } } ;
286+ const testingConfig = await getTestingViteConfig ( ) ;
287+ testingConfig . build = { ...testingConfig . build , watch : { } } ;
236288 await Promise . all ( [
237289 runViteBuild ( viteConfig , 'vite build (watch)' ) ,
290+ runViteBuild ( testingConfig , 'vite build (testing watch)' ) ,
238291 exec (
239292 'tsc -p tsconfig.client.json --watch --preserveWatchOutput' ,
240293 'client dts (watch)' ,
@@ -247,8 +300,10 @@ async function build() {
247300 } else {
248301 // Normal build: use inline vite config + type declarations
249302 const viteConfig = await getViteConfig ( ) ;
303+ const testingConfig = await getTestingViteConfig ( ) ;
250304 await Promise . all ( [
251305 runViteBuild ( viteConfig , 'vite build' ) ,
306+ runViteBuild ( testingConfig , 'vite build (testing)' ) ,
252307 exec ( 'tsc -p tsconfig.client.json' , 'client dts' ) ,
253308 exec ( 'tsc -p tsconfig.server.json' , 'server dts' ) ,
254309 ] ) ;
0 commit comments