Skip to content

Commit 6430296

Browse files
committed
Added a Node.js runtime check for the CLI dev command
1 parent 3b46a66 commit 6430296

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

.changeset/odd-poets-own.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+
Added a Node.js runtime check for the CLI

packages/cli-v3/src/commands/dev.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { isLoggedIn } from "../utilities/session.js";
4040
import { createTaskFileImports, gatherTaskFiles } from "../utilities/taskFiles";
4141
import { UncaughtExceptionError } from "../workers/common/errors";
4242
import { BackgroundWorker, BackgroundWorkerCoordinator } from "../workers/dev/backgroundWorker.js";
43+
import { runtimeCheck } from "../utilities/runtimeCheck";
4344

4445
let apiClient: CliApiClient | undefined;
4546

@@ -72,7 +73,18 @@ export function configureDevCommand(program: Command) {
7273
});
7374
}
7475

76+
const MINIMUM_NODE_MAJOR = 18;
77+
const MINIMUM_NODE_MINOR = 16;
78+
7579
export async function devCommand(dir: string, options: DevCommandOptions) {
80+
try {
81+
runtimeCheck(MINIMUM_NODE_MAJOR, MINIMUM_NODE_MINOR);
82+
} catch (e) {
83+
logger.log(`${chalkError("X Error:")} ${e}`);
84+
process.exitCode = 1;
85+
return;
86+
}
87+
7688
const authorization = await isLoggedIn(options.profile);
7789

7890
if (!authorization.ok) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { logger } from "./logger";
2+
3+
/**
4+
* This function is used by the dev CLI to make sure that the runtime is compatible
5+
*/
6+
export function runtimeCheck(minimumMajor: number, minimumMinor: number) {
7+
// Check if the runtime is Node.js
8+
if (typeof process === "undefined") {
9+
throw "The dev CLI can only be run in a Node.js compatible environment";
10+
}
11+
12+
// Check if the runtime version is compatible
13+
const [major = 0, minor = 0] = process.versions.node.split(".").map(Number);
14+
15+
const isBun = typeof process.versions.bun === "string";
16+
17+
if (major < minimumMajor || (major === minimumMajor && minor < minimumMinor)) {
18+
if (isBun) {
19+
throw `The dev CLI requires at least Node.js ${minimumMajor}.${minimumMinor}. You are running Bun ${process.versions.bun}, which is compatible with Node.js ${process.versions.node}`;
20+
} else {
21+
throw `The dev CLI requires at least Node.js ${minimumMajor}.${minimumMinor}. You are running Node.js ${process.versions.node}`;
22+
}
23+
}
24+
25+
logger.debug(
26+
`Node.js version: ${process.versions.node}${isBun ? ` (Bun ${process.versions.bun})` : ""}`
27+
);
28+
}

0 commit comments

Comments
 (0)