Skip to content

feat: support custom source map implementations - #1

Merged
intellild merged 9 commits into
masterfrom
codex/rebase-pr-1289
Oct 22, 2026
Merged

intellild merged 9 commits into
masterfrom
codex/rebase-pr-1289

Conversation

@intellild

@intellild intellild commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Support custom source map implementations so consumers such as Rspack can write mappings directly into their own representation instead of generating a Parcel source map and converting it afterward.

This brings parcel-bundler/lightningcss#1289, rebased onto current master (5aec9d4), into this repository.

  • Generalize ToCss over the sealed PrinterTrait and introduce the SourceMap writer abstraction.
  • Split custom writers behind custom_sourcemap; the default sourcemap feature continues to provide the Parcel implementation, while bundler can use custom maps without requiring it.
  • Preserve writer-assigned source indices when bundling, including prepopulated maps, deduplicated paths, and inline source map remapping.
  • Adapt the printer refactor to upstream's NonNegative values and ordered CSS Modules exports/references.
  • Preserve the fork's rspack_lightningcss package name, 0.1.0 version, and release configuration; adapt examples, benchmarks, the lockfile, and new source map tests to the renamed crate.

Examples

A bundler with its own map type can enable custom_sourcemap (or bundler) with default features disabled, implement rspack_lightningcss::printer::SourceMap, and pass its writer directly:

let mut map = MySourceMap::default();
let result = stylesheet.to_css(PrinterOptions::default(), Some(&mut map))?;

Avoiding the intermediate Parcel map removes the map conversion step and allows consumers to omit the built-in map dependency. With source map support enabled, callers that do not need a map pass None::<&mut ()>.

A custom writer may return source indices such as 100 and 110, or reuse an existing index for two equivalent paths. The bundler keeps internal stylesheet indices separate and translates them to these writer indices when emitting mappings.

The printer trait also needs to preserve generated line positions: its default std::fmt::Write::write_char implementation wrote blank lines without incrementing the map's generated line. Delegating to the printer's existing character writer restores the original positions; the CLI source map regression test now passes. The custom at-rule example also converts formatting errors to PrinterError.

Validation

  • cargo fmt --all -- --check and git diff --check: passed.
  • cargo test --all-features: 172 tests passed, including CLI source maps, custom bundler source indices, and doctests.
  • cargo check --lib --no-default-features: passed with no extra features and separately with custom_sourcemap, bundler, and serde.
  • cargo clippy --all-targets --all-features: completed with warnings.
  • cargo check --workspace --all-targets --features rspack_lightningcss/cli,rspack_lightningcss/jsonschema,rspack_lightningcss/serde,rspack_lightningcss/visitor,rspack_lightningcss/into_owned,rspack_lightningcss/substitute_variables: passed.
  • Workspace clippy is blocked by existing not_unsafe_ptr_arg_deref errors from #[js_function(1)] in unchanged node/src/lib.rs (lines 18 and 24). The selectors bench feature also requires nightly and was excluded from the stable workspace checks.
  • Revalidated after rebasing onto 5aec9d4: the full Rust suite, four library feature configurations, core clippy, and workspace compilation passed using the locked dependencies.

by OpenAI Codex

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T09:47:56.213545Z e7e0071 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@intellild
intellild force-pushed the codex/rebase-pr-1289 branch from e7e0071 to 1aeaa9d Compare October 21, 2026 08:39
@codspeed

codspeed Bot commented Oct 21, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 4 untouched benchmarks
🆕 8 new benchmarks
⏩ 4 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 no-source-map[conditional-run] N/A 13.6 ms N/A
🆕 no-source-map[large] N/A 39.5 ms N/A
🆕 no-source-map[medium] N/A 10 ms N/A
🆕 no-source-map[small] N/A 229.1 µs N/A
🆕 source-map[conditional-run] N/A 13.9 ms N/A
🆕 source-map[large] N/A 40 ms N/A
🆕 source-map[medium] N/A 10.2 ms N/A
🆕 source-map[small] N/A 234.1 µs N/A

Comparing codex/rebase-pr-1289 (1aeaa9d) with master (5aec9d4)

Open in CodSpeed

Footnotes

  1. 4 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. ↩

@intellild
intellild merged commit 31d1f8d into master Oct 22, 2026
5 checks passed
intellild added a commit that referenced this pull request Oct 22, 2026
Keep the shared custom-property extraction imports alongside the PrinterTrait refactor from PR #1.
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