-
Notifications
You must be signed in to change notification settings - Fork 3
refactor(tools/cli): execlude *.mock.compact contracts from builder
#68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,10 @@ compact-compiler [options] | |
| | `--dir <directory>` | Compile specific subdirectory within src | (all) | | ||
| | `--src <directory>` | Source directory containing `.compact` files | `src` | | ||
| | `--out <directory>` | Output directory for compiled artifacts | `artifacts` | | ||
| | `--exclude <pattern>` | Glob pattern to exclude files (can be repeated) | (none) | | ||
| | `--dry-run` | Preview which files would be compiled without compiling | `false` | | ||
| | `--hierarchical` | Preserve source directory structure in output | `false` | | ||
| | `--verbose` | Show circuit compilation details | `false` | | ||
| | `--skip-zk` | Skip zero-knowledge proof generation | `false` | | ||
| | `+<version>` | Use specific toolchain version (e.g., `+0.28.0`) | (default) | | ||
|
|
||
|
|
@@ -86,6 +89,52 @@ artifacts/ # Hierarchical output | |
| Token/ | ||
| ``` | ||
|
|
||
| ### Excluding Files | ||
|
|
||
| Use `--exclude` to skip files matching glob patterns. This is useful for excluding mock contracts, test files, or any files you don't want to compile. | ||
|
|
||
| **Supported glob patterns:** | ||
| - `*` matches any characters except `/` | ||
| - `**` matches zero or more path segments | ||
|
|
||
| **Examples:** | ||
| ```bash | ||
| # Exclude all mock contracts | ||
| compact-compiler --exclude "**/*.mock.compact" | ||
|
|
||
| # Exclude test directory | ||
| compact-compiler --exclude "**/test/**" | ||
|
|
||
| # Multiple patterns | ||
| compact-compiler --exclude "**/*.mock.compact" --exclude "**/test/**" | ||
|
|
||
| # Root-level only (no ** prefix) | ||
| compact-compiler --exclude "*.mock.compact" # Only matches root-level mocks | ||
| ``` | ||
|
|
||
| ### Dry run | ||
|
|
||
| Use `--dry-run` to see which files would be compiled without running the compiler. No environment validation or compilation is performed. Useful to verify `--exclude` patterns or to see the file list before a full run. | ||
|
|
||
| **Usage:** | ||
| ```bash | ||
| # Preview all files that would be compiled | ||
| compact-compiler --dry-run | ||
|
|
||
| # Preview with exclusions (verify your exclude patterns) | ||
| compact-compiler --exclude "**/*.mock.compact" --dry-run | ||
|
|
||
| # Dry run in a specific directory | ||
| compact-compiler --dir access --dry-run | ||
| ``` | ||
|
|
||
| **Example output:** | ||
| ``` | ||
| ℹ [DRY-RUN] Would compile 2 file(s): | ||
| Token.compact | ||
| AccessControl.compact | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ```bash | ||
|
|
@@ -112,6 +161,18 @@ compact-compiler --dir access --skip-zk --hierarchical | |
|
|
||
| # Use environment variable | ||
| SKIP_ZK=true compact-compiler | ||
|
|
||
| # Exclude mock contracts | ||
| compact-compiler --exclude "**/*.mock.compact" | ||
|
|
||
| # Exclude multiple patterns | ||
| compact-compiler --exclude "**/*.mock.compact" --exclude "**/test/**" | ||
|
|
||
| # Preview which files would be compiled (dry run) | ||
| compact-compiler --dry-run | ||
|
|
||
| # Dry run with exclusions to verify patterns | ||
| compact-compiler --exclude "**/*.mock.compact" --dry-run | ||
| ``` | ||
|
|
||
| ## Builder CLI | ||
|
|
@@ -129,7 +190,19 @@ The builder runs the compiler as a prerequisite, then executes additional build | |
| compact-builder [options] | ||
| ``` | ||
|
|
||
| Accepts all compiler options except `--skip-zk` (builds always include ZK proofs). | ||
| Accepts all compiler options except `--skip-zk` (builds always include ZK proofs). Use `--exclude` to skip mock contracts or test files during the build. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct me if I'm wrong here, but I'm not seeing any logic that filters |
||
|
|
||
| ### Options | ||
|
|
||
| | Option | Description | Default | | ||
| |--------|-------------|---------| | ||
| | `--dir <directory>` | Compile specific subdirectory within src | (all) | | ||
| | `--src <directory>` | Source directory containing `.compact` files | `src` | | ||
| | `--out <directory>` | Output directory for compiled artifacts | `artifacts` | | ||
| | `--exclude <pattern>` | Glob pattern to exclude files (can be repeated) | (none) | | ||
| | `--hierarchical` | Preserve source directory structure in output | `false` | | ||
| | `--verbose` | Show circuit compilation details (requires TTY, run directly not via turbo) | `false` | | ||
| | `+<version>` | Use specific toolchain version (e.g., `+0.28.0`) | (default) | | ||
|
|
||
| ### Examples | ||
|
|
||
|
|
@@ -142,75 +215,12 @@ compact-builder --dir token | |
|
|
||
| # Build with custom directories | ||
| compact-builder --src contracts --out build | ||
| ``` | ||
|
|
||
| ## Programmatic API | ||
|
|
||
| The compiler can be used programmatically: | ||
|
|
||
| ```typescript | ||
| import { CompactCompiler } from '@openzeppelin/compact-tools-cli'; | ||
|
|
||
| // Using options object | ||
| const compiler = new CompactCompiler({ | ||
| flags: '--skip-zk', | ||
| targetDir: 'security', | ||
| version: '0.28.0', | ||
| hierarchical: true, | ||
| srcDir: 'src', | ||
| outDir: 'artifacts', | ||
| }); | ||
|
|
||
| await compiler.compile(); | ||
|
|
||
| // Using factory method (parses CLI-style args) | ||
| const compiler = CompactCompiler.fromArgs([ | ||
| '--dir', 'security', | ||
| '--skip-zk', | ||
| '+0.28.0' | ||
| ]); | ||
|
|
||
| await compiler.compile(); | ||
| ``` | ||
|
|
||
| ### Classes and Types | ||
|
|
||
| ```typescript | ||
| // Main compiler class | ||
| class CompactCompiler { | ||
| constructor(options?: CompilerOptions, execFn?: ExecFunction); | ||
| static fromArgs(args: string[], env?: NodeJS.ProcessEnv): CompactCompiler; | ||
| static parseArgs(args: string[], env?: NodeJS.ProcessEnv): CompilerOptions; | ||
| compile(): Promise<void>; | ||
| validateEnvironment(): Promise<void>; | ||
| } | ||
|
|
||
| // Builder class | ||
| class CompactBuilder { | ||
| constructor(options?: CompilerOptions); | ||
| static fromArgs(args: string[], env?: NodeJS.ProcessEnv): CompactBuilder; | ||
| build(): Promise<void>; | ||
| } | ||
|
|
||
| // Options interface | ||
| interface CompilerOptions { | ||
| flags?: string; // Compiler flags (e.g., '--skip-zk --verbose') | ||
| targetDir?: string; // Subdirectory within srcDir to compile | ||
| version?: string; // Toolchain version (e.g., '0.28.0') | ||
| hierarchical?: boolean; // Preserve directory structure in output | ||
| srcDir?: string; // Source directory (default: 'src') | ||
| outDir?: string; // Output directory (default: 'artifacts') | ||
| } | ||
| ``` | ||
|
|
||
| ### Error Types | ||
|
|
||
| ```typescript | ||
| import { | ||
| CompactCliNotFoundError, // Compact CLI not in PATH | ||
| CompilationError, // Compilation failed (includes file path) | ||
| DirectoryNotFoundError, // Target directory doesn't exist | ||
| } from '@openzeppelin/compact-tools-cli'; | ||
| # Build excluding mock contracts | ||
| compact-builder --exclude "**/*.mock.compact" | ||
|
|
||
| # Show circuit compilation details (verbose mode) | ||
| compact-builder --verbose | ||
| ``` | ||
|
|
||
| ## Development | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,10 @@ const execAsync = promisify(exec); | |
|
|
||
| /** | ||
| * Configuration options for the Builder CLI. | ||
| * Inherits from CompilerOptions but excludes `flags` (which would allow --skip-zk). | ||
| * Builds should always include ZK proofs. | ||
| * Accepts all CompilerOptions including flags (e.g. --verbose for circuit compilation details). | ||
| * Note: builds should always include ZK proofs — avoid using --skip-zk. | ||
| */ | ||
| export type BuilderOptions = Omit<CompilerOptions, 'flags'>; | ||
| export type BuilderOptions = CompilerOptions; | ||
|
|
||
| /** | ||
| * A class to handle the build process for a project. | ||
|
|
@@ -41,7 +41,7 @@ export type BuilderOptions = Omit<CompilerOptions, 'flags'>; | |
| * Compactc version: 0.26.0 | ||
| * ✔ [BUILD] [1/3] Compiling TypeScript | ||
| * ✔ [BUILD] [2/3] Copying artifacts | ||
| * ✔ [BUILD] [3/3] Copying and cleaning .compact files | ||
| * ✔ [BUILD] [3/3] Copying .compact files | ||
| * ``` | ||
| * | ||
| * @example <caption>Failed Compilation Output</caption> | ||
|
|
@@ -76,8 +76,8 @@ export class CompactBuilder { | |
| shell: '/bin/bash', | ||
| }, | ||
| { | ||
| cmd: 'mkdir -p dist && find src -type f -name "*.compact" -exec cp {} dist/ \\; 2>/dev/null && rm dist/Mock*.compact 2>/dev/null || true', | ||
| msg: 'Copying and cleaning .compact files', | ||
| cmd: 'mkdir -p dist && find src -type f -name "*.compact" -exec cp {} dist/ \\; 2>/dev/null || true', | ||
| msg: 'Copying .compact files', | ||
| shell: '/bin/bash', | ||
| }, | ||
|
Comment on lines
78
to
82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The shell command at line 79 copies every Additionally, because The cleanest fix is to perform the copy in TypeScript, reusing the already-filtered file list from 🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain
Task: Fix
|
||
| ]; | ||
|
|
@@ -86,7 +86,7 @@ export class CompactBuilder { | |
| * Constructs a new CompactBuilder instance. | ||
| * @param options - Compiler options (flags, srcDir, outDir, hierarchical, etc.) | ||
| */ | ||
| constructor(options: CompilerOptions = {}) { | ||
| constructor(options: BuilderOptions = {}) { | ||
| this.options = options; | ||
| } | ||
|
|
||
|
|
@@ -114,7 +114,6 @@ export class CompactBuilder { | |
| * @throws Error if compilation or any build step fails | ||
| */ | ||
| public async build(): Promise<void> { | ||
| // Run compact compilation as a prerequisite | ||
| const compiler = new CompactCompiler(this.options); | ||
| await compiler.compile(); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fenced code block missing language specifier
The markdownlint MD040 warning here is valid — the example output block has no language tag. Use
text(orconsole) to satisfy the linter.📝 Proposed fix
🧰 Tools
🪛 markdownlint-cli2 (0.21.0)
[warning] 131-131: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents