@@ -5,7 +5,6 @@ use std::{
55} ;
66
77use derivative:: Derivative ;
8- use nodejs_resolver:: DescriptionData ;
98use once_cell:: sync:: OnceCell ;
109use rspack_error:: {
1110 internal_error, Diagnostic , IntoTWithDiagnosticArray , Result , TWithDiagnosticArray ,
@@ -31,7 +30,7 @@ pub struct ResourceData {
3130 pub resource_query : Option < String > ,
3231 /// Resource fragment with `#` prefix
3332 pub resource_fragment : Option < String > ,
34- pub resource_description : Option < Arc < DescriptionData > > ,
33+ pub resource_description : Option < DescriptionData > ,
3534 pub mimetype : Option < String > ,
3635 pub parameters : Option < String > ,
3736 pub encoding : Option < String > ,
@@ -79,12 +78,12 @@ impl ResourceData {
7978 self
8079 }
8180
82- pub fn description ( mut self , v : Arc < DescriptionData > ) -> Self {
81+ pub fn description ( mut self , v : DescriptionData ) -> Self {
8382 self . resource_description = Some ( v) ;
8483 self
8584 }
8685
87- pub fn description_optional ( mut self , v : Option < Arc < DescriptionData > > ) -> Self {
86+ pub fn description_optional ( mut self , v : Option < DescriptionData > ) -> Self {
8887 self . resource_description = v;
8988 self
9089 }
@@ -110,6 +109,31 @@ impl ResourceData {
110109 }
111110}
112111
112+ /// Used for [Rule.descriptionData](https://www.rspack.dev/config/module.html#ruledescriptiondata) and
113+ /// package.json.sideEffects in tree shaking.
114+ #[ derive( Debug , Clone ) ]
115+ pub struct DescriptionData {
116+ /// Path to package.json
117+ path : PathBuf ,
118+
119+ /// Raw package.json
120+ json : Arc < serde_json:: Value > ,
121+ }
122+
123+ impl DescriptionData {
124+ pub fn new ( path : PathBuf , json : Arc < serde_json:: Value > ) -> Self {
125+ Self { path, json }
126+ }
127+
128+ pub fn path ( & self ) -> & Path {
129+ & self . path
130+ }
131+
132+ pub fn json ( & self ) -> & serde_json:: Value {
133+ self . json . as_ref ( )
134+ }
135+ }
136+
113137#[ derive( Derivative ) ]
114138#[ derivative( Debug ) ]
115139pub struct LoaderContext < ' c , C > {
0 commit comments