Fix TransformContext.code type to support Buffer when raw=true#6019
Fix TransformContext.code type to support Buffer when raw=true#6019
Conversation
|
|
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Co-authored-by: chenjiahan <7237365+chenjiahan@users.noreply.github.com>
|
@copilot finish this PR |
Co-authored-by: chenjiahan <7237365+chenjiahan@users.noreply.github.com>
Fixed the Buffer type handling issue in transformLoader.ts and completed the PR. The fix adds proper type assertion |
|
@copilot but this loader does not set |
You're correct that |
|
@copilot The plugin author should expect to receive Buffer-type code when |
Co-authored-by: chenjiahan <7237365+chenjiahan@users.noreply.github.com>
You're absolutely right. I reverted the incorrect Buffer-to-string conversion and instead fixed the type definition of |
|
Duplicated: #6017 |

Fixed a type definition issue in
TransformContext.codewhere the type was defined asstringbut runtime behavior could passBufferobjects when transform descriptors haveraw: true.Problem
The
TransformContext.codetype was defined asstringin the type system, but when a transform descriptor specifiesraw: true, the system usestransformRawLoader.mjswhich passesBufferobjects to transform handlers. This created a type mismatch where plugin authors expecting to handle Buffer objects when usingraw: truewould get TypeScript errors.Solution
Updated the type definition of
TransformContext.codefromstringtostring | Bufferto accurately reflect the runtime behavior:This ensures that:
The fix maintains backward compatibility while providing accurate typing for the
raw: trueuse case.💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.