Skip to content

Commit

Permalink
fix: register files added by addWatchFile() as current module's depen…
Browse files Browse the repository at this point in the history
…dency

fix vitejs#3216
  • Loading branch information
yyx990803 authored and aleclarson committed Nov 8, 2021
1 parent 575cf23 commit c4be70f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,17 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
// node CSS imports does its own graph update in the css plugin so we
// only handle js graph updates here.
if (!isCSSRequest(importer)) {
// attached by pluginContainer.addWatchFile
const pluginImports = (this as any)._addedImports as
| Set<string>
| undefined
if (pluginImports) {
;(
await Promise.all(
[...pluginImports].map((id) => normalizeUrl(id, 0))
)
).forEach(([url]) => importedUrls.add(url))
}
const prunedImports = await moduleGraph.updateModuleInfo(
importerModule,
importedUrls,
Expand Down
4 changes: 3 additions & 1 deletion packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export async function createPluginContainer(
_activeId: string | null = null
_activeCode: string | null = null
_resolveSkips?: Set<Plugin>
_addedImports: Set<string> | null = null

constructor(initialPlugin?: Plugin) {
this._activePlugin = initialPlugin || null
Expand Down Expand Up @@ -216,8 +217,9 @@ export async function createPluginContainer(
return MODULES.keys()
}

addWatchFile(id: string) {
async addWatchFile(id: string) {
watchFiles.add(id)
;(this._addedImports || (this._addedImports = new Set())).add(id)
if (watcher) ensureWatchedFile(watcher, id, root)
}

Expand Down

0 comments on commit c4be70f

Please sign in to comment.