Skip to content

Commit b232f83

Browse files
committed
[FIX] Exit with code 1 when using unsupported Node.js version
The process should fail when using an unsupported Node.js version as indication that something went wrong. This is important for other tools or automated executions (e.g. CI) to detect that the command couldn't be executed.
1 parent 978c0b4 commit b232f83

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

bin/ui5.cjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ const ui5 = {
8484
async main() {
8585
const pkg = ui5.getPackageJson();
8686
if (!ui5.checkRequirements({pkg, nodeVersion: process.version})) {
87-
return;
88-
}
89-
const localInstallationInvoked = await ui5.invokeLocalInstallation(pkg);
90-
if (!localInstallationInvoked) {
91-
await ui5.invokeCLI(pkg);
87+
process.exit(1);
88+
} else {
89+
const localInstallationInvoked = await ui5.invokeLocalInstallation(pkg);
90+
if (!localInstallationInvoked) {
91+
await ui5.invokeCLI(pkg);
92+
}
9293
}
9394
}
9495
};

test/bin/ui5.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ test.serial("invokeLocalInstallation: Doesn't invoke local installation when it
226226
test.serial("main (unsupported Node.js version)", async (t) => {
227227
const {sinon, consoleLogStub} = t.context;
228228

229+
const processExit = new Promise((resolve) => {
230+
const processExitStub = sinon.stub(process, "exit");
231+
processExitStub.callsFake((errorCode) => {
232+
processExitStub.restore();
233+
resolve(errorCode);
234+
});
235+
});
236+
229237
const ui5 = require("../../bin/ui5.cjs");
230238
const {main} = ui5;
231239

@@ -235,6 +243,9 @@ test.serial("main (unsupported Node.js version)", async (t) => {
235243

236244
await main();
237245

246+
const errorCode = await processExit;
247+
t.is(errorCode, 1);
248+
238249
t.is(consoleLogStub.callCount, 0);
239250

240251
t.is(ui5.checkRequirements.callCount, 1);
@@ -245,6 +256,8 @@ test.serial("main (unsupported Node.js version)", async (t) => {
245256
test.serial("main (invocation of local installation)", async (t) => {
246257
const {sinon, consoleLogStub} = t.context;
247258

259+
const processExitStub = sinon.stub(process, "exit");
260+
248261
const ui5 = require("../../bin/ui5.cjs");
249262
const {main} = ui5;
250263

@@ -253,6 +266,7 @@ test.serial("main (invocation of local installation)", async (t) => {
253266

254267
await main();
255268

269+
t.is(processExitStub.callCount, 0);
256270
t.is(consoleLogStub.callCount, 0);
257271

258272
t.is(ui5.invokeLocalInstallation.callCount, 1);

0 commit comments

Comments
 (0)