Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(unplugin): emit column-accurate sourcemaps - #563

Merged
antfu merged 1 commit into
unjs:mainfrom
official-burak:fix/unplugin-sourcemap-columns
Sep 8, 2026
Merged

fix(unplugin): emit column-accurate sourcemaps#563
antfu merged 1 commit into
unjs:mainfrom
official-burak:fix/unplugin-sourcemap-columns

Conversation

@official-burak

@official-burak official-burak commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

unplugin's transform called MagicString#generateMap() with no options, so the map had one mapping per line (all at column 0) and sources: [""]. Auto-imports are prepended, so line numbers still roughly line up, but V8 coverage (@vitest/coverage-v8) drops any module that references an auto-imported global and reports 100% (0/0).

Pass { hires: 'boundary', source: id }. hires: 'boundary' matched hires: true for coverage in the report while producing a smaller map.

Fixes #562

Test plan

  • test/unplugin.test.ts: injected import is present, map.sources is the module id, and mappings have more than one segment on at least one line
  • Unchanged files still skip the transform
  • pnpm vitest run (237 tests)

Bare generateMap() collapses every mapping to column 0, so V8 coverage
drops modules that use auto-imports. Pass hires: 'boundary' and source.
@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 12ff6256-30d6-4dde-9ccf-941a6eb443f3

📥 Commits

Reviewing files that changed from the base of the PR and between a86212a and 57f3bb3.

📒 Files selected for processing (2)
  • src/unplugin.ts
  • test/unplugin.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The unplugin transform now emits boundary-level, column-aware source maps with the input file as the source. New tests verify import injection, source-map accuracy, and undefined results when no auto-import is used.

Changes

Unplugin sourcemap precision

Layer / File(s) Summary
Boundary-level sourcemap generation
src/unplugin.ts
The transform generates source maps with boundary-level mappings and the input file identifier.
Transform and sourcemap validation
test/unplugin.test.ts
Tests verify plugin transformation, injected imports, populated sources, column-level mappings, and undefined results without auto-import usage.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 57f3b

This change makes generated sourcemaps column-accurate and associates them with the transformed module while preserving unchanged-file behavior; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy issue #562 by generating boundary-level, column-accurate sourcemaps with source id populated. The tests verify injected imports, source mapping, multiple mapping segments, and unch…
Out of Scope Changes check ✅ Passed All changes are within scope. The source change fixes unplugin sourcemap generation, and the added tests validate the linked issue requirements.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: emitting column-accurate sourcemaps for the unplugin transform.
Full details: Linked Issues check

Explanation

The changes satisfy issue #562 by generating boundary-level, column-accurate sourcemaps with source id populated. The tests verify injected imports, source mapping, multiple mapping segments, and unchanged-file behavior.

  • Fix all pre-merge checks with AI
✨ 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.

@antfu
antfu merged commit febe97a into unjs:main Sep 8, 2026
1 of 4 checks passed
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.60%. Comparing base (a4a5e0a) to head (57f3bb3).
⚠️ Report is 187 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #563      +/-   ##
==========================================
- Coverage   98.73%   94.60%   -4.13%     
==========================================
  Files          14       15       +1     
  Lines        1817     1076     -741     
  Branches      374      363      -11     
==========================================
- Hits         1794     1018     -776     
- Misses         23       52      +29     
- Partials        0        6       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

unplugin's transform emits a line-only sourcemap (generateMap() with no options), silently collapsing code coverage

2 participants