@aztec/cli 0.16.3 → 0.16.5
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/bin/index.js +0 -0
- package/package.json +8 -8
- package/src/bin/index.ts +0 -22
- package/src/client.ts +0 -68
- package/src/cmds/add_contract.ts +0 -27
- package/src/cmds/add_note.ts +0 -24
- package/src/cmds/block_number.ts +0 -12
- package/src/cmds/call.ts +0 -35
- package/src/cmds/check_deploy.ts +0 -17
- package/src/cmds/compute_selector.ts +0 -10
- package/src/cmds/create_account.ts +0 -39
- package/src/cmds/deploy.ts +0 -77
- package/src/cmds/deploy_l1_contracts.ts +0 -25
- package/src/cmds/example_contracts.ts +0 -12
- package/src/cmds/generate_p2p_private_key.ts +0 -13
- package/src/cmds/generate_private_key.ts +0 -23
- package/src/cmds/get_account.ts +0 -18
- package/src/cmds/get_accounts.ts +0 -19
- package/src/cmds/get_contract_data.ts +0 -39
- package/src/cmds/get_logs.ts +0 -71
- package/src/cmds/get_node_info.ts +0 -17
- package/src/cmds/get_recipient.ts +0 -18
- package/src/cmds/get_recipients.ts +0 -19
- package/src/cmds/get_tx_receipt.ts +0 -18
- package/src/cmds/inspect_contract.ts +0 -29
- package/src/cmds/parse_parameter_struct.ts +0 -30
- package/src/cmds/register_account.ts +0 -24
- package/src/cmds/register_recipient.ts +0 -21
- package/src/cmds/send.ts +0 -40
- package/src/cmds/unbox.ts +0 -11
- package/src/encoding.ts +0 -115
- package/src/github.ts +0 -3
- package/src/index.ts +0 -487
- package/src/test/mocks.ts +0 -65
- package/src/unbox.ts +0 -345
- package/src/update/common.ts +0 -16
- package/src/update/noir.ts +0 -79
- package/src/update/npm.ts +0 -134
- package/src/update/update.ts +0 -132
- package/src/utils.ts +0 -439
package/src/unbox.ts
DELETED
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
// inspired by https://github.com/trufflesuite/truffle/blob/develop/packages/box/lib/utils/unbox.ts
|
|
2
|
-
// however, their boxes are stored as standalone git repositories, while ours are subpackages in a monorepo
|
|
3
|
-
// so we do some hacky conversions post copy to make them work as standalone packages.
|
|
4
|
-
// We download the master branch of the monorepo, and then
|
|
5
|
-
// (1) copy "boxes/{CONTRACT_NAME}" subpackage to the specified output directory
|
|
6
|
-
// (2) if the box doesnt include noir source code, we copy it from the "noir-contracts" subpackage to into a new subdirectory "X/src/contracts",
|
|
7
|
-
// These are used by a simple frontend to interact with the contract and deploy to a local sandbox instance of aztec3.
|
|
8
|
-
// The unbox logic can be tested locally by running `$ts-node --esm src/bin/index.ts unbox PrivateToken`
|
|
9
|
-
// from `yarn-project/cli/`
|
|
10
|
-
import { LogFn } from '@aztec/foundation/log';
|
|
11
|
-
|
|
12
|
-
import { promises as fs } from 'fs';
|
|
13
|
-
import JSZip from 'jszip';
|
|
14
|
-
import fetch from 'node-fetch';
|
|
15
|
-
import * as path from 'path';
|
|
16
|
-
|
|
17
|
-
import { GITHUB_OWNER, GITHUB_REPO, GITHUB_TAG_PREFIX } from './github.js';
|
|
18
|
-
|
|
19
|
-
const BOXES_PATH = 'yarn-project/boxes';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* If the box contains the noir contract source code, we don't need to download it from github.
|
|
23
|
-
* Otherwise, we download the contract source code from the `noir-contracts` and `noir-libs` subpackages.
|
|
24
|
-
*/
|
|
25
|
-
async function isDirectoryNonEmpty(directoryPath: string): Promise<boolean> {
|
|
26
|
-
try {
|
|
27
|
-
const files = await fs.readdir(directoryPath);
|
|
28
|
-
return files.length > 0;
|
|
29
|
-
} catch (e) {
|
|
30
|
-
// Directory does not exist.
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @param data - in memory unzipped clone of a github repo
|
|
38
|
-
* @param repositoryFolderPath - folder to copy from github repo
|
|
39
|
-
* @param localOutputPath - local path to copy to
|
|
40
|
-
*/
|
|
41
|
-
async function copyFolderFromGithub(data: JSZip, repositoryFolderPath: string, localOutputPath: string, log: LogFn) {
|
|
42
|
-
log(`Downloading folder from github: ${repositoryFolderPath}`);
|
|
43
|
-
const repositoryDirectories = Object.values(data.files).filter(file => {
|
|
44
|
-
return file.dir && file.name.startsWith(repositoryFolderPath);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
for (const directory of repositoryDirectories) {
|
|
48
|
-
const relativePath = directory.name.replace(repositoryFolderPath, '');
|
|
49
|
-
const targetPath = `${localOutputPath}/${relativePath}`;
|
|
50
|
-
await fs.mkdir(targetPath, { recursive: true });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const folderFiles = Object.values(data.files).filter(file => {
|
|
54
|
-
return !file.dir && file.name.startsWith(repositoryFolderPath);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
for (const file of folderFiles) {
|
|
58
|
-
const relativePath = file.name.replace(repositoryFolderPath, '');
|
|
59
|
-
const targetPath = `${localOutputPath}/${relativePath}`;
|
|
60
|
-
const content = await file.async('nodebuffer');
|
|
61
|
-
await fs.writeFile(targetPath, content);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @param data - in memory unzipped clone of a github repo
|
|
67
|
-
* @param repositoryFile - path of the file to copy from github repo
|
|
68
|
-
* @param localOutputPath - local path to copy the file to
|
|
69
|
-
*/
|
|
70
|
-
async function copyFileFromGithub(data: JSZip, repositoryFile: string, localOutputPath: string, log: LogFn) {
|
|
71
|
-
log(`Downloading file from github: ${repositoryFile}`);
|
|
72
|
-
|
|
73
|
-
const file = data.files[repositoryFile];
|
|
74
|
-
|
|
75
|
-
if (!file || file.dir) {
|
|
76
|
-
throw new Error(`File not found or it's a directory: ${repositoryFile}`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const filename = path.basename(repositoryFile);
|
|
80
|
-
const targetPath = `${localOutputPath}/${filename}`;
|
|
81
|
-
|
|
82
|
-
const content = await file.async('nodebuffer');
|
|
83
|
-
await fs.writeFile(targetPath, content);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Not flexible at at all, but quick fix to download a noir smart contract from our
|
|
88
|
-
* monorepo on github. this will copy over the `yarn-projects/boxes/{contract_name}` folder
|
|
89
|
-
* as well as the specified `directoryPath` if the box doesn't include source code
|
|
90
|
-
* `directoryPath` should point to a single noir contract in `yarn-projects/noir-contracts/src/contracts/...`
|
|
91
|
-
* @param tag - The git tag to pull.
|
|
92
|
-
* @param directoryPath - path to a noir contract's source code (folder) in the github repo
|
|
93
|
-
* @param outputPath - local path that we will copy the noir contracts and web3 starter kit to
|
|
94
|
-
* @returns
|
|
95
|
-
*/
|
|
96
|
-
async function downloadContractAndBoxFromGithub(
|
|
97
|
-
tag: string,
|
|
98
|
-
contractName: string,
|
|
99
|
-
outputPath: string,
|
|
100
|
-
log: LogFn,
|
|
101
|
-
): Promise<void> {
|
|
102
|
-
// small string conversion, in the ABI the contract name looks like PrivateToken
|
|
103
|
-
// but in the repository it looks like private_token
|
|
104
|
-
|
|
105
|
-
log(`Downloading @aztec/boxes/${contractName}/ to ${outputPath}...`);
|
|
106
|
-
// Step 1: Fetch the monorepo ZIP from GitHub, matching the CLI version
|
|
107
|
-
const url = `https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}/archive/refs/tags/${tag}.zip`;
|
|
108
|
-
const response = await fetch(url);
|
|
109
|
-
const buffer = await response.arrayBuffer();
|
|
110
|
-
|
|
111
|
-
const zip = new JSZip();
|
|
112
|
-
const data = await zip.loadAsync(buffer);
|
|
113
|
-
|
|
114
|
-
// Step 2: copy the '@aztec/boxes/{contract-name}' subpackage to the output directory
|
|
115
|
-
// this is currently only implemented for `blank`, `blank-react` and `token` under 'boxes/{box-name}/'
|
|
116
|
-
const repoDirectoryPrefix = `${GITHUB_REPO}-${tag}`;
|
|
117
|
-
|
|
118
|
-
const boxPath = `${repoDirectoryPrefix}/${BOXES_PATH}/${contractName}/`;
|
|
119
|
-
await copyFolderFromGithub(data, boxPath, outputPath, log);
|
|
120
|
-
|
|
121
|
-
// the expected noir version is contained in
|
|
122
|
-
// aztec-packages/yarn-project/noir-compiler/src/noir-version.json
|
|
123
|
-
// copy it in and use to update the package.json script to install that version of noir
|
|
124
|
-
const noirVersionPath = `${repoDirectoryPrefix}/yarn-project/noir-compiler/src/noir-version.json`;
|
|
125
|
-
await copyFileFromGithub(data, noirVersionPath, outputPath, log);
|
|
126
|
-
|
|
127
|
-
const contractTargetDirectory = path.join(outputPath, 'src', 'contracts');
|
|
128
|
-
const boxContainsNoirSource = await isDirectoryNonEmpty(contractTargetDirectory);
|
|
129
|
-
if (boxContainsNoirSource) {
|
|
130
|
-
return;
|
|
131
|
-
} else {
|
|
132
|
-
// we used to support downloading from the noir contracts monorepo but now force box to contain source code
|
|
133
|
-
// This should never happen, because of the check we do initially on the box name.
|
|
134
|
-
throw Error(`Box ${contractName} does not contain noir source code.`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Does some conversion from the package/build configurations in the monorepo to the
|
|
139
|
-
* something usable by the copied standalone unboxed folder. Adjusts relative paths
|
|
140
|
-
* and package versions.
|
|
141
|
-
* @param packageVersion - CLI npm version, which determines what npm version to grab
|
|
142
|
-
* @param tag - The git tag.
|
|
143
|
-
* @param outputPath - relative path where we are copying everything
|
|
144
|
-
* @param log - logger
|
|
145
|
-
*/
|
|
146
|
-
async function updatePackagingConfigurations(
|
|
147
|
-
packageVersion: string,
|
|
148
|
-
tag: string,
|
|
149
|
-
outputPath: string,
|
|
150
|
-
log: LogFn,
|
|
151
|
-
): Promise<void> {
|
|
152
|
-
await updatePackageJsonVersions(packageVersion, outputPath, log);
|
|
153
|
-
await updateTsConfig('tsconfig.json', outputPath, log);
|
|
154
|
-
await updateTsConfig('tsconfig.dest.json', outputPath, log);
|
|
155
|
-
await updateNargoToml(tag, outputPath, log);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Adjust the contract Nargo.toml file for copied box:
|
|
160
|
-
* change the dependency paths from pointing within the monorepo
|
|
161
|
-
* to the github tagged version matching the installed `aztec-cli --version`
|
|
162
|
-
* @param packageVersion - CLI npm version, which determines what npm version to grab
|
|
163
|
-
* @param outputPath - relative path where we are copying everything
|
|
164
|
-
* @param log - logger
|
|
165
|
-
*/
|
|
166
|
-
async function updateNargoToml(tag: string, outputPath: string, log: LogFn): Promise<void> {
|
|
167
|
-
const SUPPORTED_DEPS = ['aztec', 'value_note', 'safe_math', 'authwit'];
|
|
168
|
-
|
|
169
|
-
const nargoTomlPath = path.join(outputPath, 'src', 'contracts', 'Nargo.toml');
|
|
170
|
-
const fileContent = await fs.readFile(nargoTomlPath, 'utf-8');
|
|
171
|
-
const lines = fileContent.split('\n');
|
|
172
|
-
const updatedLines = lines.map(line => {
|
|
173
|
-
// Check if the line starts with one of the deps
|
|
174
|
-
const key: string | undefined = SUPPORTED_DEPS.find(dependencyName =>
|
|
175
|
-
line.trim().startsWith(`${dependencyName} =`),
|
|
176
|
-
);
|
|
177
|
-
if (key) {
|
|
178
|
-
// Replace the line, which was configured for compiling within the `aztec-packages` monorepo. We replace
|
|
179
|
-
// the local path with `git` and `directory` fields with a `tag` field, which points to the tagged release
|
|
180
|
-
// note that the key has a "_" in the name, but we use "-" in the github repo folder
|
|
181
|
-
return `${key} = { git="https://github.com/AztecProtocol/aztec-packages/", tag="${tag}", directory="yarn-project/aztec-nr/${key.replace(
|
|
182
|
-
'_',
|
|
183
|
-
'-',
|
|
184
|
-
)}" }`;
|
|
185
|
-
}
|
|
186
|
-
return line;
|
|
187
|
-
});
|
|
188
|
-
const updatedContent = updatedLines.join('\n');
|
|
189
|
-
await fs.writeFile(nargoTomlPath, updatedContent);
|
|
190
|
-
log(`Updated Nargo.toml to point to version ${tag} of aztec-noir libs in github.`);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* The `tsconfig.json` also needs to be updated to remove the "references" section, which
|
|
195
|
-
* points to the monorepo's subpackages. Those are unavailable in the cloned subpackage,
|
|
196
|
-
* so we remove the entries to install the the workspace packages from npm.
|
|
197
|
-
* @param outputPath - directory we are unboxing to
|
|
198
|
-
*/
|
|
199
|
-
async function updateTsConfig(filename: string, outputPath: string, log: LogFn) {
|
|
200
|
-
try {
|
|
201
|
-
const tsconfigJsonPath = path.join(outputPath, filename);
|
|
202
|
-
const data = await fs.readFile(tsconfigJsonPath, 'utf8');
|
|
203
|
-
const config = JSON.parse(data);
|
|
204
|
-
|
|
205
|
-
delete config.references;
|
|
206
|
-
|
|
207
|
-
const updatedData = JSON.stringify(config, null, 2);
|
|
208
|
-
await fs.writeFile(tsconfigJsonPath, updatedData, 'utf8');
|
|
209
|
-
|
|
210
|
-
log(`Updated ${filename}.`);
|
|
211
|
-
} catch (error) {
|
|
212
|
-
log(`Error updating ${filename}.`);
|
|
213
|
-
throw error;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* We pin to "workspace:^" in the package.json for subpackages, but we need to replace it with
|
|
219
|
-
* an the actual version number in the cloned starter kit
|
|
220
|
-
* We modify the copied package.json and pin to the version of the package that was downloaded
|
|
221
|
-
* @param packageVersion - CLI npm version, which determines what npm version to grab
|
|
222
|
-
* @param outputPath - directory we are unboxing to
|
|
223
|
-
* @param log - logger
|
|
224
|
-
*/
|
|
225
|
-
async function updatePackageJsonVersions(packageVersion: string, outputPath: string, log: LogFn): Promise<void> {
|
|
226
|
-
const packageJsonPath = path.join(outputPath, 'package.json');
|
|
227
|
-
const fileContent = await fs.readFile(packageJsonPath, 'utf-8');
|
|
228
|
-
const packageData = JSON.parse(fileContent);
|
|
229
|
-
|
|
230
|
-
// Check and replace "workspace^" pins in dependencies, which are monorepo yarn workspace references
|
|
231
|
-
if (packageData.dependencies) {
|
|
232
|
-
for (const [key, value] of Object.entries(packageData.dependencies)) {
|
|
233
|
-
if (value === 'workspace:^') {
|
|
234
|
-
packageData.dependencies[key] = `^${packageVersion}`;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Check and replace in devDependencies
|
|
240
|
-
if (packageData.devDependencies) {
|
|
241
|
-
for (const [key, value] of Object.entries(packageData.devDependencies)) {
|
|
242
|
-
if (value === 'workspace:^') {
|
|
243
|
-
// TODO: check if this right post landing. the package.json version looks like 0.1.0
|
|
244
|
-
// but the npm versions look like v0.1.0-alpha63 so we are not fully pinned
|
|
245
|
-
packageData.devDependencies[key] = `^${packageVersion}`;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
// read the `noir-version.json`, grab the expected noir version, and patch the noir install script
|
|
250
|
-
const noirVersionPath = path.join(outputPath, 'noir-version.json');
|
|
251
|
-
const noirVersionContent = await fs.readFile(noirVersionPath, 'utf-8');
|
|
252
|
-
const noirVersionJSON = JSON.parse(noirVersionContent);
|
|
253
|
-
const noirTag = noirVersionJSON.tag;
|
|
254
|
-
packageData.scripts['install:noir'] = packageData.scripts['install:noir'].replace('NOIR_VERSION', `${noirTag}`);
|
|
255
|
-
log(`Updated Noir version to: ${noirTag}`);
|
|
256
|
-
|
|
257
|
-
// modify the version of the sandbox to pull - it's set to "latest" version in the monorepo,
|
|
258
|
-
// but we need to replace with the same tagVersion as the cli and the other aztec npm packages
|
|
259
|
-
// similarly, make sure we spin up the sandbox with the same version.
|
|
260
|
-
packageData.scripts['install:sandbox'] = packageData.scripts['install:sandbox'].replace(
|
|
261
|
-
'latest',
|
|
262
|
-
`${packageVersion}`,
|
|
263
|
-
);
|
|
264
|
-
|
|
265
|
-
packageData.scripts['start:sandbox'] = packageData.scripts['start:sandbox'].replace('latest', `${packageVersion}`);
|
|
266
|
-
|
|
267
|
-
// Convert back to a string and write back to the package.json file
|
|
268
|
-
const updatedContent = JSON.stringify(packageData, null, 2);
|
|
269
|
-
await fs.writeFile(packageJsonPath, updatedContent);
|
|
270
|
-
|
|
271
|
-
log(`Updated package.json versions to: ${packageVersion}`);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
*
|
|
276
|
-
* @param outputDirectoryName - user specified directory we are "unboxing" files into
|
|
277
|
-
* @param log - logger
|
|
278
|
-
* @returns
|
|
279
|
-
*/
|
|
280
|
-
async function createDirectory(outputDirectoryName: string, log: LogFn): Promise<string> {
|
|
281
|
-
const absolutePath = path.resolve(outputDirectoryName);
|
|
282
|
-
|
|
283
|
-
try {
|
|
284
|
-
// Checking if the path exists and if it is a directory
|
|
285
|
-
const stats = await fs.stat(absolutePath);
|
|
286
|
-
if (!stats.isDirectory()) {
|
|
287
|
-
throw new Error(`The specified path ${outputDirectoryName} is not a directory/folder.`);
|
|
288
|
-
}
|
|
289
|
-
} catch (error: any) {
|
|
290
|
-
if (error.code === 'ENOENT') {
|
|
291
|
-
await fs.mkdir(absolutePath, { recursive: true });
|
|
292
|
-
log(`The directory did not exist and has been created: ${absolutePath}`);
|
|
293
|
-
} else {
|
|
294
|
-
throw error;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return absolutePath;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Unboxes a contract from `@aztec/boxes` by performing the following operations:
|
|
303
|
-
* 1. Copies the frontend template from `@aztec/boxes/{contract_name}` to the outputDirectory
|
|
304
|
-
* 2. Checks if the contract source was copied over from `@aztec/boxes/{contract_name}/src/contracts`
|
|
305
|
-
* 3. If not, copies the contract from the appropriate `@aztec/noir-contracts/src/contracts/...` folder.
|
|
306
|
-
*
|
|
307
|
-
* The box provides a simple React app which parses the contract ABI
|
|
308
|
-
* and generates a UI to deploy + interact with the contract on a local aztec testnet.
|
|
309
|
-
* @param contractName - name of contract from `@aztec/noir-contracts`, in a format like "PrivateToken" (rather than "private_token", as it appears in the noir-contracts repo)
|
|
310
|
-
* @param log - Logger instance that will output to the CLI
|
|
311
|
-
*/
|
|
312
|
-
export async function unboxContract(
|
|
313
|
-
contractName: string,
|
|
314
|
-
outputDirectoryName: string,
|
|
315
|
-
packageVersion: string,
|
|
316
|
-
log: LogFn,
|
|
317
|
-
) {
|
|
318
|
-
const contractNames = ['token', 'blank', 'blank-react'];
|
|
319
|
-
|
|
320
|
-
if (!contractNames.includes(contractName)) {
|
|
321
|
-
log(
|
|
322
|
-
`The noir contract named "${contractName}" was not found in "@aztec/boxes" package. Valid options are:
|
|
323
|
-
${contractNames.join('\n\t')}
|
|
324
|
-
We recommend "token" as a default.`,
|
|
325
|
-
);
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
const outputPath = await createDirectory(outputDirectoryName, log);
|
|
329
|
-
|
|
330
|
-
const tag = `${GITHUB_TAG_PREFIX}-v${packageVersion}`;
|
|
331
|
-
// downloads the selected contract's relevant folder in @aztec/boxes/{contract_name}
|
|
332
|
-
await downloadContractAndBoxFromGithub(tag, contractName, outputPath, log);
|
|
333
|
-
// make adjustments for packaging to work as a standalone, as opposed to part of yarn workspace
|
|
334
|
-
// as in the monorepo source files. replace things like "workspace^" with the actual version number
|
|
335
|
-
await updatePackagingConfigurations(packageVersion, tag, outputPath, log);
|
|
336
|
-
|
|
337
|
-
log('');
|
|
338
|
-
log(`${contractName} has been successfully initialized!`);
|
|
339
|
-
log('To get started, simply run the following commands:');
|
|
340
|
-
log(` cd ${outputDirectoryName}`);
|
|
341
|
-
log(' yarn');
|
|
342
|
-
log(' yarn start:sandbox');
|
|
343
|
-
log('And in another terminal in the same directory,');
|
|
344
|
-
log(' yarn start:dev');
|
|
345
|
-
}
|
package/src/update/common.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tracks changes to dependencies
|
|
3
|
-
*/
|
|
4
|
-
export type DependencyChanges = {
|
|
5
|
-
/** Which file was changed */
|
|
6
|
-
file: string;
|
|
7
|
-
/** changes done to the file */
|
|
8
|
-
dependencies: Array<{
|
|
9
|
-
/** Name of the dependency being changed */
|
|
10
|
-
name: string;
|
|
11
|
-
/** Previous version of the dependency */
|
|
12
|
-
from: string;
|
|
13
|
-
/** New version of the dependency (after the update) */
|
|
14
|
-
to: string;
|
|
15
|
-
}>;
|
|
16
|
-
};
|
package/src/update/noir.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { LogFn } from '@aztec/foundation/log';
|
|
2
|
-
import { NoirPackageConfig, parseNoirPackageConfig } from '@aztec/foundation/noir';
|
|
3
|
-
|
|
4
|
-
import TOML from '@ltd/j-toml';
|
|
5
|
-
import { readFile } from 'fs/promises';
|
|
6
|
-
import { EOL } from 'os';
|
|
7
|
-
import { join, relative, resolve } from 'path';
|
|
8
|
-
|
|
9
|
-
import { atomicUpdateFile } from '../utils.js';
|
|
10
|
-
import { DependencyChanges } from './common.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Updates Aztec.nr dependencies
|
|
14
|
-
* @param contractPath - Path to the contract to be updated
|
|
15
|
-
* @param tag - The tag to update to
|
|
16
|
-
* @param log - Logging function
|
|
17
|
-
*/
|
|
18
|
-
export async function updateAztecNr(contractPath: string, tag: string, log: LogFn): Promise<DependencyChanges> {
|
|
19
|
-
const configFilepath = resolve(join(contractPath, 'Nargo.toml'));
|
|
20
|
-
const packageConfig = parseNoirPackageConfig(TOML.parse(await readFile(configFilepath, 'utf-8')));
|
|
21
|
-
const changes: DependencyChanges = {
|
|
22
|
-
dependencies: [],
|
|
23
|
-
file: configFilepath,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
log(`Updating Aztec.nr libraries to ${tag} in ${relative(process.cwd(), changes.file)}`);
|
|
27
|
-
for (const dep of Object.values(packageConfig.dependencies)) {
|
|
28
|
-
if (!('git' in dep)) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// remove trailing slash
|
|
33
|
-
const gitUrl = dep.git.toLowerCase().replace(/\/$/, '');
|
|
34
|
-
if (gitUrl !== 'https://github.com/aztecprotocol/aztec-packages') {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (dep.tag !== tag) {
|
|
39
|
-
// show the Aztec.nr package name rather than the lib name
|
|
40
|
-
const dirParts = dep.directory?.split('/') ?? [];
|
|
41
|
-
changes.dependencies.push({
|
|
42
|
-
name: dirParts.slice(-2).join('/'),
|
|
43
|
-
from: dep.tag,
|
|
44
|
-
to: tag,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
dep.tag = tag;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (changes.dependencies.length > 0) {
|
|
52
|
-
const contents = prettyPrintTOML(packageConfig);
|
|
53
|
-
await atomicUpdateFile(configFilepath, contents);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return changes;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Pretty prints a NoirPackageConfig to a string
|
|
61
|
-
* @param packageConfig - Nargo.toml contents
|
|
62
|
-
* @returns The Nargo.toml contents as a string
|
|
63
|
-
*/
|
|
64
|
-
function prettyPrintTOML(packageConfig: NoirPackageConfig): string {
|
|
65
|
-
// hint to TOML.stringify how we want the file to look like
|
|
66
|
-
return TOML.stringify(
|
|
67
|
-
{
|
|
68
|
-
package: TOML.Section(packageConfig.package),
|
|
69
|
-
dependencies: TOML.Section(
|
|
70
|
-
Object.fromEntries(Object.entries(packageConfig.dependencies).map(([name, dep]) => [name, TOML.inline(dep)])),
|
|
71
|
-
),
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
indent: 2,
|
|
75
|
-
newline: EOL as any,
|
|
76
|
-
newlineAround: 'section',
|
|
77
|
-
},
|
|
78
|
-
);
|
|
79
|
-
}
|
package/src/update/npm.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { LogFn } from '@aztec/foundation/log';
|
|
2
|
-
|
|
3
|
-
import { spawnSync } from 'child_process';
|
|
4
|
-
import { existsSync } from 'fs';
|
|
5
|
-
import { readFile } from 'fs/promises';
|
|
6
|
-
import { join, relative, resolve } from 'path';
|
|
7
|
-
import { SemVer, parse } from 'semver';
|
|
8
|
-
|
|
9
|
-
import { atomicUpdateFile } from '../utils.js';
|
|
10
|
-
import { DependencyChanges } from './common.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Looks up a package.json file and returns its contents
|
|
14
|
-
* @param projectPath - Path to Nodejs project
|
|
15
|
-
* @returns The parsed package.json
|
|
16
|
-
*/
|
|
17
|
-
export async function readPackageJson(projectPath: string): Promise<{
|
|
18
|
-
/** dependencies */
|
|
19
|
-
dependencies?: Record<string, string>;
|
|
20
|
-
/** devDependencies */
|
|
21
|
-
devDependencies?: Record<string, string>;
|
|
22
|
-
}> {
|
|
23
|
-
const configFilepath = resolve(join(projectPath, 'package.json'));
|
|
24
|
-
const pkg = JSON.parse(await readFile(configFilepath, 'utf-8'));
|
|
25
|
-
|
|
26
|
-
return pkg;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Queries the npm registry for the latest version of a package
|
|
31
|
-
* @param packageName - The package to query
|
|
32
|
-
* @param distTag - The distribution tag
|
|
33
|
-
* @returns The latest version of the package on that distribution tag
|
|
34
|
-
*/
|
|
35
|
-
export async function getNewestVersion(packageName: string, distTag = 'latest'): Promise<SemVer> {
|
|
36
|
-
const url = new URL(packageName, 'https://registry.npmjs.org/');
|
|
37
|
-
const response = await fetch(url);
|
|
38
|
-
if (!response.ok) {
|
|
39
|
-
throw new Error(`Failed to fetch ${url}`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const body = await response.json();
|
|
43
|
-
const latestVersion = parse(body['dist-tags'][distTag]);
|
|
44
|
-
if (!latestVersion) {
|
|
45
|
-
throw new Error(`Failed to get latest version from registry`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return latestVersion;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Updates a project's \@aztec/* dependencies to the specific version
|
|
53
|
-
* @param projectPath - Path to Nodejs project
|
|
54
|
-
* @param aztecVersion - The version to update to
|
|
55
|
-
* @returns True if the project was updated
|
|
56
|
-
*/
|
|
57
|
-
export async function updateAztecDeps(
|
|
58
|
-
projectPath: string,
|
|
59
|
-
aztecVersion: SemVer,
|
|
60
|
-
log: LogFn,
|
|
61
|
-
): Promise<DependencyChanges> {
|
|
62
|
-
const pkg = await readPackageJson(projectPath);
|
|
63
|
-
const changes: DependencyChanges = {
|
|
64
|
-
file: resolve(join(projectPath, 'package.json')),
|
|
65
|
-
dependencies: [],
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
log(`Updating @aztec packages to ${aztecVersion} in ${relative(process.cwd(), changes.file)}`);
|
|
69
|
-
const version = aztecVersion.version;
|
|
70
|
-
|
|
71
|
-
for (const depType of ['dependencies', 'devDependencies'] as const) {
|
|
72
|
-
const dependencies = pkg[depType];
|
|
73
|
-
if (!dependencies) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
for (const name of Object.keys(dependencies)) {
|
|
78
|
-
if (!name.startsWith('@aztec/')) {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// different release schedule
|
|
83
|
-
if (name === '@aztec/aztec-ui') {
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (dependencies[name] !== version) {
|
|
88
|
-
changes.dependencies.push({
|
|
89
|
-
name,
|
|
90
|
-
from: dependencies[name],
|
|
91
|
-
to: version,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
dependencies[name] = version;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (changes.dependencies.length > 0) {
|
|
100
|
-
const contents = JSON.stringify(pkg, null, 2) + '\n';
|
|
101
|
-
await atomicUpdateFile(resolve(join(projectPath, 'package.json')), contents);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return changes;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Updates a project's yarn.lock or package-lock.json
|
|
109
|
-
* @param projectPath - Path to Nodejs project
|
|
110
|
-
*/
|
|
111
|
-
export function updateLockfile(projectPath: string, log: LogFn): void {
|
|
112
|
-
const isNpm = existsSync(resolve(join(projectPath, 'package-lock.json')));
|
|
113
|
-
const isYarn = existsSync(resolve(join(projectPath, 'yarn.lock')));
|
|
114
|
-
const isPnpm = existsSync(resolve(join(projectPath, 'pnpm-lock.yaml')));
|
|
115
|
-
|
|
116
|
-
if (isPnpm) {
|
|
117
|
-
spawnSync('pnpm', ['install'], {
|
|
118
|
-
cwd: projectPath,
|
|
119
|
-
stdio: 'inherit',
|
|
120
|
-
});
|
|
121
|
-
} else if (isYarn) {
|
|
122
|
-
spawnSync('yarn', ['install'], {
|
|
123
|
-
cwd: projectPath,
|
|
124
|
-
stdio: 'inherit',
|
|
125
|
-
});
|
|
126
|
-
} else if (isNpm) {
|
|
127
|
-
spawnSync('npm', ['install'], {
|
|
128
|
-
cwd: projectPath,
|
|
129
|
-
stdio: 'inherit',
|
|
130
|
-
});
|
|
131
|
-
} else {
|
|
132
|
-
log(`No lockfile found in ${projectPath}. Skipping lockfile update...`);
|
|
133
|
-
}
|
|
134
|
-
}
|