@@ -81,13 +81,29 @@ const importEsbuild = () => {
81
81
return esbuild
82
82
}
83
83
84
+ let warnedTransformWithEsbuild = false
85
+ const warnTransformWithEsbuildUsageOnce = ( ) => {
86
+ if ( warnedTransformWithEsbuild ) return
87
+ warnedTransformWithEsbuild = true
88
+
89
+ // eslint-disable-next-line no-console -- logger cannot be used here
90
+ console . warn (
91
+ colors . yellow (
92
+ '`transformWithEsbuild` is deprecated and will be removed in the future. ' +
93
+ 'Please migrate to `transformWithOxc`.' ,
94
+ ) ,
95
+ )
96
+ }
97
+
84
98
export async function transformWithEsbuild (
85
99
code : string ,
86
100
filename : string ,
87
101
options ?: EsbuildTransformOptions ,
88
102
inMap ?: object ,
89
103
config ?: ResolvedConfig ,
90
104
watcher ?: FSWatcher ,
105
+ /** @internal */
106
+ ignoreEsbuildWarning = false ,
91
107
) : Promise < ESBuildTransformResult > {
92
108
let loader = options ?. loader
93
109
@@ -202,8 +218,23 @@ export async function transformWithEsbuild(
202
218
// @ts -expect-error jsxInject exists in ESBuildOptions
203
219
delete resolvedOptions . jsxInject
204
220
221
+ let transform : typeof import ( 'esbuild' ) . transform
222
+ try {
223
+ transform = ( await importEsbuild ( ) ) . transform
224
+ } catch ( e ) {
225
+ throw new Error (
226
+ 'Failed to load `transformWithEsbuild`. ' +
227
+ 'It is deprecated and it now requires esbuild to be installed separately. ' +
228
+ 'If you are a package author, please migrate to `transformWithOxc` instead.' ,
229
+ { cause : e } ,
230
+ )
231
+ }
232
+
233
+ if ( ! ignoreEsbuildWarning ) {
234
+ warnTransformWithEsbuildUsageOnce ( )
235
+ }
236
+
205
237
try {
206
- const { transform } = await importEsbuild ( )
207
238
const result = await transform ( code , resolvedOptions )
208
239
let map : SourceMap
209
240
if ( inMap && resolvedOptions . sourcemap ) {
@@ -350,6 +381,8 @@ export const buildEsbuildPlugin = (): Plugin => {
350
381
options ,
351
382
undefined ,
352
383
config ,
384
+ undefined ,
385
+ true ,
353
386
)
354
387
355
388
if ( config . build . lib ) {
0 commit comments