Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Dec 6, 2024
1 parent df58c5c commit a941c47
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 84 deletions.
3 changes: 1 addition & 2 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
withTrailingSlash,
} from '../../shared/utils'
import type { Environment } from '../environment'
import { getChunkMetadata } from './metadata'

// referenceId is base64url but replaces - with $
export const assetUrlRE = /__VITE_ASSET__([\w$]+)__(?:\$_(.*?)__)?/g
Expand Down Expand Up @@ -97,7 +96,7 @@ export function renderAssetUrlInJS(
s ||= new MagicString(code)
const [full, referenceId, postfix = ''] = match
const file = pluginContext.getFileName(referenceId)
getChunkMetadata(chunk)!.importedAssets.add(cleanUrl(file))
chunk.viteMetadata?.importedAssets.add(cleanUrl(file))
const filename = file + postfix
const replacement = toOutputFilePathInJS(
environment,
Expand Down
23 changes: 10 additions & 13 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ import {
} from './asset'
import type { ESBuildOptions } from './esbuild'
import { getChunkOriginalFileName } from './manifest'
import { getChunkMetadata } from './metadata'

const decoder = new TextDecoder()
// const debug = createDebugger('vite:css')
Expand Down Expand Up @@ -691,7 +690,7 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
// replace asset url references with resolved url.
chunkCSS = chunkCSS.replace(assetUrlRE, (_, fileHash, postfix = '') => {
const filename = this.getFileName(fileHash) + postfix
getChunkMetadata(chunk)!.importedAssets.add(cleanUrl(filename))
chunk.viteMetadata?.importedAssets.add(cleanUrl(filename))
return encodeURIPath(
toOutputFilePathInCss(
filename,
Expand Down Expand Up @@ -803,7 +802,7 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
generatedAssets.set(referenceId, { originalFileName })

const filename = this.getFileName(referenceId)
getChunkMetadata(chunk)!.importedAssets.add(cleanUrl(filename))
chunk.viteMetadata?.importedAssets.add(cleanUrl(filename))
const replacement = toOutputFilePathInJS(
this.environment,
filename,
Expand Down Expand Up @@ -859,9 +858,7 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
source: chunkCSS,
})
generatedAssets.set(referenceId, { originalFileName, isEntry })
getChunkMetadata(chunk)!.importedCss.add(
this.getFileName(referenceId),
)
chunk.viteMetadata?.importedCss.add(this.getFileName(referenceId))
} else if (this.environment.config.consumer === 'client') {
// legacy build and inline css

Expand Down Expand Up @@ -916,9 +913,9 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
},

augmentChunkHash(chunk) {
if (getChunkMetadata(chunk)?.importedCss.size) {
if (chunk.viteMetadata?.importedCss.size) {
let hash = ''
for (const id of getChunkMetadata(chunk)!.importedCss) {
for (const id of chunk.viteMetadata.importedCss) {
hash += id
}
return hash
Expand Down Expand Up @@ -1012,14 +1009,14 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
// chunks instead.
chunk.imports = chunk.imports.filter((file) => {
if (pureCssChunkNames.includes(file)) {
const { importedCss, importedAssets } = getChunkMetadata(
bundle[file] as OutputChunk,
)!
const { importedCss, importedAssets } = (
bundle[file] as OutputChunk
).viteMetadata!
importedCss.forEach((file) =>
getChunkMetadata(chunk)!.importedCss.add(file),
chunk.viteMetadata?.importedCss.add(file),
)
importedAssets.forEach((file) =>
getChunkMetadata(chunk)!.importedAssets.add(file),
chunk.viteMetadata?.importedAssets.add(file),
)
chunkImportsPureCssChunk = true
return false
Expand Down
5 changes: 2 additions & 3 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
} from './asset'
import { cssBundleNameCache, isCSSRequest } from './css'
import { modulePreloadPolyfillId } from './modulePreloadPolyfill'
import { getChunkMetadata } from './metadata'

interface ScriptAssetsUrl {
start: number
Expand Down Expand Up @@ -818,7 +817,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): RolldownPlugin {
})
}

getChunkMetadata(chunk)!.importedCss.forEach((file) => {
chunk.viteMetadata?.importedCss.forEach((file) => {
if (!seen.has(file)) {
seen.add(file)
tags.push({
Expand Down Expand Up @@ -973,7 +972,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): RolldownPlugin {
result = result.replace(assetUrlRE, (_, fileHash, postfix = '') => {
const file = this.getFileName(fileHash)
if (chunk) {
getChunkMetadata(chunk)!.importedAssets.add(cleanUrl(file))
chunk.viteMetadata?.importedAssets.add(cleanUrl(file))
}
return encodeURIPath(toOutputAssetFilePath(file)) + postfix
})
Expand Down
7 changes: 3 additions & 4 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { genSourceMapUrl } from '../server/sourcemap'
import type { PartialEnvironment } from '../baseEnvironment'
import { removedPureCssFilesCache } from './css'
import { createParseErrorInfo } from './importAnalysis'
import { getChunkMetadata } from './metadata'

type FileDep = {
url: string
Expand Down Expand Up @@ -560,7 +559,7 @@ 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)!.importedCss.forEach((file) => {
chunk.viteMetadata?.importedCss.forEach((file) => {
deps.add(file)
})
}
Expand All @@ -569,8 +568,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): [Plugin] {
removedPureCssFilesCache.get(config)!
const chunk = removedPureCssFiles.get(filename)
if (chunk) {
if (getChunkMetadata(chunk)!.importedCss.size) {
getChunkMetadata(chunk)!.importedCss.forEach((file) => {
if (chunk.viteMetadata?.importedCss.size) {
chunk.viteMetadata?.importedCss.forEach((file) => {
deps.add(file)
})
hasRemovedPureCssChunk = true
Expand Down
2 changes: 0 additions & 2 deletions packages/vite/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { preAliasPlugin } from './preAlias'
import { definePlugin } from './define'
import { workerImportMetaUrlPlugin } from './workerImportMetaUrl'
import { assetImportMetaUrlPlugin } from './assetImportMetaUrl'
import { metadataPlugin } from './metadata'
import { dynamicImportVarsPlugin } from './dynamicImportVars'
import { importGlobPlugin } from './importMetaGlob'
import { oxcPlugin } from './oxc'
Expand All @@ -60,7 +59,6 @@ export async function resolvePlugins(

return [
depOptimizationEnabled ? optimizedDepsPlugin() : null,
isBuild ? metadataPlugin() : null,
!isWorker ? watchPackageDataPlugin(config.packageCache) : null,
!isBuild ? preAliasPlugin(config) : null,
enableNativePlugin
Expand Down
9 changes: 4 additions & 5 deletions packages/vite/src/node/plugins/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
import type { Plugin } from '../plugin'
import { normalizePath, sortObjectKeys } from '../utils'
import { perEnvironmentState } from '../environment'
import { getChunkMetadata } from './metadata'
import { generatedAssetsMap } from './asset'

const endsWithJSRE = /\.[cm]?js$/
Expand Down Expand Up @@ -108,11 +107,11 @@ export function manifestPlugin(): Plugin {
}
}

if (getChunkMetadata(chunk)?.importedCss.size) {
manifestChunk.css = [...getChunkMetadata(chunk)!.importedCss]
if (chunk.viteMetadata?.importedCss.size) {
manifestChunk.css = [...chunk.viteMetadata.importedCss]
}
if (getChunkMetadata(chunk)?.importedAssets.size) {
manifestChunk.assets = [...getChunkMetadata(chunk)!.importedAssets]
if (chunk.viteMetadata?.importedAssets.size) {
manifestChunk.assets = [...chunk.viteMetadata.importedAssets]
}

return manifestChunk
Expand Down
51 changes: 0 additions & 51 deletions packages/vite/src/node/plugins/metadata.ts

This file was deleted.

7 changes: 3 additions & 4 deletions packages/vite/src/node/ssr/ssrManifestPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
sortObjectKeys,
} from '../utils'
import { perEnvironmentState } from '../environment'
import { getChunkMetadata } from '../plugins/metadata'

export function ssrManifestPlugin(): Plugin {
// module id => preload assets mapping
Expand Down Expand Up @@ -45,11 +44,11 @@ export function ssrManifestPlugin(): Plugin {
mappedChunks.push(joinUrlSegments(base, chunk.fileName))
// <link> tags for entry chunks are already generated in static HTML,
// so we only need to record info for non-entry chunks.
getChunkMetadata(chunk)!.importedCss.forEach((file) => {
chunk.viteMetadata?.importedCss.forEach((file) => {
mappedChunks.push(joinUrlSegments(base, file))
})
}
getChunkMetadata(chunk)!.importedAssets.forEach((file) => {
chunk.viteMetadata?.importedAssets.forEach((file) => {
mappedChunks.push(joinUrlSegments(base, file))
})
}
Expand Down Expand Up @@ -87,7 +86,7 @@ export function ssrManifestPlugin(): Plugin {
analyzed.add(filename)
const chunk = bundle[filename] as OutputChunk | undefined
if (chunk) {
getChunkMetadata(chunk)!.importedCss.forEach((file) => {
chunk.viteMetadata?.importedCss.forEach((file) => {
deps.push(joinUrlSegments(base, file))
})
chunk.imports.forEach(addDeps)
Expand Down

0 comments on commit a941c47

Please sign in to comment.