fix: remove compiled plugin JS left behind in plugins/ after build

copy-bundled-plugins.cjs compiled and rewrote plugin backend TS in
place, copied it to dist/plugins, but never deleted the .js it had
just emitted next to the .ts sources. Those files shadowed the real
source for vitest/tsx and had import paths rewritten for the dist
layout, so tests failed with "Cannot find module" once a local build
had run. Affects docker, host-metrics and ai, not just this one.
This commit is contained in:
LukeGus committed 2026-09-21 15:25:17 -05:00
1 parent 504710b065
commit ee2d6b4697
1 file changed
+30 -1
+30 -1
View File
@@ -133,8 +133,33 @@ function compiledPluginBackendDirs() {
);
}
/**
* Deletes every .js file tsc just emitted directly under a plugin's own
* backend/ directory (recursively), leaving its .ts siblings untouched.
*
* Without this, the compiled .js sits next to the .ts in plugins/ after every
* build, shadowing the source when vitest/tsx resolve an import -- and since
* those .js files were rewritten for the dist/ layout (see rewriteCoreImports),
* their relative paths are wrong at the plugins/ depth, so anything importing
* them from a test fails with "Cannot find module". .gitignore already
* expects plugins/*\/backend/**\/*.js to never be tracked; this is what keeps
* the working tree matching that after a local build, the same way dist/ is
* expected to hold the only copy of compiled plugin output.
*/
function removeCompiledPluginEmits(dir) {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const entryPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
removeCompiledPluginEmits(entryPath);
continue;
}
if (entry.name.endsWith(".js")) fs.rmSync(entryPath);
}
}
compilePluginBackends();
for (const dir of compiledPluginBackendDirs()) {
const compiledDirs = compiledPluginBackendDirs();
for (const dir of compiledDirs) {
rewriteCoreImports(dir);
}
removeStrayEmits(path.join(root, "src"));
@@ -142,6 +167,10 @@ removeStrayEmits(path.join(root, "src"));
fs.rmSync(destination, { recursive: true, force: true });
fs.cpSync(source, destination, { recursive: true });
for (const dir of compiledDirs) {
removeCompiledPluginEmits(dir);
}
const bundled = fs
.readdirSync(destination, { withFileTypes: true })
.filter((entry) => entry.isDirectory())