From f68b6468788b33e10c8ad86104cf8792862eb5e9 Mon Sep 17 00:00:00 2001 From: Kainoa Kanter <44733677+ThatOneCalculator@users.noreply.github.com> Date: Sat, 19 Mar 2022 09:34:45 -0700 Subject: [PATCH] Fix: warn about outdated NodeJS fixed (#8388) * Fix #8387 * update changelog Co-authored-by: Johann150 Co-authored-by: syuilo --- CHANGELOG.md | 1 + packages/backend/package.json | 1 + packages/backend/src/boot/master.ts | 12 +++++------- packages/backend/yarn.lock | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e39000e1..b7b30d8a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ You should also include the user name that made the change. ### Improvements - Bull Dashboardを組み込み、ジョブキューの確認や操作を行えるように @syuilo +- Check that installed Node.js version fulfills version requirement @ThatOneCalculator ### Bugfixes - API: fix endpoint endpoint @Johann150 diff --git a/packages/backend/package.json b/packages/backend/package.json index bc6384192..07904098f 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -146,6 +146,7 @@ "rndstr": "1.0.0", "s-age": "1.1.2", "sanitize-html": "2.7.0", + "semver": "7.3.5", "sharp": "0.30.3", "speakeasy": "2.0.0", "strict-event-emitter-types": "2.0.0", diff --git a/packages/backend/src/boot/master.ts b/packages/backend/src/boot/master.ts index 1c909dff1..48f0f8156 100644 --- a/packages/backend/src/boot/master.ts +++ b/packages/backend/src/boot/master.ts @@ -6,6 +6,7 @@ import cluster from 'node:cluster'; import chalk from 'chalk'; import chalkTemplate from 'chalk-template'; import * as portscanner from 'portscanner'; +import semver from 'semver'; import { getConnection } from 'typeorm'; import Logger from '@/services/logger.js'; @@ -88,10 +89,6 @@ export async function masterMain() { } } -const runningNodejsVersion = process.version.slice(1).split('.').map(x => parseInt(x, 10)); -const requiredNodejsVersion = [11, 7, 0]; -const satisfyNodejsVersion = !lessThan(runningNodejsVersion, requiredNodejsVersion); - function showEnvironment(): void { const env = process.env.NODE_ENV; const logger = bootLogger.createSubLogger('env'); @@ -108,10 +105,11 @@ function showEnvironment(): void { function showNodejsVersion(): void { const nodejsLogger = bootLogger.createSubLogger('nodejs'); - nodejsLogger.info(`Version ${runningNodejsVersion.join('.')}`); + nodejsLogger.info(`Version ${process.version} detected.`); - if (!satisfyNodejsVersion) { - nodejsLogger.error(`Node.js version is less than ${requiredNodejsVersion.join('.')}. Please upgrade it.`, null, true); + const minVersion = fs.readFileSync(`${_dirname}/../../../../.node-version`, 'utf-8').trim(); + if (semver.lt(process.version, minVersion)) { + nodejsLogger.error(`At least Node.js ${minVersion} required!`); process.exit(1); } } diff --git a/packages/backend/yarn.lock b/packages/backend/yarn.lock index 6785f7d98..3210259e4 100644 --- a/packages/backend/yarn.lock +++ b/packages/backend/yarn.lock @@ -6202,6 +6202,13 @@ seedrandom@3.0.5: resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-3.0.5.tgz#54edc85c95222525b0c7a6f6b3543d8e0b3aa0a7" integrity sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg== +semver@7.3.5, semver@^7.3.5: + version "7.3.5" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7" + integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ== + dependencies: + lru-cache "^6.0.0" + semver@^5.6.0: version "5.7.1" resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" @@ -6214,13 +6221,6 @@ semver@^7.3.2, semver@^7.3.4: dependencies: lru-cache "^6.0.0" -semver@^7.3.5: - version "7.3.5" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7" - integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ== - dependencies: - lru-cache "^6.0.0" - serialize-javascript@6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8"