Skip to content

Commit

Permalink
refactor: plugin container (#17288)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored May 29, 2024
1 parent 8880bc5 commit 4aa4a80
Show file tree
Hide file tree
Showing 4 changed files with 640 additions and 558 deletions.
6 changes: 3 additions & 3 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
} from '../utils'
import type { Logger } from '../logger'
import { cleanUrl, slash } from '../../shared/utils'
import type { TransformPluginContext } from '../server/pluginContainer'
import { addToHTMLProxyTransformResult } from './html'
import {
assetUrlRE,
Expand Down Expand Up @@ -969,9 +970,8 @@ export function cssAnalysisPlugin(config: ResolvedConfig): Plugin {
!inlineRE.test(id) &&
!htmlProxyRE.test(id)
// attached by pluginContainer.addWatchFile
const pluginImports = (this as any)._addedImports as
| Set<string>
| undefined
const pluginImports = (this as unknown as TransformPluginContext)
._addedImports
if (pluginImports) {
// record deps in the module graph so edits to @import css can trigger
// main import to hot update
Expand Down
11 changes: 7 additions & 4 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
withTrailingSlash,
wrapId,
} from '../../shared/utils'
import type { TransformPluginContext } from '../server/pluginContainer'
import { throwOutdatedRequest } from './optimizedDeps'
import { isCSSRequest, isDirectCSSRequest } from './css'
import { browserExternalId } from './resolve'
Expand Down Expand Up @@ -253,7 +254,10 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
throwOutdatedRequest(importer)
}

if (!imports.length && !(this as any)._addedImports) {
if (
!imports.length &&
!(this as unknown as TransformPluginContext)._addedImports
) {
importerModule.isSelfAccepting = false
debug?.(
`${timeFrom(msAtStart)} ${colors.dim(
Expand Down Expand Up @@ -747,9 +751,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
// note that we want to handle .css?raw and .css?url here
if (!isCSSRequest(importer) || SPECIAL_QUERY_RE.test(importer)) {
// attached by pluginContainer.addWatchFile
const pluginImports = (this as any)._addedImports as
| Set<string>
| undefined
const pluginImports = (this as unknown as TransformPluginContext)
._addedImports
if (pluginImports) {
;(
await Promise.all(
Expand Down
Loading

0 comments on commit 4aa4a80

Please sign in to comment.