Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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/late-chairs-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Fix init.ts in custom trigger dirs
5 changes: 5 additions & 0 deletions .changeset/moody-squids-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Init command will now correctly install v4-beta packages
5 changes: 5 additions & 0 deletions .changeset/polite-lies-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Update nypm package to support test-based bun.lock files
5 changes: 5 additions & 0 deletions .changeset/shiny-kiwis-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Handle flush errors gracefully in dev
2 changes: 1 addition & 1 deletion packages/cli-v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"magicast": "^0.3.4",
"minimatch": "^10.0.1",
"mlly": "^1.7.1",
"nypm": "^0.3.9",
"nypm": "^0.5.4",
"object-hash": "^3.0.0",
"open": "^10.0.3",
"p-limit": "^6.2.0",
Expand Down
15 changes: 9 additions & 6 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 { join, relative, resolve } from "node:path";
import { basename, dirname, 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 Down Expand Up @@ -239,15 +239,18 @@ export async function getBundleResultFromBuild(

// Check if the entry point is an init.ts file at the root of a trigger directory
function isInitEntryPoint(entryPoint: string): boolean {
const normalizedEntryPoint = entryPoint.replace(/\\/g, "/"); // Normalize path separators
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 = dir.replace(/\\/g, "/");
return initFileNames.some(
(fileName) => normalizedEntryPoint === `${normalizedDir}/${fileName}`
);
const normalizedDir = resolve(dir);
const normalizedEntryDir = resolve(dirname(entryPoint));

if (normalizedDir !== normalizedEntryDir) {
return false;
}

return initFileNames.includes(basename(entryPoint));
});
}

Expand Down
6 changes: 4 additions & 2 deletions packages/cli-v3/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import { login } from "./login.js";
const InitCommandOptions = CommonCommandOptions.extend({
projectRef: z.string().optional(),
overrideConfig: z.boolean().default(false),
tag: z.string().default("latest"),
// TODO: Revert this to "latest" once we have a stable release
tag: z.string().default("v4-beta"),
skipPackageInstall: z.boolean().default(false),
runtime: z.string().default("node"),
pkgArgs: z.string().optional(),
Expand All @@ -60,7 +61,8 @@ export function configureInitCommand(program: Command) {
.option(
"-t, --tag <package tag>",
"The version of the @trigger.dev/sdk package to install",
"latest"
// TODO: Revert this to "latest" once we have a stable release
"v4-beta"
)
.option(
"-r, --runtime <runtime>",
Expand Down
39 changes: 38 additions & 1 deletion packages/cli-v3/src/entryPoints/dev-run-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,34 @@ const zodIpc = new ZodIpcConnection({
async function flushAll(timeoutInMs: number = 10_000) {
const now = performance.now();

await Promise.all([flushTracingSDK(timeoutInMs), flushMetadata(timeoutInMs)]);
const results = await Promise.allSettled([
flushTracingSDK(timeoutInMs),
flushMetadata(timeoutInMs),
]);

const successfulFlushes = results
.filter((result) => result.status === "fulfilled")
.map((result) => result.value.flushed);

const failedFlushes = ["tracingSDK", "runMetadata"].filter(
(flushed) => !successfulFlushes.includes(flushed)
);

if (failedFlushes.length > 0) {
logError(`Failed to flush ${failedFlushes.join(", ")}`);
}

const errorMessages = results
.filter((result) => result.status === "rejected")
.map((result) => result.reason);

if (errorMessages.length > 0) {
logError(errorMessages.join("\n"));
}

for (const flushed of successfulFlushes) {
log(`Flushed ${flushed} successfully`);
}

const duration = performance.now() - now;

Expand All @@ -487,6 +514,11 @@ async function flushTracingSDK(timeoutInMs: number = 10_000) {
const duration = performance.now() - now;

log(`Flushed tracingSDK in ${duration}ms`);

return {
flushed: "tracingSDK",
durationMs: duration,
};
}

async function flushMetadata(timeoutInMs: number = 10_000) {
Expand All @@ -497,6 +529,11 @@ async function flushMetadata(timeoutInMs: number = 10_000) {
const duration = performance.now() - now;

log(`Flushed runMetadata in ${duration}ms`);

return {
flushed: "runMetadata",
durationMs: duration,
};
}

const managedWorkerRuntime = new ManagedRuntimeManager(zodIpc, showInternalLogs);
Expand Down
49 changes: 44 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.