@@ -139,11 +139,12 @@ export async function generateWrapper(
139139 `Migration handler not found: ${ handlerFilename_ } . Run "pnpm -C packages/void build" first.` ,
140140 ) ;
141141 }
142- if ( features . migrationDialect === 'postgresql' ) {
143- await bundlePgMigrationHandler ( root , workerDir , handlerPath ) ;
144- } else {
145- copyFileSync ( handlerPath , join ( workerDir , '__void_migration_handler.mjs' ) ) ;
146- }
142+ await bundleMigrationHandler (
143+ root ,
144+ workerDir ,
145+ handlerPath ,
146+ features . migrationDialect ?? 'sqlite' ,
147+ ) ;
147148 }
148149
149150 // Write wrapper in place of original entry
@@ -157,30 +158,36 @@ export async function generateWrapper(
157158 writeFileSync ( join ( workerDir , workerMain ) , wrapperSource ) ;
158159}
159160
160- async function bundlePgMigrationHandler (
161+ async function bundleMigrationHandler (
161162 root : string ,
162163 workerDir : string ,
163164 handlerPath : string ,
165+ dialect : 'sqlite' | 'postgresql' ,
164166) : Promise < void > {
165167 const tmpDir = join ( root , '.void' , 'migration-handler' ) ;
166168 mkdirSync ( tmpDir , { recursive : true } ) ;
167169 const outDir = join ( tmpDir , 'out' ) ;
170+ const isPostgresql = dialect === 'postgresql' ;
168171 await build ( {
169172 root : tmpDir ,
170173 logLevel : 'silent' ,
171- resolve : {
172- alias : {
173- 'pg-cloudflare' : resolvePgCloudflareWorkerdEntry ( handlerPath ) ,
174- 'pg-pool' : resolvePgCjsDependency ( handlerPath , 'pg-pool' ) ,
175- } ,
176- conditions : [ 'workerd' , 'worker' , 'browser' , 'module' , 'import' , 'default' ] ,
177- } ,
178- ssr : {
179- noExternal : [ 'pg' , 'pg-cloudflare' ] ,
180- resolve : {
181- conditions : [ 'workerd' , 'worker' , 'browser' , 'module' , 'import' , 'default' ] ,
182- } ,
183- } ,
174+ resolve : isPostgresql
175+ ? {
176+ alias : {
177+ 'pg-cloudflare' : resolvePgCloudflareWorkerdEntry ( handlerPath ) ,
178+ 'pg-pool' : resolvePgCjsDependency ( handlerPath , 'pg-pool' ) ,
179+ } ,
180+ conditions : [ 'workerd' , 'worker' , 'browser' , 'module' , 'import' , 'default' ] ,
181+ }
182+ : undefined ,
183+ ssr : isPostgresql
184+ ? {
185+ noExternal : [ 'pg' , 'pg-cloudflare' ] ,
186+ resolve : {
187+ conditions : [ 'workerd' , 'worker' , 'browser' , 'module' , 'import' , 'default' ] ,
188+ } ,
189+ }
190+ : undefined ,
184191 build : {
185192 outDir,
186193 emptyOutDir : true ,
@@ -198,7 +205,9 @@ async function bundlePgMigrationHandler(
198205 } ,
199206 } ) ;
200207
201- patchPgWorkerBundle ( outDir ) ;
208+ if ( isPostgresql ) {
209+ patchPgWorkerBundle ( outDir ) ;
210+ }
202211 for ( const file of readdirSync ( outDir ) ) {
203212 copyFileSync ( join ( outDir , file ) , join ( workerDir , file ) ) ;
204213 }
0 commit comments