diff --git a/barretenberg/bbup/.gitignore b/barretenberg/bbup/.gitignore index 96f4d2d1d9f..21114ccaaac 100644 --- a/barretenberg/bbup/.gitignore +++ b/barretenberg/bbup/.gitignore @@ -2,3 +2,4 @@ node_modules yarn.lock *.js .yarn +bun.lockb diff --git a/barretenberg/bbup/bbup.js b/barretenberg/bbup/bbup.js index 13eb873dc20..6b6fac09db8 100755 --- a/barretenberg/bbup/bbup.js +++ b/barretenberg/bbup/bbup.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -import { Command } from "commander"; +import { Command, Option } from "commander"; const program = new Command(); import { installBB } from "./shell.js"; import ora from "ora"; @@ -10,20 +10,19 @@ const spinner = ora({ color: "blue", discardStdin: false }); const bbup = program .command("install", { isDefault: true }) .description("Installs Barretenberg.") - .option("-f, --frontend", "Match the version of a specific frontend language", "noir"); -const options = bbup.opts(); -if (options.frontend === "noir") { - bbup - .requiredOption("-v, --version ", "The Noir version to match", "current") - .action(async ({ version }) => { - let resolvedVersion = version; - if (version === "current") { + .addOption(new Option("-v, --version ", "The Barretenberg version to install").implies({ noirVersion: null })) + .addOption(new Option("-nv, --noir-version ", "The Noir version to match").default("current")) + .action(async ({ version, noirVersion }) => { + let resolvedBBVersion = ""; + if (noirVersion) { + let resolvedNoirVersion = noirVersion; + if (noirVersion === "current") { spinner.start(`Querying noir version from nargo`); try { const output = execSync("nargo --version", { encoding: "utf-8" }); - resolvedVersion = output.match(/nargo version = (\d+\.\d+\.\d+)/)[1]; + resolvedNoirVersion = output.match(/nargo version = (\d+\.\d+\.\d+)/)[1]; spinner.stopAndPersist({ - text: `Resolved noir version ${resolvedVersion} from nargo`, + text: `Resolved noir version ${resolvedNoirVersion} from nargo`, symbol: logSymbols.success, }); } @@ -35,14 +34,17 @@ if (options.frontend === "noir") { process.exit(1); } } - spinner.start(`Getting compatible barretenberg version for noir version ${resolvedVersion}`); - const compatibleVersion = await getBbVersionForNoir(resolvedVersion, spinner); + spinner.start(`Getting compatible barretenberg version for noir version ${resolvedNoirVersion}`); + resolvedBBVersion = await getBbVersionForNoir(resolvedNoirVersion, spinner); spinner.stopAndPersist({ - text: `Resolved to barretenberg version ${compatibleVersion}`, + text: `Resolved to barretenberg version ${resolvedBBVersion}`, symbol: logSymbols.success, }); - spinner.start(`Installing barretenberg`); - await installBB(compatibleVersion, spinner); - }); -} + } + else if (version) { + resolvedBBVersion = version; + } + spinner.start(`Installing barretenberg`); + await installBB(resolvedBBVersion, spinner); +}); bbup.parse(); diff --git a/barretenberg/bbup/bbup.ts b/barretenberg/bbup/bbup.ts index d885715a0dc..98608ae5039 100755 --- a/barretenberg/bbup/bbup.ts +++ b/barretenberg/bbup/bbup.ts @@ -33,8 +33,9 @@ const bbup = program try { const output = execSync("nargo --version", { encoding: "utf-8" }); resolvedNoirVersion = output.match( - /nargo version = (\d+\.\d+\.\d+)/ + /nargo version = (\d+\.\d+\.\d+(-\w+\.\d+)?)/ )![1]; + console.log(resolvedNoirVersion); spinner.stopAndPersist({ text: `Resolved noir version ${resolvedNoirVersion} from nargo`, symbol: logSymbols.success, diff --git a/barretenberg/bbup/package.json b/barretenberg/bbup/package.json index 935b3b06e1c..7283db443e5 100644 --- a/barretenberg/bbup/package.json +++ b/barretenberg/bbup/package.json @@ -3,7 +3,7 @@ "type": "module", "description": "Barretenberg installation script", "bin": "bbup.js", - "version": "0.0.7", + "version": "0.0.12", "license": "ISC", "scripts": { "start": "npx tsx bbup.ts", @@ -13,6 +13,7 @@ "dependencies": { "@inquirer/input": "^1.2.16", "@inquirer/select": "^1.3.3", + "@types/node": "^22.9.1", "axios": "^1.7.7", "commander": "^11.1.0", "log-symbols": "^7.0.0", diff --git a/barretenberg/bbup/shell.js b/barretenberg/bbup/shell.js index 512c2ddb9cf..b8fd1418cb9 100644 --- a/barretenberg/bbup/shell.js +++ b/barretenberg/bbup/shell.js @@ -8,21 +8,25 @@ import tar from "tar-fs"; import { promisify } from "util"; import { pipeline } from "stream"; import path from "path"; +import { appendFileSync, existsSync } from "fs"; export function sourceShellConfig() { - const shell = execSync("echo $SHELL", { encoding: "utf-8" }).trim(); - if (shell.includes("bash")) { - process.env.PATH = execSync("echo $PATH", { encoding: "utf-8" }).trim(); + const home = os.homedir(); + const bbBinPath = path.join(home, ".bb"); + const pathEntry = `export PATH="${bbBinPath}:$PATH"\n`; + if (existsSync(path.join(home, ".bashrc"))) { + const bashrcPath = path.join(home, ".bashrc"); + appendFileSync(bashrcPath, pathEntry); } - else if (shell.includes("zsh")) { - process.env.PATH = execSync('zsh -c "echo $PATH"', { - encoding: "utf-8", - }).trim(); + if (existsSync(path.join(home, ".zshrc"))) { + const zshrcPath = path.join(home, ".zshrc"); + appendFileSync(zshrcPath, pathEntry); } - else if (shell.includes("fish")) { - process.env.PATH = execSync('fish -c "echo $PATH"', { - encoding: "utf-8", - }).trim(); + if (existsSync(path.join(home, ".config", "fish", "config.fish"))) { + const fishConfigPath = path.join(home, ".config", "fish", "config.fish"); + appendFileSync(fishConfigPath, `set -gx PATH ${bbBinPath} $PATH\n`); } + // Update the current session's PATH + process.env.PATH = `${bbBinPath}:${process.env.PATH}`; } export function exec(cmd, options = {}) { return execSync(cmd, { @@ -65,4 +69,5 @@ export async function installBB(version, spinner) { text: `Installed barretenberg to ${bbPath}`, symbol: logSymbols.success, }); + sourceShellConfig(); } diff --git a/barretenberg/bbup/shell.ts b/barretenberg/bbup/shell.ts index 5ab408778c7..c2e8a6945f3 100644 --- a/barretenberg/bbup/shell.ts +++ b/barretenberg/bbup/shell.ts @@ -11,20 +11,28 @@ import { promisify } from "util"; import { pipeline } from "stream"; import path from "path"; +import { appendFileSync, existsSync } from "fs"; + export function sourceShellConfig() { - const shell = execSync("echo $SHELL", { encoding: "utf-8" }).trim(); + const home = os.homedir(); + const bbBinPath = path.join(home, ".bb"); + const pathEntry = `export PATH="${bbBinPath}:$PATH"\n`; - if (shell.includes("bash")) { - process.env.PATH = execSync("echo $PATH", { encoding: "utf-8" }).trim(); - } else if (shell.includes("zsh")) { - process.env.PATH = execSync('zsh -c "echo $PATH"', { - encoding: "utf-8", - }).trim(); - } else if (shell.includes("fish")) { - process.env.PATH = execSync('fish -c "echo $PATH"', { - encoding: "utf-8", - }).trim(); + if (existsSync(path.join(home, ".bashrc"))) { + const bashrcPath = path.join(home, ".bashrc"); + appendFileSync(bashrcPath, pathEntry); + } + if (existsSync(path.join(home, ".zshrc"))) { + const zshrcPath = path.join(home, ".zshrc"); + appendFileSync(zshrcPath, pathEntry); } + if (existsSync(path.join(home, ".config", "fish", "config.fish"))) { + const fishConfigPath = path.join(home, ".config", "fish", "config.fish"); + appendFileSync(fishConfigPath, `set -gx PATH ${bbBinPath} $PATH\n`); + } + + // Update the current session's PATH + process.env.PATH = `${bbBinPath}:${process.env.PATH}`; } export function exec(cmd: string, options = {}) { @@ -82,4 +90,5 @@ export async function installBB(version: string, spinner: Ora) { text: `Installed barretenberg to ${bbPath}`, symbol: logSymbols.success, }); + sourceShellConfig(); } diff --git a/barretenberg/bbup/versions.js b/barretenberg/bbup/versions.js index 795107f3f13..5f6dee81f7f 100644 --- a/barretenberg/bbup/versions.js +++ b/barretenberg/bbup/versions.js @@ -1,5 +1,5 @@ -import axios from 'axios'; -import logSymbols from 'log-symbols'; +import axios from "axios"; +import logSymbols from "log-symbols"; async function getNamedVersions(githubToken) { const fetchOpts = { // eslint-disable-next-line camelcase @@ -9,16 +9,18 @@ async function getNamedVersions(githubToken) { if (githubToken) fetchOpts.headers = { Authorization: `token ${githubToken}` }; const { data } = await axios.get(`https://api.github.com/repos/noir-lang/noir/releases`, fetchOpts); - const stable = data.filter((release) => !release.tag_name.includes('aztec') && !release.tag_name.includes('nightly') && !release.prerelease)[0].tag_name; - const nightly = data.filter((release) => release.tag_name.startsWith('nightly'))[0].tag_name; + const stable = data.filter((release) => !release.tag_name.includes("aztec") && + !release.tag_name.includes("nightly") && + !release.prerelease)[0].tag_name; + const nightly = data.filter((release) => release.tag_name.startsWith("nightly"))[0].tag_name; return { stable, nightly, }; } export async function getBbVersionForNoir(noirVersion, spinner, githubToken) { - let url = ''; - if (noirVersion === 'stable' || noirVersion === 'nightly') { + let url = ""; + if (noirVersion === "stable" || noirVersion === "nightly") { spinner.start(`Resolving noir version ${noirVersion}...`); const resolvedVersions = await getNamedVersions(githubToken); spinner.stopAndPersist({