Skip to content

Commit 854436b

Browse files
authored
feat: update rolldown (#415)
1 parent fee7e95 commit 854436b

File tree

7 files changed

+206
-146
lines changed

7 files changed

+206
-146
lines changed

packages/vite/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"types": "./client.d.ts"
2525
},
2626
"./module-runner": "./dist/node/module-runner.js",
27+
"./internal": "./dist/node/internal.js",
2728
"./dist/client/*": "./dist/client/*",
2829
"./types/*": {
2930
"types": "./types/*"
@@ -81,11 +82,12 @@
8182
},
8283
"//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
8384
"dependencies": {
85+
"@oxc-project/runtime": "0.89.0",
8486
"fdir": "^6.5.0",
8587
"lightningcss": "^1.30.1",
8688
"picomatch": "^4.0.3",
8789
"postcss": "^8.5.6",
88-
"rolldown": "1.0.0-beta.37",
90+
"rolldown": "1.0.0-beta.38",
8991
"tinyglobby": "^0.2.15"
9092
},
9193
"optionalDependencies": {
@@ -95,9 +97,9 @@
9597
"@babel/parser": "^7.28.4",
9698
"@jridgewell/remapping": "^2.3.5",
9799
"@jridgewell/trace-mapping": "^0.3.30",
98-
"@oxc-project/types": "0.87.0",
100+
"@oxc-project/types": "0.89.0",
99101
"@polka/compression": "^1.0.0-next.25",
100-
"@rolldown/pluginutils": "^1.0.0-beta.37",
102+
"@rolldown/pluginutils": "^1.0.0-beta.38",
101103
"@rollup/plugin-alias": "^5.1.1",
102104
"@rollup/plugin-commonjs": "^28.0.6",
103105
"@rollup/plugin-dynamic-import-vars": "2.1.4",

packages/vite/rolldown.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const nodeConfig = defineConfig({
7474
input: {
7575
index: path.resolve(__dirname, 'src/node/index.ts'),
7676
cli: path.resolve(__dirname, 'src/node/cli.ts'),
77+
internal: path.resolve(__dirname, 'src/node/internalIndex.ts'),
7778
},
7879
resolve: {
7980
alias: {

packages/vite/rolldown.dts.config.ts

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default defineConfig({
3636
input: {
3737
index: './src/node/index.ts',
3838
'module-runner': './src/module-runner/index.ts',
39+
internal: './src/node/internalIndex.ts',
3940
},
4041
output: {
4142
dir: './dist/node',
@@ -305,43 +306,46 @@ function replaceConfusingTypeNames(
305306
chunk: OutputChunk,
306307
importBindings: ImportBindings[],
307308
) {
308-
for (const modName in identifierReplacements) {
309-
const imp = importBindings.filter((imp) => imp.id === modName)
310-
// Validate that `identifierReplacements` is not outdated if there's no match
311-
if (imp.length === 0) {
312-
this.warn(
313-
`${chunk.fileName} does not import "${modName}" for replacement`,
314-
)
315-
process.exitCode = 1
316-
continue
317-
}
318-
319-
const replacements = identifierReplacements[modName]
320-
for (const id in replacements) {
309+
const isInternalEntry = chunk.fileName.startsWith('internal.')
310+
if (!isInternalEntry) {
311+
for (const modName in identifierReplacements) {
312+
const imp = importBindings.filter((imp) => imp.id === modName)
321313
// Validate that `identifierReplacements` is not outdated if there's no match
322-
if (!imp.some((i) => i.locals.includes(id))) {
314+
if (imp.length === 0) {
323315
this.warn(
324-
`${chunk.fileName} does not import "${id}" from "${modName}" for replacement`,
316+
`${chunk.fileName} does not import "${modName}" for replacement`,
325317
)
326318
process.exitCode = 1
327319
continue
328320
}
329321

330-
const betterId = replacements[id]
331-
const regexEscapedId = escapeRegex(id)
332-
// If the better id accesses a namespace, the existing `Foo as Foo$1`
333-
// named import cannot be replaced with `Foo as Namespace.Foo`, so we
334-
// pre-emptively remove the whole named import
335-
if (betterId.includes('.')) {
322+
const replacements = identifierReplacements[modName]
323+
for (const id in replacements) {
324+
// Validate that `identifierReplacements` is not outdated if there's no match
325+
if (!imp.some((i) => i.locals.includes(id))) {
326+
this.warn(
327+
`${chunk.fileName} does not import "${id}" from "${modName}" for replacement`,
328+
)
329+
process.exitCode = 1
330+
continue
331+
}
332+
333+
const betterId = replacements[id]
334+
const regexEscapedId = escapeRegex(id)
335+
// If the better id accesses a namespace, the existing `Foo as Foo$1`
336+
// named import cannot be replaced with `Foo as Namespace.Foo`, so we
337+
// pre-emptively remove the whole named import
338+
if (betterId.includes('.')) {
339+
chunk.code = chunk.code.replace(
340+
new RegExp(`\\b\\w+\\b as ${regexEscapedId},?\\s?`),
341+
'',
342+
)
343+
}
336344
chunk.code = chunk.code.replace(
337-
new RegExp(`\\b\\w+\\b as ${regexEscapedId},?\\s?`),
338-
'',
345+
new RegExp(`\\b${regexEscapedId}\\b`, 'g'),
346+
betterId,
339347
)
340348
}
341-
chunk.code = chunk.code.replace(
342-
new RegExp(`\\b${regexEscapedId}\\b`, 'g'),
343-
betterId,
344-
)
345349
}
346350
}
347351

@@ -361,16 +365,21 @@ function replaceConfusingTypeNames(
361365
)
362366
process.exitCode = 1
363367
}
364-
const notUsedConfusingTypeNames = ignoreConfusingTypeNames.filter(
365-
(id) => !identifiers.includes(id),
366-
)
367-
// Validate that `identifierReplacements` is not outdated if there's no match
368-
if (notUsedConfusingTypeNames.length) {
369-
const notUsedStr = notUsedConfusingTypeNames
370-
.map((id) => `\n- ${id}`)
371-
.join('')
372-
this.warn(`${chunk.fileName} contains unused identifier names${notUsedStr}`)
373-
process.exitCode = 1
368+
369+
if (!isInternalEntry) {
370+
const notUsedConfusingTypeNames = ignoreConfusingTypeNames.filter(
371+
(id) => !identifiers.includes(id),
372+
)
373+
// Validate that `identifierReplacements` is not outdated if there's no match
374+
if (notUsedConfusingTypeNames.length) {
375+
const notUsedStr = notUsedConfusingTypeNames
376+
.map((id) => `\n- ${id}`)
377+
.join('')
378+
this.warn(
379+
`${chunk.fileName} contains unused identifier names${notUsedStr}`,
380+
)
381+
process.exitCode = 1
382+
}
374383
}
375384
}
376385

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { reactRefreshWrapperPlugin } from 'rolldown/experimental'

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from 'node:path'
22
import url from 'node:url'
3-
import { createRequire } from 'node:module'
43
import type {
54
TransformOptions as OxcTransformOptions,
65
TransformResult as OxcTransformResult,
@@ -28,7 +27,7 @@ import type { Plugin } from '../plugin'
2827
import { cleanUrl } from '../../shared/utils'
2928
import { type Environment, perEnvironmentPlugin } from '..'
3029
import type { ViteDevServer } from '../server'
31-
import { JS_TYPES_RE } from '../constants'
30+
import { JS_TYPES_RE, VITE_PACKAGE_DIR } from '../constants'
3231
import type { Logger } from '../logger'
3332
import type { ESBuildOptions, TSCompilerOptions } from './esbuild'
3433
import { loadTsconfigJsonForFile } from './esbuild'
@@ -306,9 +305,7 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
306305
jsxRefreshInclude,
307306
jsxRefreshExclude,
308307
isServerConsumer: environment.config.consumer === 'server',
309-
runtimeResolveBase: normalizePath(
310-
url.fileURLToPath(/** #__KEEP__ */ import.meta.url),
311-
),
308+
runtimeResolveBase: '', // not used
312309
jsxInject,
313310
transformOptions,
314311
})
@@ -376,9 +373,8 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
376373

377374
return result
378375
}
379-
const require = createRequire(/** #__KEEP__ */ import.meta.url)
380376
const runtimeResolveBase = normalizePath(
381-
require.resolve('rolldown/package.json'),
377+
path.join(VITE_PACKAGE_DIR, 'package.json'),
382378
)
383379

384380
let server: ViteDevServer
@@ -388,17 +384,23 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
388384
configureServer(_server) {
389385
server = _server
390386
},
391-
resolveId: {
392-
filter: {
393-
id: prefixRegex('@oxc-project/runtime/'),
394-
},
395-
async handler(id, _importer, opts) {
396-
// @oxc-project/runtime imports will be injected by Oxc transform
397-
// since it's injected by the transform, @oxc-project/runtime should be resolved to the one Rolldown depends on
398-
const resolved = await this.resolve(id, runtimeResolveBase, opts)
399-
return resolved
400-
},
401-
},
387+
// @oxc-project/runtime resolution is handled by rolldown in build
388+
...(config.command === 'serve'
389+
? {
390+
resolveId: {
391+
filter: {
392+
id: prefixRegex('@oxc-project/runtime/'),
393+
},
394+
async handler(id, _importer, opts) {
395+
// @oxc-project/runtime imports will be injected by Oxc transform
396+
// since it's injected by the transform, @oxc-project/runtime should be resolved to the one Vite depends on
397+
const resolved = await this.resolve(id, runtimeResolveBase, opts)
398+
return resolved
399+
},
400+
order: 'pre',
401+
},
402+
}
403+
: {}),
402404
async transform(code, id) {
403405
if (filter(id) || filter(cleanUrl(id)) || jsxRefreshFilter?.(id)) {
404406
const modifiedOxcTransformOptions = getModifiedOxcTransformOptions(

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-beta.37"
13+
"rolldown": "1.0.0-beta.38"
1414
}
1515
}

0 commit comments

Comments
 (0)