Skip to content

Commit de1ab07

Browse files
knquerickzhao
andauthored
fix(cli): add descriptive error for unsupported node version (#3894)
* fix(cli): add descriptive error for unsupported node version * fix(cli): reorder imports * fix(cli): remove redundant node version check via listr2 * nits --------- Co-authored-by: Erick Zhao <erick@hotmail.ca>
1 parent d3900ee commit de1ab07

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

packages/api/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"debug": "^4.3.1",
2525
"fs-extra": "^10.0.0",
2626
"listr2": "^7.0.2",
27+
"log-symbols": "^4.0.0",
2728
"semver": "^7.2.1"
2829
},
2930
"engines": {

packages/api/cli/src/electron-forge.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
#!/usr/bin/env node
22
// This file requires a shebang above. If it is missing, this is an error.
33

4+
import chalk from 'chalk';
45
import { program } from 'commander';
5-
import { Listr } from 'listr2';
6-
7-
import './util/terminate';
6+
import logSymbols from 'log-symbols';
7+
import semver from 'semver';
88

99
import packageJSON from '../package.json';
10+
import './util/terminate';
1011

1112
import { checkSystem, SystemCheckContext } from './util/check-system';
1213

14+
if (!semver.satisfies(process.versions.node, packageJSON.engines.node)) {
15+
console.error(
16+
logSymbols.error,
17+
`You are running Node.js version ${chalk.red(process.versions.node)}, but Electron Forge requires Node.js ${chalk.red(packageJSON.engines.node)}. \n`
18+
);
19+
process.exit(1);
20+
}
21+
22+
/* eslint-disable-next-line import/order -- Listr2 import contains JS syntax that fails as early as Node 14 */
23+
import { Listr } from 'listr2';
24+
1325
program
1426
.version(packageJSON.version, '-V, --version', 'Output the current version.')
1527
.helpOption('-h, --help', 'Output usage information.')

packages/api/cli/src/util/check-system.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ async function getGitVersion(): Promise<string | null> {
1616
});
1717
}
1818

19-
async function checkNodeVersion() {
20-
const { engines } = await fs.readJson(path.resolve(__dirname, '..', '..', 'package.json'));
21-
const versionSatisfied = semver.satisfies(process.versions.node, engines.node);
22-
23-
if (!versionSatisfied) {
24-
throw new Error(`You are running Node.js version ${process.versions.node}, but Electron Forge requires Node.js ${engines.node}.`);
25-
}
26-
27-
return process.versions.node;
28-
}
29-
3019
/**
3120
* Packaging an app with Electron Forge requires `node_modules` to be on disk.
3221
* With `pnpm`, this can be done in a few different ways.
@@ -130,13 +119,6 @@ export async function checkSystem(callerTask: ForgeListrTask<SystemCheckContext>
130119
}
131120
},
132121
},
133-
{
134-
title: 'Checking node version',
135-
task: async (_, task) => {
136-
const nodeVersion = await checkNodeVersion();
137-
task.title = `Found node@${nodeVersion}`;
138-
},
139-
},
140122
{
141123
title: 'Checking package manager version',
142124
task: async (_, task) => {

0 commit comments

Comments
 (0)