@@ -22,11 +22,50 @@ type HmrOutput = Exclude<
2222 undefined
2323>
2424
25+ export class MemoryFiles {
26+ private files = new Map <
27+ string ,
28+ string | Uint8Array | ( ( ) => string | Uint8Array )
29+ > ( )
30+
31+ get size ( ) : number {
32+ return this . files . size
33+ }
34+
35+ get ( file : string ) : string | Uint8Array | undefined {
36+ const result = this . files . get ( file )
37+ if ( result === undefined ) {
38+ return undefined
39+ }
40+ if ( typeof result === 'function' ) {
41+ const content = result ( )
42+ this . files . set ( file , content )
43+ return content
44+ }
45+ return result
46+ }
47+
48+ set (
49+ file : string ,
50+ content : string | Uint8Array | ( ( ) => string | Uint8Array ) ,
51+ ) : void {
52+ this . files . set ( file , content )
53+ }
54+
55+ has ( file : string ) : boolean {
56+ return this . files . has ( file )
57+ }
58+
59+ clear ( ) : void {
60+ this . files . clear ( )
61+ }
62+ }
63+
2564export class FullBundleDevEnvironment extends DevEnvironment {
2665 private state : BundleState = { type : 'initial' }
2766
2867 watchFiles = new Set < string > ( )
29- memoryFiles = new Map < string , string | Uint8Array > ( )
68+ memoryFiles = new MemoryFiles ( )
3069
3170 constructor (
3271 name : string ,
@@ -299,14 +338,13 @@ export class FullBundleDevEnvironment extends DevEnvironment {
299338 ) {
300339 try {
301340 const startTime = Date . now ( )
302- const newMemoryFiles = new Map < string , string | Uint8Array > ( )
341+ const newMemoryFiles = new Map < string , ( ) => string | Uint8Array > ( )
303342 for ( const outputOpts of arraify ( outOpts ) ) {
304343 const output = await bundle . generate ( outputOpts )
305344 if ( signal . aborted ) return
306345
307346 for ( const outputFile of output . output ) {
308- newMemoryFiles . set (
309- outputFile . fileName ,
347+ newMemoryFiles . set ( outputFile . fileName , ( ) =>
310348 outputFile . type === 'chunk' ? outputFile . code : outputFile . source ,
311349 )
312350 }
0 commit comments