Repository navigation
Generate sourcemaps for transformed modules - #78
Conversation
When build.sourcemap is enabled, Rolldown/Vite warned with SOURCEMAP_BROKEN because the transform hook returned modified code without a sourcemap. Apply the css`` replacements and side-effect import injection through RolldownMagicString (the Rust-backed magic-string shipped with rolldown, available since 1.2.0 - no new runtime dependency) and return the generated map alongside the transformed code. Add a test that builds with sourcemaps enabled, expects zero plugin warnings, and traces a generated class name string back to the exact position of the css`` tag it replaced. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014gjLLnGPcEuNU9RydaN7W3
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe plugin now applies CSS class replacements through ChangesCSS extraction sourcemaps
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to This change adds sourcemap generation while preserving transformed output, with the stated formatting, typecheck, build, and test checks passing. No actionable merge-blocking risk remains. Sequence Diagram(s)sequenceDiagram
participant ViteBuild
participant TransformHook
participant extractCssFromCode
participant RolldownMagicString
ViteBuild->>TransformHook: provide source code and transform metadata
TransformHook->>extractCssFromCode: pass code and magic string metadata
extractCssFromCode->>RolldownMagicString: overwrite CSS class ranges
TransformHook->>RolldownMagicString: prepend CSS imports
RolldownMagicString-->>ViteBuild: return transformed code and sourcemap
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (2 skipped: 2 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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 |
Rolldown provides a lazily-created RolldownMagicString for the module's code via the transform hook's meta argument. Reuse it and return the instance itself as `code`, letting rolldown apply the edits and generate the sourcemap natively instead of serializing a JSON map through the JS side. When meta.magicString is absent (e.g. Vite's dev-mode plugin container), fall back to constructing the instance and returning stringified code plus an explicit sourcemap as before. The existing sourcemap test exercises the native path, as Vite builds run transform hooks through rolldown's bindings. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014gjLLnGPcEuNU9RydaN7W3
Use plain assertions instead of inline snapshots and a manual throw: - expect(logs).toStrictEqual([]) states the "no warnings" intent directly - vitest's assert() narrows the map instead of an if/throw guard Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014gjLLnGPcEuNU9RydaN7W3
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014gjLLnGPcEuNU9RydaN7W3
Problem
With
build.sourcemapenabled, Rolldown/Vite loggedSOURCEMAP_BROKENwarnings because the ecij transform hook returned modified code without a sourcemap, and emitted maps had empty mappings. (Sourcemaps were a listed TODO in the README.)Changes
src/index.ts: apply thecss``` `` replacements (overwrite) and side-effect import injection (prepend) throughRolldownMagicString` — the Rust-backed magic-string implementation exported by rolldown itself. No new runtime dependency: the export exists since rolldown 1.2.0, the current peer floor. The descending-order replacement sort is obsolete (magic-string edits use original offsets) and was removed.test/plugin.test.ts: new test building with sourcemaps enabled that expects zero plugin warnings, checks the map's sources/mappings, and traces the generated class name string in the output back to the exact line/column of thecss``` `` tag it replaced (via new devDependency@jridgewell/trace-mapping). The build helper gained asourcemapoption and now tolerates the extra.js.map` asset.When Rolldown provides a lazily-created MagicString via the transform hook's
meta.magicString, that instance is mutated and returned directly ascode, letting Rolldown apply the edits and generate the sourcemap natively. When it is absent (e.g. Vite's dev-mode plugin container, which passes nomagicStringand wouldn't handle an objectcode), the hook falls back to the classic{ code: string, map }shape withgenerateMap({ hires: 'boundary' }).Verification
SOURCEMAP_BROKENbefore the fix and passes after.CI=true), where they import the builtdistplugin instead of the source.format,typecheck,build,testall green.🤖 Generated with Claude Code
https://claude.ai/code/session_014gjLLnGPcEuNU9RydaN7W3
Summary by CodeRabbit
New Features
Bug Fixes
Documentation