@@ -13,6 +13,9 @@ import type {
13
13
* We are going to deprecate these types and we can try to use them back in the future.
14
14
*/
15
15
16
+ // same default value of "moduleInfo.meta" as in Rollup
17
+ const EMPTY_OBJECT = Object . freeze ( { } )
18
+
16
19
export class ModuleNode {
17
20
_moduleGraph : ModuleGraph
18
21
_clientModule : EnvironmentModuleNode | undefined
@@ -76,6 +79,48 @@ export class ModuleNode {
76
79
}
77
80
return importedModules
78
81
}
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
+
79
124
get url ( ) : string {
80
125
return this . _get ( 'url' )
81
126
}
@@ -97,11 +142,13 @@ export class ModuleNode {
97
142
get type ( ) : 'js' | 'css' {
98
143
return this . _get ( 'type' )
99
144
}
145
+ // `info` needs special care as it's defined as a proxy in `pluginContainer`,
146
+ // so we also merge it as a proxy too
100
147
get info ( ) : ModuleInfo | undefined {
101
- return this . _get ( 'info' )
148
+ return this . _getModuleInfoUnion ( 'info' )
102
149
}
103
150
get meta ( ) : Record < string , any > | undefined {
104
- return this . _get ( 'meta' )
151
+ return this . _getModuleObjectUnion ( 'meta' )
105
152
}
106
153
get importers ( ) : Set < ModuleNode > {
107
154
return this . _getModuleSetUnion ( 'importers' )
0 commit comments