Skip to content
Merged
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/orange-rocks-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Fix init.ts detection when using the sentry esbuild plugin
22 changes: 3 additions & 19 deletions packages/cli-v3/src/build/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -17,6 +17,7 @@ import {
getRunWorkerForTarget,
isIndexControllerForTarget,
isIndexWorkerForTarget,
isInitEntryPoint,
isLoaderEntryPoint,
isRunControllerForTarget,
isRunWorkerForTarget,
Expand Down Expand Up @@ -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);
Expand All @@ -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 (
Expand Down
26 changes: 25 additions & 1 deletion packages/cli-v3/src/build/packageModules.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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));
});
}