Skip to content

Commit

Permalink
fix: watch loop caused by the custom output path
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Mar 9, 2025
1 parent 6153263 commit 65283eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ type RoutesInfo = Record<string, {
params: string[];
}>

export const DEFAULT_OUTPUT_DIR_PATH = './.react-router/types'
export const DEFAULT_OUTPUT_DIR_PATH = './.react-router/types';
export const TYPE_FILE_NAME = 'safe-routes.d.ts';

async function buildHelpers(config: RequiredReactRouterConfig): Promise<[RoutesInfo, string[]]> {
const routesInfo: RoutesInfo = {};
Expand Down Expand Up @@ -103,7 +104,7 @@ function generate(root: string, config: RequiredReactRouterConfig, routesInfo: R
if (!fs.existsSync(outputPath)) {
mkdirp.sync(outputPath);
}
fs.writeFileSync(path.join(outputPath, 'safe-routes.d.ts'), tsCode);
fs.writeFileSync(path.join(outputPath, TYPE_FILE_NAME), tsCode);
}

function parse(routes: RouteManifestEntry[]) {
Expand Down
6 changes: 5 additions & 1 deletion src/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import replace from '@rollup/plugin-replace';
import * as Vite from 'vite';
import { join } from 'node:path';
import { placeholder } from './basename.js';
import { DEFAULT_OUTPUT_DIR_PATH, build } from './build.js';
import { DEFAULT_OUTPUT_DIR_PATH, TYPE_FILE_NAME, build } from './build.js';
import { ReactRouterPluginContext } from './types.js';

export interface PluginOptions {
Expand Down Expand Up @@ -67,6 +67,10 @@ export function safeRoutes(pluginConfig: PluginOptions = {}): Vite.Plugin {
return;
}

if (pluginConfig.outDir && id === join(rootDirectory, pluginConfig.outDir, TYPE_FILE_NAME)) {
return;
}

await reloadCtx();
generateTypeFile();
},
Expand Down

0 comments on commit 65283eb

Please sign in to comment.