From 3e128bf6c4ca6e0ea256c927c1fd258ecb241a2c Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Mon, 11 Dec 2023 14:46:42 -0500 Subject: [PATCH] Fix node check --- common/shell/src/index.ts | 7 ++++--- package-lock.json | 1 - scripts/root/check.ts | 33 +++++++++++++++------------------ 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/common/shell/src/index.ts b/common/shell/src/index.ts index 61fb785f8..8975bf85a 100644 --- a/common/shell/src/index.ts +++ b/common/shell/src/index.ts @@ -1,12 +1,13 @@ -import { exec, execSync } from "child_process" +import { ExecOptions, exec, execSync } from "child_process" +import { ObjectEncodingOptions } from "fs" /** * Run any shell command in a child process and return a promise * @param command - The full command to run * @returns A promise that resolves when the command exits */ -export async function run(command: string) { - const child = exec(command) +export async function run(command: string, options?: ObjectEncodingOptions & ExecOptions) { + const child = exec(command, options) let data = "" return new Promise((resolve, reject) => { child.on("error", reject) diff --git a/package-lock.json b/package-lock.json index ddca2eb13..18f3b06cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5814,7 +5814,6 @@ }, "node_modules/@parcel/watcher-wasm/node_modules/napi-wasm": { "version": "1.1.0", - "extraneous": true, "inBundle": true, "license": "MIT" }, diff --git a/scripts/root/check.ts b/scripts/root/check.ts index 4bbeec81a..ca0da6c28 100644 --- a/scripts/root/check.ts +++ b/scripts/root/check.ts @@ -6,24 +6,22 @@ import fs from "fs" */ void async function () { if (process.env.CI !== "true") { - const submodules = fs.readFileSync(".gitmodules", "utf8") - const submoduleDirs = submodules.match(/path = (.*)/g)?.map((path) => path.replace("path = ", "")) - if (submoduleDirs) { - try { - for (const dir of submoduleDirs) { - const content = fs.readdirSync(dir) - if (!content.length) { - throw new Error("🚩 Missing ssh key for submodules") - } + try { + const submodules = fs.readFileSync(".gitmodules", "utf8") + const submoduleDirs = submodules.match(/path = (.*)/g)?.map((path) => path.replace("path = ", "")) + submoduleDirs?.forEach((dir) => { + const content = fs.readdirSync(dir) + if (!content.length) { + throw new Error("🚩 Missing ssh key for submodules") } - } catch (error) { - console.error(error.message) - throw new Error("🚩 Please add an ssh key for submodules (see https://github.com/consensusnetworks/casimir#prerequisites #1)") - } + }) + } catch (error) { + console.error(error.message) + throw new Error("🚩 Please add an ssh key for submodules (see https://github.com/consensusnetworks/casimir#prerequisites #1)") } - const docker = await run("docker --version") as string try { + const docker = await run("docker --version") as string const dockerSplit = docker.split(" ") const dockerNumber = dockerSplit[2] const dockerNumberSplit = dockerNumber.split(".") @@ -36,8 +34,8 @@ void async function () { throw new Error("🚩 Please install docker 24.x (see https://github.com/consensusnetworks/casimir#prerequisites #2)") } - const go = await run("go version") as string try { + const go = await run("go version") as string if (!go.includes("1.20")) { throw new Error("🚩 Incompatible go version") } @@ -48,9 +46,8 @@ void async function () { try { const node = await run("node --version") as string - const nodeLtsList = (await run("nvm ls-remote --lts") as string).split("\n") - const nodeLts = nodeLtsList[nodeLtsList.length - 1].split(" ")[0] - if (!nodeLts.includes(node)) { + const nodeLts = await run("source ~/.nvm/nvm.sh && nvm ls-remote --lts | grep 'Latest LTS' | tail -n 1 | awk '{print $2}'") as string + if (!nodeLts.trim().includes(node.trim())) { throw new Error("🚩 Incompatible node version") } } catch (error) {