From 6665cd9e254e4a05d863942da7ab333b6ba3ebf9 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Thu, 15 Jun 2023 18:09:27 +0200 Subject: [PATCH] refactor: write as constant --- packages/runtime/src/cli/repl.ts | 7 ++++--- packages/vm/tests/integration/crypto.test.ts | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/runtime/src/cli/repl.ts b/packages/runtime/src/cli/repl.ts index 1c568d05..918bfdb9 100644 --- a/packages/runtime/src/cli/repl.ts +++ b/packages/runtime/src/cli/repl.ts @@ -5,6 +5,8 @@ import { join } from 'path' import { EdgeRuntime } from '../edge-runtime' +const [NODE_MAJOR] = process.versions.node.split('.').map((v) => Number(v)) + const format = createFormat() const writer: createRepl.REPLWriter = (output) => { @@ -12,7 +14,7 @@ const writer: createRepl.REPLWriter = (output) => { } const repl = createRepl.start({ prompt: 'ƒ => ', writer }) -repl.setupHistory(join(homedir(), '.edge_runtime_repl_history'), () => {}) +repl.setupHistory(join(homedir(), '.edge_runtime_repl_history'), () => { }) Object.getOwnPropertyNames(repl.context).forEach( (mod) => delete repl.context[mod] @@ -33,8 +35,7 @@ Object.defineProperty(repl.context, 'EdgeRuntime', { value: runtime.context.EdgeRuntime, }) -const nodeMajorVersion = parseInt(process.versions.node.split('.')[0]) -if (nodeMajorVersion < 16) { +if (NODE_MAJOR < 16) { repl.context.util = { inspect: (...args: any[]) => { const stack = new Error().stack ?? '' diff --git a/packages/vm/tests/integration/crypto.test.ts b/packages/vm/tests/integration/crypto.test.ts index ab0f9ad0..050907f7 100644 --- a/packages/vm/tests/integration/crypto.test.ts +++ b/packages/vm/tests/integration/crypto.test.ts @@ -1,6 +1,8 @@ import { EdgeVM } from '../../src' import { createHash } from 'crypto' +const [NODE_MAJOR] = process.versions.node.split('.').map((v) => Number(v)) + test('crypto.subtle.digest returns an ArrayBuffer', async () => { const vm = new EdgeVM() @@ -59,8 +61,7 @@ test('crypto.generateKey works with a Uint8Array from the VM', async () => { await vm.evaluate(`(${fn})()`) }) -const nodeMajorVersion = parseInt(process.versions.node.split('.')[0]) -if (nodeMajorVersion >= 16) { +if (NODE_MAJOR >= 16) { test('Ed25519', async () => { const vm = new EdgeVM()