Skip to content

Log CSS extraction failures as plugin warnings#58

Merged
nstepien merged 1 commit into
mainfrom
warnings
Apr 28, 2026
Merged

Log CSS extraction failures as plugin warnings#58
nstepien merged 1 commit into
mainfrom
warnings

Conversation

@nstepien
Copy link
Copy Markdown
Owner

@nstepien nstepien commented Apr 28, 2026

Summary by CodeRabbit

  • New Features

    • Warning logs now displayed when CSS template literal interpolations cannot be extracted due to complexity or unresolved values, improving error visibility.
  • Documentation

    • Removed completed task from README TODO section.

@nstepien nstepien self-assigned this Apr 28, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

📝 Walkthrough

Walkthrough

The PR adds warning logging to the CSS extraction plugin, emitting warnings when template literal interpolations are complex or unresolved. Test infrastructure is updated to intercept and record these warnings via Rolldown's onLog callback, with test assertions updated to verify warning output. Formatter configuration is enhanced to sort imports, and a completed TODO item is removed from the README.

Changes

Cohort / File(s) Summary
Configuration & Documentation
.oxfmtrc.json, README.md
Formatter configuration now includes sortImports: true. Completed TODO item "Log CSS extraction failures" removed from README.
Core Plugin Logic
src/index.ts
Adds context.warn calls for two scenarios: COMPLEX_INTERPOLATION when interpolation is not a simple identifier, and UNRESOLVED_INTERPOLATION when an identifier cannot be resolved. Reorders existing rolldown imports without changing content.
Test Infrastructure
test/plugin.test.ts
Implements warning log interception via rolldownOptions.onLog, normalizes log paths for snapshot stability, and augments buildWithPlugin return value to include logs array. Test cases updated to assert empty logs for successful extractions or snapshots containing PLUGIN_WARNING objects for skipped extractions.
Test Fixtures
test/fixtures/comprehensive.input.ts, test/fixtures/scoping.input.ts
Import reordering and spacing adjustments aligned with new sort-imports formatter configuration.

Sequence Diagram

sequenceDiagram
    participant Plugin as CSS Plugin<br/>(src/index.ts)
    participant Context as Build Context
    participant Rolldown as Rolldown<br/>(onLog handler)
    participant TestHarness as Test Harness

    Plugin->>Plugin: Encounter CSS template<br/>interpolation
    alt Complex interpolation (not simple identifier)
        Plugin->>Context: context.warn('COMPLEX_INTERPOLATION')
    else Unresolved identifier
        Plugin->>Context: context.warn('UNRESOLVED_INTERPOLATION')
    end
    Context->>Rolldown: Emit log event
    Rolldown->>Rolldown: Normalize log.id &<br/>log.loc.file paths
    Rolldown->>TestHarness: Invoke onLog callback
    TestHarness->>TestHarness: Collect warning<br/>in logs[] array
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 The plugin now whispers of tangles and rifts,
When interpolations prove troublesome gifts,
We gather these warnings with careful refrain,
While sorting imports in orderly chain,
Let logs trace the path where CSS can't remain!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Log CSS extraction failures as plugin warnings' accurately summarizes the main change: adding warning logs when CSS extraction encounters complex or unresolved interpolations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch warnings

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.

Copy link
Copy Markdown

@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.

Caution

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

⚠️ Outside diff range comments (1)
test/plugin.test.ts (1)

6-35: ⚠️ Potential issue | 🟡 Minor

Normalize Windows paths before matching /test/.

The normalize() function is incomplete for Windows compatibility. On Windows, Rolldown paths contain backslashes (e.g., C:\...\test\file.ts), so the regex /^.*\/test\// will not match. This causes snapshot drift on Windows runners. The codebase already normalizes backslashes in src/index.ts for the same reason—apply the same pattern here.

♻️ Suggested fix
-const normalize = (path: string) => path.replace(/^.*\/test\//, 'test/');
+const normalize = (value: string) =>
+  value.replace(/\\/g, '/').replace(/^.*\/test\//, 'test/');
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/plugin.test.ts` around lines 6 - 35, The normalize function in
test/plugin.test.ts doesn't handle Windows backslashes so its regex
/^.*\/test\// won't match paths like C:\...\test\file.ts; update normalize (used
by buildWithPlugin) to first replace backslashes with forward slashes (or use a
regex that accepts both separators) before applying the existing /^.*\/test\//
replacement so ids and loc.file values are normalized consistently across
platforms.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@test/plugin.test.ts`:
- Around line 6-35: The normalize function in test/plugin.test.ts doesn't handle
Windows backslashes so its regex /^.*\/test\// won't match paths like
C:\...\test\file.ts; update normalize (used by buildWithPlugin) to first replace
backslashes with forward slashes (or use a regex that accepts both separators)
before applying the existing /^.*\/test\// replacement so ids and loc.file
values are normalized consistently across platforms.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9b5995b8-6220-4fb3-a416-8d0886d78a03

📥 Commits

Reviewing files that changed from the base of the PR and between 06e2979 and 6e1da92.

📒 Files selected for processing (6)
  • .oxfmtrc.json
  • README.md
  • src/index.ts
  • test/fixtures/comprehensive.input.ts
  • test/fixtures/scoping.input.ts
  • test/plugin.test.ts
💤 Files with no reviewable changes (1)
  • README.md

@nstepien nstepien merged commit ac058d0 into main Apr 28, 2026
6 checks passed
@nstepien nstepien deleted the warnings branch April 28, 2026 22:34
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.

1 participant