refactor: prepare for release#79
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe PR reorganizes the Compact toolchain from a monolithic package into three separately published packages: extracting the programmatic compiler/builder APIs into ChangesCompact Builder Library and CLI Refactoring
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI as `@openzeppelin/compact-cli`<br/>(bin wrapper)
participant Builder as `@openzeppelin/compact-builder`<br/>(programmatic API)
participant Services as Compiler/File/<br/>Environment Services
participant Shell as child_process.exec
participant Compact as Compact Toolchain<br/>(compactc binary)
User->>CLI: yarn compact-compiler --dir src --exclude mock
CLI->>Builder: CompactCompiler.fromArgs(args)
Builder->>Builder: parseArgs() → CompilerOptions
Builder->>Services: validateEnvironment()
Services->>Shell: compact --version
Shell->>Compact: check CLI available
Compact-->>Shell: "Compactc version: 0.29.0"
Shell-->>Services: devToolsVersion, toolchainVersion
Services-->>Builder: environment validated
Builder->>Services: FileDiscovery.getCompactFiles(dir)
Services-->>Builder: [file1.compact, file2.compact]
Builder->>Services: compile each file with spinner
Services->>Shell: compact compile file.compact --out dist
Shell->>Compact: compile
Compact-->>Shell: stdout/stderr
Shell-->>Services: compilation result
Services-->>Builder: per-file success/error
Builder->>Builder: display progress, handle errors
Builder-->>CLI: compilation complete
CLI-->>User: exit(0) or exit(1)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes The changes span a large structural refactoring involving new package creation, extracted services/APIs, refactored orchestrators, CLI repointing, manifest updates, and documentation revisions across multiple directories. The complexity stems from coordinated changes across interconnected files (service wiring, type definitions, CLI imports, tests), new test coverage for builder/compiler logic, and careful validation that the extracted builder library maintains the same behavior as the original embedded CLI implementation. While individual files are manageable, the reviewer must trace the dependency graph and validate the complete flow across the monorepo.
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
6980ab0 to
6225d51
Compare
There was a problem hiding this comment.
Actionable comments posted: 7
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/cli/src/runCompiler.ts (1)
133-141:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winRoute all argument-validation errors to usage help and document
--exclude.Only one parser error string is recognized today.
--src,--out, and--excludevalidation failures will be shown as “Unexpected error”, and the help text is missing--exclude.Suggested patch
- if (errorMessage.includes('--dir flag requires a directory name')) { + const parseErrorMessages = [ + '--dir flag requires a directory name', + '--src flag requires a directory path', + '--out flag requires a directory path', + '--exclude flag requires a pattern', + ]; + if (parseErrorMessages.some((msg) => errorMessage.includes(msg))) { spinner.fail( - chalk.red('[COMPILE] Error: --dir flag requires a directory name'), + chalk.red(`[COMPILE] Error: ${errorMessage}`), ); showUsageHelp(); return; }console.log( chalk.yellow( ' --hierarchical Preserve source directory structure in artifacts output', ), ); + console.log( + chalk.yellow( + ' --exclude <glob> Exclude matching .compact files (repeatable)', + ), + );Also applies to: 171-195
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/cli/src/runCompiler.ts` around lines 133 - 141, The argument parsing only handles one specific parser error; update the arg-validation handling in runCompiler.ts to detect all relevant flag errors (at least '--dir', '--src', '--out', and '--exclude') instead of only checking for the single string; on errorMessage containing patterns like "flag requires a directory name" or "flag requires a value" or specific substrings for '--src', '--out', '--exclude', call spinner.fail with a clear message naming the missing flag (e.g., "[COMPILE] Error: --exclude flag requires a value"), then call showUsageHelp() and return; also update the usage/help text emitted by showUsageHelp (or the usage constant it prints) to include documentation for the --exclude flag; apply the same fix to the other validation block referenced (the block around the 171-195 region) so all parser errors are routed to usage help consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/builder/src/Builder.ts`:
- Around line 237-250: The catch block in Builder.executeStep (CompactBuilder)
currently calls process.exit(1), which library code must not do; remove the
process.exit(1) call and instead propagate the error to callers by rethrowing
the caught error (or throwing a new Error with contextual message) after
logging/printing via printOutput/isPromisifiedChildProcessError; ensure
executeStep's signature still returns a rejected Promise on failure so callers
(CLI wrappers) can decide exit behavior.
In `@packages/builder/src/Compiler.ts`:
- Around line 191-194: The current loop in Compiler.ts that conditionally pushes
into the flags array (checking if (!flags.includes(args[i]))
flags.push(args[i])) incorrectly deduplicates forwarded compiler args and can
change CLI semantics; modify the loop in the Compiler class where args and flags
are handled to always push the arg (remove the includes check) so forwarded args
are preserved in original order and repeats are allowed.
- Around line 308-320: The guard using isPromisifiedChildProcessError on the
CompilationError instance is unreachable; instead, inside the CompilationError
branch (the code handling error instanceof CompilationError in Compiler.ts)
unwrap the underlying error via error.cause, check
isPromisifiedChildProcessError(error.cause) and then treat that cause as the
execError (accessing stdout/stderr from the cause), apply the same filtering and
UIService.printOutput calls (use the same filteredOutput logic and
execError.stderr) so you read child-process output from error.cause rather than
from the CompilationError itself.
In `@packages/cli/src/runBuilder.ts`:
- Around line 41-42: Update the example command string in runBuilder.ts to fix
the archive exclude glob by removing the literal backslashes: replace the wrong
pattern '*\/archive\/*' with the correct shell glob '*/archive/*' (so the
exclude becomes --exclude '*/archive/*'); edit the comment/example where the
command is defined to ensure users won't include backslashes that prevent
matching.
In `@README.md`:
- Line 141: Update the README.md sentence that links to packages/cli/README.md
and remove the phrase “programmatic API” (the current text: "See
[packages/cli/README.md](./packages/cli/README.md) for full documentation
including all options, programmatic API, and examples."); edit it to only
reference the CLI docs (e.g., "for full documentation including all options and
examples") or otherwise omit “programmatic API”, and if needed add a brief
separate pointer to `@openzeppelin/compact-builder` for the programmatic API.
In `@RELEASING.md`:
- Around line 47-48: The release runbook uses an ambiguous short name
"`-builder`" in the release-order step; update the text to use the full package
name "`compact-builder`" so it's unambiguous (replace the string "`-builder`"
with "`compact-builder`" in the RELEASING.md step that currently reads
"`compact-cli` (depends on `-builder`; pull `main` first...)`). Ensure the
surrounding sentence still reads naturally after the change.
- Around line 34-39: The fenced code block that starts with "compact-cli (bin
wrapper)" in RELEASING.md is missing a language tag which triggers markdownlint
MD040; update that fenced block to include a language identifier (for example
"text") so it reads ```text ... ``` around the existing lines (the block
containing "compact-cli (bin wrapper)", "└─ depends on compact-builder",
"compact-builder (library)", "compact-simulator (library)").
---
Outside diff comments:
In `@packages/cli/src/runCompiler.ts`:
- Around line 133-141: The argument parsing only handles one specific parser
error; update the arg-validation handling in runCompiler.ts to detect all
relevant flag errors (at least '--dir', '--src', '--out', and '--exclude')
instead of only checking for the single string; on errorMessage containing
patterns like "flag requires a directory name" or "flag requires a value" or
specific substrings for '--src', '--out', '--exclude', call spinner.fail with a
clear message naming the missing flag (e.g., "[COMPILE] Error: --exclude flag
requires a value"), then call showUsageHelp() and return; also update the
usage/help text emitted by showUsageHelp (or the usage constant it prints) to
include documentation for the --exclude flag; apply the same fix to the other
validation block referenced (the block around the 171-195 region) so all parser
errors are routed to usage help consistently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e5aa748f-94ae-4204-9a21-7b636701a81a
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (34)
.github/workflows/release.ymlREADME.mdRELEASING.mdpackage.jsonpackages/builder/CHANGELOG.mdpackages/builder/README.mdpackages/builder/package.jsonpackages/builder/src/Builder.tspackages/builder/src/Compiler.tspackages/builder/src/index.tspackages/builder/src/services/CompilerService.tspackages/builder/src/services/EnvironmentValidator.tspackages/builder/src/services/FileDiscovery.tspackages/builder/src/services/UIService.tspackages/builder/src/types/errors.tspackages/builder/src/types/options.tspackages/builder/src/utils.tspackages/builder/test/Builder.test.tspackages/builder/test/Compiler.test.tspackages/builder/tsconfig.jsonpackages/builder/vitest.config.tspackages/cli/CHANGELOG.mdpackages/cli/README.mdpackages/cli/package.jsonpackages/cli/src/Builder.tspackages/cli/src/Compiler.tspackages/cli/src/runBuilder.tspackages/cli/src/runCompiler.tspackages/cli/test/runCompiler.test.tspackages/cli/tsconfig.jsonpackages/simulator/CHANGELOG.mdpackages/simulator/README.mdpackages/simulator/package.jsonturbo.json
💤 Files with no reviewable changes (2)
- packages/cli/src/Builder.ts
- packages/cli/src/Compiler.ts
…unwrap CompilationError, parser-error routing)
…s, generalize toolchain version) - Drop pre-baseline CHANGELOGs for builder/cli/simulator and remove them from package.json file lists (no released baseline yet) - RELEASING.md: drop the changesets-migration TODO section and the CHANGELOG preamble - README.md: remove submodule-consumption section; drop busy "## Packages" walkthrough (each package has its own README); rename "Getting started" -> "Development"; linkify package list - packages/cli/README.md: split em-dash sentence per review; replace hardcoded +0.29.0 with +<version> placeholder - runCompiler.ts: generalize +<version> in help text + JSDoc; update matching test assertions - runBuilder.ts: drop confusing JSDoc @example block; point to cli README for usage examples - Set author = "OpenZeppelin Community <maintainers@openzeppelin.org>" across builder/cli/simulator package.json
b08798e to
7f70dc9
Compare
|
Thank you @andrew-fleming! agree with all the comments and fixed them all. |
andrew-fleming
left a comment
There was a problem hiding this comment.
@0xisk amazing work on the PR + improvements! Separating the compiler service into multiple files is much cleaner and will be easier to maintain 👍 LGTM!
| - [`packages/simulator`](./packages/simulator) — TypeScript simulator to run and test Compact contracts locally | ||
|
|
||
| ## External usage (via git submodule until npm publish) | ||
| See each package's README for usage, options, and examples. |
Types of changes
What types of changes does your code introduce to OpenZeppelin Midnight Contracts? Put an `` in the boxes that apply
Fixes #???
@openzeppelin/compact-builder(library),@openzeppelin/compact-cli(bins, depends on-builder),@openzeppelin/compact-simulator.services/,types/options.ts,utils.ts.BuilderOptions):--clean-dist,--exclude <glob>(drives both compiler discovery and builder copy),--copy <path>,--hierarchicalnow also drives.compactcopy layout.RELEASING.mdupdated with new dependency chain + first-release order.typestask nowdependsOn: ["^build"].PR Checklist
Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...
Summary by CodeRabbit
New Features
@openzeppelin/compact-builderpackage with programmatic compiler and build APIs.Documentation
Chores
compact-tools-cli→compact-cli,compact-tools-simulator→compact-simulator.