From 94568f4fc81233ad43d17cbf26f1d2210580beaa Mon Sep 17 00:00:00 2001 From: Charlie <5764343+charlielye@users.noreply.github.com> Date: Fri, 4 Sep 2026 15:18:55 +0000 Subject: [PATCH] refactor(ipc-codegen): keep the generator to erasable TypeScript generate.ts advertises "runs with Node.js 22+ via --experimental-strip-types", but it could not: three parameter properties made Node reject it at module load with ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX, which takes out every --lang at once rather than only the TypeScript backend. Nothing noticed because all eleven call sites also pass --experimental-transform-types, which compiles those constructs, so the documented invocation was never exercised -- the one test that does run strip-only imports only schema_visitor.ts and never reaches generate.ts. Expanding the three into an explicit field plus an assignment in the constructor body -- what the transform emitted anyway -- makes the source erasable, so the transform flag comes off all eleven call sites and the generator runs under the type stripping that Node 23.6+ does by default. Generated output is byte-identical for all four languages, checked against the previous invocation. Keeping this property needs a test, since the failure mode is invisible while any caller passes the transform flag: scripts/strip_only_test.sh generates one of each --lang strip-only, and is wired into test_cmds. Reintroducing a parameter property fails it with the ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX above. --experimental-strip-types is kept even though it is a no-op on the pinned Node (.nvmrc is v24.15.0): it is what the Node 22 the header mentions still needs. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_016einpgfthfjLYGwCB3iQqD --- .../cpp/src/barretenberg/avm/CMakeLists.txt | 2 +- .../cpp/src/barretenberg/cdb/CMakeLists.txt | 2 +- .../cpp/src/barretenberg/wsdb/CMakeLists.txt | 2 +- barretenberg/ts/bootstrap.sh | 4 ++-- ipc-codegen/README.md | 2 +- ipc-codegen/bootstrap.sh | 3 +++ ipc-codegen/echo_example/cpp/bootstrap.sh | 2 +- ipc-codegen/echo_example/rust/bootstrap.sh | 2 +- ipc-codegen/echo_example/ts/bootstrap.sh | 2 +- .../echo_example/ts_package/bootstrap.sh | 2 +- ipc-codegen/echo_example/zig/bootstrap.sh | 2 +- ipc-codegen/scripts/strip_only_test.sh | 20 +++++++++++++++++++ ipc-codegen/src/cpp_codegen.ts | 6 +++++- ipc-codegen/src/typescript_package_codegen.ts | 12 +++++++++-- wsdb/bootstrap.sh | 2 +- 15 files changed, 50 insertions(+), 15 deletions(-) create mode 100755 ipc-codegen/scripts/strip_only_test.sh diff --git a/barretenberg/cpp/src/barretenberg/avm/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/avm/CMakeLists.txt index 16610a355d99..733eb7537f37 100644 --- a/barretenberg/cpp/src/barretenberg/avm/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/avm/CMakeLists.txt @@ -14,7 +14,7 @@ file(GLOB_RECURSE IPC_CODEGEN_SRC ) add_custom_command( OUTPUT ${AVM_GEN_OUTPUTS} - COMMAND node --experimental-strip-types --experimental-transform-types --no-warnings + COMMAND node --experimental-strip-types --no-warnings ${IPC_CODEGEN_DIR}/src/generate.ts --schema ${AVM_SCHEMA} --lang cpp diff --git a/barretenberg/cpp/src/barretenberg/cdb/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/cdb/CMakeLists.txt index f0b040ebb80a..a194a5d9fbc5 100644 --- a/barretenberg/cpp/src/barretenberg/cdb/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/cdb/CMakeLists.txt @@ -15,7 +15,7 @@ file(GLOB_RECURSE IPC_CODEGEN_SRC ) add_custom_command( OUTPUT ${CDB_GEN_OUTPUTS} - COMMAND node --experimental-strip-types --experimental-transform-types --no-warnings + COMMAND node --experimental-strip-types --no-warnings ${IPC_CODEGEN_DIR}/src/generate.ts --schema ${CDB_SCHEMA} --lang cpp diff --git a/barretenberg/cpp/src/barretenberg/wsdb/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/wsdb/CMakeLists.txt index ca88f8e4b9ab..8fdf042a3ca2 100644 --- a/barretenberg/cpp/src/barretenberg/wsdb/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/wsdb/CMakeLists.txt @@ -21,7 +21,7 @@ file(GLOB_RECURSE IPC_CODEGEN_SRC ) add_custom_command( OUTPUT ${WSDB_GEN_OUTPUTS} - COMMAND node --experimental-strip-types --experimental-transform-types --no-warnings + COMMAND node --experimental-strip-types --no-warnings ${IPC_CODEGEN_DIR}/src/generate.ts --schema ${WSDB_SCHEMA} --lang cpp diff --git a/barretenberg/ts/bootstrap.sh b/barretenberg/ts/bootstrap.sh index cce5c066b393..20c7ff56775d 100755 --- a/barretenberg/ts/bootstrap.sh +++ b/barretenberg/ts/bootstrap.sh @@ -15,7 +15,7 @@ hash=$(hash_str \ $(semver check $REF_NAME && echo 1 || echo 0)) function generate_bb_avm_sim_package { - node --experimental-strip-types --experimental-transform-types --no-warnings \ + node --experimental-strip-types --no-warnings \ "$ROOT/ipc-codegen/src/generate.ts" \ --schema "$ROOT/barretenberg/cpp/src/barretenberg/avm/avm_schema.json" \ --lang ts \ @@ -33,7 +33,7 @@ function generate_bb_avm_sim_package { # Server binding package for the AVM CDB protocol: generated wire types + # Handler/dispatch + the schema itself. Pure TS — no binary, no arch packages. function generate_cdb_package { - node --experimental-strip-types --experimental-transform-types --no-warnings \ + node --experimental-strip-types --no-warnings \ "$ROOT/ipc-codegen/src/generate.ts" \ --schema "$ROOT/barretenberg/cpp/src/barretenberg/cdb/cdb_schema.json" \ --lang ts \ diff --git a/ipc-codegen/README.md b/ipc-codegen/README.md index ddde1aaf1e44..75cfec10b023 100644 --- a/ipc-codegen/README.md +++ b/ipc-codegen/README.md @@ -84,7 +84,7 @@ Invoked once per (schema, language) pair. Run directly with `node --experimental-strip-types`, or via `bootstrap.sh`. ``` -node --experimental-strip-types --experimental-transform-types --no-warnings \ +node --experimental-strip-types --no-warnings \ src/generate.ts --schema --lang --out [flags] ``` diff --git a/ipc-codegen/bootstrap.sh b/ipc-codegen/bootstrap.sh index fa01a18fa960..cfaeadd9d9ad 100755 --- a/ipc-codegen/bootstrap.sh +++ b/ipc-codegen/bootstrap.sh @@ -49,6 +49,9 @@ function test_cmds { # Generator unit tests (schema validation). echo "$prefix node --experimental-strip-types --no-warnings ipc-codegen/test/schema_visitor.test.ts" + # The generator itself must load under type stripping alone (no transform step). + echo "$prefix ipc-codegen/scripts/strip_only_test.sh" + # Golden tests (each language verifies it can deserialize the goldens # baked by build(), and re-encode them byte-identically). echo "$prefix $script golden rust" diff --git a/ipc-codegen/echo_example/cpp/bootstrap.sh b/ipc-codegen/echo_example/cpp/bootstrap.sh index 9f536ff54fe4..acba8e0db118 100755 --- a/ipc-codegen/echo_example/cpp/bootstrap.sh +++ b/ipc-codegen/echo_example/cpp/bootstrap.sh @@ -3,7 +3,7 @@ set -euo pipefail DIR="$(cd "$(dirname "$0")" && pwd)" CODEGEN="$(cd "$DIR/../.." && pwd)" -NODE="node --experimental-strip-types --experimental-transform-types --no-warnings" +NODE="node --experimental-strip-types --no-warnings" $NODE "$CODEGEN/src/generate.ts" \ --schema "$DIR/../schema/schema.jsonc" \ diff --git a/ipc-codegen/echo_example/rust/bootstrap.sh b/ipc-codegen/echo_example/rust/bootstrap.sh index 570221c29f41..635d588d2a7c 100755 --- a/ipc-codegen/echo_example/rust/bootstrap.sh +++ b/ipc-codegen/echo_example/rust/bootstrap.sh @@ -3,7 +3,7 @@ set -euo pipefail DIR="$(cd "$(dirname "$0")" && pwd)" CODEGEN="$(cd "$DIR/../.." && pwd)" -NODE="node --experimental-strip-types --experimental-transform-types --no-warnings" +NODE="node --experimental-strip-types --no-warnings" $NODE "$CODEGEN/src/generate.ts" \ --schema "$DIR/../schema/schema.jsonc" \ diff --git a/ipc-codegen/echo_example/ts/bootstrap.sh b/ipc-codegen/echo_example/ts/bootstrap.sh index 03cd9e1f4657..fc03e8d6d5d9 100755 --- a/ipc-codegen/echo_example/ts/bootstrap.sh +++ b/ipc-codegen/echo_example/ts/bootstrap.sh @@ -4,7 +4,7 @@ set -euo pipefail DIR="$(cd "$(dirname "$0")" && pwd)" CODEGEN="$(cd "$DIR/../.." && pwd)" REPO_ROOT="$(cd "$CODEGEN/.." && pwd)" -NODE="node --experimental-strip-types --experimental-transform-types --no-warnings" +NODE="node --experimental-strip-types --no-warnings" $NODE "$CODEGEN/src/generate.ts" \ --schema "$DIR/../schema/schema.jsonc" \ diff --git a/ipc-codegen/echo_example/ts_package/bootstrap.sh b/ipc-codegen/echo_example/ts_package/bootstrap.sh index bff76ba45456..9a747160e4f2 100755 --- a/ipc-codegen/echo_example/ts_package/bootstrap.sh +++ b/ipc-codegen/echo_example/ts_package/bootstrap.sh @@ -4,7 +4,7 @@ set -euo pipefail DIR="$(cd "$(dirname "$0")" && pwd)" CODEGEN="$(cd "$DIR/../.." && pwd)" REPO_ROOT="$(cd "$CODEGEN/.." && pwd)" -NODE="node --experimental-strip-types --experimental-transform-types --no-warnings" +NODE="node --experimental-strip-types --no-warnings" $NODE "$CODEGEN/src/generate.ts" \ --schema "$DIR/../schema/schema.jsonc" \ diff --git a/ipc-codegen/echo_example/zig/bootstrap.sh b/ipc-codegen/echo_example/zig/bootstrap.sh index a65642aac36a..985d4219873d 100755 --- a/ipc-codegen/echo_example/zig/bootstrap.sh +++ b/ipc-codegen/echo_example/zig/bootstrap.sh @@ -3,7 +3,7 @@ set -euo pipefail DIR="$(cd "$(dirname "$0")" && pwd)" CODEGEN="$(cd "$DIR/../.." && pwd)" -NODE="node --experimental-strip-types --experimental-transform-types --no-warnings" +NODE="node --experimental-strip-types --no-warnings" $NODE "$CODEGEN/src/generate.ts" \ --schema "$DIR/../schema/schema.jsonc" \ diff --git a/ipc-codegen/scripts/strip_only_test.sh b/ipc-codegen/scripts/strip_only_test.sh new file mode 100755 index 000000000000..28749deeab40 --- /dev/null +++ b/ipc-codegen/scripts/strip_only_test.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# +# The generator must run under Node's type stripping alone, with no transform +# step: only erasable TypeScript, so no parameter properties, enums, namespaces +# or decorators in ipc-codegen/src. Node reports those as +# ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX at module load, which takes out every +# --lang at once, so generate one of each here rather than trusting the callers +# to notice. +source $(git rev-parse --show-toplevel)/ci3/source + +schema="$root/ipc-codegen/echo_example/schema/schema.jsonc" +out=$(mktemp -d) +trap "rm -rf $out" EXIT + +for lang in rust ts zig cpp; do + node --experimental-strip-types --no-warnings "$root/ipc-codegen/src/generate.ts" \ + --schema "$schema" --lang "$lang" --out "$out/$lang" --server --client >/dev/null +done + +echo "generate.ts runs strip-only for rust, ts, zig and cpp." diff --git a/ipc-codegen/src/cpp_codegen.ts b/ipc-codegen/src/cpp_codegen.ts index c1df1e42ca61..0e41ec5089d5 100644 --- a/ipc-codegen/src/cpp_codegen.ts +++ b/ipc-codegen/src/cpp_codegen.ts @@ -41,7 +41,11 @@ export interface CppCodegenOptions { } export class CppCodegen { - constructor(private opts: CppCodegenOptions) {} + private opts: CppCodegenOptions; + + constructor(opts: CppCodegenOptions) { + this.opts = opts; + } private primitiveType(type: import("./schema_visitor.ts").Type): string { switch (type.primitive) { diff --git a/ipc-codegen/src/typescript_package_codegen.ts b/ipc-codegen/src/typescript_package_codegen.ts index 7bed8586850e..038934b86ea3 100644 --- a/ipc-codegen/src/typescript_package_codegen.ts +++ b/ipc-codegen/src/typescript_package_codegen.ts @@ -100,7 +100,11 @@ export interface TypeScriptServerPackageOptions { * from @aztec-foundation/ipc-runtime). */ export class TypeScriptServerPackageCodegen { - constructor(private opts: TypeScriptServerPackageOptions) {} + private opts: TypeScriptServerPackageOptions; + + constructor(opts: TypeScriptServerPackageOptions) { + this.opts = opts; + } generatePackageJson(): string { const pkg = { @@ -175,7 +179,11 @@ runs \`yarn build\`. } export class TypeScriptPackageCodegen { - constructor(private opts: TypeScriptPackageOptions) {} + private opts: TypeScriptPackageOptions; + + constructor(opts: TypeScriptPackageOptions) { + this.opts = opts; + } generatePackageJson(): string { const archPackages = archPackageNames(this.opts.packageName); diff --git a/wsdb/bootstrap.sh b/wsdb/bootstrap.sh index a45dc4a55e3b..cbafb558434b 100755 --- a/wsdb/bootstrap.sh +++ b/wsdb/bootstrap.sh @@ -10,7 +10,7 @@ hash=$(hash_str \ $(cache_content_hash .rebuild_patterns)) function generate_ts_package { - node --experimental-strip-types --experimental-transform-types --no-warnings \ + node --experimental-strip-types --no-warnings \ "$ROOT/ipc-codegen/src/generate.ts" \ --schema "$ROOT/barretenberg/cpp/src/barretenberg/wsdb/wsdb_schema.jsonc" \ --lang ts \