Skip to content

Commit

Permalink
refactor: update deps based on running sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Nov 1, 2023
1 parent ed378c6 commit 96b5992
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 220 deletions.
7 changes: 6 additions & 1 deletion yarn-project/cli/aztec-cli
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ AZTEC_CLI_EXTRA_ARGS=""

# first process commands with positional arguments
# assumes positional arguments are the first thing
if [[ "$AZTEC_CLI_COMMAND" == "compile" || "$AZTEC_CLI_COMMAND" == "deploy" || "$AZTEC_CLI_COMMAND" == "inspect-contract" || "$AZTEC_CLI_COMMAND" == "update-aztecnr" ]]; then
if [[ "$AZTEC_CLI_COMMAND" == "compile" || "$AZTEC_CLI_COMMAND" == "deploy" || "$AZTEC_CLI_COMMAND" == "inspect-contract" ]]; then
add_mount "$2"
fi

Expand All @@ -115,6 +115,11 @@ if [[ "$AZTEC_CLI_COMMAND" == "unbox" ]]; then
add_mount "$DIR"
fi

if [[ "$AZTEC_CLI_COMMAND" == "update" ]]; then
# update command defaults to current directory
add_mount "$PWD"
fi

# process flags
if [[ "$AZTEC_CLI_COMMAND" == "compile" || "$AZTEC_CLI_COMMAND" == "call" || "$AZTEC_CLI_COMMAND" == "send" ]]; then

Expand Down
39 changes: 6 additions & 33 deletions yarn-project/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ import { mnemonicToAccount } from 'viem/accounts';

import { createCompatibleClient } from './client.js';
import { encodeArgs, parseStructString } from './encoding.js';
import { GITHUB_TAG_PREFIX } from './github.js';
import { unboxContract } from './unbox.js';
import { updateAztecDeps } from './update-aztec.js';
import { aztecNrVersionToTagName, getLatestAztecNrTag, updateAztecNr } from './update-aztecnr.js';
import { update } from './update/update.js';
import {
deployAztecContracts,
getContractArtifact,
Expand Down Expand Up @@ -706,37 +704,12 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
program
.command('update')
.description('Updates Nodejs and Noir dependencies')
.argument('<projectPath>', 'Path to the project directory')
.option(
'--aztec-version <semver|current|latest>',
'Semver version to update to or `current` for the current version compatible with the CLI or `latest` for the most recent stable version',
'current',
)
.option('--no-nodejs', 'Disable updating @aztec/* packages in package.json')
.option('--no-noir', 'Disable updating Aztec.nr libraries in Nargo.toml')
.argument('[projectPath]', 'Path to the project directory', process.cwd())
.option('--contract [paths...]', 'Paths to contracts to update dependencies', [])
.addOption(pxeOption)
.action(async (projectPath: string, options) => {
const { aztecVersion, nodejs, noir } = options;

let noirTagName = '';
let npmVersion = '';
if (aztecVersion === 'current') {
noirTagName = `${GITHUB_TAG_PREFIX}-${cliVersion}`;
npmVersion = cliVersion;
} else if (aztecVersion === 'latest') {
noirTagName = await getLatestAztecNrTag();
npmVersion = 'latest';
} else {
noirTagName = await aztecNrVersionToTagName(aztecVersion);
npmVersion = aztecVersion;
}

if (nodejs) {
updateAztecDeps(projectPath, npmVersion, log);
}

if (noir) {
await updateAztecNr(projectPath, noirTagName, log);
}
const { contract } = options;
await update(projectPath, contract, options.rpcUrl, log, debugLogger);
});

compileContract(program, 'compile', log);
Expand Down
62 changes: 0 additions & 62 deletions yarn-project/cli/src/update-aztec.ts

This file was deleted.

123 changes: 0 additions & 123 deletions yarn-project/cli/src/update-aztecnr.ts

This file was deleted.

69 changes: 69 additions & 0 deletions yarn-project/cli/src/update/noir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { LogFn } from '@aztec/foundation/log';
import { NoirPackageConfig, parseNoirPackageConfig } from '@aztec/foundation/noir';

import TOML from '@ltd/j-toml';
import { readFile } from 'fs/promises';
import { EOL } from 'os';
import { join, resolve } from 'path';

import { atomicUpdateFile } from '../utils.js';

/**
* Updates Aztec.nr dependencies
* @param contractPath - Path to the contract to be updated
* @param tag - The tag to update to
* @param log - Logging function
*/
export async function updateAztecNr(contractPath: string, tag: string, log: LogFn) {
const configFilepath = resolve(join(contractPath, 'Nargo.toml'));
const packageConfig = parseNoirPackageConfig(TOML.parse(await readFile(configFilepath, 'utf-8')));
let dirty = false;

log(`\nUpdating Aztec.nr libraries to ${tag} in ${contractPath}`);
for (const dep of Object.values(packageConfig.dependencies)) {
if (!('git' in dep)) {
continue;
}

// remove trailing slash
const gitUrl = dep.git.toLowerCase().replace(/\/$/, '');
if (gitUrl !== 'https://github.com/aztecprotocol/aztec-packages') {
continue;
}

if (dep.tag !== tag) {
dirty = true;
dep.tag = tag;
}
}

if (dirty) {
const contents = prettyPrintTOML(packageConfig);
await atomicUpdateFile(configFilepath, contents);
log(`${join(contractPath, 'Nargo.toml')} updated`);
} else {
log('No updates required');
}
}

/**
* Pretty prints a NoirPackageConfig to a string
* @param packageConfig - Nargo.toml contents
* @returns The Nargo.toml contents as a string
*/
function prettyPrintTOML(packageConfig: NoirPackageConfig): string {
// hint to TOML.stringify how we want the file to look like
return TOML.stringify(
{
package: TOML.Section(packageConfig.package),
dependencies: TOML.Section(
Object.fromEntries(Object.entries(packageConfig.dependencies).map(([name, dep]) => [name, TOML.inline(dep)])),
),
},
{
indent: 2,
newline: EOL as any,
newlineAround: 'section',
},
);
}
Loading

0 comments on commit 96b5992

Please sign in to comment.