diff --git a/apps/interpreter/src/index.ts b/apps/interpreter/src/index.ts index 306a158f7..5a7487b91 100644 --- a/apps/interpreter/src/index.ts +++ b/apps/interpreter/src/index.ts @@ -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_]*)=(.*)$/; @@ -29,6 +30,7 @@ function collectRuntimeParameters( return previous; } +assertNodeVersion(); const program = new Command(); const version: string = packageJsonVersion as string; diff --git a/apps/interpreter/src/prerequisites.ts b/apps/interpreter/src/prerequisites.ts new file mode 100644 index 000000000..4721e0cda --- /dev/null +++ b/apps/interpreter/src/prerequisites.ts @@ -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]!; +}