Skip to content

Commit 1ee5c7f

Browse files
shulaodasapphi-red
andauthored
feat: update rolldown to 1.0.0-rc.4 (vitejs#21617)
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
1 parent 1766931 commit 1ee5c7f

File tree

9 files changed

+195
-122
lines changed

9 files changed

+195
-122
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"picocolors": "^1.1.1",
6565
"playwright-chromium": "^1.58.2",
6666
"prettier": "3.8.1",
67-
"rolldown": "1.0.0-rc.3",
67+
"rolldown": "1.0.0-rc.4",
6868
"rollup": "^4.43.0",
6969
"simple-git-hooks": "^2.13.1",
7070
"tsx": "^4.21.0",

packages/vite/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@
7373
},
7474
"//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
7575
"dependencies": {
76-
"@oxc-project/runtime": "0.112.0",
76+
"@oxc-project/runtime": "0.113.0",
7777
"fdir": "^6.5.0",
7878
"lightningcss": "^1.31.1",
7979
"picomatch": "^4.0.3",
8080
"postcss": "^8.5.6",
81-
"rolldown": "1.0.0-rc.3",
81+
"rolldown": "1.0.0-rc.4",
8282
"tinyglobby": "^0.2.15"
8383
},
8484
"optionalDependencies": {
@@ -88,7 +88,7 @@
8888
"@babel/parser": "^7.29.0",
8989
"@jridgewell/remapping": "^2.3.5",
9090
"@jridgewell/trace-mapping": "^0.3.31",
91-
"@oxc-project/types": "0.112.0",
91+
"@oxc-project/types": "0.113.0",
9292
"@polka/compression": "^1.0.0-next.25",
9393
"@rollup/plugin-alias": "^5.1.1",
9494
"@rollup/plugin-commonjs": "^29.0.0",

packages/vite/rolldown.dts.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ const identifierReplacements: Record<string, Record<string, string>> = {
8383
Plugin$1: 'Rolldown.Plugin',
8484
TransformResult$1: 'Rolldown.TransformResult',
8585
},
86-
'rolldown/experimental': {
87-
TransformOptions$1: 'rolldown_experimental_TransformOptions',
88-
TransformResult$2: 'rolldown_experimental_TransformResult',
86+
'rolldown/utils': {
87+
TransformOptions$1: 'rolldown_utils_TransformOptions',
88+
TransformResult$2: 'rolldown_utils_TransformResult',
8989
},
9090
'node:http': {
9191
Server$1: 'http.Server',

packages/vite/src/node/__tests__/plugins/define.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe.skipIf(!process.env._VITE_TEST_JS_PLUGIN)('definePlugin', () => {
9292
// assert that the default behavior is to replace import.meta.hot with undefined
9393
const transform = await createDefinePluginTransform()
9494
expect(await transform('export const hot = import.meta.hot;')).toBe(
95-
'export const hot = void 0;\n',
95+
'export const hot = undefined;\n',
9696
)
9797
// assert that we can specify a user define to preserve import.meta.hot
9898
const overrideTransform = await createDefinePluginTransform({

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import fs from 'node:fs'
22
import fsp from 'node:fs/promises'
33
import path from 'node:path'
44
import { performance } from 'node:perf_hooks'
5-
import { scan, transformSync } from 'rolldown/experimental'
5+
import { scan } from 'rolldown/experimental'
6+
import { transformSync } from 'rolldown/utils'
67
import type { PartialResolvedId, Plugin } from 'rolldown'
78
import colors from 'picocolors'
89
import { glob } from 'tinyglobby'
@@ -386,7 +387,10 @@ function rolldownScanPlugin(
386387
let transpiledContents: string
387388
// transpile because `transformGlobImport` only expects js
388389
if (loader !== 'js') {
389-
const result = transformSync(id, contents, { lang: loader })
390+
const result = transformSync(id, contents, {
391+
lang: loader,
392+
tsconfig: false,
393+
})
390394
if (result.errors.length > 0) {
391395
throw new AggregateError(result.errors, 'oxc transform error')
392396
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { transformSync } from 'rolldown/experimental'
1+
import { transformSync } from 'rolldown/utils'
22
import type { ResolvedConfig } from '../config'
33
import type { Plugin } from '../plugin'
44
import { escapeRegex, isCSSRequest } from '../utils'
@@ -221,6 +221,7 @@ export async function replaceDefine(
221221
environment.config.command === 'build'
222222
? !!environment.config.build.sourcemap
223223
: true,
224+
tsconfig: false,
224225
})
225226

226227
if (result.errors.length > 0) {

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

Lines changed: 94 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import path from 'node:path'
22
import type {
33
TransformOptions as OxcTransformOptions,
44
TransformResult as OxcTransformResult,
5-
} from 'rolldown/experimental'
6-
import {
7-
viteTransformPlugin as nativeTransformPlugin,
8-
transformSync,
9-
} from 'rolldown/experimental'
5+
} from 'rolldown/utils'
6+
import { transformSync } from 'rolldown/utils'
7+
import { viteTransformPlugin as nativeTransformPlugin } from 'rolldown/experimental'
108
import type { RawSourceMap } from '@jridgewell/remapping'
11-
import type { RollupError, SourceMap } from 'rolldown'
9+
import type { RolldownError, RolldownLog, SourceMap } from 'rolldown'
1210
import { TSConfckParseError } from 'tsconfck'
1311
import colors from 'picocolors'
1412
import { prefixRegex } from 'rolldown/filter'
@@ -17,7 +15,6 @@ import {
1715
combineSourcemaps,
1816
createFilter,
1917
ensureWatchedFile,
20-
generateCodeFrame,
2118
normalizePath,
2219
} from '../utils'
2320
import type { ResolvedConfig } from '../config'
@@ -212,14 +209,64 @@ function setOxcTransformOptionsFromTsconfigOptions(
212209
!useDefineForClassFields
213210
}
214211

212+
// Copy from rolldown's packages/rolldown/src/utils/errors.ts
213+
function joinNewLine(s1: string, s2: string): string {
214+
// ensure single new line in between
215+
return s1.replace(/\n+$/, '') + '\n' + s2.replace(/^\n+/, '')
216+
}
217+
218+
// Copy from rolldown's packages/rolldown/src/utils/errors.ts
219+
function getErrorMessage(e: RolldownError): string {
220+
// If the `kind` field is present, we assume it represents
221+
// a custom error defined by rolldown on the Rust side.
222+
if (Object.hasOwn(e, 'kind')) {
223+
return e.message
224+
}
225+
226+
let s = ''
227+
if (e.plugin) {
228+
s += `[plugin ${e.plugin}]`
229+
}
230+
const id = e.id ?? e.loc?.file
231+
if (id) {
232+
s += ' ' + id
233+
if (e.loc) {
234+
s += `:${e.loc.line}:${e.loc.column}`
235+
}
236+
}
237+
if (s) {
238+
s += '\n'
239+
}
240+
const message = `${e.name ?? 'Error'}: ${e.message}`
241+
s += message
242+
if (e.frame) {
243+
s = joinNewLine(s, e.frame)
244+
}
245+
// copy stack since it's important for js plugin error
246+
if (e.stack) {
247+
s = joinNewLine(s, e.stack.replace(message, ''))
248+
}
249+
if (e.cause) {
250+
s = joinNewLine(s, 'Caused by:')
251+
s = joinNewLine(
252+
s,
253+
getErrorMessage(e.cause as any)
254+
.split('\n')
255+
.map((line) => ' ' + line)
256+
.join('\n'),
257+
)
258+
}
259+
return s
260+
}
261+
215262
export async function transformWithOxc(
216263
code: string,
217264
filename: string,
218265
options?: OxcTransformOptions,
219266
inMap?: object,
220267
config?: ResolvedConfig,
221268
watcher?: FSWatcher,
222-
): Promise<Omit<OxcTransformResult, 'errors'> & { warnings: string[] }> {
269+
): Promise<Omit<OxcTransformResult, 'errors'>> {
223270
const warnings: string[] = []
224271
let lang = options?.lang
225272

@@ -243,6 +290,7 @@ export async function transformWithOxc(
243290
sourcemap: true,
244291
...options,
245292
lang,
293+
tsconfig: false,
246294
}
247295

248296
if (lang === 'ts' || lang === 'tsx') {
@@ -272,23 +320,33 @@ export async function transformWithOxc(
272320
const result = transformSync(filename, code, resolvedOptions)
273321

274322
if (result.errors.length > 0) {
275-
const firstError = result.errors[0]
276-
const error: RollupError = new Error(firstError.message)
277-
let frame = ''
278-
frame += firstError.labels
279-
.map(
280-
(l) =>
281-
(l.message ? `${l.message}\n` : '') +
282-
generateCodeFrame(code, l.start, l.end),
283-
)
284-
.join('\n')
285-
if (firstError.helpMessage) {
286-
frame += '\n' + firstError.helpMessage
323+
// Copy from rolldown's packages/rolldown/src/utils/errors.ts
324+
let summary = `Transform failed with ${result.errors.length} error${result.errors.length < 2 ? '' : 's'}:\n`
325+
for (let i = 0; i < result.errors.length; i++) {
326+
summary += '\n'
327+
if (i >= 5) {
328+
summary += '...'
329+
break
330+
}
331+
summary += getErrorMessage(result.errors[i])
287332
}
288-
error.frame = frame
289-
error.pos =
290-
firstError.labels.length > 0 ? firstError.labels[0].start : undefined
291-
throw error
333+
334+
const wrapper = new Error(summary)
335+
// expose individual errors as getters so that
336+
// `console.error(wrapper)` doesn't expand unnecessary details
337+
// when they are already presented in `wrapper.message`
338+
Object.defineProperty(wrapper, 'errors', {
339+
configurable: true,
340+
enumerable: true,
341+
get: () => result.errors,
342+
set: (value) =>
343+
Object.defineProperty(wrapper, 'errors', {
344+
configurable: true,
345+
enumerable: true,
346+
value,
347+
}),
348+
})
349+
throw wrapper
292350
}
293351

294352
let map: SourceMap
@@ -305,7 +363,6 @@ export async function transformWithOxc(
305363
return {
306364
...result,
307365
map,
308-
warnings,
309366
}
310367
}
311368

@@ -319,6 +376,15 @@ function resolveTsconfigTarget(target: string | undefined): number | 'next' {
319376
return parseInt(targetLowered.slice(2))
320377
}
321378

379+
const warnedMessages = new Set<string>()
380+
function shouldSkipWarning(warning: RolldownLog): boolean {
381+
if (warning.code === 'UNSUPPORTED_TSCONFIG_OPTION') {
382+
if (warnedMessages.has(warning.message)) return true
383+
warnedMessages.add(warning.message)
384+
}
385+
return false
386+
}
387+
322388
export function oxcPlugin(config: ResolvedConfig): Plugin {
323389
if (config.isBundled && config.nativePluginEnabledLevel >= 1) {
324390
return perEnvironmentPlugin('native:transform', (environment) => {
@@ -458,7 +524,9 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
458524
result.code = jsxInject + ';' + result.code
459525
}
460526
for (const warning of result.warnings) {
461-
this.environment.logger.warnOnce(warning)
527+
if (!shouldSkipWarning(warning)) {
528+
this.warn(warning)
529+
}
462530
}
463531
return {
464532
code: result.code,

playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"convert-source-map": "^2.0.0",
1111
"css-color-names": "^1.0.1",
1212
"kill-port": "^1.6.1",
13-
"rolldown": "1.0.0-rc.3"
13+
"rolldown": "1.0.0-rc.4"
1414
}
1515
}

0 commit comments

Comments
 (0)