@@ -5,7 +5,7 @@ import VirtualModulesPlugin from 'webpack-virtual-modules'
5
5
import type { ResolvePluginInstance , Resolver } from 'webpack'
6
6
import type { ResolvedUnpluginOptions , UnpluginContext , UnpluginContextMeta , UnpluginFactory , UnpluginInstance , WebpackCompiler } from '../types'
7
7
import { normalizeAbsolutePath , shouldLoad , toArray , transformUse } from '../utils'
8
- import { createContext } from './context'
8
+ import { contextOptionsFromCompilation , createContext } from './context'
9
9
10
10
const TRANSFORM_LOADER = resolve (
11
11
__dirname ,
@@ -89,7 +89,18 @@ export function getWebpackPlugin<UserOptions = Record<string, never>>(
89
89
const isEntry = requestContext . issuer === ''
90
90
91
91
// call hook
92
- const context = createContext ( )
92
+ // resolveContext.fileDependencies is typed as a WriteOnlySet, so make our own copy here
93
+ // so we can return it from getWatchFiles.
94
+ const fileDependencies = new Set < string > ( )
95
+ const context = createContext ( {
96
+ addWatchFile ( file ) {
97
+ fileDependencies . add ( file )
98
+ resolveContext . fileDependencies ?. add ( file )
99
+ } ,
100
+ getWatchFiles ( ) {
101
+ return Array . from ( fileDependencies )
102
+ } ,
103
+ } )
93
104
let error : Error | undefined
94
105
const pluginContext : UnpluginContext = {
95
106
error ( msg : string | Error ) {
@@ -178,7 +189,7 @@ export function getWebpackPlugin<UserOptions = Record<string, never>>(
178
189
179
190
if ( plugin . watchChange || plugin . buildStart ) {
180
191
compiler . hooks . make . tapPromise ( plugin . name , async ( compilation ) => {
181
- const context = createContext ( compilation )
192
+ const context = createContext ( contextOptionsFromCompilation ( compilation ) , compilation )
182
193
if ( plugin . watchChange && ( compiler . modifiedFiles || compiler . removedFiles ) ) {
183
194
const promises : Promise < void > [ ] = [ ]
184
195
if ( compiler . modifiedFiles ) {
@@ -201,7 +212,7 @@ export function getWebpackPlugin<UserOptions = Record<string, never>>(
201
212
202
213
if ( plugin . buildEnd ) {
203
214
compiler . hooks . emit . tapPromise ( plugin . name , async ( compilation ) => {
204
- await plugin . buildEnd ! . call ( createContext ( compilation ) )
215
+ await plugin . buildEnd ! . call ( createContext ( contextOptionsFromCompilation ( compilation ) , compilation ) )
205
216
} )
206
217
}
207
218
0 commit comments