Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-cli-config-strip-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Prevent unrelated files with names matching the Trigger configuration file from being transformed during bundling.
54 changes: 53 additions & 1 deletion packages/cli-v3/src/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { build } from "esbuild";
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { runInNewContext } from "node:vm";
import { afterEach, describe, expect, it, vi } from "vitest";
import { loadConfig } from "./config.js";
import { configPlugin, loadConfig } from "./config.js";

const projectDirs: string[] = [];

Expand Down Expand Up @@ -89,3 +91,53 @@ describe("loadConfig bun runtime warnings", () => {
expect(await outputWhileLoading("bun-1.4")).not.toMatch(/deprecated/i);
});
});

describe("configPlugin", () => {
it("strips build options only from the resolved config file", async () => {
const cwd = await createProject();
await writeFile(
join(cwd, "trigger.config.ts"),
`export default {
project: "proj_runtime_config_test",
maxDuration: 60,
dirs: ["./trigger"],
build: { external: ["build-only-marker"] },
};
`
);
await mkdir(join(cwd, "nested"));
await writeFile(join(cwd, "nested", "trigger.config.ts"), 'export const value = "nested";');
await writeFile(join(cwd, "other-trigger.config.ts"), 'export const value = "suffix";');
await writeFile(
join(cwd, "entry.ts"),
`export { default as config } from "./trigger.config";
export { value as nested } from "./nested/trigger.config";
export { value as suffix } from "./other-trigger.config";
`
);

const resolvedConfig = await loadConfig({ cwd, warn: false });
const plugin = configPlugin(resolvedConfig);
expect(plugin).toBeDefined();

const result = await build({
absWorkingDir: cwd,
entryPoints: ["entry.ts"],
bundle: true,
write: false,
platform: "node",
format: "cjs",
plugins: [plugin!],
});
Comment on lines +124 to +131

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Symlink handling lacks regression coverage

The test imports a regular config file. createEntryPointManager instead passes the config as an entry point. Exercise a symlinked entry point with different link and target names under both symlink settings.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.


const module = { exports: {} };
runInNewContext(result.outputFiles[0].text, { module, exports: module.exports });

expect(module.exports).toMatchObject({
config: { project: "proj_runtime_config_test", build: {} },
nested: "nested",
suffix: "suffix",
});
expect(result.outputFiles[0].text).not.toContain("build-only-marker");
});
});
21 changes: 14 additions & 7 deletions packages/cli-v3/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
import * as c12 from "c12";
import { defu } from "defu";
import type * as esbuild from "esbuild";
import { readdir } from "node:fs/promises";
import { basename, dirname, isAbsolute, join, relative } from "node:path";
import { readdir, realpath } from "node:fs/promises";
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
import { findWorkspaceDir, resolveLockfile, resolvePackageJSON, resolveTSConfig } from "pkg-types";
import { generateCode, loadFile } from "./imports/magicast.js";
import { logger } from "./utilities/logger.js";
Expand Down Expand Up @@ -111,14 +111,21 @@ export function configPlugin(resolvedConfig: ResolvedConfig): esbuild.Plugin | u
// We need to strip the "build" key from the config file, so build dependencies don't make it into the final bundle
return {
name: "trigger-config-strip",
setup(build) {
const filename = basename(configFile);
// Convert the filename to a regex to filter against
const filter = new RegExp(`${filename.replace(/\./g, "\\.")}$`);
async setup(build) {
const configPath = build.initialOptions.preserveSymlinks
? resolve(configFile)
: await realpath(configFile);
const filename = basename(configPath);
// Narrow the callback to likely matches, then verify the full path.
const filter = new RegExp(`${filename.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`);

logger.debug("trigger-config-strip.filter", filter);

build.onLoad({ filter }, async (args) => {
build.onLoad({ filter, namespace: "file" }, async (args) => {
if (resolve(args.path) !== configPath) {
return;
}
Comment on lines +125 to +127

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Build options retained on Windows

On case-insensitive Windows, configPlugin skips stripping when --config spells a parent directory with different casing. esbuild keeps the supplied spelling, but realpath returns the on-disk spelling. Build-only options stay in the worker bundle.

Learn more

The deploy command passes --config to loadConfig. The pinned c12 loader uses Jiti, whose ESM resolver uses Node's JavaScript realpathSync; it preserves the spelling of ordinary, non-symlink path components. createEntryPointManager passes that absolute path to esbuild, whose file resolver keeps the supplied parent directory spelling. In contrast, the Windows native realpath used during plugin setup returns the normalized filesystem path. The old basename filter still matched when only the directory casing differed, but the new full-path comparison rejects the config.

Example: On case-insensitive NTFS, deploy with --config C:\WORK\app\trigger.config.ts when the directory is named Work. Both spellings open the same file, but the plugin skips it and leaves its build options in the generated config.

Recommended fix: When symlinks are not preserved, compare paths canonicalized by the same API, including canonicalizing candidate paths that miss the fast lexical comparison. Include both the supplied and canonical basenames in the filter so a differently cased filename can reach the comparison. Do not unconditionally lowercase paths, since Windows also supports case-sensitive directories. Add an integration case that passes a differently cased config path on a case-insensitive filesystem.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.


logger.debug("trigger-config-strip.onLoad", args);

const $mod = await loadFile(args.path);
Expand Down