@@ -42,9 +42,11 @@ import type {
42
42
LoadResult ,
43
43
MinimalPluginContext ,
44
44
ModuleInfo ,
45
+ ModuleOptions ,
45
46
NormalizedInputOptions ,
46
47
OutputOptions ,
47
48
ParallelPluginHooks ,
49
+ PartialNull ,
48
50
PartialResolvedId ,
49
51
ResolvedId ,
50
52
RollupError ,
@@ -126,8 +128,6 @@ export interface PluginContainer {
126
128
127
129
type PluginContext = Omit <
128
130
RollupPluginContext ,
129
- // not supported
130
- | 'load'
131
131
// not documented
132
132
| 'cache'
133
133
// deprecated
@@ -221,6 +221,10 @@ export async function createPluginContainer(
221
221
if ( key in info ) {
222
222
return info [ key ]
223
223
}
224
+ // Don't throw an error when returning from an async function
225
+ if ( key === 'then' ) {
226
+ return undefined
227
+ }
224
228
throw Error (
225
229
`[vite] The "${ key } " property of ModuleInfo is not supported.` ,
226
230
)
@@ -306,6 +310,28 @@ export async function createPluginContainer(
306
310
return out as ResolvedId | null
307
311
}
308
312
313
+ async load (
314
+ options : {
315
+ id : string
316
+ resolveDependencies ?: boolean
317
+ } & Partial < PartialNull < ModuleOptions > > ,
318
+ ) : Promise < ModuleInfo > {
319
+ // We may not have added this to our module graph yet, so ensure it exists
320
+ await moduleGraph ?. ensureEntryFromUrl ( options . id )
321
+ // Not all options passed to this function make sense in the context of loading individual files,
322
+ // but we can at least update the module info properties we support
323
+ updateModuleInfo ( options . id , options )
324
+
325
+ await container . load ( options . id , { ssr : this . ssr } )
326
+ const moduleInfo = this . getModuleInfo ( options . id )
327
+ // This shouldn't happen due to calling ensureEntryFromUrl, but 1) our types can't ensure that
328
+ // and 2) moduleGraph may not have been provided (though in the situations where that happens,
329
+ // we should never have plugins calling this.load)
330
+ if ( ! moduleInfo )
331
+ throw Error ( `Failed to load module with id ${ options . id } ` )
332
+ return moduleInfo
333
+ }
334
+
309
335
getModuleInfo ( id : string ) {
310
336
return getModuleInfo ( id )
311
337
}
0 commit comments