Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: rollup v4 #14508

Merged
merged 41 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8596dfd
wip: bump rollup
sapphi-red Sep 30, 2023
b907e6e
wip: remove `acorn`/`acornInjectPlugins` option, remove additional op…
sapphi-red Sep 30, 2023
e6474ba
wip: replace "assertions" with "attributes"
sapphi-red Sep 30, 2023
00e0ece
wip: replace RollupWarning with RollupLog
sapphi-red Sep 30, 2023
0c488c7
wip: remove omit `moduleIds`
sapphi-red Sep 30, 2023
d9085f7
wip: call `this.addWatchFile` in vite:load-fallback plugin
sapphi-red Sep 30, 2023
4d49292
wip: remove utf8 BOM for now
sapphi-red Sep 30, 2023
f161d22
wip: use parse function from rollup
sapphi-red Sep 30, 2023
ddde37f
wip: bump rollup for plugin-legacy
sapphi-red Sep 30, 2023
49dafa0
wip: default of skipSelf is now true
sapphi-red Sep 30, 2023
176f6d5
wip: ignore rollup version mismatch type error
sapphi-red Sep 30, 2023
9f36ca3
wip: bump rollup
sapphi-red Oct 3, 2023
6b00745
wip: revert "wip: remove utf8 BOM for now"
sapphi-red Oct 3, 2023
632d3b0
wip: new hash algorithm
sapphi-red Oct 3, 2023
a3c750f
wip: new hash algorithm
sapphi-red Oct 3, 2023
ae0b4c4
wip: new hash algorithm
sapphi-red Oct 3, 2023
fa7a370
chore: merge main
sapphi-red Oct 5, 2023
e5bf794
chore: update rollup plugins
sapphi-red Oct 5, 2023
a274f82
wip: update rollup
sapphi-red Oct 5, 2023
19c2d76
wip: use parseAst function from rollup
sapphi-red Oct 5, 2023
60bb4fd
wip: remove ensureWatchedFile
sapphi-red Oct 5, 2023
1edfeff
wip: bump rollup to 4.0.0
sapphi-red Oct 5, 2023
dafc6d7
wip: use ^4.0.0 instead of 4.0.0
sapphi-red Oct 5, 2023
e2c9e8a
wip: add `addWatchFile` to assetPlugin
sapphi-red Oct 5, 2023
90f1344
wip: remove ensureWatchPlugin
sapphi-red Oct 5, 2023
924c4b0
wip: add migration guide
sapphi-red Oct 5, 2023
e56494e
wip: remove RollupParseFunc type
sapphi-red Oct 6, 2023
9ab9f61
wip: remove the tweak to workaround rollup/acorn inconsistency
sapphi-red Oct 6, 2023
522f77c
wip: update docs
sapphi-red Oct 6, 2023
c9eb9f3
wip: restore ensureWatchedFile in indexHtml.ts
sapphi-red Oct 6, 2023
342716a
chore: merge main
sapphi-red Oct 6, 2023
aae78cf
wip: new hash algorithm
sapphi-red Oct 6, 2023
c1fad36
wip: new hash algorithm
sapphi-red Oct 6, 2023
31ed8b1
chore: merge main
sapphi-red Oct 9, 2023
0728839
chore: merge main
sapphi-red Oct 11, 2023
3d081e3
chore: merge main
sapphi-red Oct 12, 2023
8915ca5
chore: bump vitepress
sapphi-red Oct 12, 2023
22d7bd9
chore: merge main
sapphi-red Oct 16, 2023
d5bd340
chore: bump rollup-plugin-license
sapphi-red Oct 16, 2023
72a4624
chore: bump rollup and magic-string
sapphi-red Oct 16, 2023
6a5d4dd
chore: merge main
sapphi-red Oct 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/guide/migration.md
Expand Up @@ -4,6 +4,17 @@

Vite no longer supports Node.js 14 / 16 / 17 / 19, which reached its EOL. Node.js 18 / 20+ is now required.

## Rollup 4

Vite is now using Rollup 4 which also brings along its breaking changes, in particular:

- Import assertions (`assertions` prop) has been renamed to import attributes (`attributes` prop).
- Acorn plugins are no longer supported.
- For Vite plugins, `this.resolve` `skipSelf` option is now `true` by default.
- For Vite plugins, `this.parse` now only supports the `allowReturnOutsideFunction` option for now.

Read the full breaking changes in [Rollup's release notes](https://github.com/rollup/rollup/releases/tag/v4.0.0) for build-related changes in `build.rollupOptions`.

## Deprecate CJS Node API

The CJS Node API of Vite is deprecated. When calling `require('vite')`, a deprecation warning is now logged. You should update your files or frameworks to import the ESM build of Vite instead.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -76,7 +76,7 @@
"playwright-chromium": "^1.39.0",
"prettier": "3.0.3",
"rimraf": "^5.0.5",
"rollup": "^3.29.2",
"rollup": "^4.1.4",
"simple-git-hooks": "^2.9.0",
"tslib": "^2.6.2",
"tsx": "^3.13.0",
Expand Down
1 change: 1 addition & 0 deletions packages/create-vite/build.config.ts
Expand Up @@ -23,6 +23,7 @@ export default defineBuildConfig({
'rollup:options'(ctx, options) {
options.plugins = [
options.plugins,
// @ts-expect-error TODO: unbuild uses rollup v3 and Vite uses rollup v4
licensePlugin(
path.resolve(__dirname, './LICENSE'),
'create-vite license',
Expand Down
7 changes: 0 additions & 7 deletions packages/vite/LICENSE.md
Expand Up @@ -566,13 +566,6 @@ Repository: https://github.com/acornjs/acorn.git

---------------------------------------

## acorn-import-assertions
License: MIT
By: Sven Sauleau
Repository: https://github.com/xtuc/acorn-import-assertions

---------------------------------------

## acorn-walk
License: MIT
By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/package.json
Expand Up @@ -76,7 +76,7 @@
"dependencies": {
"esbuild": "^0.19.3",
"postcss": "^8.4.31",
"rollup": "^3.29.4"
"rollup": "^4.1.4"
},
"optionalDependencies": {
"fsevents": "~2.3.3"
Expand All @@ -94,7 +94,6 @@
"@types/escape-html": "^1.0.2",
"@types/pnpapi": "^0.0.3",
"acorn": "^8.10.0",
"acorn-import-assertions": "^1.9.0",
"acorn-walk": "^8.2.0",
"cac": "^6.7.14",
"chokidar": "^3.5.3",
Expand Down
1 change: 1 addition & 0 deletions packages/vite/rollup.config.ts
Expand Up @@ -161,6 +161,7 @@ function createNodeConfig(isProduction: boolean) {
external: [
'fsevents',
'lightningcss',
'rollup/parseAst',
...Object.keys(pkg.dependencies),
...(isProduction ? [] : Object.keys(pkg.devDependencies)),
],
Expand Down
5 changes: 1 addition & 4 deletions packages/vite/src/node/build.ts
Expand Up @@ -14,7 +14,6 @@ import type {
RollupLog,
RollupOptions,
RollupOutput,
RollupWarning,
RollupWatcher,
WatcherOptions,
} from 'rollup'
Expand Down Expand Up @@ -45,7 +44,6 @@ import { initDepsOptimizer } from './optimizer'
import { loadFallbackPlugin } from './plugins/loadFallback'
import { findNearestPackageData } from './packages'
import type { PackageCache } from './packages'
import { ensureWatchPlugin } from './plugins/ensureWatch'
import { ESBUILD_MODULES_TARGET, VERSION } from './constants'
import { resolveChokidarOptions } from './watch'
import { completeSystemWrapPlugin } from './plugins/completeSystemWrap'
Expand Down Expand Up @@ -426,7 +424,6 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{
return {
pre: [
completeSystemWrapPlugin(),
...(options.watch ? [ensureWatchPlugin()] : []),
...(usePluginCommonjs ? [commonjsPlugin(options.commonjsOptions)] : []),
dataURIPlugin(),
...((
Expand Down Expand Up @@ -858,7 +855,7 @@ const dynamicImportWarningIgnoreList = [
]

export function onRollupWarning(
warning: RollupWarning,
warning: RollupLog,
warn: LoggingFunction,
config: ResolvedConfig,
): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugin.ts
Expand Up @@ -150,7 +150,7 @@ export interface Plugin<A = any> extends RollupPlugin<A> {
source: string,
importer: string | undefined,
options: {
assertions: Record<string, string>
attributes: Record<string, string>
custom?: CustomPluginOptions
ssr?: boolean
/**
Expand Down
10 changes: 6 additions & 4 deletions packages/vite/src/node/plugins/asset.ts
Expand Up @@ -27,7 +27,8 @@ import {
} from '../utils'
import { FS_PREFIX } from '../constants'

export const assetUrlRE = /__VITE_ASSET__([a-z\d]+)__(?:\$_(.*?)__)?/g
// referenceId is base64url but replaces - with $
export const assetUrlRE = /__VITE_ASSET__([\w$]+)__(?:\$_(.*?)__)?/g

const rawRE = /(?:\?|&)raw(?:&|$)/
export const urlRE = /(\?|&)url(?:&|$)/
Expand Down Expand Up @@ -78,10 +79,10 @@ export function renderAssetUrlInJS(
let s: MagicString | undefined

// Urls added with JS using e.g.
// imgElement.src = "__VITE_ASSET__5aa0ddc0__" are using quotes
// imgElement.src = "__VITE_ASSET__5aA0Ddc0__" are using quotes

// Urls added in CSS that is imported in JS end up like
// var inlined = ".inlined{color:green;background:url(__VITE_ASSET__5aa0ddc0__)}\n";
// var inlined = ".inlined{color:green;background:url(__VITE_ASSET__5aA0Ddc0__)}\n";

// In both cases, the wrapping should already be fine

Expand All @@ -107,7 +108,7 @@ export function renderAssetUrlInJS(
s.update(match.index, match.index + full.length, replacementString)
}

// Replace __VITE_PUBLIC_ASSET__5aa0ddc0__ with absolute paths
// Replace __VITE_PUBLIC_ASSET__5aA0Ddc0__ with absolute paths

const publicAssetUrlMap = publicAssetUrlCache.get(config)!
publicAssetUrlRE.lastIndex = 0
Expand Down Expand Up @@ -179,6 +180,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
// raw requests, read from disk
if (rawRE.test(id)) {
const file = checkPublicFile(id, config) || cleanUrl(id)
this.addWatchFile(file)
// raw query, read file and return as string
return `export default ${JSON.stringify(
await fsp.readFile(file, 'utf-8'),
Expand Down
17 changes: 0 additions & 17 deletions packages/vite/src/node/plugins/ensureWatch.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/vite/src/node/plugins/importAnalysis.ts
Expand Up @@ -408,7 +408,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
ss: expStart,
se: expEnd,
d: dynamicIndex,
a: assertIndex,
a: attributeIndex,
} = importSpecifier

// #2083 User may use escape path,
Expand Down Expand Up @@ -464,8 +464,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {

const isDynamicImport = dynamicIndex > -1

// strip import assertions as we can process them ourselves
if (!isDynamicImport && assertIndex > -1) {
// strip import attributes as we can process them ourselves
if (!isDynamicImport && attributeIndex > -1) {
str().remove(end + 1, expEnd)
}

Expand Down
10 changes: 6 additions & 4 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Expand Up @@ -261,7 +261,9 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
}
}

const resolved = await this.resolve(url, importerFile)
const resolved = await this.resolve(url, importerFile, {
skipSelf: false,
})

if (!resolved) {
// in ssr, we should let node handle the missing modules
Expand Down Expand Up @@ -305,13 +307,13 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
se: expEnd,
n: specifier,
d: dynamicIndex,
a: assertIndex,
a: attributeIndex,
} = imports[index]

const isDynamicImport = dynamicIndex > -1

// strip import assertions as we can process them ourselves
if (!isDynamicImport && assertIndex > -1) {
// strip import attributes as we can process them ourselves
if (!isDynamicImport && attributeIndex > -1) {
str().remove(end + 1, expEnd)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/importMetaGlob.ts
Expand Up @@ -486,7 +486,7 @@ type IdResolver = (
id: string,
importer?: string,
options?: {
assertions?: Record<string, string>
attributes?: Record<string, string>
custom?: CustomPluginOptions
isEntry?: boolean
skipSelf?: boolean
Expand Down
3 changes: 0 additions & 3 deletions packages/vite/src/node/plugins/index.ts
Expand Up @@ -21,7 +21,6 @@ import { preAliasPlugin } from './preAlias'
import { definePlugin } from './define'
import { workerImportMetaUrlPlugin } from './workerImportMetaUrl'
import { assetImportMetaUrlPlugin } from './assetImportMetaUrl'
import { ensureWatchPlugin } from './ensureWatch'
import { metadataPlugin } from './metadata'
import { dynamicImportVarsPlugin } from './dynamicImportVars'
import { importGlobPlugin } from './importMetaGlob'
Expand All @@ -33,7 +32,6 @@ export async function resolvePlugins(
postPlugins: Plugin[],
): Promise<Plugin[]> {
const isBuild = config.command === 'build'
const isWatch = isBuild && !!config.build.watch
const buildPlugins = isBuild
? await (await import('../build')).resolveBuildPlugins(config)
: { pre: [], post: [] }
Expand All @@ -48,7 +46,6 @@ export async function resolvePlugins(
: optimizedDepsPlugin(config),
]
: []),
isWatch ? ensureWatchPlugin() : null,
isBuild ? metadataPlugin() : null,
watchPackageDataPlugin(config.packageCache),
preAliasPlugin(config),
Expand Down
10 changes: 7 additions & 3 deletions packages/vite/src/node/plugins/loadFallback.ts
Expand Up @@ -10,10 +10,14 @@ export function loadFallbackPlugin(): Plugin {
name: 'vite:load-fallback',
async load(id) {
try {
// if we don't add `await` here, we couldn't catch the error in readFile
return await fsp.readFile(cleanUrl(id), 'utf-8')
const cleanedId = cleanUrl(id)
const content = await fsp.readFile(cleanedId, 'utf-8')
this.addWatchFile(cleanedId)
return content
} catch (e) {
return fsp.readFile(id, 'utf-8')
const content = await fsp.readFile(id, 'utf-8')
this.addWatchFile(id)
return content
}
},
}
Expand Down
5 changes: 1 addition & 4 deletions packages/vite/src/node/plugins/optimizedDeps.ts
Expand Up @@ -102,10 +102,7 @@ export function optimizedDepsBuildPlugin(config: ResolvedConfig): Plugin {
// When a optimized dep is aliased, we need to avoid waiting for it before optimizing
return
}
const resolved = await this.resolve(id, importer, {
...options,
skipSelf: true,
})
const resolved = await this.resolve(id, importer, options)
if (resolved && !resolved.external) {
depsOptimizer.delayDepsOptimizerUntil(resolved.id, async () => {
await this.load(resolved)
Expand Down
1 change: 0 additions & 1 deletion packages/vite/src/node/plugins/preAlias.ts
Expand Up @@ -56,7 +56,6 @@ export function preAliasPlugin(config: ResolvedConfig): Plugin {
const resolved = await this.resolve(id, importer, {
...options,
custom: { ...options.custom, 'vite:pre-alias': true },
skipSelf: true,
})
if (resolved && !depsOptimizer.isOptimizedDepFile(resolved.id)) {
const optimizeDeps = depsOptimizer.options
Expand Down