@@ -17,7 +17,7 @@ import {
17
17
generateCodeFrame ,
18
18
} from '../utils'
19
19
import type { ResolvedConfig } from '../config'
20
- import type { Plugin , PluginContext } from '../plugin'
20
+ import type { Plugin } from '../plugin'
21
21
import { cleanUrl } from '../../shared/utils'
22
22
import type { Environment , Logger } from '..'
23
23
import type { ViteDevServer } from '../server'
@@ -46,14 +46,14 @@ export interface OxcOptions
46
46
}
47
47
48
48
export async function transformWithOxc (
49
- ctx : PluginContext | undefined ,
50
49
code : string ,
51
50
filename : string ,
52
51
options ?: OxcTransformOptions ,
53
52
inMap ?: object ,
54
53
config ?: ResolvedConfig ,
55
54
watcher ?: FSWatcher ,
56
- ) : Promise < OxcTransformResult > {
55
+ ) : Promise < Omit < OxcTransformResult , 'errors' > & { warnings : string [ ] } > {
56
+ const warnings : string [ ] = [ ]
57
57
let lang = options ?. lang
58
58
59
59
if ( ! lang ) {
@@ -164,7 +164,7 @@ export async function transformWithOxc(
164
164
resolvedOptions . typescript ??= { }
165
165
resolvedOptions . typescript . onlyRemoveTypeImports = false
166
166
} else {
167
- ctx ?. warn (
167
+ warnings . push (
168
168
`preserveValueImports=${ preserveValueImports } + importsNotUsedAsValues=${ importsNotUsedAsValues } is not supported by oxc.` +
169
169
'Please migrate to the new verbatimModuleSyntax option.' ,
170
170
)
@@ -217,7 +217,7 @@ export async function transformWithOxc(
217
217
}
218
218
219
219
if ( set ) {
220
- ctx ?. warn (
220
+ warnings . push (
221
221
'target was modified to include ES2022' +
222
222
' because useDefineForClassFields is set to false' +
223
223
' and oxc does not support transforming useDefineForClassFields=false for ES2022+ yet' ,
@@ -271,6 +271,7 @@ export async function transformWithOxc(
271
271
return {
272
272
...result ,
273
273
map,
274
+ warnings,
274
275
}
275
276
}
276
277
@@ -350,7 +351,6 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
350
351
this . environment ,
351
352
)
352
353
const result = await transformWithOxc (
353
- this ,
354
354
code ,
355
355
id ,
356
356
modifiedOxcTransformOptions ,
@@ -361,6 +361,9 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
361
361
if ( jsxInject && jsxExtensionsRE . test ( id ) ) {
362
362
result . code = jsxInject + ';' + result . code
363
363
}
364
+ for ( const warning of result . warnings ) {
365
+ this . environment . logger . warnOnce ( warning )
366
+ }
364
367
return {
365
368
code : result . code ,
366
369
map : result . map ,
@@ -391,13 +394,15 @@ export const buildOxcPlugin = (): Plugin => {
391
394
}
392
395
393
396
const res = await transformWithOxc (
394
- this ,
395
397
code ,
396
398
chunk . fileName ,
397
399
options ,
398
400
undefined ,
399
401
config ,
400
402
)
403
+ for ( const warning of res . warnings ) {
404
+ this . environment . logger . warnOnce ( warning )
405
+ }
401
406
402
407
const runtimeHelpers = Object . entries ( res . helpersUsed )
403
408
if ( runtimeHelpers . length > 0 ) {
0 commit comments