Skip to content

Commit f901731

Browse files
committed
Revert "fix(unpluing-vue-i18n): Support for transform.handler in vite:json plugin (#484)"
This reverts commit 03e03a7.
1 parent 4a955df commit f901731

File tree

2 files changed

+4
-55
lines changed

2 files changed

+4
-55
lines changed

packages/unplugin-vue-i18n/src/core/resource.ts

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,7 @@ import { createHash } from 'node:crypto'
1515
import fs from 'node:fs'
1616
import { dirname, parse as parsePath, resolve } from 'node:path'
1717
import { parse } from 'vue/compiler-sfc'
18-
import {
19-
checkVuePlugin,
20-
error,
21-
getVitePlugin,
22-
getVitePluginTransform,
23-
overrideVitePluginTransform,
24-
raiseError,
25-
resolveNamespace,
26-
warn
27-
} from '../utils'
18+
import { checkVuePlugin, error, getVitePlugin, raiseError, resolveNamespace, warn } from '../utils'
2819
import { getVueCompiler, parseVueRequest } from '../vue'
2920

3021
import type { CodeGenOptions, CodeGenResult } from '@intlify/bundle-utils'
@@ -178,23 +169,12 @@ export function resourcePlugin(opts: ResolvedOptions, meta: UnpluginContextMeta)
178169
ctx.sourceMap = config.command === 'build' ? !!config.build.sourcemap : false
179170
debug(`configResolved: isProduction = ${ctx.prod}, sourceMap = ${ctx.sourceMap}`)
180171

181-
/**
182-
* NOTE:
183-
* For the native rolldown plugin, we need to change to another solution from the current workaround.
184-
* Currently, the rolldown team and vite team are discussing this issue.
185-
* https://github.com/vitejs/rolldown-vite/issues/120
186-
*/
187-
188172
// json transform handling
189173
const jsonPlugin = getVitePlugin(config, 'vite:json')
190174
if (jsonPlugin) {
191-
// saving `vite:json` plugin instance
192-
const [orgTransform, transformWay] = getVitePluginTransform(jsonPlugin)
193-
if (!orgTransform) {
194-
throw new Error('vite:json plugin not found!')
195-
}
196-
197-
async function overrideViteJsonPlugin(code: string, id: string) {
175+
// backup @rollup/plugin-json
176+
const orgTransform = jsonPlugin.transform
177+
jsonPlugin.transform = async function (code: string, id: string) {
198178
if (!/\.json$/.test(id) || filter(id)) {
199179
return
200180
}
@@ -216,9 +196,6 @@ export function resourcePlugin(opts: ResolvedOptions, meta: UnpluginContextMeta)
216196
// @ts-expect-error
217197
return orgTransform!.apply(this, [code, id])
218198
}
219-
220-
// override `vite:json` plugin transform function
221-
overrideVitePluginTransform(jsonPlugin, overrideViteJsonPlugin, transformWay!)
222199
}
223200
}
224201
},

packages/unplugin-vue-i18n/src/utils/plugin.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,6 @@ export function getVitePlugin(config: UserConfig, name: string): RollupPlugin |
1515
return config.plugins.find(p => p.name === name) as RollupPlugin
1616
}
1717

18-
export function getVitePluginTransform(
19-
plugin: RollupPlugin
20-
): [RollupPlugin['transform'], 'handler' | 'transform' | undefined] {
21-
if (plugin.transform) {
22-
return 'handler' in plugin.transform
23-
? [plugin.transform.handler, 'handler']
24-
: [plugin.transform, 'transform']
25-
} else {
26-
return [undefined, undefined]
27-
}
28-
}
29-
30-
// TODO: `override` type, we need more strict type
31-
export function overrideVitePluginTransform(
32-
plugin: RollupPlugin,
33-
override: Function,
34-
to: 'handler' | 'transform'
35-
): void {
36-
if (plugin.transform == undefined) {
37-
throw new Error('plugin.transform is undefined')
38-
}
39-
if (to === 'handler' && 'handler' in plugin.transform) {
40-
plugin.transform.handler = override as typeof plugin.transform.handler
41-
} else {
42-
plugin.transform = override as typeof plugin.transform
43-
}
44-
}
45-
4618
export function checkVuePlugin(vuePlugin: RollupPlugin | null): boolean {
4719
if (vuePlugin == null || !vuePlugin.api) {
4820
error(

0 commit comments

Comments
 (0)