diff --git a/.changeset/orange-rocks-grow.md b/.changeset/orange-rocks-grow.md new file mode 100644 index 0000000000..c8a6bdaa23 --- /dev/null +++ b/.changeset/orange-rocks-grow.md @@ -0,0 +1,5 @@ +--- +"trigger.dev": patch +--- + +Fix init.ts detection when using the sentry esbuild plugin diff --git a/packages/cli-v3/src/build/bundle.ts b/packages/cli-v3/src/build/bundle.ts index 4f01c29370..90abe7c1d1 100644 --- a/packages/cli-v3/src/build/bundle.ts +++ b/packages/cli-v3/src/build/bundle.ts @@ -3,7 +3,7 @@ import { DEFAULT_RUNTIME, ResolvedConfig } from "@trigger.dev/core/v3/build"; import { BuildManifest, BuildTarget, TaskFile } from "@trigger.dev/core/v3/schemas"; import * as esbuild from "esbuild"; import { createHash } from "node:crypto"; -import { basename, dirname, join, relative, resolve } from "node:path"; +import { join, relative, resolve } from "node:path"; import { createFile } from "../utilities/fileSystem.js"; import { logger } from "../utilities/logger.js"; import { resolveFileSources } from "../utilities/sourceFiles.js"; @@ -17,6 +17,7 @@ import { getRunWorkerForTarget, isIndexControllerForTarget, isIndexWorkerForTarget, + isInitEntryPoint, isLoaderEntryPoint, isRunControllerForTarget, isRunWorkerForTarget, @@ -246,23 +247,6 @@ export async function getBundleResultFromBuild( ? relative(resolvedConfig.workingDir, resolvedConfig.configFile) : "trigger.config.ts"; - // Check if the entry point is an init.ts file at the root of a trigger directory - function isInitEntryPoint(entryPoint: string): boolean { - const initFileNames = ["init.ts", "init.mts", "init.cts", "init.js", "init.mjs", "init.cjs"]; - - // Check if it's directly in one of the trigger directories - return resolvedConfig.dirs.some((dir) => { - const normalizedDir = resolve(dir); - const normalizedEntryDir = resolve(dirname(entryPoint)); - - if (normalizedDir !== normalizedEntryDir) { - return false; - } - - return initFileNames.includes(basename(entryPoint)); - }); - } - for (const [outputPath, outputMeta] of Object.entries(result.metafile.outputs)) { if (outputPath.endsWith(".mjs")) { const $outputPath = resolve(workingDir, outputPath); @@ -283,7 +267,7 @@ export async function getBundleResultFromBuild( indexControllerEntryPoint = $outputPath; } else if (isIndexWorkerForTarget(outputMeta.entryPoint, target)) { indexWorkerEntryPoint = $outputPath; - } else if (isInitEntryPoint(outputMeta.entryPoint)) { + } else if (isInitEntryPoint(outputMeta.entryPoint, resolvedConfig.dirs)) { initEntryPoint = $outputPath; } else { if ( diff --git a/packages/cli-v3/src/build/packageModules.ts b/packages/cli-v3/src/build/packageModules.ts index 2932b2ac38..ada72e8773 100644 --- a/packages/cli-v3/src/build/packageModules.ts +++ b/packages/cli-v3/src/build/packageModules.ts @@ -1,5 +1,5 @@ import { BuildTarget } from "@trigger.dev/core/v3"; -import { join } from "node:path"; +import { basename, dirname, join, resolve } from "node:path"; import { sourceDir } from "../sourceDir.js"; import { assertExhaustive } from "../utilities/assertExhaustive.js"; @@ -235,3 +235,27 @@ export function getIndexControllerForTarget(target: BuildTarget) { export function isConfigEntryPoint(entryPoint: string) { return entryPoint.startsWith("trigger.config.ts"); } + +// Check if the entry point is an init.ts file at the root of a trigger directory +export function isInitEntryPoint(entryPoint: string, triggerDirs: string[]): boolean { + const initFileNames = ["init.ts", "init.mts", "init.cts", "init.js", "init.mjs", "init.cjs"]; + + // Check if it's directly in one of the trigger directories + return triggerDirs.some((dir) => { + const normalizedDir = resolve(dir); + const normalizedEntryDir = resolve(dirname(entryPoint)); + + if (normalizedDir !== normalizedEntryDir) { + return false; + } + + // Strip query string suffixes (e.g., ?sentryProxyModule=true) + const entryPointWithoutSuffix = entryPoint.split("?")[0]; + + if (!entryPointWithoutSuffix) { + return false; + } + + return initFileNames.includes(basename(entryPointWithoutSuffix)); + }); +}