You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(rspack): keep binary files intact and allow emitFile from buildEnd - #630
Implements plans/002-rspack-loader-parity.md: two webpack fixes that never reached rspack.
Binary files survive the rspack loaders.fix(webpack): keep binary files intact in the load and transform loaders #623 made the webpack load/transform loaders raw so images and fonts the hook doesn't handle are passed on as a Buffer instead of being decoded as UTF-8 and corrupted (Binary file corruption: unplugin treats binary files as text #524). The rspack loaders are near-copies and were not changed, so rspack and Rsbuild users with an unfiltered load/transform hook still got corrupted assets. Both rspack loaders now export raw = true and give the hook a string while passing the original source through untouched.
buildEnd can emit assets on rspack.fix(webpack): allow emitting assets from buildEnd #619 moved webpack's buildEnd to the processAssets compilation hook so this.emitFile() works there; rspack still tapped compiler.hooks.emit, where emitAsset is too late. rspack now taps processAssets at PROCESS_ASSETS_STAGE_ADDITIONAL too.
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.
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements
plans/002-rspack-loader-parity.md: two webpack fixes that never reached rspack.load/transformloaders raw so images and fonts the hook doesn't handle are passed on as aBufferinstead of being decoded as UTF-8 and corrupted (Binary file corruption: unplugin treats binary files as text #524). The rspack loaders are near-copies and were not changed, so rspack and Rsbuild users with an unfilteredload/transformhook still got corrupted assets. Both rspack loaders now exportraw = trueand give the hook a string while passing the original source through untouched.buildEndcan emit assets on rspack. fix(webpack): allow emitting assets from buildEnd #619 moved webpack'sbuildEndto theprocessAssetscompilation hook sothis.emitFile()works there; rspack still tappedcompiler.hooks.emit, whereemitAssetis too late. rspack now tapsprocessAssetsatPROCESS_ASSETS_STAGE_ADDITIONALtoo.Tests
rawflag, binary pass-through with the handler not called,Buffer→ string for the handler).test/unit-tests/binary-assetsbuilds a project importing a PNG viaasset/resourcethrough an unfiltered plugin on webpack and rspack and asserts the emitted bytes equal the input. Onmainthe 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→emitFileintegration test extended to rspack, assertingbuildEndruns beforeemitand the asset lands on disk. Fails onmainwithexpected true to be false(emit had already started).pnpm test→ 208 passed;lint/typecheckgreen.Created with the help of an agent.
Summary by CodeRabbit