@@ -118,13 +118,13 @@ function fakeDevServer(
118118 return { server, invalidated, restart, emit, logError } ;
119119}
120120
121- function startDevServer (
121+ async function startDevServer (
122122 plugin : RoutingPlugin ,
123123 moduleIds ?: Array < string > ,
124124 extraEnvironments ?: Record < string , unknown > ,
125125) {
126126 const dev = fakeDevServer ( moduleIds , extraEnvironments ) ;
127- ( getHookHandler ( plugin . configureServer ) as ( server : unknown ) => void ) ( dev . server ) ;
127+ await ( getHookHandler ( plugin . configureServer ) as ( server : unknown ) => Promise < void > ) ( dev . server ) ;
128128 return dev ;
129129}
130130
@@ -188,6 +188,26 @@ describe('routingPlugin', () => {
188188 expect ( database ) . toContain ( 'requireRuntimeBinding<D1Database>("AUTH_DB")' ) ;
189189 } ) ;
190190
191+ it ( 'writes auth files before later configureServer hooks can load the Worker' , async ( ) => {
192+ const root = createTempRoot ( ) ;
193+ writeFileSync (
194+ join ( root , 'auth.ts' ) ,
195+ "export type {} from 'void/auth';\nexport default { user: { additionalFields: { nickname: { type: 'string' } } } };" ,
196+ ) ;
197+ const plugin = createRoutingPlugin ( root , { isAuthEnabled : ( ) => true } ) ;
198+ resolveConfig ( plugin , 'serve' ) ;
199+ const dev = fakeDevServer ( ) ;
200+
201+ await ( getHookHandler ( plugin . configureServer ) as ( server : unknown ) => Promise < void > ) (
202+ dev . server ,
203+ ) ;
204+
205+ expect ( readFileSync ( join ( root , '.void' , 'better-auth-schema.ts' ) , 'utf8' ) ) . toContain (
206+ '"nickname"' ,
207+ ) ;
208+ expect ( existsSync ( join ( root , '.void' , 'better-auth-db.ts' ) ) ) . toBe ( true ) ;
209+ } ) ;
210+
191211 it ( 'resolves extensionless and Vite alias imports in auth.ts during a build' , async ( ) => {
192212 const root = createTempRoot ( ) ;
193213 mkdirSync ( join ( root , 'lib' ) ) ;
@@ -384,7 +404,7 @@ describe('routingPlugin', () => {
384404 } ) ;
385405 resolveConfig ( plugin , 'serve' ) ;
386406 await runBuildStart ( plugin ) ;
387- const { emit, restart } = startDevServer ( plugin ) ;
407+ const { emit, restart } = await startDevServer ( plugin ) ;
388408 restart . mockImplementation ( ( ) => runBuildStart ( plugin ) ) ;
389409
390410 const addedPath = join ( root , 'routes' , addedRoute ) ;
@@ -405,7 +425,7 @@ describe('routingPlugin', () => {
405425 ) ;
406426
407427 const plugin = createRoutingPlugin ( root , { isAuthEnabled : ( ) => false } ) ;
408- const { emit, invalidated } = startDevServer ( plugin , PAGE_MODULE_IDS ) ;
428+ const { emit, invalidated } = await startDevServer ( plugin , PAGE_MODULE_IDS ) ;
409429
410430 writeFileSync (
411431 join ( root , 'pages' , 'test.tsx' ) ,
@@ -429,7 +449,7 @@ describe('routingPlugin', () => {
429449
430450 const plugin = createRoutingPlugin ( root , { isAuthEnabled : ( ) => false } ) ;
431451 resolveConfig ( plugin , 'serve' , plugins ) ;
432- const { emit, invalidated, logError } = startDevServer ( plugin , PAGE_MODULE_IDS ) ;
452+ const { emit, invalidated, logError } = await startDevServer ( plugin , PAGE_MODULE_IDS ) ;
433453
434454 // Moving about.tsx to about/index.tsx adds the new file before the old one goes.
435455 const indexPath = join ( root , 'pages' , 'about' , 'index.tsx' ) ;
@@ -463,7 +483,7 @@ describe('routingPlugin', () => {
463483 runConfig ( plugin , { command : 'serve' , mode : 'development' } ) ;
464484 resolveConfig ( plugin , 'serve' ) ;
465485 await runBuildStart ( plugin ) ;
466- const { emit, logError } = startDevServer ( plugin , PAGE_MODULE_IDS ) ;
486+ const { emit, logError } = await startDevServer ( plugin , PAGE_MODULE_IDS ) ;
467487 const typesPath = join ( root , '.void' , 'routes.d.ts' ) ;
468488 const before = readFileSync ( typesPath , 'utf8' ) ;
469489 expect ( before ) . toContain ( 'pages/home.dev.server.ts' ) ;
@@ -490,7 +510,7 @@ describe('routingPlugin', () => {
490510 const plugin = createRoutingPlugin ( root , { isAuthEnabled : ( ) => false } ) ;
491511 resolveConfig ( plugin , 'serve' ) ;
492512 await runBuildStart ( plugin ) ;
493- const { emit, invalidated } = startDevServer ( plugin , PAGE_MODULE_IDS ) ;
513+ const { emit, invalidated } = await startDevServer ( plugin , PAGE_MODULE_IDS ) ;
494514
495515 writeFileSync ( pagePath , 'export default function Index() { return <h1>Updated</h1>; }' ) ;
496516 await emit ( 'change' , pagePath ) ;
@@ -519,7 +539,7 @@ describe('routingPlugin', () => {
519539 const plugin = createRoutingPlugin ( root , { isAuthEnabled : ( ) => false } ) ;
520540 resolveConfig ( plugin , 'serve' ) ;
521541 await runBuildStart ( plugin ) ;
522- const { emit, invalidated } = startDevServer ( plugin , PAGE_MODULE_IDS ) ;
542+ const { emit, invalidated } = await startDevServer ( plugin , PAGE_MODULE_IDS ) ;
523543
524544 writeFileSync (
525545 serverPath ,
@@ -562,7 +582,9 @@ describe('routingPlugin', () => {
562582
563583 const typesPath = join ( root , '.void' , 'routes.d.ts' ) ;
564584 const previousTypes = readFileSync ( typesPath , 'utf-8' ) ;
565- const { server, emit, invalidated, logError } = startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
585+ const { server, emit, invalidated, logError } = await startDevServer ( plugin , [
586+ 'virtual:void-routes' ,
587+ ] ) ;
566588
567589 expect ( previousTypes ) . not . toContain ( 'POST: {' ) ;
568590
@@ -624,7 +646,7 @@ describe('routingPlugin', () => {
624646 const plugin = createRoutingPlugin ( root , { isAuthEnabled : ( ) => false } ) ;
625647 resolveConfig ( plugin , 'serve' ) ;
626648 await runBuildStart ( plugin ) ;
627- const { emit, invalidated } = startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
649+ const { emit, invalidated } = await startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
628650
629651 writeFileSync ( envPath , 'export default { example: true };' ) ;
630652 await emit ( 'change' , envPath ) ;
@@ -645,7 +667,9 @@ describe('routingPlugin', () => {
645667 const plugin = createRoutingPlugin ( root , { isAuthEnabled : ( ) => false } ) ;
646668 resolveConfig ( plugin , 'serve' ) ;
647669 await runBuildStart ( plugin ) ;
648- const { server, emit, invalidated, logError } = startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
670+ const { server, emit, invalidated, logError } = await startDevServer ( plugin , [
671+ 'virtual:void-routes' ,
672+ ] ) ;
649673 vi . spyOn (
650674 server . environments . void_worker . moduleGraph ,
651675 'invalidateModule' ,
@@ -673,7 +697,7 @@ describe('routingPlugin', () => {
673697 const plugin = createRoutingPlugin ( root , { isAuthEnabled : ( ) => false } ) ;
674698 resolveConfig ( plugin , 'serve' ) ;
675699 await runBuildStart ( plugin ) ;
676- const { emit, invalidated } = startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
700+ const { emit, invalidated } = await startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
677701 const typesPath = join ( root , '.void' , 'routes.d.ts' ) ;
678702 const types = readFileSync ( typesPath , 'utf8' ) ;
679703
@@ -701,7 +725,7 @@ describe('routingPlugin', () => {
701725 ) ;
702726 const plugin = routingPlugin ( root , { isAuthEnabled : ( ) => true , getApplicationAnalysis } ) ;
703727 resolveConfig ( plugin , 'serve' ) ;
704- const { emit, invalidated } = startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
728+ const { emit, invalidated } = await startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
705729 if ( overlap === 'another save' ) {
706730 await runBuildStart ( plugin ) ;
707731 }
@@ -768,7 +792,7 @@ describe('routingPlugin', () => {
768792 const plugin = createRoutingPlugin ( root , { isAuthEnabled : ( ) => true } ) ;
769793 resolveConfig ( plugin , 'serve' ) ;
770794 await runBuildStart ( plugin ) ;
771- const { emit, invalidated } = startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
795+ const { emit, invalidated } = await startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
772796 writeFileSync ( configPath , 'export default ' + JSON . stringify ( config ) ) ;
773797 writeFileSync ( routePath , 'export const GET = () => new Response("updated");' ) ;
774798 await emit ( 'change' , routePath ) ;
@@ -797,7 +821,7 @@ describe('routingPlugin', () => {
797821 const plugin = createRoutingPlugin ( root , { target, isAuthEnabled : ( ) => auth } ) ;
798822 resolveConfig ( plugin , 'serve' ) ;
799823 await runBuildStart ( plugin ) ;
800- const { emit, invalidated } = startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
824+ const { emit, invalidated } = await startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
801825 const outputs = files . map ( ( file ) => {
802826 const path = join ( root , '.void' , file ) ;
803827 const content = readFileSync ( path , 'utf8' ) ;
@@ -969,7 +993,7 @@ describe('routingPlugin', () => {
969993 isAuthEnabled : ( ) => false ,
970994 onDevAssetRoutingPolicyChange : onPolicyChange ,
971995 } ) ;
972- const { emit, invalidated } = startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
996+ const { emit, invalidated } = await startDevServer ( plugin , [ 'virtual:void-routes' ] ) ;
973997
974998 const routePath = join ( root , 'src' , 'routes' , 'api.ts' ) ;
975999 writeFileSync ( routePath , 'export const GET = () => new Response("ok");\n' ) ;
@@ -988,7 +1012,7 @@ describe('routingPlugin', () => {
9881012 mkdirSync ( join ( root , 'src' , 'pages' ) , { recursive : true } ) ;
9891013
9901014 const plugin = createRoutingPlugin ( root , { isAuthEnabled : ( ) => false } ) ;
991- const { emit, invalidated } = startDevServer ( plugin , PAGE_MODULE_IDS ) ;
1015+ const { emit, invalidated } = await startDevServer ( plugin , PAGE_MODULE_IDS ) ;
9921016
9931017 const pagePath = join ( root , 'src' , 'pages' , 'test.tsx' ) ;
9941018 writeFileSync ( pagePath , 'export default function Test() { return null; }' ) ;
0 commit comments