Skip to content

Commit 206a2c3

Browse files
authored
Fix init.ts detection for sentry plugin users (#2051)
* fix init.ts detection when using the sentry plugin * add changeset
1 parent eb39298 commit 206a2c3

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

.changeset/orange-rocks-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Fix init.ts detection when using the sentry esbuild plugin

packages/cli-v3/src/build/bundle.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DEFAULT_RUNTIME, ResolvedConfig } from "@trigger.dev/core/v3/build";
33
import { BuildManifest, BuildTarget, TaskFile } from "@trigger.dev/core/v3/schemas";
44
import * as esbuild from "esbuild";
55
import { createHash } from "node:crypto";
6-
import { basename, dirname, join, relative, resolve } from "node:path";
6+
import { join, relative, resolve } from "node:path";
77
import { createFile } from "../utilities/fileSystem.js";
88
import { logger } from "../utilities/logger.js";
99
import { resolveFileSources } from "../utilities/sourceFiles.js";
@@ -17,6 +17,7 @@ import {
1717
getRunWorkerForTarget,
1818
isIndexControllerForTarget,
1919
isIndexWorkerForTarget,
20+
isInitEntryPoint,
2021
isLoaderEntryPoint,
2122
isRunControllerForTarget,
2223
isRunWorkerForTarget,
@@ -246,23 +247,6 @@ export async function getBundleResultFromBuild(
246247
? relative(resolvedConfig.workingDir, resolvedConfig.configFile)
247248
: "trigger.config.ts";
248249

249-
// Check if the entry point is an init.ts file at the root of a trigger directory
250-
function isInitEntryPoint(entryPoint: string): boolean {
251-
const initFileNames = ["init.ts", "init.mts", "init.cts", "init.js", "init.mjs", "init.cjs"];
252-
253-
// Check if it's directly in one of the trigger directories
254-
return resolvedConfig.dirs.some((dir) => {
255-
const normalizedDir = resolve(dir);
256-
const normalizedEntryDir = resolve(dirname(entryPoint));
257-
258-
if (normalizedDir !== normalizedEntryDir) {
259-
return false;
260-
}
261-
262-
return initFileNames.includes(basename(entryPoint));
263-
});
264-
}
265-
266250
for (const [outputPath, outputMeta] of Object.entries(result.metafile.outputs)) {
267251
if (outputPath.endsWith(".mjs")) {
268252
const $outputPath = resolve(workingDir, outputPath);
@@ -283,7 +267,7 @@ export async function getBundleResultFromBuild(
283267
indexControllerEntryPoint = $outputPath;
284268
} else if (isIndexWorkerForTarget(outputMeta.entryPoint, target)) {
285269
indexWorkerEntryPoint = $outputPath;
286-
} else if (isInitEntryPoint(outputMeta.entryPoint)) {
270+
} else if (isInitEntryPoint(outputMeta.entryPoint, resolvedConfig.dirs)) {
287271
initEntryPoint = $outputPath;
288272
} else {
289273
if (

packages/cli-v3/src/build/packageModules.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BuildTarget } from "@trigger.dev/core/v3";
2-
import { join } from "node:path";
2+
import { basename, dirname, join, resolve } from "node:path";
33
import { sourceDir } from "../sourceDir.js";
44
import { assertExhaustive } from "../utilities/assertExhaustive.js";
55

@@ -235,3 +235,27 @@ export function getIndexControllerForTarget(target: BuildTarget) {
235235
export function isConfigEntryPoint(entryPoint: string) {
236236
return entryPoint.startsWith("trigger.config.ts");
237237
}
238+
239+
// Check if the entry point is an init.ts file at the root of a trigger directory
240+
export function isInitEntryPoint(entryPoint: string, triggerDirs: string[]): boolean {
241+
const initFileNames = ["init.ts", "init.mts", "init.cts", "init.js", "init.mjs", "init.cjs"];
242+
243+
// Check if it's directly in one of the trigger directories
244+
return triggerDirs.some((dir) => {
245+
const normalizedDir = resolve(dir);
246+
const normalizedEntryDir = resolve(dirname(entryPoint));
247+
248+
if (normalizedDir !== normalizedEntryDir) {
249+
return false;
250+
}
251+
252+
// Strip query string suffixes (e.g., ?sentryProxyModule=true)
253+
const entryPointWithoutSuffix = entryPoint.split("?")[0];
254+
255+
if (!entryPointWithoutSuffix) {
256+
return false;
257+
}
258+
259+
return initFileNames.includes(basename(entryPointWithoutSuffix));
260+
});
261+
}

0 commit comments

Comments
 (0)