@@ -96,12 +96,40 @@ pub struct CachedExternalModule {
9696}
9797
9898impl CachedExternalModule {
99- pub fn request ( & self ) -> Cow < ' _ , str > {
99+ pub fn virtual_package ( & self ) -> Option < String > {
100100 if let Some ( target) = & self . target {
101101 use turbo_tasks_hash:: DeterministicHash ;
102102 let mut hasher = Xxh3Hash64Hasher :: new ( ) ;
103103 target. path . deterministic_hash ( & mut hasher) ;
104- Cow :: Owned ( format ! ( "{}-{}" , self . request, encode_hex( hasher. finish( ) ) ) )
104+ let hash = encode_hex ( hasher. finish ( ) ) ;
105+
106+ let parent = target. parent ( ) ;
107+ let parent_filename = parent. file_name ( ) ;
108+ let filename = target. file_name ( ) ;
109+ if parent_filename. starts_with ( '@' ) {
110+ Some ( format ! ( "{}-{}-{}" , parent_filename, filename, hash) )
111+ } else {
112+ Some ( format ! ( "{}-{}" , filename, hash) )
113+ }
114+ } else {
115+ None
116+ }
117+ }
118+
119+ pub fn request ( & self ) -> Cow < ' _ , str > {
120+ if let Some ( virtual_package) = self . virtual_package ( ) {
121+ let request = if self . request . starts_with ( "@" ) {
122+ // Split off org
123+ self . request . split_once ( "/" ) . unwrap ( ) . 1
124+ } else {
125+ & * self . request
126+ } ;
127+
128+ if let Some ( ( _, subpath) ) = request. split_once ( "/" ) {
129+ Cow :: Owned ( format ! ( "{}/{}" , virtual_package, subpath) )
130+ } else {
131+ Cow :: Owned ( virtual_package)
132+ }
105133 } else {
106134 Cow :: Borrowed ( & * self . request )
107135 }
@@ -403,12 +431,12 @@ impl OutputAssetsReference for CachedExternalModuleChunkItem {
403431 #[ turbo_tasks:: function]
404432 async fn references ( & self ) -> Result < Vc < OutputAssetsWithReferenced > > {
405433 let module = self . module . await ?;
406- let assets = if let Some ( target ) = & module. target {
434+ let assets = if let Some ( virtual_package ) = module. virtual_package ( ) {
407435 ResolvedVc :: cell ( vec ! [ ResolvedVc :: upcast(
408436 SymlinkAsset :: new(
409437 * self . chunking_context,
410- module . request ( ) . into_owned ( ) . into( ) ,
411- target. clone( ) ,
438+ virtual_package . into( ) ,
439+ module . target. clone( ) . unwrap ( ) ,
412440 )
413441 . to_resolved( )
414442 . await ?,
0 commit comments