From ee2d6b469745be128e6f3c6e3df6f543012755d1 Mon Sep 17 00:00:00 2001 From: LukeGus Date: Mon, 21 Sep 2026 15:25:17 -0500 Subject: [PATCH] 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. --- scripts/copy-bundled-plugins.cjs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/scripts/copy-bundled-plugins.cjs b/scripts/copy-bundled-plugins.cjs index cf5582ea1..b54532aad 100644 --- a/scripts/copy-bundled-plugins.cjs +++ b/scripts/copy-bundled-plugins.cjs @@ -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())