@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
22import { dirname , join , relative , resolve } from 'node:path' ;
33import { readConfiguration } from '@angular/compiler-cli' ;
44import { parseSync } from 'oxc-parser' ;
5- import { normalizePath , type Plugin } from 'vite' ;
5+ import { normalizePath , searchForWorkspaceRoot , type Plugin } from 'vite' ;
66
77import {
88 createRouteFileDiscovery ,
@@ -27,14 +27,14 @@ export interface TypedRoutesPluginOptions extends TypedRoutingOptions {
2727}
2828
2929export function typedRoutes ( options : TypedRoutesPluginOptions = { } ) : Plugin {
30- const workspaceRoot = normalizePath ( options . workspaceRoot ?? process . cwd ( ) ) ;
3130 const outFile = options . outFile ?? 'src/routeTree.gen.d.ts' ;
3231 if ( ! outFile . endsWith ( '.d.ts' ) ) {
3332 throw new Error (
3433 '[analog] Typed routing outFile must end in .d.ts. Include this declaration in your application tsconfig.' ,
3534 ) ;
3635 }
3736 let root : string ;
37+ let workspaceRoot : string ;
3838 let command : 'build' | 'serve' ;
3939 let discovery : RouteFileDiscovery ;
4040
@@ -113,7 +113,14 @@ export function typedRoutes(options: TypedRoutesPluginOptions = {}): Plugin {
113113 name : 'analog-typed-routes' ,
114114 config ( config , env ) {
115115 command = env . command ;
116- root = normalizePath ( resolve ( workspaceRoot , config . root ?? '.' ) ) ;
116+ root = normalizePath (
117+ resolve ( options . workspaceRoot ?? process . cwd ( ) , config . root ?? '.' ) ,
118+ ) ;
119+ workspaceRoot = normalizePath (
120+ options . workspaceRoot ??
121+ process . env [ 'NX_WORKSPACE_ROOT' ] ??
122+ searchForWorkspaceRoot ( root ) ,
123+ ) ;
117124 discovery = createRouteFileDiscovery ( {
118125 root,
119126 workspaceRoot,
0 commit comments