Skip to content

Conversation

@transphorm
Copy link
Member

@transphorm transphorm commented Aug 11, 2025

Summary

  • add tsup config and CJS tsconfig for mobile SDK alpha
  • generate metro shims and nested package.json files after build
  • expand exports map and streamline build script

Testing

  • yarn workspace @selfxyz/mobile-sdk-alpha nice
  • yarn lint
  • yarn build
  • yarn types
  • yarn workspace @selfxyz/mobile-sdk-alpha test

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

Summary by CodeRabbit

  • New Features

    • Introduced an explicit browser export for easier browser-targeted imports.
    • ESM-first distribution with dual ESM/CJS builds for broader compatibility.
    • Improved React Native/Metro compatibility via resolution shims.
    • Enhanced treeshaking and bundler support; sourcemaps now available.
  • Chores

    • Reworked build pipeline and added a post-build step to structure outputs and metadata.

@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 2 minutes and 25 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 d057648 and c4077b6.

📒 Files selected for processing (2)
  • packages/mobile-sdk-alpha/scripts/postBuild.mjs (1 hunks)
  • packages/mobile-sdk-alpha/tsup.config.ts (1 hunks)

Walkthrough

Restructures mobile-sdk-alpha packaging to a dual ESM/CJS layout. Updates exports in package.json, adds a browser subpath export, introduces tsup multi-target builds, adds a CJS tsconfig, and implements a post-build script that writes distribution package.json files and generates Metro shims.

Changes

Cohort / File(s) Summary
Packaging & Exports
packages/mobile-sdk-alpha/package.json
Switches to ESM-first exports with CJS fallbacks; adds "./browser" export; updates main/module/types paths to dist/esm and dist/cjs; replaces build script with tsup + postbuild pipeline.
Post-build Scripts & Shims
packages/mobile-sdk-alpha/scripts/postBuild.mjs, packages/mobile-sdk-alpha/scripts/shimConfigs.js
Adds post-build script to write dist-level package.json files (esm/cjs roots, exports) and generate Metro-compatible shims based on shimConfigs (initially for browser).
Build Configurations
packages/mobile-sdk-alpha/tsup.config.ts, packages/mobile-sdk-alpha/tsconfig.cjs.json
Introduces split builds: ESM (types, dist/esm) and CJS (no types, dist/cjs). Adds CJS tsconfig directing outputs to dist/cjs with CommonJS module settings.

Sequence Diagram(s)

sequenceDiagram
  participant Dev as Developer
  participant NPM as Package Scripts
  participant TSUP as tsup (ESM+CJS)
  participant PB as postBuild.mjs
  participant FS as File System

  Dev->>NPM: yarn build
  NPM->>FS: rm -rf dist
  NPM->>TSUP: build ESM (types) and CJS
  TSUP->>FS: emit dist/esm/* and dist/cjs/*
  NPM->>PB: yarn postbuild
  PB->>FS: write dist/esm/package.json (module)
  PB->>FS: write dist/cjs/package.json (commonjs)
  PB->>FS: write dist/package.json (name, version, exports)
  PB->>FS: create Metro shims from shimConfigs
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • aaronmgdr

Poem

Split the streams: ESM sails, CJS rows,
Shims appear where Metro goes.
Exports aligned, the browser has a door,
postBuild whispers, “package once more.”
Dist wakes tidy, version in hand—
Ship the SDK across every land. ✨

✨ 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/update-mobile-sdk-alpha-build-process

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 build: configure tsup and add metro shims feat: modernize mobile sdk build pipeline Aug 11, 2025
@transphorm transphorm marked this pull request as ready for review August 11, 2025 03:47
@transphorm
Copy link
Member Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

✅ Actions performed

Full review triggered.

@transphorm
Copy link
Member Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

✅ Actions performed

Full review triggered.

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: 2

🧹 Nitpick comments (2)
packages/mobile-sdk-alpha/scripts/postBuild.mjs (1)

37-44: Consider using template literals for better readability.

The string concatenation for shim content could be more readable with template literals.

-  writeFileSync(
-    path.join(shimDir, 'index.js'),
-    `// Shim file to help Metro resolve @selfxyz/mobile-sdk-alpha/${name}\nmodule.exports = require('${cjsTargetPath}');`,
-  );
-  writeFileSync(
-    path.join(shimDir, 'index.d.ts'),
-    `// Shim file to help Metro resolve @selfxyz/mobile-sdk-alpha/${name} types\nexport * from "${dtsTarget}";`,
-  );
+  writeFileSync(
+    path.join(shimDir, 'index.js'),
+    `// Shim file to help Metro resolve @selfxyz/mobile-sdk-alpha/${name}
+module.exports = require('${cjsTargetPath}');`
+  );
+  writeFileSync(
+    path.join(shimDir, 'index.d.ts'),
+    `// Shim file to help Metro resolve @selfxyz/mobile-sdk-alpha/${name} types
+export * from "${dtsTarget}";`
+  );
packages/mobile-sdk-alpha/package.json (1)

37-37: Consider adding error handling to the postbuild script.

While the postbuild script integration looks good, consider what happens if the post-build step fails. The build process might appear successful even if shim generation fails.

Consider updating the build script to handle post-build failures:

-    "build": "rm -rf dist && tsup && yarn postbuild",
+    "build": "rm -rf dist && tsup && yarn postbuild || (echo 'Post-build failed' && exit 1)",
📜 Review details

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

📥 Commits

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

📒 Files selected for processing (5)
  • packages/mobile-sdk-alpha/package.json (1 hunks)
  • packages/mobile-sdk-alpha/scripts/postBuild.mjs (1 hunks)
  • packages/mobile-sdk-alpha/scripts/shimConfigs.js (1 hunks)
  • packages/mobile-sdk-alpha/tsconfig.cjs.json (1 hunks)
  • packages/mobile-sdk-alpha/tsup.config.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/mobile-sdk-alpha/scripts/postBuild.mjs (1)
packages/mobile-sdk-alpha/scripts/shimConfigs.js (2)
  • shimConfigs (2-2)
  • shimConfigs (2-2)
🔇 Additional comments (7)
packages/mobile-sdk-alpha/tsconfig.cjs.json (1)

1-10: LGTM! Clean CommonJS configuration.

The TypeScript configuration properly extends the base config and sets appropriate CommonJS-specific options. The esModuleInterop setting ensures proper interoperability between ESM and CJS modules, which is crucial for the dual-format build pipeline.

packages/mobile-sdk-alpha/scripts/shimConfigs.js (1)

2-2: Relative Path Resolution Verified

The targetPath: '../esm/browser.js' correctly includes the /esm/ segment, so in the post-build script:

  • .replace('/esm/', '/cjs/').replace('.js', '.cjs') yields ../cjs/browser.cjs
  • .replace('.js', '') yields ../esm/browser

When shims are emitted under dist/browser/, these relative imports point to dist/esm/browser.js (and its CJS equivalent) as intended. No changes needed.

packages/mobile-sdk-alpha/scripts/postBuild.mjs (2)

1-11: LGTM! Proper ESM imports and setup.

Good use of Node.js built-in modules with the node: prefix and proper ESM import.meta.url handling for directory resolution.


34-35: String replacement logic is valid for current shimConfigs
All targetPath entries in packages/mobile-sdk-alpha/scripts/shimConfigs.js use the /esm/…​.js pattern, and our test confirms they transform correctly to /cjs/…​.cjs and strip the .js for DTS output. No mismatches were found.

packages/mobile-sdk-alpha/tsup.config.ts (1)

3-32: Excellent dual-build configuration!

The tsup configuration is well-designed with several smart choices:

  1. Efficient DTS generation: Only the ESM build generates TypeScript declarations (dts: true), avoiding duplication since both builds would produce identical .d.ts files.

  2. Proper cleaning strategy: clean: true only on the ESM build prevents race conditions during concurrent builds.

  3. Appropriate settings: splitting: false is correct for library builds, and target: 'es2020' provides good compatibility.

  4. Correct tsconfig usage: Each build uses its appropriate TypeScript configuration.

packages/mobile-sdk-alpha/package.json (2)

14-28: Well-structured exports map for dual-package setup!

The exports configuration follows Node.js dual-package best practices:

  1. Proper condition ordering: types first, followed by environment-specific conditions (react-native, browser), then module format conditions (import, require), and finally default.

  2. Comprehensive browser support: The new ./browser export provides a clean public API for browser-specific functionality.

  3. Consistent path structure: All paths correctly reference the dual build output directories.


36-37: Secure build script with proper cleanup.

The build script properly cleans the dist directory before building and includes the post-build step. The use of rm -rf dist is appropriate here since it's a controlled build environment.

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