Skip to content

feat(rspeedy): add css sourcemap option#2442

Merged
upupming merged 4 commits intolynx-family:mainfrom
luhc228:hc/css-sourcemap-option
Apr 20, 2026
Merged

feat(rspeedy): add css sourcemap option#2442
upupming merged 4 commits intolynx-family:mainfrom
luhc228:hc/css-sourcemap-option

Conversation

@luhc228
Copy link
Copy Markdown
Collaborator

@luhc228 luhc228 commented Apr 10, 2026

Related PR: luhc228#2

Summary by CodeRabbit

  • New Features

    • Added a CSS sourcemap toggle (sourceMap.css) to enable/disable emitting CSS sourcemaps; defaults to false.
  • Tests

    • Expanded test coverage and fixtures to verify CSS sourcemap behavior: default absence, enabled emission, and correct source mappings.
  • Chores

    • Added a changeset documenting the new option.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

Copilot AI review requested due to automatic review settings April 10, 2026 06:55
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 10, 2026

🦋 Changeset detected

Latest commit: 019c264

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@lynx-js/rspeedy Patch
create-rspeedy Patch
upgrade-rspeedy Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

Adds an optional output.sourceMap.css boolean (default false) to rspeedy, updates types and config, extends type and runtime tests, adds CSS test fixtures, and refactors/extends plugin-react sourcemap tests to verify CSS sourcemap emission.

Changes

Cohort / File(s) Summary
Changeset
\.changeset/add-css-sourcemap-option.md
New changeset documenting the sourceMap.css option and usage.
Public API / Types
packages/rspeedy/core/etc/rspeedy.api.md, packages/rspeedy/core/src/config/output/source-map.ts
Extended the SourceMap interface to include css?: boolean | undefined.
Type tests
packages/rspeedy/core/test/config/output.test-d.ts
Added type assertions accepting sourceMap: { css: true }/false and a @ts-expect-error case for non-boolean values.
Runtime validation tests
packages/rspeedy/core/test/config/validate.test.ts
Added valid/invalid cases for output.sourceMap covering boolean, js-only, css-only, and combined configs; added snapshot for invalid input.
Test fixtures
packages/rspeedy/plugin-react/test/fixtures/sourcemap/index.css, packages/rspeedy/plugin-react/test/fixtures/sourcemap/index.tsx
Added CSS fixture and imported it from the test entry to produce CSS output for sourcemap tests.
Plugin-react tests
packages/rspeedy/plugin-react/test/sourcemap.test.ts
Refactored to use buildSourcemapFixture() helper; added temp-dir lifecycle management; broadened map discovery to **/*.map; added tests asserting default JS-only maps and CSS maps when { css: true }; parsed and asserted CSS sourcemap contents; updated plugin loader simulation and inline snapshots.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • upupming
  • colinaaa

Poem

🐰 I hopped through folders, sniffed each file,
Found tiny maps that made me smile.
CSS breadcrumbs now gleam and chart,
Every rule returns to its start.
Happy hops — sourcemaps warm my heart! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(rspeedy): add css sourcemap option' directly and clearly describes the main feature being added, matching the changeset across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for emitting CSS sourcemaps via output.sourceMap.css in the Rspeedy config, aligning config typing/validation with expected bundler behavior and extending integration tests to cover CSS map emission.

Changes:

  • Extend SourceMap config to include css?: boolean and update extracted API docs.
  • Add config validation + d.ts type tests for the new output.sourceMap.css option.
  • Update plugin-react sourcemap fixture/tests to include CSS and assert CSS maps are only emitted when enabled; add a changeset entry.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/rspeedy/plugin-react/test/sourcemap.test.ts Refactors sourcemap tests and adds assertions for optional CSS sourcemap emission.
packages/rspeedy/plugin-react/test/fixtures/sourcemap/index.tsx Imports fixture CSS to produce a CSS output for sourcemap verification.
packages/rspeedy/plugin-react/test/fixtures/sourcemap/index.css New fixture stylesheet used to validate CSS sourcemap mapping.
packages/rspeedy/core/test/config/validate.test.ts Adds validation coverage for output.sourceMap boolean/object forms including css.
packages/rspeedy/core/test/config/output.test-d.ts Adds type-level assertions for output.sourceMap.css and rejects non-boolean values.
packages/rspeedy/core/src/config/output/source-map.ts Introduces the css option in the public SourceMap interface with docs.
packages/rspeedy/core/etc/rspeedy.api.md Updates extracted public API surface to include SourceMap.css.
.changeset/add-css-sourcemap-option.md Documents the new option and bumps @lynx-js/rspeedy with a patch changeset.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/rspeedy/plugin-react/test/sourcemap.test.ts
Comment thread .changeset/add-css-sourcemap-option.md Outdated
Comment thread packages/rspeedy/plugin-react/test/sourcemap.test.ts
Comment thread packages/rspeedy/plugin-react/test/sourcemap.test.ts
Comment thread packages/rspeedy/plugin-react/test/sourcemap.test.ts
Comment thread packages/rspeedy/plugin-react/test/sourcemap.test.ts
Copy link
Copy Markdown
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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/rspeedy/plugin-react/test/sourcemap.test.ts (1)

5-6: ⚠️ Potential issue | 🟠 Major

Replace fs/promises.glob with a Node.js 18+ compatible alternative.

The package declares "engines": { "node": ">=18" } but fs/promises.glob was introduced in Node.js v22.0.0. The ESLint suppression masks a real runtime error on Node 18–21. Remove the suppression and either update the package's engines field to "node": "^22 || ^24" to match the root requirement, or use a compatible glob utility (e.g., glob npm package) that works across all declared Node versions. Per coding guidelines, ESLint rules must be followed, not suppressed to hide incompatibilities.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rspeedy/plugin-react/test/sourcemap.test.ts` around lines 5 - 6, The
current import uses fs/promises.glob (seen on the import line importing glob,
mkdtemp, readFile) which is only available in Node 22+, so remove the ESLint
suppression and replace the use of fs/promises.glob with a Node‑18 compatible
glob utility: install the "glob" npm package, import its promise API (or
promisify glob) instead of destructuring glob from 'node:fs/promises', keep
mkdtemp and readFile from 'node:fs/promises' as-is, and update any code
referencing the old glob symbol to call the new glob promise function;
alternatively, if you prefer to require Node ≥22, update the package's engines
field to match (e.g., "^22 || ^24") and remove the suppression.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.changeset/add-css-sourcemap-option.md:
- Around line 12-16: The example places sourceMap at the config root; update the
snippet so sourceMap is nested under output by moving the sourceMap block inside
an output object (i.e., use defineConfig with output.sourceMap.css: true) so
enabling CSS sourcemaps actually works; adjust the example to reference output
and the sourceMap.css option rather than a top-level sourceMap.

In `@packages/rspeedy/plugin-react/test/sourcemap.test.ts`:
- Around line 111-123: The helper getSourceMapFiles collects .map paths in
traversal order which can vary; update getSourceMapFiles to sort the resulting
sourceMapFiles array (e.g., lexicographically) before returning so tests
comparing the full array in order are deterministic; locate the function
getSourceMapFiles and add a stable sort on sourceMapFiles (or use .sort()) just
prior to returning the array.
- Around line 169-180: The test passes a 1-based generated column to
SourceMapConsumer.originalPositionFor, causing wrong mappings; update the
cssColumn computation used for cssConsumer.originalPositionFor so it uses the
zero-based index from .indexOf('.app') (remove the +1) and pass that zero-based
column into cssConsumer.originalPositionFor while keeping the line (cssLine) as
1-based; adjust the same for any analogous js/other source column calculations
(referencing cssColumn and cssConsumer.originalPositionFor).

---

Outside diff comments:
In `@packages/rspeedy/plugin-react/test/sourcemap.test.ts`:
- Around line 5-6: The current import uses fs/promises.glob (seen on the import
line importing glob, mkdtemp, readFile) which is only available in Node 22+, so
remove the ESLint suppression and replace the use of fs/promises.glob with a
Node‑18 compatible glob utility: install the "glob" npm package, import its
promise API (or promisify glob) instead of destructuring glob from
'node:fs/promises', keep mkdtemp and readFile from 'node:fs/promises' as-is, and
update any code referencing the old glob symbol to call the new glob promise
function; alternatively, if you prefer to require Node ≥22, update the package's
engines field to match (e.g., "^22 || ^24") and remove the suppression.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 77a1206f-c53b-4d7a-b491-8f91d18d90de

📥 Commits

Reviewing files that changed from the base of the PR and between 5151fcf and 271f725.

📒 Files selected for processing (8)
  • .changeset/add-css-sourcemap-option.md
  • packages/rspeedy/core/etc/rspeedy.api.md
  • packages/rspeedy/core/src/config/output/source-map.ts
  • packages/rspeedy/core/test/config/output.test-d.ts
  • packages/rspeedy/core/test/config/validate.test.ts
  • packages/rspeedy/plugin-react/test/fixtures/sourcemap/index.css
  • packages/rspeedy/plugin-react/test/fixtures/sourcemap/index.tsx
  • packages/rspeedy/plugin-react/test/sourcemap.test.ts

Comment thread .changeset/add-css-sourcemap-option.md
Comment thread packages/rspeedy/plugin-react/test/sourcemap.test.ts Outdated
Comment thread packages/rspeedy/plugin-react/test/sourcemap.test.ts
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 10, 2026

Merging this PR will improve performance by 11.56%

⚡ 1 improved benchmark
✅ 80 untouched benchmarks
⏩ 26 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
transform 1000 view elements 45.5 ms 40.8 ms +11.56%

Comparing luhc228:hc/css-sourcemap-option (019c264) with main (12edf6b)

Open in CodSpeed

Footnotes

  1. 26 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 10, 2026

React External

#501 Bundle Size — 580.35KiB (0%).

019c264(current) vs 95c2dc3 main#499(baseline)

Bundle metrics  no changes
                 Current
#501
     Baseline
#499
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 17 17
No change  Duplicate Modules 5 5
No change  Duplicate Code 8.59% 8.59%
No change  Packages 0 0
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#501
     Baseline
#499
No change  Other 580.35KiB 580.35KiB

Bundle analysis reportBranch luhc228:hc/css-sourcemap-optionProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 10, 2026

React Example

#7384 Bundle Size — 223.33KiB (0%).

019c264(current) vs 95c2dc3 main#7382(baseline)

Bundle metrics  no changes
                 Current
#7384
     Baseline
#7382
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 179 179
No change  Duplicate Modules 69 69
No change  Duplicate Code 44.48% 44.48%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#7384
     Baseline
#7382
No change  IMG 145.76KiB 145.76KiB
No change  Other 77.58KiB 77.58KiB

Bundle analysis reportBranch luhc228:hc/css-sourcemap-optionProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 10, 2026

React MTF Example

#517 Bundle Size — 193.94KiB (0%).

019c264(current) vs 95c2dc3 main#515(baseline)

Bundle metrics  no changes
                 Current
#517
     Baseline
#515
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 173 173
No change  Duplicate Modules 66 66
No change  Duplicate Code 43.94% 43.94%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#517
     Baseline
#515
No change  IMG 111.23KiB 111.23KiB
No change  Other 82.71KiB 82.71KiB

Bundle analysis reportBranch luhc228:hc/css-sourcemap-optionProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 10, 2026

Web Explorer

#8958 Bundle Size — 749.55KiB (0%).

019c264(current) vs 95c2dc3 main#8956(baseline)

Bundle metrics  Change 2 changes
                 Current
#8958
     Baseline
#8956
No change  Initial JS 44.45KiB 44.45KiB
No change  Initial CSS 2.16KiB 2.16KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 8 8
No change  Assets 10 10
Change  Modules 148(-0.67%) 149
No change  Duplicate Modules 11 11
Change  Duplicate Code 34.99%(+0.03%) 34.98%
No change  Packages 3 3
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#8958
     Baseline
#8956
No change  Other 401.63KiB 401.63KiB
No change  JS 345.76KiB 345.76KiB
No change  CSS 2.16KiB 2.16KiB

Bundle analysis reportBranch luhc228:hc/css-sourcemap-optionProject dashboard


Generated by RelativeCIDocumentationReport issue

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Hengchang Lu <luhengchang228@126.com>
@luhc228 luhc228 marked this pull request as ready for review April 18, 2026 02:56
Copy link
Copy Markdown
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.

♻️ Duplicate comments (1)
packages/rspeedy/plugin-react/test/sourcemap.test.ts (1)

197-232: ⚠️ Potential issue | 🟡 Minor

originalPositionFor() still receives 1-based generated columns.

The + 1 on lines 203 and 230 converts the 0-based indexOf() result into a 1-based column. SourceMapConsumer.originalPositionFor({ line, column }) expects column to be 0-based (only line is 1-based), so these lookups are shifted past the token start and can resolve to an adjacent/wrong segment, making the CSS/JS mapping assertions (basename check + inline snapshot) sensitive to minifier/formatter changes.

Suggested fix
       const cssColumn = cssSource
         .split('\n')
         .at(cssLine - 1)!
-        .indexOf('.app') + 1
+        .indexOf('.app')
@@
         backgroundSourceLines.forEach((lineContent, index) => {
           if (lineContent.includes(name)) {
             line = index + 1
-            column = lineContent.indexOf(name) + 1
+            column = lineContent.indexOf(name)
           }
         })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rspeedy/plugin-react/test/sourcemap.test.ts` around lines 197 - 232,
The test is passing 1-based columns to SourceMapConsumer.originalPositionFor (it
adds +1 to indexOf results), which is wrong because originalPositionFor expects
0-based columns; locate the cssColumn computation (the indexOf('.app') + 1 used
before calling cssConsumer.originalPositionFor) and the background lookup that
sets column = lineContent.indexOf(name) + 1 inside the loop (used later with
consumer.originalPositionFor) and change both to use the raw 0-based indexOf
result (remove the +1), keeping line numbers 1-based, and ensure any downstream
code that assumes 1-based columns is adjusted accordingly so mappings resolve to
the correct segment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/rspeedy/plugin-react/test/sourcemap.test.ts`:
- Around line 197-232: The test is passing 1-based columns to
SourceMapConsumer.originalPositionFor (it adds +1 to indexOf results), which is
wrong because originalPositionFor expects 0-based columns; locate the cssColumn
computation (the indexOf('.app') + 1 used before calling
cssConsumer.originalPositionFor) and the background lookup that sets column =
lineContent.indexOf(name) + 1 inside the loop (used later with
consumer.originalPositionFor) and change both to use the raw 0-based indexOf
result (remove the +1), keeping line numbers 1-based, and ensure any downstream
code that assumes 1-based columns is adjusted accordingly so mappings resolve to
the correct segment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5416ace0-4650-44c0-824b-1cc443c03726

📥 Commits

Reviewing files that changed from the base of the PR and between cd01fae and 019c264.

📒 Files selected for processing (1)
  • packages/rspeedy/plugin-react/test/sourcemap.test.ts

@upupming upupming merged commit 97f4ecf into lynx-family:main Apr 20, 2026
76 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants