Skip to content

Commit

Permalink
Log an error if node version is smaller than 17.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
georg-schwarz committed Jul 19, 2023
1 parent 2daac55 commit 1396515
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/interpreter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Command } from 'commander';

import { version as packageJsonVersion } from '../package.json';

import { assertNodeVersion } from './prerequisites';
import { runAction } from './run-action';

const runtimeParameterRegex = /^([_a-zA-Z][\w_]*)=(.*)$/;
Expand All @@ -29,6 +30,7 @@ function collectRuntimeParameters(
return previous;
}

assertNodeVersion();
const program = new Command();

const version: string = packageJsonVersion as string;
Expand Down
39 changes: 39 additions & 0 deletions apps/interpreter/src/prerequisites.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg
//
// SPDX-License-Identifier: AGPL-3.0-only

/**
* Asserts that a certain node version is installed on the executing machine.
* Exits the process if this prerequisite is not fulfilled.
*/
export function assertNodeVersion() {
const requiredNodeMajorVersion = 17;
const currentNodeMajorVersion = getNodeMajorVersion();

if (currentNodeMajorVersion < requiredNodeMajorVersion) {
console.error(
`Jayvee requires node version ${requiredNodeMajorVersion}.0.0 or higher.`,
);
console.info(
`Your current node version is ${currentNodeMajorVersion} - please upgrade!`,
);
process.exit(1);
}
}

/**
* Returns the node version of the executing machine.
* Exits the process if no node process is running.
*/
function getNodeMajorVersion(): number {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const nodeVersion = process?.versions?.node;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (nodeVersion === undefined) {
console.error('Could not find a nodejs runtime.');
process.exit(1);
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return +nodeVersion.split('.')[0]!;
}

0 comments on commit 1396515

Please sign in to comment.