-
-
Notifications
You must be signed in to change notification settings - Fork 44
fix(unpluing-vue-i18n): Support for transform.handler in vite:json plugin
#484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the handling of the Vite JSON plugin to support the new transform.handler hook introduced in Vite 6.3, in preparation for Vite 7.
- Introduces helper functions getVitePluginTransform and overrideVitePluginTransform to manage different transform hook types.
- Updates the resource plugin to use the new transform override mechanism for the vite:json plugin.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/unplugin-vue-i18n/src/utils/plugin.ts | Adds utility functions to extract and override the Vite plugin transform hook based on the new handler pattern. |
| packages/unplugin-vue-i18n/src/core/resource.ts | Adapts the JSON transform handling in the resource plugin to leverage the new transform override utilities. |
| // TODO: `override` type, we need more strict type | ||
| export function overrideVitePluginTransform( | ||
| plugin: RollupPlugin, | ||
| override: Function, | ||
| to: 'handler' | 'transform' |
Copilot
AI
Apr 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Refine the type for the override parameter to improve type safety and prevent potential runtime issues.
| // TODO: `override` type, we need more strict type | |
| export function overrideVitePluginTransform( | |
| plugin: RollupPlugin, | |
| override: Function, | |
| to: 'handler' | 'transform' | |
| // TODO: Refined `override` type for stricter type safety | |
| export function overrideVitePluginTransform< | |
| T extends 'handler' | 'transform' | |
| >( | |
| plugin: RollupPlugin, | |
| override: T extends 'handler' | |
| ? typeof plugin.transform extends { handler: infer H } | |
| ? H | |
| : never | |
| : typeof plugin.transform, | |
| to: T |
| } | ||
|
|
||
| // override `vite:json` plugin transform function | ||
| overrideVitePluginTransform(jsonPlugin, overrideViteJsonPlugin, transformWay!) |
Copilot
AI
Apr 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a non-null assertion on transformWay, consider validating its presence before overriding to ensure more robust error handling.
| overrideVitePluginTransform(jsonPlugin, overrideViteJsonPlugin, transformWay!) | |
| overrideVitePluginTransform(jsonPlugin, overrideViteJsonPlugin, transformWay) |
Description
In vite 6.3, the handling of plugin hooks has been changed from transform to transform.handler internally.
Currently, vite is minimizing the impact on end users through a patch, but in vite 7, the patch for transform will be removed.
Linked Issues
Additional context
Rollup used internally in Vite will be replaced by Rolldown in the future. Rolldown plans to provide JSON transform plugin natively, but the current workaround that hijacks the unplugin-vue-i18n Vite JSON plugin cannot be used.
Regarding this issue, the Rolldown team and Vite team are currently discussing a workaround mechanism at the following URL.
vitejs/rolldown-vite#120