Harden dev-watch excludes for nested UI outputs

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
dotta 2026-03-26 12:27:17 -05:00
parent a8894799e4
commit 9ddf960312
3 changed files with 27 additions and 4 deletions

View file

@ -7,7 +7,7 @@ import { resolveServerDevWatchIgnorePaths } from "../src/dev-watch-ignore.ts";
const require = createRequire(import.meta.url);
const tsxCliPath = require.resolve("tsx/dist/cli.mjs");
const serverRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const ignoreArgs = resolveServerDevWatchIgnorePaths(serverRoot).flatMap((ignorePath) => ["--ignore", ignorePath]);
const ignoreArgs = resolveServerDevWatchIgnorePaths(serverRoot).flatMap((ignorePath) => ["--exclude", ignorePath]);
const child = spawn(
process.execPath,

View file

@ -25,10 +25,18 @@ describe("resolveServerDevWatchIgnorePaths", () => {
const ignorePaths = resolveServerDevWatchIgnorePaths(serverRoot);
expect(ignorePaths).toContain(path.join(worktreeUiRoot, "node_modules"));
expect(ignorePaths).toContain(`${path.join(worktreeUiRoot, "node_modules").replaceAll(path.sep, "/")}/**`);
expect(ignorePaths).toContain(fs.realpathSync(path.join(sharedUiRoot, "node_modules")));
expect(ignorePaths).toContain(`${fs.realpathSync(path.join(sharedUiRoot, "node_modules")).replaceAll(path.sep, "/")}/**`);
expect(ignorePaths).toContain(path.join(worktreeUiRoot, "node_modules", ".vite-temp"));
expect(ignorePaths).toContain(
`${path.join(worktreeUiRoot, "node_modules", ".vite-temp").replaceAll(path.sep, "/")}/**`,
);
expect(ignorePaths).toContain(path.join(worktreeUiRoot, ".vite"));
expect(ignorePaths).toContain(fs.realpathSync(path.join(sharedUiRoot, ".vite")));
expect(ignorePaths).toContain(path.join(worktreeUiRoot, "dist"));
expect(ignorePaths).toContain(fs.realpathSync(path.join(sharedUiRoot, "dist")));
expect(ignorePaths).toContain("**/{node_modules,bower_components,vendor}/**");
expect(ignorePaths).toContain("**/.vite-temp/**");
});
});

View file

@ -1,19 +1,34 @@
import fs from "node:fs";
import path from "node:path";
function toGlobstarPath(candidate: string): string {
return `${candidate.replaceAll(path.sep, "/")}/**`;
}
function addIgnorePath(target: Set<string>, candidate: string): void {
target.add(candidate);
target.add(toGlobstarPath(candidate));
try {
target.add(fs.realpathSync(candidate));
const realPath = fs.realpathSync(candidate);
target.add(realPath);
target.add(toGlobstarPath(realPath));
} catch {
// Ignore paths that do not exist in the current checkout.
}
}
export function resolveServerDevWatchIgnorePaths(serverRoot: string): string[] {
const ignorePaths = new Set<string>();
const ignorePaths = new Set<string>([
"**/{node_modules,bower_components,vendor}/**",
"**/.vite-temp/**",
]);
for (const relativePath of ["../ui/node_modules", "../ui/.vite", "../ui/dist"]) {
for (const relativePath of [
"../ui/node_modules",
"../ui/node_modules/.vite-temp",
"../ui/.vite",
"../ui/dist",
]) {
addIgnorePath(ignorePaths, path.resolve(serverRoot, relativePath));
}