Repository navigation
fix(cli): restrict config stripping to resolved config path #5166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"; | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Build options retained on Windows On case-insensitive Windows, Learn moreThe deploy command passes Example: On case-insensitive NTFS, deploy with 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. Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| logger.debug("trigger-config-strip.onLoad", args); | ||
|
|
||
| const $mod = await loadFile(args.path); | ||
|
|
||
There was a problem hiding this comment.
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.
Was this helpful? React with 👍 or 👎 to provide feedback.