@@ -47,6 +47,7 @@ pub enum CachedExternalType {
4747 EcmaScriptViaImport ,
4848 Global ,
4949 Script ,
50+ Umd ,
5051}
5152
5253impl Display for CachedExternalType {
@@ -57,6 +58,7 @@ impl Display for CachedExternalType {
5758 CachedExternalType :: EcmaScriptViaImport => write ! ( f, "esm_import" ) ,
5859 CachedExternalType :: Global => write ! ( f, "global" ) ,
5960 CachedExternalType :: Script => write ! ( f, "script" ) ,
61+ CachedExternalType :: Umd => write ! ( f, "umd" ) ,
6062 }
6163 }
6264}
@@ -98,11 +100,11 @@ impl CachedExternalModule {
98100 CachedExternalType :: Global => {
99101 if self . request . is_empty ( ) {
100102 writeln ! ( code, "const mod = {{}};" ) ?;
101- } else if self . request . contains ( '/ ' ) {
103+ } else if self . request . contains ( ' ' ) {
102104 // Handle requests with '/' by splitting into nested global access
103105 let global_access = self
104106 . request
105- . split ( '/ ' )
107+ . split ( ' ' )
106108 . fold ( "globalThis" . to_string ( ) , |acc, part| {
107109 format ! ( "{}[{}]" , acc, StringifyJs ( part) )
108110 } ) ;
@@ -116,6 +118,22 @@ impl CachedExternalModule {
116118 ) ?;
117119 }
118120 }
121+ CachedExternalType :: Umd => {
122+ // request format is: "root React commonjs react"
123+ let parts = self . request . split ( ' ' ) . collect :: < Vec < _ > > ( ) ;
124+ let global_name = parts[ 1 ] ;
125+ let module_name = parts[ 3 ] ;
126+
127+ writeln ! (
128+ code,
129+ "let mod; if (typeof exports === 'object' && typeof module === 'object') {{ \
130+ mod = {TURBOPACK_EXTERNAL_REQUIRE}({}, () => require({})); }} else {{ mod = \
131+ globalThis[{}] }}",
132+ StringifyJs ( module_name) ,
133+ StringifyJs ( module_name) ,
134+ StringifyJs ( global_name) ,
135+ ) ?;
136+ }
119137 CachedExternalType :: Script => {
120138 // Parse the request format: "variableName@url"
121139 // e.g., "foo@https://test.test.com"
0 commit comments