@aztec/cli 0.13.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/github.d.ts +4 -0
- package/dest/github.d.ts.map +1 -0
- package/dest/github.js +4 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +22 -4
- package/dest/unbox.d.ts.map +1 -1
- package/dest/unbox.js +2 -4
- package/dest/update/common.d.ts +17 -0
- package/dest/update/common.d.ts.map +1 -0
- package/dest/update/common.js +2 -0
- package/dest/update/noir.d.ts +10 -0
- package/dest/update/noir.d.ts.map +1 -0
- package/dest/update/noir.js +63 -0
- package/dest/update/npm.d.ts +32 -0
- package/dest/update/npm.d.ts.map +1 -0
- package/dest/update/npm.js +106 -0
- package/dest/update/update.d.ts +3 -0
- package/dest/update/update.d.ts.map +1 -0
- package/dest/update/update.js +93 -0
- package/dest/utils.d.ts +6 -0
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +27 -2
- package/package.json +9 -8
- package/src/github.ts +3 -0
- package/src/index.ts +25 -3
- package/src/unbox.ts +2 -3
- package/src/update/common.ts +16 -0
- package/src/update/noir.ts +79 -0
- package/src/update/npm.ts +129 -0
- package/src/update/update.ts +126 -0
- package/src/utils.ts +29 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
2
|
+
import { DebugLogger, LogFn } from '@aztec/foundation/log';
|
|
3
|
+
|
|
4
|
+
import { relative, resolve } from 'path';
|
|
5
|
+
import { SemVer, coerce, gt, lt, parse } from 'semver';
|
|
6
|
+
|
|
7
|
+
import { createCompatibleClient } from '../client.js';
|
|
8
|
+
import { GITHUB_TAG_PREFIX } from '../github.js';
|
|
9
|
+
import { DependencyChanges } from './common.js';
|
|
10
|
+
import { updateAztecNr } from './noir.js';
|
|
11
|
+
import { getNewestVersion as getLatestVersion, readPackageJson, updateAztecDeps, updateLockfile } from './npm.js';
|
|
12
|
+
|
|
13
|
+
const SANDBOX_PACKAGE = '@aztec/aztec-sandbox';
|
|
14
|
+
|
|
15
|
+
export async function update(
|
|
16
|
+
projectPath: string,
|
|
17
|
+
contracts: string[],
|
|
18
|
+
pxeUrl: string,
|
|
19
|
+
sandboxVersion: string,
|
|
20
|
+
log: LogFn,
|
|
21
|
+
debugLog: DebugLogger,
|
|
22
|
+
): Promise<void> {
|
|
23
|
+
const targetSandboxVersion =
|
|
24
|
+
sandboxVersion === 'latest' ? await getLatestVersion(SANDBOX_PACKAGE, 'latest') : parse(sandboxVersion);
|
|
25
|
+
|
|
26
|
+
if (!targetSandboxVersion) {
|
|
27
|
+
throw new Error(`Invalid aztec version ${sandboxVersion}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let currentSandboxVersion = await getNpmSandboxVersion(projectPath, log);
|
|
31
|
+
|
|
32
|
+
if (!currentSandboxVersion) {
|
|
33
|
+
currentSandboxVersion = await getRemoteSandboxVersion(pxeUrl, log, debugLog);
|
|
34
|
+
|
|
35
|
+
if (currentSandboxVersion && lt(currentSandboxVersion, targetSandboxVersion)) {
|
|
36
|
+
log(`
|
|
37
|
+
Sandbox is older than version ${targetSandboxVersion}. If running via docker-compose, follow update instructions:
|
|
38
|
+
https://docs.aztec.network/dev_docs/cli/updating
|
|
39
|
+
|
|
40
|
+
Once the sandbox is updated, run the \`aztec-cli update\` command again`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!currentSandboxVersion) {
|
|
46
|
+
throw new Error('Sandbox version could not be detected');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// sanity check
|
|
50
|
+
if (gt(currentSandboxVersion, targetSandboxVersion)) {
|
|
51
|
+
throw new Error('Local sandbox version is newer than latest version.');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const npmChanges = await updateAztecDeps(projectPath, targetSandboxVersion, log);
|
|
55
|
+
if (npmChanges.dependencies.length > 0) {
|
|
56
|
+
updateLockfile(projectPath, log);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const contractChanges: DependencyChanges[] = [];
|
|
60
|
+
for (const contract of contracts) {
|
|
61
|
+
try {
|
|
62
|
+
contractChanges.push(
|
|
63
|
+
await updateAztecNr(
|
|
64
|
+
resolve(projectPath, contract),
|
|
65
|
+
`${GITHUB_TAG_PREFIX}-v${targetSandboxVersion.version}`,
|
|
66
|
+
log,
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
} catch (err) {
|
|
70
|
+
if (err instanceof Error && 'code' in err && err.code === 'ENOENT') {
|
|
71
|
+
log(`No Nargo.toml found in ${relative(process.cwd(), contract)}. Skipping...`);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
printChanges(npmChanges, log);
|
|
80
|
+
|
|
81
|
+
contractChanges.forEach(changes => {
|
|
82
|
+
printChanges(changes, log);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function printChanges(changes: DependencyChanges, log: LogFn): void {
|
|
87
|
+
log(`\nIn ${relative(process.cwd(), changes.file)}:`);
|
|
88
|
+
if (changes.dependencies.length === 0) {
|
|
89
|
+
log(' No changes');
|
|
90
|
+
} else {
|
|
91
|
+
changes.dependencies.forEach(({ name, from, to }) => {
|
|
92
|
+
log(` Updated ${name} from ${from} to ${to}`);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function getNpmSandboxVersion(projectPath: string, log: LogFn): Promise<SemVer | null> {
|
|
98
|
+
try {
|
|
99
|
+
const pkg = await readPackageJson(projectPath);
|
|
100
|
+
// use coerce instead of parse because it eliminates semver operators like ~ and ^
|
|
101
|
+
return coerce(pkg.dependencies?.[SANDBOX_PACKAGE]);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
if (err instanceof Error && 'code' in err && err.code === 'ENOENT') {
|
|
104
|
+
log(`No package.json found in ${projectPath}`);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function getRemoteSandboxVersion(pxeUrl: string, log: LogFn, debugLog: DebugLogger): Promise<SemVer | null> {
|
|
113
|
+
try {
|
|
114
|
+
const client = await createCompatibleClient(pxeUrl, debugLog);
|
|
115
|
+
const nodeInfo = await client.getNodeInfo();
|
|
116
|
+
|
|
117
|
+
return parse(nodeInfo.sandboxVersion);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
if (err instanceof Error && err.message === 'fetch failed') {
|
|
120
|
+
log(`Could not connect to Sandbox running on ${pxeUrl}`);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
throw err;
|
|
125
|
+
}
|
|
126
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from '@aztec/l1-artifacts';
|
|
17
17
|
import { LogId } from '@aztec/types';
|
|
18
18
|
|
|
19
|
-
import { InvalidArgumentError } from 'commander';
|
|
19
|
+
import { CommanderError, InvalidArgumentError } from 'commander';
|
|
20
20
|
import fs from 'fs';
|
|
21
21
|
import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
22
22
|
|
|
@@ -403,3 +403,31 @@ export function parseField(field: string): Fr {
|
|
|
403
403
|
export function parseFields(fields: string[]): Fr[] {
|
|
404
404
|
return fields.map(parseField);
|
|
405
405
|
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Updates a file in place atomically.
|
|
409
|
+
* @param filePath - Path to file
|
|
410
|
+
* @param contents - New contents to write
|
|
411
|
+
*/
|
|
412
|
+
export async function atomicUpdateFile(filePath: string, contents: string) {
|
|
413
|
+
const tmpFilepath = filePath + '.tmp';
|
|
414
|
+
try {
|
|
415
|
+
await fs.promises.writeFile(tmpFilepath, contents, {
|
|
416
|
+
// let's crash if the tmp file already exists
|
|
417
|
+
flag: 'wx',
|
|
418
|
+
});
|
|
419
|
+
await fs.promises.rename(tmpFilepath, filePath);
|
|
420
|
+
} catch (e) {
|
|
421
|
+
if (e instanceof Error && 'code' in e && e.code === 'EEXIST') {
|
|
422
|
+
const commanderError = new CommanderError(
|
|
423
|
+
1,
|
|
424
|
+
e.code,
|
|
425
|
+
`Temporary file already exists: ${tmpFilepath}. Delete this file and try again.`,
|
|
426
|
+
);
|
|
427
|
+
commanderError.nestedError = e.message;
|
|
428
|
+
throw commanderError;
|
|
429
|
+
} else {
|
|
430
|
+
throw e;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|