Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/vite/src/node/optimizer/rolldownDepPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const externalTypes = [
...KNOWN_ASSET_TYPES,
]


const optionalPeerDepNamespace = 'optional-peer-dep:'
const browserExternalNamespace = 'browser-external:'

Expand Down Expand Up @@ -328,4 +327,4 @@ export function rolldownCjsExternalPlugin(
}
},
}
}
}
43 changes: 22 additions & 21 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import glob from 'fast-glob'
import type { Plugin } from 'rolldown'
import { scan } from 'rolldown/experimental'
import type { Loader } from 'esbuild'
import { transform } from 'esbuild'
import { transform } from 'esbuild'
import colors from 'picocolors'
import type { ResolvedConfig } from '..'
import {
Expand Down Expand Up @@ -101,15 +101,13 @@ export function scanImports(config: ResolvedConfig): {
if (!context || scanContext?.cancelled) {
return { deps: {}, missing: {} }
}
return context
.build()
.then(() => {
return {
// Ensure a fixed order so hashes are stable and improve logs
deps: orderedDependencies(deps),
missing,
}
})
return context.build().then(() => {
return {
// Ensure a fixed order so hashes are stable and improve logs
deps: orderedDependencies(deps),
missing,
}
})
})
.catch(async (e) => {
// if (e.errors && e.message.includes('The build was canceled')) {
Expand All @@ -130,7 +128,7 @@ export function scanImports(config: ResolvedConfig): {
// })
// e.message = prependMessage + msgs.join('\n')
// } else {
e.message = prependMessage + e.message
e.message = prependMessage + e.message
// }
throw e
})
Expand Down Expand Up @@ -381,11 +379,12 @@ function rolldownScanPlugin(
if (contents.includes('import.meta.glob')) {
scripts[key] = {
contents: await doTransformGlobImport(contents, p),
loader
loader,
}
} else {
scripts[key] = {
contents, loader
contents,
loader,
}
}

Expand Down Expand Up @@ -418,10 +417,13 @@ function rolldownScanPlugin(
return js
}

const scripts: Record<string, {
contents: string,
loader: Loader,
}> = {}
const scripts: Record<
string,
{
contents: string
loader: Loader
}
> = {}

const ASSET_TYPE_RE = new RegExp(`\\.(${KNOWN_ASSET_TYPES.join('|')})$`)

Expand Down Expand Up @@ -577,7 +579,7 @@ function rolldownScanPlugin(
if (htmlTypesRE.test(id)) {
return {
code: await htmlTypeOnLoadCallback(id),
moduleType: 'js'
moduleType: 'js',
}
}

Expand All @@ -598,7 +600,7 @@ function rolldownScanPlugin(
if (loader !== 'js') {
let tsconfigRaw
const tsconfigResult = await loadTsconfigJsonForFile(
path.join(config.root, '_dummy.js'),
path.join(config.root, '_dummy.js'),
)
if (tsconfigResult.compilerOptions?.experimentalDecorators) {
tsconfigRaw = { compilerOptions: { experimentalDecorators: true } }
Expand All @@ -622,7 +624,6 @@ function rolldownScanPlugin(
}
}


/**
* when using TS + (Vue + `<script setup>`) or Svelte, imports may seem
* unused to esbuild and dropped in the build output, which prevents
Expand Down Expand Up @@ -664,4 +665,4 @@ function isScannable(id: string, extensions: string[] | undefined): boolean {
extensions?.includes(path.extname(id)) ||
false
)
}
}
6 changes: 5 additions & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ import { getDepOptimizationConfig } from '../config'
import type { ResolvedConfig } from '../config'
import type { Plugin } from '../plugin'
import { shouldExternalizeForSSR } from '../ssr/ssrExternal'
import { getDepsOptimizer, optimizedDepInfoFromFile, optimizedDepNeedsInterop } from '../optimizer'
import {
getDepsOptimizer,
optimizedDepInfoFromFile,
optimizedDepNeedsInterop,
} from '../optimizer'
import {
cleanUrl,
unwrapId,
Expand Down
16 changes: 10 additions & 6 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,19 +533,23 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
chunk.imports.forEach(addDeps)
// Ensure that the css imported by current chunk is loaded after the dependencies.
// So the style of current chunk won't be overwritten unexpectedly.
getChunkMetadata(chunk.name)!.importedCss.forEach((file) => {
deps.add(file)
})
getChunkMetadata(chunk.name)!.importedCss.forEach(
(file) => {
deps.add(file)
},
)
}
} else {
const removedPureCssFiles =
removedPureCssFilesCache.get(config)!
const chunk = removedPureCssFiles.get(filename)
if (chunk) {
if (getChunkMetadata(chunk.name)!.importedCss.size) {
getChunkMetadata(chunk.name)!.importedCss.forEach((file) => {
deps.add(file)
})
getChunkMetadata(chunk.name)!.importedCss.forEach(
(file) => {
deps.add(file)
},
)
hasRemovedPureCssChunk = true
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ export function metadataPlugin(): Plugin {

export function getChunkMetadata(name: string): ChunkMetadata | undefined {
return chunkMetadataMap.get(name)
}
}
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/preAlias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function preAliasPlugin(config: ResolvedConfig): Plugin {
if (depsOptimizer.options.noDiscovery) {
return
}
// TODO @underfin
// TODO @underfin
const resolved = await this.resolve(id, importer, {
// ...options,
// custom: { ...options.custom, 'vite:pre-alias': true },
Expand Down
38 changes: 19 additions & 19 deletions packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,25 +187,25 @@ export function webWorkerPostPlugin(): Plugin {
return {
name: 'vite:worker-post',
// TODO @underfin it's not unsupported yet
// resolveImportMeta(property, { format }) {
// // document is undefined in the worker, so we need to avoid it in iife
// if (format === 'iife') {
// // compiling import.meta
// if (!property) {
// // rollup only supports `url` property. we only support `url` property as well.
// // https://github.com/rollup/rollup/blob/62b648e1cc6a1f00260bb85aa2050097bb4afd2b/src/ast/nodes/MetaProperty.ts#L164-L173
// return `{
// url: self.location.href
// }`
// }
// // compiling import.meta.url
// if (property === 'url') {
// return 'self.location.href'
// }
// }

// return null
// },
// resolveImportMeta(property, { format }) {
// // document is undefined in the worker, so we need to avoid it in iife
// if (format === 'iife') {
// // compiling import.meta
// if (!property) {
// // rollup only supports `url` property. we only support `url` property as well.
// // https://github.com/rollup/rollup/blob/62b648e1cc6a1f00260bb85aa2050097bb4afd2b/src/ast/nodes/MetaProperty.ts#L164-L173
// return `{
// url: self.location.href
// }`
// }
// // compiling import.meta.url
// if (property === 'url') {
// return 'self.location.href'
// }
// }

// return null
// },
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/server/sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function applySourcemapIgnoreList(
) {
const sourcePath = map.sources[sourcesIndex]
if (!sourcePath) continue

const ignoreList = sourcemapIgnoreList(
path.isAbsolute(sourcePath)
? sourcePath
Expand All @@ -136,7 +136,7 @@ export function applySourcemapIgnoreList(
if (logger && typeof ignoreList !== 'boolean') {
logger.warn('sourcemapIgnoreList function must return a boolean.')
}

if (ignoreList && !x_google_ignoreList.includes(sourcesIndex)) {
x_google_ignoreList.push(sourcesIndex)
}
Expand Down
2 changes: 0 additions & 2 deletions packages/vite/src/node/ssr/runtime/__tests__/fixtures/c.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


export { a as c } from './a'

import.meta.hot?.accept(() => {
Expand Down
2 changes: 0 additions & 2 deletions packages/vite/src/node/ssr/runtime/__tests__/fixtures/d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


export { c as d } from './c'

import.meta.hot?.accept(() => {
Expand Down
8 changes: 5 additions & 3 deletions packages/vite/src/node/ssr/ssrManifestPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ export function ssrManifestPlugin(config: ResolvedConfig): Plugin {
analyzed.add(filename)
const chunk = bundle[filename] as OutputChunk | undefined
if (chunk) {
getChunkMetadata(chunk.name)!.importedCss.forEach((file) => {
deps.push(joinUrlSegments(base, file)) // TODO:base
})
getChunkMetadata(chunk.name)!.importedCss.forEach(
(file) => {
deps.push(joinUrlSegments(base, file)) // TODO:base
},
)
chunk.imports.forEach(addDeps)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1467,4 +1467,4 @@ export function parseRequest(id: string): Record<string, string> | null {
return null
}
return Object.fromEntries(new URLSearchParams(search))
}
}