refactor: standardize source map handling across compressors#2800
refactor: standardize source map handling across compressors#2800
Conversation
- Create sourceMap.ts utility with getSourceMapBoolean and extractSourceMapOption - Add comprehensive tests for source map utilities - Update swc, oxc, lightningcss, esbuild to use new utilities - Reduces duplication and improves consistency across compressors
- Mark P3 source map utilities as completed in github_action_implementation_plan.md
|
📝 WalkthroughWalkthroughRefactors sourceMap option handling into two new utilities and applies them across compressor packages; implements a JavaScript GitHub Action with associated files, docs and tests, and adds tests for the new utilities. Changes
Sequence Diagram(s)sequenceDiagram
participant Runner as Runner
participant Action as Action (packages/action)
participant Minifiers as Minifier Modules
participant Reporters as Reporters (summary/comment/annotations)
participant GH as GitHub API
Runner->>Action: trigger with inputs
Action->>Minifiers: discover files & call minifier (uses extractSourceMapOption)
Minifiers-->>Action: return code + optional map
Action->>Reporters: build reports (summary/comment/annotations)
Reporters->>GH: post comments/annotations & update summary
GH-->>Runner: workflow status
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||
Greptile OverviewGreptile SummaryThis refactoring extracts duplicated
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Compressor as Compressor<br/>(swc/oxc/lightningcss/esbuild)
participant Utils as @node-minify/utils
participant MinifyLib as Minify Library<br/>(swc/oxc/lightningcss/esbuild)
User->>Compressor: minify({ settings, content })
Note over Compressor: settings.options = { sourceMap: true, ... }
alt esbuild compressor
Compressor->>Utils: extractSourceMapOption(options)
Utils-->>Compressor: { sourceMap: true, restOptions: {...} }
Compressor->>MinifyLib: transform(content, { sourcemap: true, ...restOptions })
else swc/oxc/lightningcss
Compressor->>Utils: getSourceMapBoolean(options)
Utils-->>Compressor: true
Compressor->>MinifyLib: minify(content, { sourceMap: true, ...options })
end
MinifyLib-->>Compressor: { code, map }
Compressor-->>User: { code, map }
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||
Use extractSourceMapOption to separate sourceMap from restOptions, preventing user-provided sourceMap from overriding normalized boolean.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2800 +/- ##
===========================================
+ Coverage 95.07% 95.09% +0.02%
===========================================
Files 72 73 +1
Lines 1686 1693 +7
Branches 512 509 -3
===========================================
+ Hits 1603 1610 +7
Misses 83 83 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
User description
Summary
!!options.sourceMappattern into shared utilities in@node-minify/utilsgetSourceMapBoolean()— normalizes sourceMap option to boolean (used by swc, oxc, lightningcss)extractSourceMapOption()— extracts sourceMap boolean + remaining options (used by esbuild).plans/github_action_implementation_plan.mdto reflect completed workChanges
packages/utils/src/sourceMap.ts+ 18 testsswc,oxc,lightningcss,esbuildcompressors to use shared utilitiesPR Type
Enhancement, Tests
Description
Extract duplicated sourceMap handling into shared utility functions
Add
getSourceMapBoolean()andextractSourceMapOption()utilitiesUpdate swc, oxc, lightningcss, esbuild compressors to use new utilities
Add comprehensive test suite with 18 test cases for sourceMap utilities
Update implementation plan to reflect completed GitHub Action work
Diagram Walkthrough
File Walkthrough
sourceMap.ts
New sourceMap utility functions for compressorspackages/utils/src/sourceMap.ts
getSourceMapBoolean()normalizes sourceMap option to booleanextractSourceMapOption()extracts sourceMap and remaining optionsseparately
!!options.sourceMappattern across compressorsindex.ts
Export sourceMap utilities from utils packagepackages/utils/src/index.ts
getSourceMapBooleanandextractSourceMapOptionfrom utilspackage
index.ts
Update swc to use sourceMap utilitypackages/swc/src/index.ts
getSourceMapBooleanfrom utils!!options.sourceMapwithgetSourceMapBoolean(options)callindex.ts
Update oxc to use sourceMap utilitypackages/oxc/src/index.ts
getSourceMapBooleanfrom utils!!options.sourceMapwithgetSourceMapBoolean(options)callindex.ts
Update lightningcss to use sourceMap utilitypackages/lightningcss/src/index.ts
getSourceMapBooleanfrom utils!!options.sourceMapwithgetSourceMapBoolean(options)callindex.ts
Update esbuild to use sourceMap utilitypackages/esbuild/src/index.ts
extractSourceMapOptionfrom utilsextractSourceMapOption()callsourceMap.test.ts
Complete test coverage for sourceMap utilitiespackages/utils/tests/sourceMap.test.ts
getSourceMapBoolean()covering undefined, empty, falsy,truthy, and mixed options
extractSourceMapOption()covering extraction, preservation,and immutability
github_action_implementation_plan.md
Update implementation plan with completion status.plans/github_action_implementation_plan.md
Summary by CodeRabbit
New Features
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.