-
Notifications
You must be signed in to change notification settings - Fork 498
Bump rollup from 1.32.1 to 4.32.0 #1535
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: master
Are you sure you want to change the base?
Conversation
amitsingh05667
commented
Oct 22, 2025
- Changed the build script to set PROD environment variable for production builds.
- Updated rollup and related plugins to their latest versions.
- Replaced deprecated rollup plugins with their new counterparts.
- Added a custom plugin to fix ES5 compatibility by replacing optional catch bindings.
- Improved commonjs plugin configuration for better module handling.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…mpatibility in Rollup config
|
Claude finished @amitsingh05667's task —— View job Overall Assessment❌ This PR is not ready to be merged. While the Rollup upgrade from 1.32.1 to 4.32.0 is a positive modernization effort, there are several critical issues with the custom ES5 compatibility plugin and configuration choices that need to be addressed before merging. Key Issues Found:Critical:
Code Quality:
I've provided inline comments with specific suggestions for each issue. The most critical concern is the regex-based catch block transformation, which should ideally be replaced with a proper AST-based approach for production code targeting IE9. |
| // More robust regex that matches optional catch bindings | ||
| // This pattern looks for 'catch' followed by optional whitespace and an opening brace | ||
| // We use a more specific pattern to avoid false positives in strings/comments | ||
| const catchRegex = /}\s*catch\s*\{\s*/g; |
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.
The regex pattern }\s*catch\s*\{\s*/g may match catch blocks inside string literals or comments, leading to false positives. The comment on line 32 claims to avoid this, but the regex doesn't actually prevent matching inside strings or template literals.
For production code targeting IE9, consider using a proper AST-based approach (e.g., via a Babel plugin) rather than regex-based string replacement to avoid corrupting string literals or comments that contain the pattern "} catch {".
| commonjs({ | ||
| // Safe to ignore dynamic requires since the codebase doesn't use them | ||
| // Verified via grep - no require() calls in src/ | ||
| ignoreDynamicRequires: true, |
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.
The comment claims "Safe to ignore dynamic requires since the codebase doesn't use them" and states it was "Verified via grep - no require() calls in src/". However, this is a dangerous assumption:
- Dependencies in
node_modules/may use dynamic requires that need proper handling - The
superagentdependency (included in Babel transforms line 84) may contain dynamic requires - Setting
ignoreDynamicRequires: truecan cause runtime errors if any bundled code usesrequire()with dynamic expressions
Unless you've verified that all bundled dependencies are free of dynamic requires, this setting could break the build. Consider removing this option or being more thorough in the verification.
| ignoreDynamicRequires: true, | ||
| // Keep default behavior for better compatibility with CommonJS modules | ||
| // 'auto' attempts to detect the correct export style, which is safer for mixed module types | ||
| defaultIsModuleExports: 'auto' |
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.
The comment justifies using defaultIsModuleExports: 'auto' for "better compatibility", but this is actually the default value in @rollup/plugin-commonjs v28.
The explicit configuration adds no value and creates maintenance overhead. Consider removing this line to rely on the plugin's default behavior, which is already 'auto'.
| compress: true, | ||
| output: { comments: false }, | ||
| // Enable mangle for better minification in production builds | ||
| mangle: true |
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.
The comment "Enable mangle for better minification in production builds" is misleading because mangle: true is already the default in terser. This explicit configuration adds no functional value.
Consider removing this line to reduce configuration noise and rely on terser's defaults.
| const startPos = match.index; | ||
| const endPos = startPos + match[0].length; | ||
| const originalText = match[0]; | ||
| const replacement = originalText.replace(/catch\s*\{/, 'catch (e) {'); |
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.
The regex replacement originalText.replace(/catch\s*\{/, 'catch (e) {') is applied to text that has already been matched by the outer regex. This creates a redundant nested regex operation.
Since originalText is guaranteed to contain the pattern from line 33's match, you can construct the replacement string directly without another regex:
| const replacement = originalText.replace(/catch\s*\{/, 'catch (e) {'); | |
| const replacement = originalText.replace('catch {', 'catch (e) {'); |
This is more efficient and clearer.
| while ((match = catchRegex.exec(code)) !== null) { | ||
| const startPos = match.index; | ||
| const endPos = startPos + match[0].length; | ||
| const originalText = match[0]; | ||
| const replacement = originalText.replace(/catch\s*\{/, 'catch (e) {'); | ||
|
|
||
| magicString.overwrite(startPos, endPos, replacement); | ||
| hasReplacements = true; | ||
| } |
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.
The loop modifies magicString multiple times but only returns a single source map at the end. When making multiple edits with MagicString, each overwrite call updates the internal source map state, but the source mappings may become inaccurate if the replacements overlap or affect each other's positions.
While this likely works for non-overlapping replacements, a more robust approach would be to collect all match positions first, then apply them in reverse order (end to start) to avoid position shifting issues:
const matches = [];
let match;
while ((match = catchRegex.exec(code)) !== null) {
matches.push(match);
}
// Apply replacements in reverse order to avoid position shifting
for (let i = matches.length - 1; i >= 0; i--) {
const match = matches[i];
const startPos = match.index;
const endPos = startPos + match[0].length;
const originalText = match[0];
const replacement = originalText.replace('catch {', 'catch (e) {');
magicString.overwrite(startPos, endPos, replacement);
}| "clean": "rm -rf dist && rm -rf build", | ||
| "start": "npm run clean && rollup -c --watch", | ||
| "build": "npm run clean && rollup -c --prod && cp -rf dist build", | ||
| "build": "npm run clean && cross-env PROD=true rollup -c && cp -rf dist build", |
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.
The build script now uses cross-env PROD=true to set the production flag, but this creates an inconsistency: the rollup config also checks for argv.prod (line 59 in rollup.config.js).
This dual-checking mechanism could lead to confusion. Consider standardizing on a single approach - either environment variable OR CLI argument, not both.
| renderChunk(code, chunk, options) { | ||
| // Only apply to UMD and ES formats | ||
| if (options.format === 'umd' || options.format === 'es') { | ||
| // Use MagicString for proper source map handling |
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.
The fixES5 plugin only runs on UMD and ES formats, but the config also generates production builds with these exact formats (lines 116, 122). However, there's a logical issue: the plugin runs for all builds when added to getPlugins(), not just production builds.
For development builds with inline sourcemaps (line 147, 169), applying this transformation adds unnecessary overhead. Consider:
- Only applying
fixES5()to production builds where ES5 compatibility truly matters - Or document why development builds also need this transformation