fix(cli): stop the bundle archiver dropping the indexer entry points

The bundler emits the controller entry points at paths mirroring the
CLI's install location, which contains a node_modules segment when the
CLI runs via npx. The archiver's blanket node_modules exclusion silently
stripped them from the uploaded bundle, so the image build failed at the
indexer stage with MODULE_NOT_FOUND. Only .DS_Store is excluded now.
This commit is contained in:
Saadi Myftija
2026-07-22 13:13:47 +02:00
parent 5c373ad643
commit 08ce247f06
2 changed files with 35 additions and 6 deletions
@@ -60,11 +60,23 @@ describe("createBundleArchive", () => {
expect(skill).toBe("# skill");
});
it("excludes node_modules and .DS_Store but nothing else", async () => {
it("excludes only .DS_Store — node_modules paths must survive", async () => {
await writeFile(join(bundleDir, "build.json"), "{}");
await writeFile(join(bundleDir, ".DS_Store"), "junk");
await mkdir(join(bundleDir, "node_modules", "leftover"), { recursive: true });
await writeFile(join(bundleDir, "node_modules", "leftover", "index.js"), "x");
// The bundler emits controller entry points at paths mirroring the CLI's
// install location — under npx that contains a node_modules segment. Those
// files are load-bearing (the Containerfile's indexer stage runs them).
const controllerDir = join(
bundleDir,
".npm",
"_npx",
"abc123",
"node_modules",
"trigger.dev",
"dist"
);
await mkdir(controllerDir, { recursive: true });
await writeFile(join(controllerDir, "managed-index-controller.mjs"), "x");
// dist-like names must NOT be excluded — the bundle IS build output
await mkdir(join(bundleDir, "dist"), { recursive: true });
await writeFile(join(bundleDir, "dist", "chunk.mjs"), "x");
@@ -77,7 +89,22 @@ describe("createBundleArchive", () => {
await tar.extract({ file: archivePath, cwd: extractDir });
const rootEntries = (await readdir(extractDir)).sort();
expect(rootEntries).toEqual(["build.json", "dist"].sort());
expect(rootEntries).toEqual(["build.json", "dist", ".npm"].sort());
const controller = await readFile(
join(
extractDir,
".npm",
"_npx",
"abc123",
"node_modules",
"trigger.dev",
"dist",
"managed-index-controller.mjs"
),
"utf-8"
);
expect(controller).toBe("x");
});
it("throws when the bundle dir is empty", async () => {
+4 -2
View File
@@ -5,8 +5,10 @@ import { logger } from "../utilities/logger.js";
// The bundle dir is generated build output (bundled JS, synthesized package.json,
// build.json, Containerfile, .trigger/skills). Unlike the source-context archiver,
// it must NOT apply the usual build-output ignores (dist, build, .trigger) — those
// would strip the bundle itself. Only genuinely unwanted entries are excluded.
const BUNDLE_IGNORES = ["**/node_modules", "**/.DS_Store"];
// would strip the bundle itself. node_modules must NOT be excluded either: the
// bundler emits the controller entry points at paths mirroring the CLI's install
// location, which contains a node_modules segment when the CLI runs via npx.
const BUNDLE_IGNORES = ["**/.DS_Store"];
/**
* Archives a pre-built bundle directory (the buildWorker destination) so its