Skip to content

Conversation

@vio
Copy link
Member

@vio vio commented Aug 7, 2025

Summary by CodeRabbit

  • New Features

    • Improved module support with separate CommonJS and ES module builds for better compatibility.
    • Enhanced type declaration support for easier TypeScript integration.
  • Chores

    • Updated build scripts and configuration for clearer module resolution and output structure.
    • Added new dependencies to support JSON imports.
    • Enabled source map generation for improved debugging.

@coderabbitai
Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

The rollup-plugin package build system was updated to output both CommonJS and ES module formats, with improved type declaration handling. The package.json, Rollup config, and TypeScript configs were modified to support dual builds, explicit module entry points, and better type resolution. Two new TypeScript configs for CJS and ESM outputs were introduced.

Changes

Cohort / File(s) Change Summary
Package Metadata & Scripts
packages/rollup-plugin/package.json
Updated to support dual module formats with "main", "module", and "exports" fields; improved type declaration paths; added new build scripts and dependency.
Rollup Build Configuration
packages/rollup-plugin/rollup.config.mjs
Split into separate CJS and ESM builds with dedicated output directories, plugin configurations, and TypeScript settings; adjusted plugin options and external patterns.
TypeScript Base Config
packages/rollup-plugin/tsconfig.base.json
Changed declaration output directory to ./lib/types, enabled source map generation, and added strictness and code quality compiler options; changed base config extension.
TypeScript CJS Config
packages/rollup-plugin/tsconfig.cjs.json
New config extending base, outputs compiled files to ./lib/cjs.
TypeScript ESM Config
packages/rollup-plugin/tsconfig.esm.json
New config extending base, outputs compiled files to ./lib/esm.
TypeScript Main Config Simplification
packages/rollup-plugin/tsconfig.json
Simplified by extending base config and removing redundant compiler options and ts-node settings; sets output directory to ./lib.
Source Code Import Refinement
packages/rollup-plugin/src/index.ts
Changed import of Plugin from a direct to a type-only import; removed unnecessary // @ts-ignore comment.
Rollup Plugin Config Naming & Options
packages/plugin-webpack-filter/rollup.config.mjs
Renamed source directory constant from CONTEXT to CONTEXT_DIR; simplified CommonJS and ESM build commonjsPlugin options by removing explicit settings.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Node.js (CJS)
    participant ESM Loader
    participant Package

    User->>Node.js (CJS): require('rollup-plugin-bundle-stats')
    Node.js (CJS)->>Package: Loads ./lib/cjs/index.js

    User->>ESM Loader: import 'rollup-plugin-bundle-stats'
    ESM Loader->>Package: Loads ./lib/esm/index.js

    User->>Package: import types from 'rollup-plugin-bundle-stats'
    Package->>Package: Loads ./lib/types/index.d.ts
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

  • Use rollup #4928: Also modifies the packages/rollup-plugin package to adopt Rollup for building, including changes to package.json scripts, dependencies, and build configuration, showing a direct connection at the build and packaging level.

Poem

A hop and a skip, the build hops anew,
With CJS and ESM, now both in the stew.
Types are much clearer, the exports precise,
Rollup rolls smoother—oh, isn’t that nice?
With configs aligned and scripts set to run,
This bunny’s delighted—the build’s never been more fun!
🐇✨

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch update-build-flows

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@socket-security
Copy link

socket-security bot commented Aug 7, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​rollup/​plugin-json@​6.1.010010010081100

View full report

@relativeci
Copy link

relativeci bot commented Aug 7, 2025

#12472 Bundle Size — 382.46KiB (0%).

032baca(current) vs 19b2c70 master#12458(baseline)

Warning

Bundle contains 2 duplicate packages – View duplicate packages

Bundle metrics  no changes
                 Current
#12472
     Baseline
#12458
No change  Initial JS 334.85KiB 334.85KiB
No change  Initial CSS 47.61KiB 47.61KiB
Change  Cache Invalidation 0% 28.65%
No change  Chunks 3 3
No change  Assets 4 4
No change  Modules 701 701
No change  Duplicate Modules 0 0
No change  Duplicate Code 0% 0%
No change  Packages 39 39
No change  Duplicate Packages 1 1
Bundle size by type  no changes
                 Current
#12472
     Baseline
#12458
No change  JS 334.85KiB 334.85KiB
No change  CSS 47.61KiB 47.61KiB

Bundle analysis reportBranch update-build-flowsProject dashboard


Generated by RelativeCIDocumentationReport issue

Copy link

@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: 0

🧹 Nitpick comments (1)
packages/rollup-plugin/package.json (1)

16-17: Improve cross-platform compatibility of build-type script.

The current echo-based approach may have cross-platform issues. Consider using a more robust approach for generating the module type files.

-    "build-type": "echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json && echo '{\"type\":\"module\"}' > lib/esm/package.json",
+    "build-type": "node -e \"const fs = require('fs'); fs.writeFileSync('lib/cjs/package.json', '{\\\"type\\\":\\\"commonjs\\\"}'); fs.writeFileSync('lib/esm/package.json', '{\\\"type\\\":\\\"module\\\"}');\"",

This approach is more reliable across different operating systems and shell environments.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19b2c70 and 5ab5bc7.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • packages/rollup-plugin/package.json (3 hunks)
  • packages/rollup-plugin/rollup.config.mjs (2 hunks)
  • packages/rollup-plugin/tsconfig.base.json (1 hunks)
  • packages/rollup-plugin/tsconfig.cjs.json (1 hunks)
  • packages/rollup-plugin/tsconfig.esm.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (11)
packages/rollup-plugin/tsconfig.base.json (1)

7-8: LGTM! Proper setup for dual module builds.

The changes correctly separate type declarations into a dedicated directory and enable source maps, which supports the new dual build architecture where both CJS and ESM builds can share the same type definitions.

packages/rollup-plugin/tsconfig.cjs.json (1)

1-6: LGTM! Clean CommonJS TypeScript configuration.

The configuration properly extends the base config and sets the correct output directory for the CommonJS build. The minimal approach is appropriate.

packages/rollup-plugin/tsconfig.esm.json (1)

1-6: LGTM! Clean ESM TypeScript configuration.

The configuration properly extends the base config and sets the correct output directory for the ES module build. The structure is consistent with the CJS configuration.

packages/rollup-plugin/rollup.config.mjs (5)

5-5: Good addition for JSON import support.

The JSON plugin import enables proper handling of JSON imports in both build configurations.


17-17: Correct entry file naming for dual builds.

The entryFileNames configuration properly separates CJS and ESM outputs into their respective subdirectories.

Also applies to: 44-44


25-36: Well-configured CommonJS build setup.

The CJS build configuration includes:

  • Proper extension resolution for CJS context
  • defaultIsModuleExports: 'auto' for better CommonJS compatibility
  • JSON plugin for JSON imports
  • Dedicated TypeScript config for CJS output
  • Test file exclusion

38-65: ESM build configuration looks good overall.

The ESM build properly:

  • Uses dedicated TypeScript config for ESM output
  • Includes broader extension resolution (.mjs support)
  • Maintains consistent plugin setup with JSON support
  • Excludes test files appropriately

55-58: ESM build CommonJS plugin settings are correct

The ESM output excludes all node_modules via external, and our source contains no require, module.exports, or exports. patterns—so the default CommonJS plugin behavior is sufficient. No changes are needed here.

packages/rollup-plugin/package.json (3)

5-7: Excellent dual module configuration.

The package entry points are properly configured:

  • main points to CommonJS build
  • module points to ESM build
  • types points to shared type declarations

This follows Node.js best practices for dual module packages.


51-51: Correct dependency addition for JSON plugin.

The @rollup/plugin-json dependency is properly added to support JSON imports in the Rollup configuration.


55-61: Well-structured exports field for modern module resolution.

The exports field properly defines entry points for:

  • require (CommonJS)
  • import (ESM)
  • types (TypeScript declarations)

This enables proper module resolution in modern Node.js environments and bundlers.

@vio vio force-pushed the update-build-flows branch 2 times, most recently from e80aa9b to d6d5fc5 Compare August 8, 2025 16:04
@vio vio force-pushed the update-build-flows branch from d6d5fc5 to 032baca Compare August 8, 2025 16:08
Copy link

@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: 1

🧹 Nitpick comments (3)
packages/plugin-webpack-filter/rollup.config.mjs (3)

7-7: OK to rename; minor note

CONTEXT_DIR looks fine. If you adopt the suggestions below (remove context and switch preserveModulesRoot to 'src'), this constant may become unnecessary.


20-20: Prefer a stable preserveModulesRoot

Using an absolute path can be sensitive to platform-specific path normalization. Most setups use the source folder name.

Option A (simple, common):

-      preserveModulesRoot: CONTEXT_DIR,
+      preserveModulesRoot: 'src',

Option B (if you want to keep absolute but ensure POSIX matching):

-const CONTEXT_DIR = path.join(process.cwd(), './src');
+const CONTEXT_DIR = path.resolve('src');
+const CONTEXT_POSIX = CONTEXT_DIR.split(path.sep).join('/');
...
-      preserveModulesRoot: CONTEXT_DIR,
+      preserveModulesRoot: CONTEXT_POSIX,

Please confirm which approach you prefer. If you pick Option A and remove the context property per above, CONTEXT_DIR can be dropped entirely.

Also applies to: 46-46


23-23: Make externals robust to monorepos/PNPM and avoid path-coupling

external: /node_modules/ ties behavior to install location and can miss symlinked deps. Prefer externalizing bare imports + node: builtins.

-    external: /node_modules/,
+    external: (id) =>
+      id.startsWith('node:') ||
+      (!id.startsWith('.') && !path.isAbsolute(id)),

Applies to both outputs (Lines 23 and 49). This is the common pattern across Rollup repos and works well with monorepos.

Also applies to: 49-49

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6d5fc5 and 032baca.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • packages/plugin-webpack-filter/rollup.config.mjs (2 hunks)
  • packages/rollup-plugin/package.json (3 hunks)
  • packages/rollup-plugin/rollup.config.mjs (1 hunks)
  • packages/rollup-plugin/src/index.ts (1 hunks)
  • packages/rollup-plugin/tsconfig.base.json (1 hunks)
  • packages/rollup-plugin/tsconfig.cjs.json (1 hunks)
  • packages/rollup-plugin/tsconfig.esm.json (1 hunks)
  • packages/rollup-plugin/tsconfig.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/rollup-plugin/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/rollup-plugin/tsconfig.cjs.json
  • packages/rollup-plugin/tsconfig.esm.json
  • packages/rollup-plugin/tsconfig.json
  • packages/rollup-plugin/tsconfig.base.json
  • packages/rollup-plugin/rollup.config.mjs
  • packages/rollup-plugin/package.json
🔇 Additional comments (2)
packages/plugin-webpack-filter/rollup.config.mjs (2)

54-54: LGTM: default CommonJS interop for ESM build

Using commonjsPlugin() with defaults for the ESM bundle is fine and keeps the config simple.


28-30: Asymmetry in CommonJS plugin config; also summary mismatch

CJS config still sets defaultIsModuleExports: 'auto' (Lines 28–30), while ESM uses plugin defaults (Line 54). If that’s intentional, all good—just confirm. If the PR intent was to simplify both, consider unifying:

-      commonjsPlugin({
-        defaultIsModuleExports: 'auto',
-      }),
+      commonjsPlugin(),

If you do need the option for CJS due to specific dependencies, add a brief inline comment explaining why to help future maintainers.

Also applies to: 54-54

Likely an incorrect or invalid review comment.

export default defineConfig([
{
context: CONTEXT,
context: CONTEXT_DIR,
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Remove Rollup “context” — it’s not a directory path

Rollup’s config option context sets the top-level this binding during bundling; passing a filesystem path here is misleading and not what the option is for. It’s safe to drop it for both outputs.

Apply:

-    context: CONTEXT_DIR,
+    // context not needed; use default module semantics

To verify repo-wide, search for any other misuse:

Also applies to: 38-38


🏁 Script executed:

#!/bin/bash
fd -t f "rollup.config.*" | xargs -I{} rg -n --no-heading "^\s*context\s*:" {}

Length of output: 221


🏁 Script executed:

#!/bin/bash
# Search all Rollup config files for any context usages, including file names
fd -t f "rollup.config.*" | xargs -I{} rg -n "^\s*context\s*:" {}

Length of output: 208


🏁 Script executed:

#!/bin/bash
# List all occurrences of `context:` in Rollup config files with file paths
rg -nH '^\s*context\s*:' -g 'rollup.config.*'

Length of output: 425


Drop misused Rollup context option across plugin configs

Rollup’s context option sets the top-level this binding during bundling; passing a filesystem path here is misleading. We can safely remove it (or replace with a comment) in all outputs:

• packages/rollup-plugin/rollup.config.mjs (line 13)
• packages/plugin-webpack-filter/rollup.config.mjs (lines 12, 38)
• packages/plugin-webpack-validate/rollup.config.mjs (lines 13, 38)

Apply the same diff in each file:

-    context: CONTEXT_DIR,
+    // context not needed; use default module semantics

-    context: CONTEXT,
+    // context not needed; use default module semantics

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/plugin-webpack-filter/rollup.config.mjs at line 12, the Rollup
`context` option is incorrectly set to a filesystem path, which is misleading
because `context` should define the top-level `this` binding. Remove the
`context: CONTEXT_DIR,` line entirely from the config to fix this misuse. Also,
apply the same removal to the specified lines in the other mentioned files for
consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants