Skip to content

Commit 5497abe

Browse files
authored
chore: upgrade rollup to 3.25.2 (#13608)
1 parent 621ae5a commit 5497abe

File tree

10 files changed

+133
-101
lines changed

10 files changed

+133
-101
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"prettier": "2.8.8",
8282
"resolve": "^1.22.2",
8383
"rimraf": "^5.0.1",
84-
"rollup": "^3.21.0",
84+
"rollup": "^3.25.2",
8585
"simple-git-hooks": "^2.8.1",
8686
"tslib": "^2.5.3",
8787
"tsx": "^3.12.7",

packages/vite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"dependencies": {
7070
"esbuild": "^0.18.6",
7171
"postcss": "^8.4.24",
72-
"rollup": "^3.21.0"
72+
"rollup": "^3.25.2"
7373
},
7474
"optionalDependencies": {
7575
"fsevents": "~2.3.2"

packages/vite/src/node/build.ts

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ import type {
55
ExternalOption,
66
InputOption,
77
InternalModuleFormat,
8+
LoggingFunction,
89
ModuleFormat,
910
OutputOptions,
1011
Plugin,
1112
RollupBuild,
1213
RollupError,
14+
RollupLog,
1315
RollupOptions,
1416
RollupOutput,
1517
RollupWarning,
1618
RollupWatcher,
17-
WarningHandler,
1819
WatcherOptions,
1920
} from 'rollup'
2021
import type { Terser } from 'dep-types/terser'
@@ -867,47 +868,58 @@ const dynamicImportWarningIgnoreList = [
867868

868869
export function onRollupWarning(
869870
warning: RollupWarning,
870-
warn: WarningHandler,
871+
warn: LoggingFunction,
871872
config: ResolvedConfig,
872873
): void {
873-
function viteWarn(warning: RollupWarning) {
874-
if (warning.code === 'UNRESOLVED_IMPORT') {
875-
const id = warning.id
876-
const exporter = warning.exporter
877-
// throw unless it's commonjs external...
878-
if (!id || !/\?commonjs-external$/.test(id)) {
879-
throw new Error(
880-
`[vite]: Rollup failed to resolve import "${exporter}" from "${id}".\n` +
881-
`This is most likely unintended because it can break your application at runtime.\n` +
882-
`If you do want to externalize this module explicitly add it to\n` +
883-
`\`build.rollupOptions.external\``,
884-
)
885-
}
886-
}
874+
const viteWarn: LoggingFunction = (warnLog) => {
875+
let warning: string | RollupLog
887876

888-
if (
889-
warning.plugin === 'rollup-plugin-dynamic-import-variables' &&
890-
dynamicImportWarningIgnoreList.some((msg) =>
891-
warning.message.includes(msg),
892-
)
893-
) {
894-
return
877+
if (typeof warnLog === 'function') {
878+
warning = warnLog()
879+
} else {
880+
warning = warnLog
895881
}
896882

897-
if (warningIgnoreList.includes(warning.code!)) {
898-
return
899-
}
883+
if (typeof warning === 'object') {
884+
if (warning.code === 'UNRESOLVED_IMPORT') {
885+
const id = warning.id
886+
const exporter = warning.exporter
887+
// throw unless it's commonjs external...
888+
if (!id || !/\?commonjs-external$/.test(id)) {
889+
throw new Error(
890+
`[vite]: Rollup failed to resolve import "${exporter}" from "${id}".\n` +
891+
`This is most likely unintended because it can break your application at runtime.\n` +
892+
`If you do want to externalize this module explicitly add it to\n` +
893+
`\`build.rollupOptions.external\``,
894+
)
895+
}
896+
}
900897

901-
if (warning.code === 'PLUGIN_WARNING') {
902-
config.logger.warn(
903-
`${colors.bold(
904-
colors.yellow(`[plugin:${warning.plugin}]`),
905-
)} ${colors.yellow(warning.message)}`,
906-
)
907-
return
898+
if (
899+
warning.plugin === 'rollup-plugin-dynamic-import-variables' &&
900+
dynamicImportWarningIgnoreList.some((msg) =>
901+
// @ts-expect-error warning is RollupLog
902+
warning.message.includes(msg),
903+
)
904+
) {
905+
return
906+
}
907+
908+
if (warningIgnoreList.includes(warning.code!)) {
909+
return
910+
}
911+
912+
if (warning.code === 'PLUGIN_WARNING') {
913+
config.logger.warn(
914+
`${colors.bold(
915+
colors.yellow(`[plugin:${warning.plugin}]`),
916+
)} ${colors.yellow(warning.message)}`,
917+
)
918+
return
919+
}
908920
}
909921

910-
warn(warning)
922+
warn(warnLog)
911923
}
912924

913925
const tty = process.stdout.isTTY && !process.env.CI

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
606606

607607
async generateBundle(options, bundle) {
608608
const analyzedChunk: Map<OutputChunk, number> = new Map()
609+
const inlineEntryChunk = new Set<string>()
609610
const getImportedChunks = (
610611
chunk: OutputChunk,
611612
seen: Set<string> = new Set(),
@@ -826,8 +827,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
826827
})
827828

828829
if (chunk && canInlineEntry) {
829-
// all imports from entry have been inlined to html, prevent rollup from outputting it
830-
delete bundle[chunk.fileName]
830+
inlineEntryChunk.add(chunk.fileName)
831831
}
832832

833833
const shortEmitName = normalizePath(path.relative(config.root, id))
@@ -837,6 +837,11 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
837837
source: result,
838838
})
839839
}
840+
841+
for (const fileName of inlineEntryChunk) {
842+
// all imports from entry have been inlined to html, prevent rollup from outputting it
843+
delete bundle[fileName]
844+
}
840845
},
841846
}
842847
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
221221
try {
222222
imports = parseImports(source)[0]
223223
} catch (e: any) {
224-
this.error(e, e.idx)
224+
this.error(e)
225225
}
226226

227227
if (!imports.length) {
@@ -462,7 +462,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
462462
try {
463463
imports = parseImports(code)[0].filter((i) => i.d > -1)
464464
} catch (e: any) {
465-
this.error(e, e.idx)
465+
this.error(e)
466466
}
467467

468468
const s = new MagicString(code)

packages/vite/src/node/server/middlewares/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function prepareError(err: Error | RollupError): ErrorPayload['err'] {
1515
id: (err as RollupError).id,
1616
frame: strip((err as RollupError).frame || ''),
1717
plugin: (err as RollupError).plugin,
18-
pluginCode: (err as RollupError).pluginCode,
18+
pluginCode: (err as RollupError).pluginCode?.toString(),
1919
loc: (err as RollupError).loc,
2020
}
2121
}

packages/vite/src/node/server/pluginContainer.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import type {
5050
PartialResolvedId,
5151
ResolvedId,
5252
RollupError,
53+
RollupLog,
5354
PluginContext as RollupPluginContext,
5455
SourceDescription,
5556
SourceMap,
@@ -84,6 +85,8 @@ import { createPluginHookUtils } from '../plugins'
8485
import { buildErrorMessage } from './middlewares/error'
8586
import type { ModuleGraph } from './moduleGraph'
8687

88+
const noop = () => {}
89+
8790
export const ERR_CLOSED_SERVER = 'ERR_CLOSED_SERVER'
8891

8992
export function throwClosedServerError(): never {
@@ -186,6 +189,11 @@ export async function createPluginContainer(
186189
rollupVersion,
187190
watchMode: true,
188191
},
192+
debug: noop,
193+
info: noop,
194+
warn: noop,
195+
// @ts-expect-error noop
196+
error: noop,
189197
}
190198

191199
function warnIncompatibleMethod(method: string, plugin: string) {
@@ -271,7 +279,7 @@ export async function createPluginContainer(
271279
// active plugin in that pipeline can be tracked in a concurrency-safe manner.
272280
// using a class to make creating new contexts more efficient
273281
class Context implements PluginContext {
274-
meta = minimalContext.meta
282+
meta = minimalContext.meta!
275283
ssr = false
276284
_scan = false
277285
_activePlugin: Plugin | null
@@ -377,10 +385,10 @@ export async function createPluginContainer(
377385
}
378386

379387
warn(
380-
e: string | RollupError,
388+
e: string | RollupLog | (() => string | RollupLog),
381389
position?: number | { column: number; line: number },
382390
) {
383-
const err = formatError(e, position, this)
391+
const err = formatError(typeof e === 'function' ? e() : e, position, this)
384392
const msg = buildErrorMessage(
385393
err,
386394
[colors.yellow(`warning: ${err.message}`)],
@@ -400,6 +408,9 @@ export async function createPluginContainer(
400408
// the the error middleware.
401409
throw formatError(e, position, this)
402410
}
411+
412+
debug = noop
413+
info = noop
403414
}
404415

405416
function formatError(
@@ -493,7 +504,7 @@ export async function createPluginContainer(
493504
}
494505
}
495506
if (code) {
496-
err.frame = generateCodeFrame(code, err.loc)
507+
err.frame = generateCodeFrame(`${code}`, err.loc)
497508
}
498509
}
499510
}

packages/vite/src/node/ssr/ssrManifestPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function ssrManifestPlugin(config: ResolvedConfig): Plugin {
4242
try {
4343
imports = parseImports(code)[0].filter((i) => i.n && i.d > -1)
4444
} catch (e: any) {
45-
this.error(e, e.idx)
45+
this.error(e)
4646
}
4747
if (imports.length) {
4848
for (let index = 0; index < imports.length; index++) {

playground/html/__tests__/html.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe.runIf(isBuild)('build', () => {
150150
const countPreloadTags = _countTags.bind(this, 'link[rel=modulepreload]')
151151

152152
test('is inlined', async () => {
153-
await page.goto(viteTestUrl + '/inline/shared-1.html?v=1')
153+
await page.goto(viteTestUrl + '/inline/shared-2.html?v=1')
154154
expect(await countScriptTags()).toBeGreaterThan(1)
155155
expect(await countPreloadTags()).toBe(0)
156156
})
@@ -162,6 +162,10 @@ describe.runIf(isBuild)('build', () => {
162162
})
163163

164164
test('execution order when inlined', async () => {
165+
await page.goto(viteTestUrl + '/inline/shared-1.html?v=1')
166+
expect((await page.textContent('#output')).trim()).toBe(
167+
'dep1 common dep2 dep3 shared',
168+
)
165169
await page.goto(viteTestUrl + '/inline/shared-2.html?v=1')
166170
expect((await page.textContent('#output')).trim()).toBe(
167171
'dep1 common dep2 dep3 shared',

0 commit comments

Comments
 (0)