@@ -32,22 +32,22 @@ describe('plugin container', () => {
32
32
} ,
33
33
load ( id ) {
34
34
if ( id === entryUrl ) {
35
- const { meta } = this . getModuleInfo ( entryUrl )
35
+ const { meta } = this . getModuleInfo ( entryUrl ) ?? { }
36
36
metaArray . push ( meta )
37
37
38
38
return { code : 'export {}' , meta : { x : 2 } }
39
39
}
40
40
} ,
41
41
transform ( code , id ) {
42
42
if ( id === entryUrl ) {
43
- const { meta } = this . getModuleInfo ( entryUrl )
43
+ const { meta } = this . getModuleInfo ( entryUrl ) ?? { }
44
44
metaArray . push ( meta )
45
45
46
46
return { meta : { x : 3 } }
47
47
}
48
48
} ,
49
49
buildEnd ( ) {
50
- const { meta } = this . getModuleInfo ( entryUrl )
50
+ const { meta } = this . getModuleInfo ( entryUrl ) ?? { }
51
51
metaArray . push ( meta )
52
52
} ,
53
53
}
@@ -84,7 +84,7 @@ describe('plugin container', () => {
84
84
name : 'p2' ,
85
85
load ( id ) {
86
86
if ( id === entryUrl ) {
87
- const { meta } = this . getModuleInfo ( entryUrl )
87
+ const { meta } = this . getModuleInfo ( entryUrl ) ?? { }
88
88
expect ( meta ) . toEqual ( { x : 1 } )
89
89
return null
90
90
}
@@ -184,6 +184,38 @@ describe('plugin container', () => {
184
184
const result : any = await container . transform ( loadResult . code , entryUrl )
185
185
expect ( result . code ) . equals ( '2' )
186
186
} )
187
+
188
+ it ( 'will load and transform the module' , async ( ) => {
189
+ const entryUrl = '/x.js'
190
+ const otherUrl = '/y.js'
191
+
192
+ const plugin : Plugin = {
193
+ name : 'p1' ,
194
+ resolveId ( id ) {
195
+ return id
196
+ } ,
197
+ load ( id ) {
198
+ if ( id === entryUrl ) return { code : '1' }
199
+ else if ( id === otherUrl ) return { code : '2' , meta : { code : '2' } }
200
+ } ,
201
+ async transform ( code , id ) {
202
+ if ( id === entryUrl ) {
203
+ // NOTE: ModuleInfo.code not implemented, used `.meta.code` for now
204
+ return ( await this . load ( { id : otherUrl } ) ) ?. meta . code
205
+ } else if ( id === otherUrl ) {
206
+ return { code : '3' , meta : { code : '3' } }
207
+ }
208
+ } ,
209
+ }
210
+
211
+ const container = await getPluginContainer ( {
212
+ plugins : [ plugin ] ,
213
+ } )
214
+ await moduleGraph . ensureEntryFromUrl ( entryUrl , false )
215
+ const loadResult : any = await container . load ( entryUrl )
216
+ const result : any = await container . transform ( loadResult . code , entryUrl )
217
+ expect ( result . code ) . equals ( '3' )
218
+ } )
187
219
} )
188
220
} )
189
221
0 commit comments