Skip to content

Commit 2ec5a00

Browse files
committed
chore: dedupe OXC warnings
1 parent 618dfca commit 2ec5a00

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

packages/vite/src/node/optimizer/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,6 @@ export async function extractExportsData(
10951095
throw new Error(`Unable to parse : ${filePath}.`)
10961096
}
10971097
const transformed = await transformWithOxc(
1098-
undefined,
10991098
entryContent,
11001099
filePath,
11011100
{ lang },

packages/vite/src/node/plugins/oxc.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
generateCodeFrame,
1818
} from '../utils'
1919
import type { ResolvedConfig } from '../config'
20-
import type { Plugin, PluginContext } from '../plugin'
20+
import type { Plugin } from '../plugin'
2121
import { cleanUrl } from '../../shared/utils'
2222
import type { Environment, Logger } from '..'
2323
import type { ViteDevServer } from '../server'
@@ -46,14 +46,14 @@ export interface OxcOptions
4646
}
4747

4848
export async function transformWithOxc(
49-
ctx: PluginContext | undefined,
5049
code: string,
5150
filename: string,
5251
options?: OxcTransformOptions,
5352
inMap?: object,
5453
config?: ResolvedConfig,
5554
watcher?: FSWatcher,
56-
): Promise<OxcTransformResult> {
55+
): Promise<Omit<OxcTransformResult, 'errors'> & { warnings: string[] }> {
56+
const warnings: string[] = []
5757
let lang = options?.lang
5858

5959
if (!lang) {
@@ -164,7 +164,7 @@ export async function transformWithOxc(
164164
resolvedOptions.typescript ??= {}
165165
resolvedOptions.typescript.onlyRemoveTypeImports = false
166166
} else {
167-
ctx?.warn(
167+
warnings.push(
168168
`preserveValueImports=${preserveValueImports} + importsNotUsedAsValues=${importsNotUsedAsValues} is not supported by oxc.` +
169169
'Please migrate to the new verbatimModuleSyntax option.',
170170
)
@@ -217,7 +217,7 @@ export async function transformWithOxc(
217217
}
218218

219219
if (set) {
220-
ctx?.warn(
220+
warnings.push(
221221
'target was modified to include ES2022' +
222222
' because useDefineForClassFields is set to false' +
223223
' and oxc does not support transforming useDefineForClassFields=false for ES2022+ yet',
@@ -271,6 +271,7 @@ export async function transformWithOxc(
271271
return {
272272
...result,
273273
map,
274+
warnings,
274275
}
275276
}
276277

@@ -350,7 +351,6 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
350351
this.environment,
351352
)
352353
const result = await transformWithOxc(
353-
this,
354354
code,
355355
id,
356356
modifiedOxcTransformOptions,
@@ -361,6 +361,9 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
361361
if (jsxInject && jsxExtensionsRE.test(id)) {
362362
result.code = jsxInject + ';' + result.code
363363
}
364+
for (const warning of result.warnings) {
365+
this.environment.logger.warnOnce(warning)
366+
}
364367
return {
365368
code: result.code,
366369
map: result.map,
@@ -391,13 +394,15 @@ export const buildOxcPlugin = (): Plugin => {
391394
}
392395

393396
const res = await transformWithOxc(
394-
this,
395397
code,
396398
chunk.fileName,
397399
options,
398400
undefined,
399401
config,
400402
)
403+
for (const warning of res.warnings) {
404+
this.environment.logger.warnOnce(warning)
405+
}
401406

402407
const runtimeHelpers = Object.entries(res.helpersUsed)
403408
if (runtimeHelpers.length > 0) {

0 commit comments

Comments
 (0)