| 1 | import chalk from 'chalk'; |
| 2 | import semVer from 'semver'; |
| 3 | import packageJson from './package.json' assert { type: 'json' }; |
| 4 | |
| 5 | /** |
| 6 | * Check if the current node version match the required engines version. |
| 7 | */ |
| 8 | export function checkNodeVersion() { |
| 9 | const enginesNodeVersion = packageJson.engines.node; |
| 10 | if (semVer.satisfies(process.version, enginesNodeVersion) === false) { |
| 11 | console.error( |
| 12 | chalk.red( |
| 13 | `Required node version ${enginesNodeVersion} not satisfied with current version ${process.version}.`, |
| 14 | ), |
| 15 | ); |
| 16 | // eslint-disable-next-line n/no-process-exit |
| 17 | process.exit(1); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | checkNodeVersion(); |