Skip to content

Commit e3e6de0

Browse files
fix(platform): resolve typed routes workspace root from the project root (#2756)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 3befc24 commit e3e6de0

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎packages/platform/src/lib/typed-routes-plugin.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
22
import { dirname, join, relative, resolve } from 'node:path';
33
import { readConfiguration } from '@angular/compiler-cli';
44
import { parseSync } from 'oxc-parser';
5-
import { normalizePath, type Plugin } from 'vite';
5+
import { normalizePath, searchForWorkspaceRoot, type Plugin } from 'vite';
66

77
import {
88
createRouteFileDiscovery,
@@ -27,14 +27,14 @@ export interface TypedRoutesPluginOptions extends TypedRoutingOptions {
2727
}
2828

2929
export 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

Comments
 (0)