@@ -13,6 +13,9 @@ import type {
1313 * We are going to deprecate these types and we can try to use them back in the future.
1414 */
1515
16+ // same default value of "moduleInfo.meta" as in Rollup
17+ const EMPTY_OBJECT = Object . freeze ( { } )
18+
1619export class ModuleNode {
1720 _moduleGraph : ModuleGraph
1821 _clientModule : EnvironmentModuleNode | undefined
@@ -76,6 +79,48 @@ export class ModuleNode {
7679 }
7780 return importedModules
7881 }
82+ _getModuleInfoUnion ( prop : 'info' ) : ModuleInfo | undefined {
83+ const _clientValue = this . _clientModule ?. [ prop ]
84+ const _ssrValue = this . _ssrModule ?. [ prop ]
85+
86+ if ( _clientValue == null && _ssrValue == null ) return undefined
87+
88+ return new Proxy ( { } as any , {
89+ get : ( _ , key : string ) => {
90+ // `meta` refers to `ModuleInfo.meta` so we refer to `this.meta` to
91+ // handle the object union between client and ssr
92+ if ( key === 'meta' ) {
93+ return this . meta || EMPTY_OBJECT
94+ }
95+ if ( _clientValue ) {
96+ if ( key in _clientValue ) {
97+ return _clientValue [ key as keyof ModuleInfo ]
98+ }
99+ }
100+ if ( _ssrValue ) {
101+ if ( key in _ssrValue ) {
102+ return _ssrValue [ key as keyof ModuleInfo ]
103+ }
104+ }
105+ } ,
106+ } )
107+ }
108+ _getModuleObjectUnion ( prop : 'meta' ) : Record < string , any > | undefined {
109+ const _clientValue = this . _clientModule ?. [ prop ]
110+ const _ssrValue = this . _ssrModule ?. [ prop ]
111+
112+ if ( _clientValue == null && _ssrValue == null ) return undefined
113+
114+ const info : Record < string , any > = { }
115+ if ( _ssrValue ) {
116+ Object . assign ( info , _ssrValue )
117+ }
118+ if ( _clientValue ) {
119+ Object . assign ( info , _clientValue )
120+ }
121+ return info
122+ }
123+
79124 get url ( ) : string {
80125 return this . _get ( 'url' )
81126 }
@@ -97,11 +142,13 @@ export class ModuleNode {
97142 get type ( ) : 'js' | 'css' {
98143 return this . _get ( 'type' )
99144 }
145+ // `info` needs special care as it's defined as a proxy in `pluginContainer`,
146+ // so we also merge it as a proxy too
100147 get info ( ) : ModuleInfo | undefined {
101- return this . _get ( 'info' )
148+ return this . _getModuleInfoUnion ( 'info' )
102149 }
103150 get meta ( ) : Record < string , any > | undefined {
104- return this . _get ( 'meta' )
151+ return this . _getModuleObjectUnion ( 'meta' )
105152 }
106153 get importers ( ) : Set < ModuleNode > {
107154 return this . _getModuleSetUnion ( 'importers' )
0 commit comments