fix: stop the dev runner rebuilding plugins when windows reports file reads as changes

This commit is contained in:
LukeGus committed 2026-10-06 17:44:17 -05:00
1 parent 2d71e886ac
commit fb904554e8
8 files changed
+57 -407

No files matched your search

+29
View File
@@ -7,6 +7,7 @@ import {
createSerialQueue,
dataDirFor,
findBuildablePlugins,
isPluginEdit,
isPluginSourceChange,
needsDocker,
parseDevArgs,
@@ -46,6 +47,34 @@ describe("isPluginSourceChange", () => {
});
});
describe("isPluginEdit", () => {
function repo() {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "termix-edit-"));
cleanups.push(() => fs.rmSync(dir, { recursive: true, force: true }));
fs.mkdirSync(path.join(dir, "src", "frontend"), { recursive: true });
fs.writeFileSync(path.join(dir, "src", "frontend", "index.ts"), "");
return dir;
}
it("ignores a folder being read", () => {
expect(isPluginEdit(repo(), "src/frontend", () => true)).toBe(false);
});
it("rebuilds an edited file only while the build is out of date", () => {
const dir = repo();
expect(isPluginEdit(dir, "src/frontend/index.ts", () => true)).toBe(true);
expect(isPluginEdit(dir, "src/frontend/index.ts", () => false)).toBe(false);
});
it("rebuilds after a source file is deleted", () => {
expect(isPluginEdit(repo(), "src/gone.ts", () => false)).toBe(true);
});
it("skips paths that do not feed the build", () => {
expect(isPluginEdit(repo(), "dist/index.js", () => true)).toBe(false);
});
});
describe("findBuildablePlugins", () => {
it("lists repos with a manifest and installed dependencies", () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "termix-dev-"));
+2 -2
View File
@@ -29,7 +29,7 @@ import {
createSerialQueue,
dataDirFor,
findBuildablePlugins,
isPluginSourceChange,
isPluginEdit,
needsDocker,
parseDevArgs,
parseTscStatus,
@@ -575,7 +575,7 @@ function watchPlugins(dir) {
);
for (const plugin of plugins) {
watch(plugin.repo, true, (_event, filename) => {
if (isPluginSourceChange(filename)) changed(plugin.id);
if (isPluginEdit(plugin.repo, filename)) changed(plugin.id);
});
}
log(`watching ${plugins.length} plugin(s) in ${dir}`);
+26
View File
@@ -1,5 +1,10 @@
import fs from "node:fs";
import path from "node:path";
import { createRequire } from "node:module";
const { isLocalBuildStale } = createRequire(import.meta.url)(
"./bundled-plugins.cjs",
);
const ID = /^[a-z0-9][a-z0-9-]*$/;
const SOURCE_DIRS = new Set(["src", "locales", "migrations"]);
@@ -19,6 +24,27 @@ export function isPluginSourceChange(filename) {
return SOURCE_DIRS.has(parts[0]);
}
/**
* Whether a watcher event in a plugin repo is an edit worth a rebuild.
*
* On Windows, fs.watch also reports a folder or file being read (its last
* access time changing, which NTFS writes lazily), so reading a repo looks
* like editing it. Folder events are ignored, and a file event only counts
* while its sources are newer than the last build. A path that no longer
* exists was deleted, which always counts.
*/
export function isPluginEdit(repo, filename, isStale = isLocalBuildStale) {
if (!isPluginSourceChange(filename)) return false;
let stat;
try {
stat = fs.statSync(path.join(repo, String(filename)));
} catch {
return true;
}
if (stat.isDirectory()) return false;
return isStale(repo);
}
/** Plugin repos under dir that can be built (manifest.json and node_modules). */
export function findBuildablePlugins(dir) {
const plugins = [];