fix(build): colocateLlmlinguaOptionals skip-check treated a Next-traced stub as fully copied

Debugging the omniroute-beta Docker rebuild: `npm run build` (and the
Dockerfile's own post-build verification) failed with
`Cannot find module '.../node_modules/@atjsh/llmlingua-2/dist/index.js'`.

Root cause, reproduced directly (both against a live Docker builder image
and in a unit test): Next.js's own standalone trace creates a stub
directory for `@atjsh/llmlingua-2` containing only `package.json` — it
references the package (a dynamically-imported optional dependency) but
can't fully bundle it. colocateLlmlinguaOptionals's skip checks (both the
closure-level early return and the per-package loop) only tested
`existsSync(dest)`, so that stub was indistinguishable from "already fully
co-located" — the function skipped copying the real `dist/` output
entirely, silently shipping a package with a manifest but no code.

Fix: check for the package's declared `main` entry file when it has one
(the real-world case for every actual SLM optional). Packages with no
`main` field fall back to comparing the destination's top-level entries
against the source's — correct both for genuinely multi-file packages and
for a metadata-only source (package.json is then its complete, faithfully-
copied contents), which the existing idempotency test exercises.

Covered by tests/unit/colocate-optionals.test.ts's new stub-reproduction
case (fails against the pre-fix code, passes after — confirmed directly)
plus the 6 pre-existing cases, all still green.

(cherry picked from commit 359aba59c7)
This commit is contained in:
Markus Hartung
2026-08-07 02:33:28 +02:00
committed by diegosouzapw
parent aae408f585
commit 4d816a4d8a
2 changed files with 37 additions and 6 deletions

View File

@@ -157,9 +157,7 @@ export function colocateLlmlinguaOptionals({
if (!existsSync(targetNm)) {
return {
skipped: true,
reason: targetNodeModulesDir
? "no target node_modules"
: "no standalone dist/node_modules",
reason: targetNodeModulesDir ? "no target node_modules" : "no standalone dist/node_modules",
};
}
@@ -198,9 +196,7 @@ export function colocateLlmlinguaOptionals({
});
copied++;
} catch (err) {
log(
` ⚠️ LLMLingua optional co-location failed for ${name}: ${err.message}`
);
log(` ⚠️ LLMLingua optional co-location failed for ${name}: ${err.message}`);
}
}