Skip to content

Commit f51756e

Browse files
authored
feat: update rolldown (#366)
1 parent 2603932 commit f51756e

File tree

6 files changed

+259
-30
lines changed

6 files changed

+259
-30
lines changed

packages/vite/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"lightningcss": "^1.30.1",
8686
"picomatch": "^4.0.3",
8787
"postcss": "^8.5.6",
88-
"rolldown": "1.0.0-beta.31",
88+
"rolldown": "1.0.0-beta.32",
8989
"tinyglobby": "^0.2.14"
9090
},
9191
"optionalDependencies": {
@@ -95,9 +95,9 @@
9595
"@ampproject/remapping": "^2.3.0",
9696
"@babel/parser": "^7.28.0",
9797
"@jridgewell/trace-mapping": "^0.3.29",
98-
"@oxc-project/types": "0.80.0",
98+
"@oxc-project/types": "0.81.0",
9999
"@polka/compression": "^1.0.0-next.25",
100-
"@rolldown/pluginutils": "1.0.0-beta.31",
100+
"@rolldown/pluginutils": "1.0.0-beta.32",
101101
"@rollup/plugin-alias": "^5.1.1",
102102
"@rollup/plugin-commonjs": "^28.0.6",
103103
"@rollup/plugin-dynamic-import-vars": "2.1.4",

packages/vite/src/node/__tests__/build.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ test.for([true, false])(
861861
([client, ssr, custom1, custom2] as RolldownOutput[]).map(
862862
(o) => o.output[0].code.split('\n').length,
863863
),
864-
).toEqual([1, 5, 1, 5])
864+
).toEqual([1, 6, 1, 6])
865865
},
866866
)
867867

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

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { manifestPlugin as nativeManifestPlugin } from 'rolldown/experimental'
44
import type { Plugin } from '../plugin'
55
import { normalizePath, sortObjectKeys } from '../utils'
66
import { perEnvironmentState } from '../environment'
7-
import { type ResolvedConfig, perEnvironmentPlugin } from '..'
7+
import { type Environment, type ResolvedConfig, perEnvironmentPlugin } from '..'
88
import { cssEntriesMap } from './asset'
99

1010
const endsWithJSRE = /\.[cm]?js$/
@@ -25,6 +25,16 @@ export interface ManifestChunk {
2525
}
2626

2727
export function manifestPlugin(config: ResolvedConfig): Plugin {
28+
const getState = perEnvironmentState(() => {
29+
return {
30+
manifest: {} as Manifest,
31+
outputCount: 0,
32+
reset() {
33+
this.manifest = {}
34+
this.outputCount = 0
35+
},
36+
}
37+
})
2838
if (
2939
config.build.manifest &&
3040
config.experimental.enableNativePlugin === true
@@ -38,6 +48,8 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
3848
? '.vite/manifest.json'
3949
: environment.config.build.manifest
4050

51+
const isLegacySet = new Set<string>()
52+
const envs: Record<string, Environment> = {}
4153
function getChunkName(chunk: OutputChunk) {
4254
return (
4355
getChunkOriginalFileName(chunk, root, false) ??
@@ -46,7 +58,36 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
4658
}
4759

4860
return [
49-
nativeManifestPlugin({ root, outPath }),
61+
{
62+
name: 'native:manifest-envs',
63+
buildStart() {
64+
envs[environment.name] = this.environment
65+
},
66+
...(config.isOutputOptionsForLegacyChunks
67+
? {
68+
generateBundle(opts) {
69+
const isLegacy =
70+
environment.config.isOutputOptionsForLegacyChunks?.(opts) ??
71+
false
72+
if (isLegacy) {
73+
isLegacySet.add(environment.name)
74+
} else {
75+
isLegacySet.delete(environment.name)
76+
}
77+
},
78+
}
79+
: {}),
80+
},
81+
nativeManifestPlugin({
82+
root,
83+
outPath,
84+
isLegacy: config.isOutputOptionsForLegacyChunks
85+
? () => isLegacySet.has(environment.name)
86+
: undefined,
87+
cssEntries() {
88+
return cssEntriesMap.get(envs[environment.name])!
89+
},
90+
}),
5091
{
5192
name: 'native:manifest-compatible',
5293
generateBundle(_, bundle) {
@@ -69,27 +110,32 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
69110
item.assets = [...importedAssets]
70111
}
71112
}
72-
if (manifest) {
113+
const output =
114+
this.environment.config.build.rolldownOptions.output
115+
const outputLength = Array.isArray(output) ? output.length : 1
116+
if (manifest && outputLength === 1) {
73117
asset.source = JSON.stringify(manifest)
118+
return
119+
}
120+
121+
const state = getState(this)
122+
state.outputCount++
123+
state.manifest = Object.assign(
124+
state.manifest,
125+
manifest ?? JSON.parse(asset.source.toString()),
126+
)
127+
if (state.outputCount >= outputLength) {
128+
asset.source = JSON.stringify(state.manifest, undefined, 2)
129+
state.reset()
130+
} else {
131+
delete bundle[outPath]
74132
}
75133
}
76134
},
77135
},
78136
]
79137
})
80138
}
81-
82-
const getState = perEnvironmentState(() => {
83-
return {
84-
manifest: {} as Manifest,
85-
outputCount: 0,
86-
reset() {
87-
this.manifest = {}
88-
this.outputCount = 0
89-
},
90-
}
91-
})
92-
93139
return {
94140
name: 'vite:manifest',
95141

playground/js-sourcemap/__tests__/js-sourcemap.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe.runIf(isBuild)('build tests', () => {
144144
{
145145
"debugId": "00000000-0000-0000-0000-000000000000",
146146
"ignoreList": [],
147-
"mappings": ";8CAAA,OAAO,6BAAuB,wBAE9B,QAAQ,IAAI,wBAAuB",
147+
"mappings": ";grCAAA,OAAO,6BAAuB,wBAE9B,QAAQ,IAAI,wBAAuB",
148148
"sources": [
149149
"../../after-preload-dynamic.js",
150150
],

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

0 commit comments

Comments
 (0)