Skip to content

fix(rspack): keep binary files intact and allow emitFile from buildEnd - #630

Merged
antfu merged 3 commits into
unjs:mainfrom
antfubot:fix/rspack-loader-parity
Oct 27, 2026
Merged

antfu merged 3 commits into
unjs:mainfrom
antfubot:fix/rspack-loader-parity

Conversation

@antfubot

@antfubot antfubot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements plans/002-rspack-loader-parity.md: two webpack fixes that never reached rspack.

Tests

  • Loader unit tests ported from the webpack twins (raw flag, binary pass-through with the handler not called, Buffer → string for the handler).
  • New test/unit-tests/binary-assets builds a project importing a PNG via asset/resource through an unfiltered plugin on webpack and rspack and asserts the emitted bytes equal the input. On main the rspack case fails (11-byte PNG comes out as 17 bytes); the loader unit tests alone can't show that because they don't exercise rspack's loader-runner.
  • buildEnd → emitFile integration test extended to rspack, asserting buildEnd runs before emit and the asset lands on disk. Fails on main with expected true to be false (emit had already started).

pnpm test → 208 passed; lint/typecheck green.


Created with the help of an agent.

Summary by CodeRabbit

  • Bug Fixes
    • Preserved binary assets through load and transform hooks in both Webpack and Rspack, avoiding changes to non-text file contents.
    • Rspack’s build-end hook now runs during asset processing, allowing it to emit assets before the compiler’s emit phase.
  • Chores
    • Updated the execution plan status to DONE.

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

The Rspack loaders now accept raw Buffer input, and buildEnd runs during the compilation’s processAssets hook. Tests cover binary asset preservation and the Rspack build lifecycle. Plan 002’s status changed to DONE.

Changes: Rspack compatibility

Layer / File(s) Summary
Raw loader input and binary pass-through
src/rspack/loaders/load.ts, src/rspack/loaders/transform.ts, test/unit-tests/rspack/loaders/*, test/unit-tests/binary-assets/binary-assets.test.ts
The Rspack loaders accept raw Buffer input. Tests check that unhandled binary sources pass through unchanged, that matching transform hooks receive decoded text, and that emitted PNG bytes match the input in Webpack and Rspack.
buildEnd lifecycle
src/rspack/index.ts, test/unit-tests/build-end/build-end.test.ts, plans/README.md
The Rspack adapter awaits buildEnd during processAssets at the additional-assets stage. The integration test checks that the emit hook has not started and verifies the emitted JSON. Plan 002’s status is now DONE.

Priority: Not assessed

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • unjs/unplugin#524 — Reports binary asset corruption when a loader passes through an unhandled source. This PR adds raw-input handling and binary pass-through for the Rspack loaders.

Possibly related PRs

  • unjs/unplugin#619 — Moves Webpack buildEnd to processAssets; this PR applies the corresponding lifecycle change to Rspack.
  • unjs/unplugin#623 — Adds binary preservation to the Webpack loaders; this PR adds corresponding raw-input handling to the Rspack loaders.
  • unjs/unplugin#608 — Adds an Rsbuild adapter that reuses Rspack hook wiring, which this PR changes.

Suggested reviewers: sxzz, antfu

Merge Risk: Minimal · up to 24c3d

The Rspack compatibility changes appear ready to merge after normal checks.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/rspack/index.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/rspack/loaders/load.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

src/rspack/loaders/transform.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

  • 4 others

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.

@pkg-pr-new

pkg-pr-new Bot commented Oct 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/unjs/unplugin@630

commit: 24c3d24

@antfu
antfu merged commit 0ecc344 into unjs:main Oct 27, 2026
12 of 13 checks passed
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.

2 participants