Skip to content

Commit f9adbc2

Browse files
nicktrnmatt-aitken
authored andcommitted
Fix bun detection, dev flushing, and init command (#1914)
* update nypm to support text-based bun lockfiles * add nypm changeset * handle dev flushing failures gracefully * fix path normalization for init.ts * add changesets * chore: remove pre.json after exiting pre mode * init command to install v4-beta packages * Revert "chore: remove pre.json after exiting pre mode" This reverts commit f5694fd. * make init default to cli version for all packages
1 parent a6223fd commit f9adbc2

File tree

9 files changed

+119
-16
lines changed

9 files changed

+119
-16
lines changed

.changeset/late-chairs-ring.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Fix init.ts in custom trigger dirs

.changeset/moody-squids-count.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Init command will now correctly install v4-beta packages

.changeset/polite-lies-fix.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Update nypm package to support test-based bun.lock files

.changeset/shiny-kiwis-beam.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Handle flush errors gracefully in dev

packages/cli-v3/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"magicast": "^0.3.4",
110110
"minimatch": "^10.0.1",
111111
"mlly": "^1.7.1",
112-
"nypm": "^0.3.9",
112+
"nypm": "^0.5.4",
113113
"object-hash": "^3.0.0",
114114
"open": "^10.0.3",
115115
"p-limit": "^6.2.0",

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

+9-6
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 { join, relative, resolve } from "node:path";
6+
import { basename, dirname, 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";
@@ -239,15 +239,18 @@ export async function getBundleResultFromBuild(
239239

240240
// Check if the entry point is an init.ts file at the root of a trigger directory
241241
function isInitEntryPoint(entryPoint: string): boolean {
242-
const normalizedEntryPoint = entryPoint.replace(/\\/g, "/"); // Normalize path separators
243242
const initFileNames = ["init.ts", "init.mts", "init.cts", "init.js", "init.mjs", "init.cjs"];
244243

245244
// Check if it's directly in one of the trigger directories
246245
return resolvedConfig.dirs.some((dir) => {
247-
const normalizedDir = dir.replace(/\\/g, "/");
248-
return initFileNames.some(
249-
(fileName) => normalizedEntryPoint === `${normalizedDir}/${fileName}`
250-
);
246+
const normalizedDir = resolve(dir);
247+
const normalizedEntryDir = resolve(dirname(entryPoint));
248+
249+
if (normalizedDir !== normalizedEntryDir) {
250+
return false;
251+
}
252+
253+
return initFileNames.includes(basename(entryPoint));
251254
});
252255
}
253256

packages/cli-v3/src/commands/init.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ import { printStandloneInitialBanner } from "../utilities/initialBanner.js";
3232
import { logger } from "../utilities/logger.js";
3333
import { spinner } from "../utilities/windows.js";
3434
import { login } from "./login.js";
35+
import { VERSION } from "../version.js";
36+
37+
const cliVersion = VERSION as string;
38+
const cliTag = cliVersion.includes("v4-beta") ? "v4-beta" : "latest";
3539

3640
const InitCommandOptions = CommonCommandOptions.extend({
3741
projectRef: z.string().optional(),
3842
overrideConfig: z.boolean().default(false),
39-
tag: z.string().default("latest"),
43+
tag: z.string().default(cliVersion),
4044
skipPackageInstall: z.boolean().default(false),
4145
runtime: z.string().default("node"),
4246
pkgArgs: z.string().optional(),
@@ -60,7 +64,7 @@ export function configureInitCommand(program: Command) {
6064
.option(
6165
"-t, --tag <package tag>",
6266
"The version of the @trigger.dev/sdk package to install",
63-
"latest"
67+
cliVersion
6468
)
6569
.option(
6670
"-r, --runtime <runtime>",
@@ -193,7 +197,7 @@ async function _initCommand(dir: string, options: InitCommandOptions) {
193197
log.info("Next steps:");
194198
log.info(
195199
` 1. To start developing, run ${chalk.green(
196-
`npx trigger.dev@${options.tag} dev${options.profile ? "" : ` --profile ${options.profile}`}`
200+
`npx trigger.dev@${cliTag} dev${options.profile ? "" : ` --profile ${options.profile}`}`
197201
)} in your project directory`
198202
);
199203
log.info(` 2. Visit your ${projectDashboard} to view your newly created tasks.`);

packages/cli-v3/src/entryPoints/dev-run-worker.ts

+38-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,34 @@ const zodIpc = new ZodIpcConnection({
472472
async function flushAll(timeoutInMs: number = 10_000) {
473473
const now = performance.now();
474474

475-
await Promise.all([flushTracingSDK(timeoutInMs), flushMetadata(timeoutInMs)]);
475+
const results = await Promise.allSettled([
476+
flushTracingSDK(timeoutInMs),
477+
flushMetadata(timeoutInMs),
478+
]);
479+
480+
const successfulFlushes = results
481+
.filter((result) => result.status === "fulfilled")
482+
.map((result) => result.value.flushed);
483+
484+
const failedFlushes = ["tracingSDK", "runMetadata"].filter(
485+
(flushed) => !successfulFlushes.includes(flushed)
486+
);
487+
488+
if (failedFlushes.length > 0) {
489+
logError(`Failed to flush ${failedFlushes.join(", ")}`);
490+
}
491+
492+
const errorMessages = results
493+
.filter((result) => result.status === "rejected")
494+
.map((result) => result.reason);
495+
496+
if (errorMessages.length > 0) {
497+
logError(errorMessages.join("\n"));
498+
}
499+
500+
for (const flushed of successfulFlushes) {
501+
log(`Flushed ${flushed} successfully`);
502+
}
476503

477504
const duration = performance.now() - now;
478505

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

489516
log(`Flushed tracingSDK in ${duration}ms`);
517+
518+
return {
519+
flushed: "tracingSDK",
520+
durationMs: duration,
521+
};
490522
}
491523

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

499531
log(`Flushed runMetadata in ${duration}ms`);
532+
533+
return {
534+
flushed: "runMetadata",
535+
durationMs: duration,
536+
};
500537
}
501538

502539
const managedWorkerRuntime = new ManagedRuntimeManager(zodIpc, showInternalLogs);

pnpm-lock.yaml

+44-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)