@aztec/builder 0.46.5 → 0.46.6

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.
Files changed (47) hide show
  1. package/dest/cli.js +4 -25
  2. package/package.json +4 -20
  3. package/src/cli.ts +3 -25
  4. package/dest/cli/codegen.d.ts +0 -10
  5. package/dest/cli/codegen.d.ts.map +0 -1
  6. package/dest/cli/codegen.js +0 -71
  7. package/dest/cli/update/common.d.ts +0 -17
  8. package/dest/cli/update/common.d.ts.map +0 -1
  9. package/dest/cli/update/common.js +0 -2
  10. package/dest/cli/update/github.d.ts +0 -4
  11. package/dest/cli/update/github.d.ts.map +0 -1
  12. package/dest/cli/update/github.js +0 -4
  13. package/dest/cli/update/noir.d.ts +0 -10
  14. package/dest/cli/update/noir.d.ts.map +0 -1
  15. package/dest/cli/update/noir.js +0 -47
  16. package/dest/cli/update/npm.d.ts +0 -34
  17. package/dest/cli/update/npm.d.ts.map +0 -1
  18. package/dest/cli/update/npm.js +0 -125
  19. package/dest/cli/update/update.d.ts +0 -3
  20. package/dest/cli/update/update.d.ts.map +0 -1
  21. package/dest/cli/update/update.js +0 -58
  22. package/dest/cli/update/utils.d.ts +0 -14
  23. package/dest/cli/update/utils.d.ts.map +0 -1
  24. package/dest/cli/update/utils.js +0 -43
  25. package/dest/contract-interface-gen/typescript.d.ts +0 -9
  26. package/dest/contract-interface-gen/typescript.d.ts.map +0 -1
  27. package/dest/contract-interface-gen/typescript.js +0 -349
  28. package/dest/index.d.ts +0 -2
  29. package/dest/index.d.ts.map +0 -1
  30. package/dest/index.js +0 -2
  31. package/dest/mocked_keys.d.ts +0 -2
  32. package/dest/mocked_keys.d.ts.map +0 -1
  33. package/dest/mocked_keys.js +0 -2
  34. package/dest/utils.d.ts +0 -10
  35. package/dest/utils.d.ts.map +0 -1
  36. package/dest/utils.js +0 -32
  37. package/src/cli/codegen.ts +0 -91
  38. package/src/cli/update/common.ts +0 -16
  39. package/src/cli/update/github.ts +0 -3
  40. package/src/cli/update/noir.ts +0 -57
  41. package/src/cli/update/npm.ts +0 -154
  42. package/src/cli/update/update.ts +0 -78
  43. package/src/cli/update/utils.ts +0 -50
  44. package/src/contract-interface-gen/typescript.ts +0 -389
  45. package/src/index.ts +0 -1
  46. package/src/mocked_keys.ts +0 -2
  47. package/src/utils.ts +0 -33
@@ -1,57 +0,0 @@
1
- import { type LogFn } from '@aztec/foundation/log';
2
- import { parseNoirPackageConfig } from '@aztec/foundation/noir';
3
-
4
- import TOML from '@iarna/toml';
5
- import { readFile } from 'fs/promises';
6
- import { join, relative, resolve } from 'path';
7
-
8
- import { type DependencyChanges } from './common.js';
9
- import { atomicUpdateFile, prettyPrintNargoToml } from './utils.js';
10
-
11
- /**
12
- * Updates Aztec.nr dependencies
13
- * @param contractPath - Path to the contract to be updated
14
- * @param tag - The tag to update to
15
- * @param log - Logging function
16
- */
17
- export async function updateAztecNr(contractPath: string, tag: string, log: LogFn): Promise<DependencyChanges> {
18
- const configFilepath = resolve(join(contractPath, 'Nargo.toml'));
19
- const packageConfig = parseNoirPackageConfig(TOML.parse(await readFile(configFilepath, 'utf-8')));
20
- const changes: DependencyChanges = {
21
- dependencies: [],
22
- file: configFilepath,
23
- };
24
-
25
- log(`Updating Aztec.nr libraries to ${tag} in ${relative(process.cwd(), changes.file)}`);
26
- for (const dep of Object.values(packageConfig.dependencies)) {
27
- if (!('git' in dep)) {
28
- continue;
29
- }
30
-
31
- // remove trailing slash
32
- const gitUrl = dep.git.toLowerCase().replace(/\/$/, '');
33
- if (gitUrl !== 'https://github.com/aztecprotocol/aztec-packages') {
34
- continue;
35
- }
36
-
37
- if (dep.tag !== tag) {
38
- // show the Aztec.nr package name rather than the lib name
39
- const dirParts = dep.directory?.split('/') ?? [];
40
- changes.dependencies.push({
41
- name: dirParts.slice(-2).join('/'),
42
- from: dep.tag,
43
- to: tag,
44
- });
45
-
46
- dep.tag = tag;
47
- dep.directory = dep.directory?.replace('yarn-project/', 'noir-projects/');
48
- }
49
- }
50
-
51
- if (changes.dependencies.length > 0) {
52
- const contents = prettyPrintNargoToml(packageConfig);
53
- await atomicUpdateFile(configFilepath, contents);
54
- }
55
-
56
- return changes;
57
- }
@@ -1,154 +0,0 @@
1
- import { type 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 { type SemVer, parse } from 'semver';
8
-
9
- import { type DependencyChanges } from './common.js';
10
- import { atomicUpdateFile } from './utils.js';
11
-
12
- const deprecatedNpmPackages = new Set<string>(['@aztec/cli', '@aztec/aztec-sandbox']);
13
- const npmDeprecationMessage = `
14
- The following packages have been deprecated and will no longer be updated on the npm registry:
15
- ${Array.from(deprecatedNpmPackages)
16
- .map(pkg => ` - ${pkg}`)
17
- .join('\n')}
18
- Remove them from package.json
19
- `;
20
-
21
- /**
22
- * Looks up a package.json file and returns its contents
23
- * @param projectPath - Path to Nodejs project
24
- * @returns The parsed package.json
25
- */
26
- export async function readPackageJson(projectPath: string): Promise<{
27
- /** dependencies */
28
- dependencies?: Record<string, string>;
29
- /** devDependencies */
30
- devDependencies?: Record<string, string>;
31
- }> {
32
- const configFilepath = resolve(join(projectPath, 'package.json'));
33
- const pkg = JSON.parse(await readFile(configFilepath, 'utf-8'));
34
-
35
- return pkg;
36
- }
37
-
38
- /**
39
- * Queries the npm registry for the latest version of a package
40
- * @param packageName - The package to query
41
- * @param distTag - The distribution tag
42
- * @returns The latest version of the package on that distribution tag
43
- */
44
- export async function getNewestVersion(packageName: string, distTag = 'latest'): Promise<SemVer> {
45
- const url = new URL(packageName, 'https://registry.npmjs.org/');
46
- const response = await fetch(url);
47
- if (!response.ok) {
48
- throw new Error(`Failed to fetch ${url}`);
49
- }
50
-
51
- const body = await response.json();
52
- const latestVersion = parse(body['dist-tags'][distTag]);
53
- if (!latestVersion) {
54
- throw new Error(`Failed to get latest version from registry`);
55
- }
56
-
57
- return latestVersion;
58
- }
59
-
60
- /**
61
- * Updates a project's \@aztec/* dependencies to the specific version
62
- * @param projectPath - Path to Nodejs project
63
- * @param aztecVersion - The version to update to
64
- * @returns True if the project was updated
65
- */
66
- export async function updateAztecDeps(
67
- projectPath: string,
68
- aztecVersion: SemVer,
69
- log: LogFn,
70
- ): Promise<DependencyChanges> {
71
- const pkg = await readPackageJson(projectPath);
72
- const changes: DependencyChanges = {
73
- file: resolve(join(projectPath, 'package.json')),
74
- dependencies: [],
75
- };
76
-
77
- log(`Updating @aztec packages to ${aztecVersion} in ${relative(process.cwd(), changes.file)}`);
78
- const version = aztecVersion.version;
79
-
80
- let detectedDeprecatedPackages = false;
81
-
82
- for (const depType of ['dependencies', 'devDependencies'] as const) {
83
- const dependencies = pkg[depType];
84
- if (!dependencies) {
85
- continue;
86
- }
87
-
88
- for (const name of Object.keys(dependencies)) {
89
- if (!name.startsWith('@aztec/')) {
90
- continue;
91
- }
92
-
93
- // different release schedule
94
- if (name === '@aztec/aztec-ui') {
95
- continue;
96
- }
97
-
98
- if (deprecatedNpmPackages.has(name)) {
99
- detectedDeprecatedPackages = true;
100
- continue;
101
- }
102
-
103
- if (dependencies[name] !== version) {
104
- changes.dependencies.push({
105
- name,
106
- from: dependencies[name],
107
- to: version,
108
- });
109
-
110
- dependencies[name] = version;
111
- }
112
- }
113
- }
114
-
115
- if (detectedDeprecatedPackages) {
116
- log(npmDeprecationMessage);
117
- }
118
-
119
- if (changes.dependencies.length > 0) {
120
- const contents = JSON.stringify(pkg, null, 2) + '\n';
121
- await atomicUpdateFile(resolve(join(projectPath, 'package.json')), contents);
122
- }
123
-
124
- return changes;
125
- }
126
-
127
- /**
128
- * Updates a project's yarn.lock or package-lock.json
129
- * @param projectPath - Path to Nodejs project
130
- */
131
- export function updateLockfile(projectPath: string, log: LogFn): void {
132
- const isNpm = existsSync(resolve(join(projectPath, 'package-lock.json')));
133
- const isYarn = existsSync(resolve(join(projectPath, 'yarn.lock')));
134
- const isPnpm = existsSync(resolve(join(projectPath, 'pnpm-lock.yaml')));
135
-
136
- if (isPnpm) {
137
- spawnSync('pnpm', ['install'], {
138
- cwd: projectPath,
139
- stdio: 'inherit',
140
- });
141
- } else if (isYarn) {
142
- spawnSync('yarn', ['install'], {
143
- cwd: projectPath,
144
- stdio: 'inherit',
145
- });
146
- } else if (isNpm) {
147
- spawnSync('npm', ['install'], {
148
- cwd: projectPath,
149
- stdio: 'inherit',
150
- });
151
- } else {
152
- log(`No lockfile found in ${projectPath}. Skipping lockfile update...`);
153
- }
154
- }
@@ -1,78 +0,0 @@
1
- /* eslint-disable jsdoc/require-jsdoc */
2
- import { type LogFn } from '@aztec/foundation/log';
3
-
4
- import { relative, resolve } from 'path';
5
- import { parse } from 'semver';
6
-
7
- import { type DependencyChanges } from './common.js';
8
- import { GITHUB_TAG_PREFIX } from './github.js';
9
- import { updateAztecNr } from './noir.js';
10
- import { getNewestVersion, updateAztecDeps, updateLockfile } from './npm.js';
11
-
12
- const AZTECJS_PACKAGE = '@aztec/aztec.js';
13
- const UPDATE_DOCS_URL = 'https://docs.aztec.network/developers/updating';
14
-
15
- export async function update(
16
- projectPath: string,
17
- contracts: string[],
18
- aztecVersion: string,
19
- log: LogFn,
20
- ): Promise<void> {
21
- const targetAztecVersion =
22
- aztecVersion === 'latest' ? await getNewestVersion(AZTECJS_PACKAGE, 'latest') : parse(aztecVersion);
23
-
24
- if (!targetAztecVersion) {
25
- throw new Error(`Invalid aztec version ${aztecVersion}`);
26
- }
27
-
28
- const projectDependencyChanges: DependencyChanges[] = [];
29
- try {
30
- const npmChanges = await updateAztecDeps(resolve(process.cwd(), projectPath), targetAztecVersion, log);
31
- if (npmChanges.dependencies.length > 0) {
32
- updateLockfile(projectPath, log);
33
- }
34
-
35
- projectDependencyChanges.push(npmChanges);
36
- } catch (err) {
37
- if (err instanceof Error && 'code' in err && err.code === 'ENOENT') {
38
- log(`No package.json found in ${projectPath}. Skipping npm update...`);
39
- } else {
40
- throw err;
41
- }
42
- }
43
-
44
- for (const contract of contracts) {
45
- try {
46
- projectDependencyChanges.push(
47
- await updateAztecNr(
48
- resolve(process.cwd(), projectPath, contract),
49
- `${GITHUB_TAG_PREFIX}-v${targetAztecVersion.version}`,
50
- log,
51
- ),
52
- );
53
- } catch (err) {
54
- if (err instanceof Error && 'code' in err && err.code === 'ENOENT') {
55
- log(`No Nargo.toml found in ${relative(process.cwd(), contract)}. Skipping...`);
56
- } else {
57
- throw err;
58
- }
59
- }
60
- }
61
-
62
- log(`To update Docker containers follow instructions at ${UPDATE_DOCS_URL}`);
63
-
64
- projectDependencyChanges.forEach(changes => {
65
- printChanges(changes, log);
66
- });
67
- }
68
-
69
- function printChanges(changes: DependencyChanges, log: LogFn): void {
70
- log(`\nIn ${relative(process.cwd(), changes.file)}:`);
71
- if (changes.dependencies.length === 0) {
72
- log(' No changes');
73
- } else {
74
- changes.dependencies.forEach(({ name, from, to }) => {
75
- log(` Updated ${name} from ${from} to ${to}`);
76
- });
77
- }
78
- }
@@ -1,50 +0,0 @@
1
- import { type NoirPackageConfig } from '@aztec/foundation/noir';
2
-
3
- import TOML from '@iarna/toml';
4
- import { CommanderError } from 'commander';
5
- import { rename, writeFile } from 'fs/promises';
6
-
7
- /**
8
- * Updates a file in place atomically.
9
- * @param filePath - Path to file
10
- * @param contents - New contents to write
11
- */
12
- export async function atomicUpdateFile(filePath: string, contents: string) {
13
- const tmpFilepath = filePath + '.tmp';
14
- try {
15
- await writeFile(tmpFilepath, contents, {
16
- // let's crash if the tmp file already exists
17
- flag: 'wx',
18
- });
19
- await rename(tmpFilepath, filePath);
20
- } catch (e) {
21
- if (e instanceof Error && 'code' in e && e.code === 'EEXIST') {
22
- const commanderError = new CommanderError(
23
- 1,
24
- e.code,
25
- `Temporary file already exists: ${tmpFilepath}. Delete this file and try again.`,
26
- );
27
- commanderError.nestedError = e.message;
28
- throw commanderError;
29
- } else {
30
- throw e;
31
- }
32
- }
33
- }
34
-
35
- /**
36
- * Pretty prints Nargo.toml contents to a string
37
- * @param config - Nargo.toml contents
38
- * @returns The Nargo.toml contents as a string
39
- */
40
- export function prettyPrintNargoToml(config: NoirPackageConfig): string {
41
- const withoutDependencies = Object.fromEntries(Object.entries(config).filter(([key]) => key !== 'dependencies'));
42
-
43
- const partialToml = TOML.stringify(withoutDependencies);
44
- const dependenciesToml = Object.entries(config.dependencies).map(([name, dep]) => {
45
- const depToml = TOML.stringify.value(dep);
46
- return `${name} = ${depToml}`;
47
- });
48
-
49
- return partialToml + '\n[dependencies]\n' + dependenciesToml.join('\n') + '\n';
50
- }