Harden dev-watch excludes for nested UI outputs
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
a8894799e4
commit
9ddf960312
3 changed files with 27 additions and 4 deletions
|
|
@ -7,7 +7,7 @@ import { resolveServerDevWatchIgnorePaths } from "../src/dev-watch-ignore.ts";
|
||||||
const require = createRequire(import.meta.url);
|
const require = createRequire(import.meta.url);
|
||||||
const tsxCliPath = require.resolve("tsx/dist/cli.mjs");
|
const tsxCliPath = require.resolve("tsx/dist/cli.mjs");
|
||||||
const serverRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
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(
|
const child = spawn(
|
||||||
process.execPath,
|
process.execPath,
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,18 @@ describe("resolveServerDevWatchIgnorePaths", () => {
|
||||||
const ignorePaths = resolveServerDevWatchIgnorePaths(serverRoot);
|
const ignorePaths = resolveServerDevWatchIgnorePaths(serverRoot);
|
||||||
|
|
||||||
expect(ignorePaths).toContain(path.join(worktreeUiRoot, "node_modules"));
|
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")));
|
||||||
|
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(path.join(worktreeUiRoot, ".vite"));
|
||||||
expect(ignorePaths).toContain(fs.realpathSync(path.join(sharedUiRoot, ".vite")));
|
expect(ignorePaths).toContain(fs.realpathSync(path.join(sharedUiRoot, ".vite")));
|
||||||
expect(ignorePaths).toContain(path.join(worktreeUiRoot, "dist"));
|
expect(ignorePaths).toContain(path.join(worktreeUiRoot, "dist"));
|
||||||
expect(ignorePaths).toContain(fs.realpathSync(path.join(sharedUiRoot, "dist")));
|
expect(ignorePaths).toContain(fs.realpathSync(path.join(sharedUiRoot, "dist")));
|
||||||
|
expect(ignorePaths).toContain("**/{node_modules,bower_components,vendor}/**");
|
||||||
|
expect(ignorePaths).toContain("**/.vite-temp/**");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,34 @@
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
|
function toGlobstarPath(candidate: string): string {
|
||||||
|
return `${candidate.replaceAll(path.sep, "/")}/**`;
|
||||||
|
}
|
||||||
|
|
||||||
function addIgnorePath(target: Set<string>, candidate: string): void {
|
function addIgnorePath(target: Set<string>, candidate: string): void {
|
||||||
target.add(candidate);
|
target.add(candidate);
|
||||||
|
target.add(toGlobstarPath(candidate));
|
||||||
try {
|
try {
|
||||||
target.add(fs.realpathSync(candidate));
|
const realPath = fs.realpathSync(candidate);
|
||||||
|
target.add(realPath);
|
||||||
|
target.add(toGlobstarPath(realPath));
|
||||||
} catch {
|
} catch {
|
||||||
// Ignore paths that do not exist in the current checkout.
|
// Ignore paths that do not exist in the current checkout.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveServerDevWatchIgnorePaths(serverRoot: string): string[] {
|
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));
|
addIgnorePath(ignorePaths, path.resolve(serverRoot, relativePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue