From 41984b891262c0b2b8741bafa1bf5a403e2dfcca Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 31 Mar 2022 23:37:25 +0300 Subject: [PATCH] Throwing human-readable error for unsupported node.js versions (#145) fixes #143 --- package-lock.json | 29 ++++++++++++++++++++++++++--- package.json | 3 ++- src/internal/FluencePeer.ts | 4 +++- src/internal/utils.ts | 11 +++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index df853c5f..2447d5d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@fluencelabs/fluence", - "version": "0.0.1-fix-sig.0", + "version": "0.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@fluencelabs/fluence", - "version": "0.0.1-fix-sig.0", + "version": "0.0.0", "license": "Apache-2.0", "dependencies": { "@chainsafe/libp2p-noise": "^4.1.1", @@ -15,7 +15,6 @@ "@fluencelabs/avm-runner-interface": "^0.2.0", "@fluencelabs/marine-js": "0.1.0", "async": "3.2.0", - "browser-or-node": "^2.0.0", "bs58": "4.0.1", "buffer": "^6.0.3", "cids": "0.8.1", @@ -29,6 +28,7 @@ "multiaddr": "^10.0.1", "multiformats": "^9.6.4", "peer-id": "=0.15.4", + "platform": "^1.3.6", "rxjs": "^7.3.0", "ts-pattern": "^3.3.3", "uuid": "8.3.0" @@ -40,6 +40,7 @@ "@fluencelabs/aqua": "^0.7.0-285", "@fluencelabs/aqua-lib": "^0.4.3", "@types/jest": "^26.0.22", + "@types/platform": "^1.3.4", "jest": "^26.6.3", "js-base64": "^3.7.2", "ts-jest": "^26.5.4", @@ -1398,6 +1399,12 @@ "integrity": "sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==", "dev": true }, + "node_modules/@types/platform": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@types/platform/-/platform-1.3.4.tgz", + "integrity": "sha512-U0o4K+GNiK0PNxoDwd8xRnvLVe4kzei6opn3/FCjAriqaP+rfrDdSl1kP/hLL6Y3/Y3hhGnBwD4dCkkAqs1W/Q==", + "dev": true + }, "node_modules/@types/prettier": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.3.2.tgz", @@ -7594,6 +7601,11 @@ "node": ">=8" } }, + "node_modules/platform": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz", + "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==" + }, "node_modules/posix-character-classes": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz", @@ -10848,6 +10860,12 @@ "integrity": "sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==", "dev": true }, + "@types/platform": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@types/platform/-/platform-1.3.4.tgz", + "integrity": "sha512-U0o4K+GNiK0PNxoDwd8xRnvLVe4kzei6opn3/FCjAriqaP+rfrDdSl1kP/hLL6Y3/Y3hhGnBwD4dCkkAqs1W/Q==", + "dev": true + }, "@types/prettier": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.3.2.tgz", @@ -15868,6 +15886,11 @@ "find-up": "^4.0.0" } }, + "platform": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz", + "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==" + }, "posix-character-classes": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz", diff --git a/package.json b/package.json index c70fadf1..911e148d 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "@fluencelabs/avm-runner-interface": "^0.2.0", "@fluencelabs/marine-js": "0.1.0", "async": "3.2.0", - "browser-or-node": "^2.0.0", "bs58": "4.0.1", "buffer": "^6.0.3", "cids": "0.8.1", @@ -42,6 +41,7 @@ "multiaddr": "^10.0.1", "multiformats": "^9.6.4", "peer-id": "=0.15.4", + "platform": "^1.3.6", "rxjs": "^7.3.0", "ts-pattern": "^3.3.3", "uuid": "8.3.0" @@ -50,6 +50,7 @@ "@fluencelabs/aqua": "^0.7.0-285", "@fluencelabs/aqua-lib": "^0.4.3", "@types/jest": "^26.0.22", + "@types/platform": "^1.3.4", "jest": "^26.6.3", "js-base64": "^3.7.2", "ts-jest": "^26.5.4", diff --git a/src/internal/FluencePeer.ts b/src/internal/FluencePeer.ts index 814828e2..9c2304ea 100644 --- a/src/internal/FluencePeer.ts +++ b/src/internal/FluencePeer.ts @@ -20,7 +20,7 @@ import { PeerIdB58 } from './commonTypes'; import { FluenceConnection } from './FluenceConnection'; import { Particle, ParticleExecutionStage, ParticleQueueItem } from './Particle'; import { KeyPair } from './KeyPair'; -import { dataToString, jsonify } from './utils'; +import { throwIfNotSupported, dataToString, jsonify } from './utils'; import { concatMap, filter, pipe, Subject, tap } from 'rxjs'; import log from 'loglevel'; import { builtInServices } from './builtins/common'; @@ -171,6 +171,8 @@ export class FluencePeer { * @param config - object specifying peer configuration */ async start(config?: PeerConfig): Promise { + throwIfNotSupported(); + if (config?.KeyPair) { this._keyPair = config!.KeyPair; } else { diff --git a/src/internal/utils.ts b/src/internal/utils.ts index 81b2df12..9d68d610 100644 --- a/src/internal/utils.ts +++ b/src/internal/utils.ts @@ -19,6 +19,7 @@ import { CallServiceData, CallServiceResult, CallServiceResultType, ResultCodes import { FluencePeer } from './FluencePeer'; import { Particle, ParticleExecutionStage } from './Particle'; import Buffer from './Buffer'; +import platform from 'platform'; export const MakeServiceCall = (fn: (args: any[]) => CallServiceResultType) => { return (req: CallServiceData): CallServiceResult => { @@ -144,3 +145,13 @@ export function dataToString(data: Uint8Array) { export function jsonify(obj) { return JSON.stringify(obj, null, 4); } + +export function throwIfNotSupported() { + if (platform.name === 'Node.js') { + const version = platform.version.split('.').map(Number); + const major = version[0]; + if (major < 16) { + throw new Error('FluenceJS requires node.js version >= "16.x"; Detected ' + platform.description + ' Please update node.js to version 16 or higher.\nYou can use https://nvm.sh utility to update node.js version: "nvm install 17 && nvm use 17 && nvm alias default 17"'); + } + } +}