Skip to content

Commit 305054b

Browse files
committed
feat: check node version
1 parent 3bb1c86 commit 305054b

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

packages/start-slicemachine/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"newtype-ts": "^0.3.5",
7272
"node-fetch": "^3.3.1",
7373
"open": "^8.4.2",
74+
"semver": "^7.3.8",
7475
"serve-static": "^1.15.0"
7576
},
7677
"devDependencies": {

packages/start-slicemachine/src/StartSliceMachineProcess.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/* eslint-disable no-console */
22

33
import type { AddressInfo } from "node:net";
4+
import { readFileSync } from "node:fs";
5+
import { fileURLToPath } from "node:url";
6+
import { dirname, join } from "node:path";
47
import chalk from "chalk";
58
import open from "open";
69
import os from "node:os";
10+
import semver from "semver";
711

812
import {
913
PrismicUserProfile,
@@ -70,6 +74,8 @@ export class StartSliceMachineProcess {
7074
* Runs the process.
7175
*/
7276
async run(): Promise<void> {
77+
this._checkNodeVersion();
78+
7379
// This migration needs to run before the plugins are initialised
7480
// Nothing can start without the config file
7581
await migrateSMJSON(this._sliceMachineManager);
@@ -165,6 +171,34 @@ export class StartSliceMachineProcess {
165171
}
166172
}
167173

174+
/**
175+
* Checks if the current Node.js version satisfies the required version and
176+
* displays a warning if it doesn't.
177+
*/
178+
private _checkNodeVersion(): void {
179+
const __dirname = dirname(fileURLToPath(import.meta.url));
180+
const pkg = JSON.parse(
181+
readFileSync(join(__dirname, "../package.json"), "utf8"),
182+
);
183+
184+
const requiredVersion = pkg.engines?.node;
185+
186+
if (!requiredVersion) {
187+
return;
188+
}
189+
190+
const currentVersion = process.version;
191+
192+
if (!semver.satisfies(currentVersion, requiredVersion)) {
193+
console.warn(
194+
chalk.yellow(
195+
`⚠️ Warning: You are using Node.js ${currentVersion}, but this tool requires ${requiredVersion}.\n` +
196+
` Some features may not work correctly. Please upgrade your Node.js version.\n`,
197+
),
198+
);
199+
}
200+
}
201+
168202
/**
169203
* Returns a string with Slice Machine info formatted for the console.
170204
*

0 commit comments

Comments
 (0)