Skip to content

Conversation

@transphorm
Copy link
Member

@transphorm transphorm commented Aug 11, 2025

Summary

  • add tsup config and CJS tsconfig to build circuits utilities in both ESM and CJS
  • emit Metro-compatible package metadata and shims after build
  • expand circuits package.json exports and scripts for dual-module output

Testing

  • yarn workspace @selfxyz/circuits nice
  • yarn lint
  • yarn build
  • yarn types
  • yarn workspace @selfxyz/circuits test (fails: Cannot read properties of undefined (reading 'rsa'))

https://chatgpt.com/codex/tasks/task_b_68993d84b87c832da8aa191136fa5a71

Summary by CodeRabbit

  • New Features

    • Publish both ESM and CommonJS builds with sourcemaps and shipped TypeScript definitions.
    • Clear public entry points and subpath exports for improved compatibility.
  • Chores

    • Migrated build to a bundler-based dual-target workflow with watch support.
    • Added a post-build step to generate distribution metadata and compatibility shims.
    • Restricted published files to built artifacts and public package content.
  • Tests

    • Centralized test utilities exports for simpler imports.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

Warning

Rate limit exceeded

@transphorm has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 2ed8bcf and b5540ab.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (10)
  • circuits/package.json (2 hunks)
  • circuits/scripts/organize-types.mjs (1 hunks)
  • circuits/scripts/postBuild.mjs (1 hunks)
  • circuits/scripts/shimConfigs.js (1 hunks)
  • circuits/src/index.ts (1 hunks)
  • circuits/src/testing/index.ts (1 hunks)
  • circuits/tsconfig.cjs.json (1 hunks)
  • circuits/tsconfig.json (1 hunks)
  • circuits/tsconfig.types.json (1 hunks)
  • circuits/tsup.config.ts (1 hunks)

Walkthrough

Switches circuits package to a tsup-based dual ESM/CJS build with emitted types, adds package exports/main/module/types/files, introduces post-build shim generation script and shim config placeholder, and adds a barrel src entry plus tsconfig files for both outputs.

Changes

Cohort / File(s) Summary
Package manifest & scripts
circuits/package.json
Adds exports, main, module, types, and files; replaces build script with tsup && yarn build:types && yarn postbuild; adds postbuild, build:types, build:watch; adds tsup devDependency.
Bundler config
circuits/tsup.config.ts
New tsup config defining dual builds (ESM -> dist/esm, CJS -> dist/cjs) with sourcemaps and shared entry src/index.ts.
TypeScript configs
circuits/tsconfig.json, circuits/tsconfig.cjs.json
Adjusts outDir to dist/esm, disables declaration emission in main tsconfig; adds composite true and includes test JSONs; adds CJS-specific tsconfig targeting CommonJS output to dist/cjs.
Post-build shim tooling
circuits/scripts/postBuild.mjs, circuits/scripts/shimConfigs.js
Adds postBuild script that writes dist package.json files (ESM/CJS), generates per-shim ESM/CJS JS wrappers and .d.ts re-exports driven by shimConfigs (currently empty).
Module entry / barrel
circuits/src/index.ts
New barrel exporting multiple test utilities and test-case registries to serve as the package entry.

Sequence Diagram(s)

sequenceDiagram
  participant Dev as Developer
  participant Yarn as yarn/npm
  participant TSUP as tsup
  participant TSC as tsc (decl only)
  participant PB as postBuild.mjs
  participant FS as File System

  Dev->>Yarn: yarn build
  Yarn->>TSUP: tsup (build ESM -> dist/esm)
  TSUP->>FS: write dist/esm/*
  Yarn->>TSUP: tsup (build CJS -> dist/cjs)
  TSUP->>FS: write dist/cjs/*
  Yarn->>TSC: tsc --emitDeclarationOnly -> dist/src/index.d.ts
  TSC->>FS: write declarations
  Yarn->>Yarn: mv dist/src/index.d.ts -> dist/esm/index.d.ts
  Yarn->>PB: node ./scripts/postBuild.mjs
  PB->>FS: write dist/package.json, dist/esm/package.json, dist/cjs/package.json
  PB->>FS: create shim files per shimConfigs
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • remicolin
  • aaronmgdr
  • motemotech

Poem

Build scripts hum and shims take flight,
ESM and CJS both dressed up right.
Types march to dist in tidy rows,
Postbuild crafts the exports it knows.
Small barrel set — let tests ignite. ⚡️

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/add-circuits-build-configuration-and-scripts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@transphorm transphorm changed the title Add tsup build and shims for circuits utilities feat: modernize circuits build pipeline Aug 11, 2025
@transphorm transphorm marked this pull request as ready for review August 11, 2025 03:45
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (7)
circuits/scripts/shimConfigs.js (1)

1-2: Document and freeze shim config shape

Minor: add a typedef for clarity and freeze the array to avoid accidental mutation.

-// Shim configurations for @selfxyz/circuits
-export const shimConfigs = [];
+// Shim configurations for @selfxyz/circuits
+/**
+ * @typedef {{ shimPath: string; targetPath: string }} ShimConfig
+ * @type {ReadonlyArray<ShimConfig>}
+ */
+export const shimConfigs = Object.freeze([]);
circuits/tsconfig.cjs.json (1)

4-9: Align moduleResolution with NodeNext for consistency

Using moduleResolution: "Node" while the base config uses "NodeNext" can cause subtle path/extension resolution differences. Consider using NodeNext here too to match Node 22 behavior.

-    "moduleResolution": "Node",
+    "moduleResolution": "NodeNext",
circuits/tsup.config.ts (2)

1-7: Use node: specifier and set platform explicitly

Minor ergonomics: import built-ins via node: scheme, and set platform: 'node' explicitly.

-import path from 'path';
-import { fileURLToPath } from 'url';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';

12-35: Tweak build flags for clarity and slimmer bundles

  • Explicitly set platform: 'node' (tsup default, but being explicit helps).
  • Enable treeshake for better dead-code elimination.
  • Target modern Node for optimal output.
 export default defineConfig([
   {
     tsconfig: './tsconfig.json',
     entry,
     format: ['esm'],
     outDir: path.resolve(__dirname, 'dist/esm'),
     dts: false,
     splitting: false,
     clean: true,
     sourcemap: true,
-    target: 'es2020',
+    target: 'node22',
+    platform: 'node',
+    treeshake: true,
   },
   {
     tsconfig: './tsconfig.cjs.json',
     entry,
     format: ['cjs'],
     outDir: path.resolve(__dirname, 'dist/cjs'),
     dts: false,
     splitting: false,
     clean: false,
     sourcemap: true,
-    target: 'es2020',
+    target: 'node22',
+    platform: 'node',
+    treeshake: true,
   },
 ]);
circuits/package.json (3)

19-22: Publish surface is good; consider adding sideEffects for better tree-shaking

If modules are side-effect free at top level, set "sideEffects": false to help bundlers.

   "files": [
     "dist/**/*",
     "circuits/**/*"
   ],
+  "sideEffects": false,

23-25: Build pipeline order is sound; small safety improvement

Consider guarding postbuild to fail loudly if dist artifacts are missing (e.g., tsup failed). Alternatively, make postbuild idempotent and verify dist exists before writing.


8-15: Exports are correct; no deep imports detected

I ran a repo-wide search for @selfxyz/circuits/… in all JS/TS files and found no deep imports, so your current wildcard subpath ("./circuits/*": "./circuits/*") covers existing usage. You can defer adding explicit subpath mappings until you actually expose new internals.

Recommendations:

  • Verify that the package is truly side-effect-free (no global state mutations, polyfills, etc.)
  • If it is, add
    "sideEffects": false
    to circuits/package.json to unlock better tree-shaking.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 29c620b and c17d874.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (7)
  • circuits/package.json (3 hunks)
  • circuits/scripts/postBuild.mjs (1 hunks)
  • circuits/scripts/shimConfigs.js (1 hunks)
  • circuits/src/index.ts (1 hunks)
  • circuits/tsconfig.cjs.json (1 hunks)
  • circuits/tsconfig.json (1 hunks)
  • circuits/tsup.config.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-01T17:11:39.232Z
Learnt from: transphorm
PR: selfxyz/self#823
File: common/package.json:21-60
Timestamp: 2025-08-01T17:11:39.232Z
Learning: Explicit export mappings in package.json exports field provide better tree shaking than wildcard patterns because they enable easier static analysis by bundlers, allowing for more precise dependency graph understanding and better dead code elimination.

Applied to files:

  • circuits/src/index.ts
🧬 Code Graph Analysis (2)
circuits/scripts/postBuild.mjs (1)
circuits/scripts/shimConfigs.js (2)
  • shimConfigs (2-2)
  • shimConfigs (2-2)
circuits/tsup.config.ts (2)
common/scripts/testExports.js (1)
  • __filename (12-12)
circuits/scripts/postBuild.mjs (1)
  • __dirname (6-6)
🔇 Additional comments (1)
circuits/package.json (1)

36-38: Fix types script: avoid invoking full build pipeline

types currently runs yarn build --noEmit which passes an unknown flag to tsup and re-invokes postbuild. Use tsc for type-check only.

-    "types": "yarn build --noEmit"
+    "types": "tsc -p tsconfig.json --noEmit"

Likely an incorrect or invalid review comment.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (1)
circuits/tsconfig.json (1)

16-16: Exclude tests from the base tsconfig to avoid leaking test code into the library build

Including tests//* (and tests//*.json) in the base config can:

  • Confuse tooling and type resolution.
  • Risk accidental bundling of test-only code/helpers.
  • Increase build surface for editors/tsserver.

Limit base tsconfig to src only; keep tests under tsconfig.spec.json.

-  "include": ["tests/**/*", "tests/**/*.json", "src/**/*"],
+  "include": ["src/**/*"],
🧹 Nitpick comments (2)
circuits/package.json (2)

8-15: Add a react-native condition to exports for Metro

To make Metro prefer the ESM build without heuristics, add a react-native condition to the root export.

   "exports": {
     ".": {
-      "types": "./dist/esm/index.d.ts",
-      "import": "./dist/esm/index.js",
-      "require": "./dist/cjs/index.cjs"
+      "types": "./dist/esm/index.d.ts",
+      "react-native": "./dist/esm/index.js",
+      "import": "./dist/esm/index.js",
+      "require": "./dist/cjs/index.cjs"
     },
     "./circuits/*": "./circuits/*"
   },

19-22: Double-check publishing size and RN compatibility for './circuits/*' files

"files": ["dist//*", "circuits//*"] will publish everything under circuits, which may include large artifacts (e.g., wasm, zkey) and Node-centric assets. If only shims are needed, consider narrowing the pattern to exactly what Metro consumes.

Please confirm the minimum subpaths needed by Metro shims (postBuild). If feasible, prefer something like:

"files": ["dist/**/*", "circuits/**/*.json", "circuits/**/*.shim.*", "circuits/**/*.js"]
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c17d874 and 320cd4f.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • circuits/package.json (2 hunks)
  • circuits/scripts/postBuild.mjs (1 hunks)
  • circuits/src/index.ts (1 hunks)
  • circuits/tsconfig.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • circuits/scripts/postBuild.mjs
⏰ Context from checks skipped due to timeout of 300000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: run_circuit_tests
  • GitHub Check: build
🔇 Additional comments (1)
circuits/package.json (1)

102-102: LGTM: tsup devDependency

Adopting tsup is appropriate here and aligns with your dual ESM/CJS strategy.

@transphorm
Copy link
Member Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

✅ Actions performed

Full review triggered.

@transphorm transphorm merged commit ab1f229 into dev Aug 11, 2025
8 checks passed
@transphorm transphorm deleted the codex/add-circuits-build-configuration-and-scripts branch August 11, 2025 05:26
@coderabbitai coderabbitai bot mentioned this pull request Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants