@@ -17,13 +17,13 @@ import * as Typegen from "../typegen";
1717import { preloadVite , getVite } from "../vite/vite" ;
1818
1919export async function routes (
20- reactRouterRoot ?: string ,
20+ rootDirectory ?: string ,
2121 flags : {
2222 config ?: string ;
2323 json ?: boolean ;
2424 } = { }
2525) : Promise < void > {
26- let rootDirectory = reactRouterRoot ?? process . cwd ( ) ;
26+ rootDirectory = resolveRootDirectory ( rootDirectory , flags ) ;
2727 let configResult = await loadConfig ( { rootDirectory } ) ;
2828
2929 if ( ! configResult . ok ) {
@@ -39,9 +39,7 @@ export async function build(
3939 root ?: string ,
4040 options : ViteBuildOptions = { }
4141) : Promise < void > {
42- if ( ! root ) {
43- root = process . env . REACT_ROUTER_ROOT || process . cwd ( ) ;
44- }
42+ root = resolveRootDirectory ( root , options ) ;
4543
4644 let { build } = await import ( "../vite/build" ) ;
4745 if ( options . profile ) {
@@ -54,12 +52,14 @@ export async function build(
5452 }
5553}
5654
57- export async function dev ( root : string , options : ViteDevOptions = { } ) {
55+ export async function dev ( root ? : string , options : ViteDevOptions = { } ) {
5856 let { dev } = await import ( "../vite/dev" ) ;
5957 if ( options . profile ) {
6058 await profiler . start ( ) ;
6159 }
6260 exitHook ( ( ) => profiler . stop ( console . info ) ) ;
61+
62+ root = resolveRootDirectory ( root , options ) ;
6363 await dev ( root , options ) ;
6464
6565 // keep `react-router dev` alive by waiting indefinitely
@@ -77,20 +77,20 @@ let conjunctionListFormat = new Intl.ListFormat("en", {
7777
7878export async function generateEntry (
7979 entry ?: string ,
80- reactRouterRoot ?: string ,
80+ rootDirectory ?: string ,
8181 flags : {
8282 typescript ?: boolean ;
8383 config ?: string ;
8484 } = { }
8585) {
8686 // if no entry passed, attempt to create both
8787 if ( ! entry ) {
88- await generateEntry ( "entry.client" , reactRouterRoot , flags ) ;
89- await generateEntry ( "entry.server" , reactRouterRoot , flags ) ;
88+ await generateEntry ( "entry.client" , rootDirectory , flags ) ;
89+ await generateEntry ( "entry.server" , rootDirectory , flags ) ;
9090 return ;
9191 }
9292
93- let rootDirectory = reactRouterRoot ?? process . cwd ( ) ;
93+ rootDirectory = resolveRootDirectory ( rootDirectory , flags ) ;
9494 let configResult = await loadConfig ( { rootDirectory } ) ;
9595
9696 if ( ! configResult . ok ) {
@@ -162,6 +162,17 @@ export async function generateEntry(
162162 ) ;
163163}
164164
165+ function resolveRootDirectory ( root ?: string , flags ?: { config ?: string } ) {
166+ if ( root ) {
167+ return path . resolve ( root ) ;
168+ }
169+
170+ return (
171+ process . env . REACT_ROUTER_ROOT ||
172+ ( flags ?. config ? path . dirname ( path . resolve ( flags . config ) ) : process . cwd ( ) )
173+ ) ;
174+ }
175+
165176async function checkForEntry (
166177 rootDirectory : string ,
167178 appDirectory : string ,
@@ -198,8 +209,14 @@ async function createClientEntry(
198209 return contents ;
199210}
200211
201- export async function typegen ( root : string , flags : { watch : boolean } ) {
202- root ??= process . cwd ( ) ;
212+ export async function typegen (
213+ root : string ,
214+ flags : {
215+ watch ?: boolean ;
216+ config ?: string ;
217+ }
218+ ) {
219+ root = resolveRootDirectory ( root , flags ) ;
203220
204221 if ( flags . watch ) {
205222 await preloadVite ( ) ;
0 commit comments