Skip to content

Fix bun detection, dev flushing, and init command #1914

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

Merged
merged 9 commits into from
Apr 11, 2025
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/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
10 changes: 7 additions & 3 deletions packages/cli-v3/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ import { printStandloneInitialBanner } from "../utilities/initialBanner.js";
import { logger } from "../utilities/logger.js";
import { spinner } from "../utilities/windows.js";
import { login } from "./login.js";
import { VERSION } from "../version.js";

const cliVersion = VERSION as string;
const cliTag = cliVersion.includes("v4-beta") ? "v4-beta" : "latest";

const InitCommandOptions = CommonCommandOptions.extend({
projectRef: z.string().optional(),
overrideConfig: z.boolean().default(false),
tag: z.string().default("latest"),
tag: z.string().default(cliVersion),
skipPackageInstall: z.boolean().default(false),
runtime: z.string().default("node"),
pkgArgs: z.string().optional(),
Expand All @@ -60,7 +64,7 @@ export function configureInitCommand(program: Command) {
.option(
"-t, --tag <package tag>",
"The version of the @trigger.dev/sdk package to install",
"latest"
cliVersion
)
.option(
"-r, --runtime <runtime>",
Expand Down Expand Up @@ -193,7 +197,7 @@ async function _initCommand(dir: string, options: InitCommandOptions) {
log.info("Next steps:");
log.info(
` 1. To start developing, run ${chalk.green(
`npx trigger.dev@${options.tag} dev${options.profile ? "" : ` --profile ${options.profile}`}`
`npx trigger.dev@${cliTag} dev${options.profile ? "" : ` --profile ${options.profile}`}`
)} in your project directory`
);
log.info(` 2. Visit your ${projectDashboard} to view your newly created tasks.`);
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.

Loading