@@ -34,7 +34,8 @@ use crate::{
3434 layer:: { LayerBlockRule , LayerName } ,
3535 Location ,
3636 } ,
37- values:: ident:: DashedIdentReference , traits:: ToCss ,
37+ traits:: ToCss ,
38+ values:: ident:: DashedIdentReference ,
3839} ;
3940use crate :: {
4041 error:: { Error , ParserError } ,
@@ -189,7 +190,7 @@ impl<'i, T: std::error::Error> BundleErrorKind<'i, T> {
189190
190191impl < ' a , ' o , ' s , P : SourceProvider , T : AtRuleParser < ' a > + Clone + Sync + Send > Bundler < ' a , ' o , ' s , P , T >
191192where
192- T :: AtRule : Sync + Send + ToCss
193+ T :: AtRule : Sync + Send + ToCss ,
193194{
194195 /// Creates a new Bundler using the given source provider.
195196 /// If a source map is given, the content of each source file included in the bundle will
@@ -547,7 +548,11 @@ where
547548 fn order ( & mut self ) {
548549 process ( self . stylesheets . get_mut ( ) . unwrap ( ) , 0 , & mut HashSet :: new ( ) ) ;
549550
550- fn process < ' i , T : AtRuleParser < ' i > > ( stylesheets : & mut Vec < BundleStyleSheet < ' i , ' _ , T > > , source_index : u32 , visited : & mut HashSet < u32 > ) {
551+ fn process < ' i , T : AtRuleParser < ' i > > (
552+ stylesheets : & mut Vec < BundleStyleSheet < ' i , ' _ , T > > ,
553+ source_index : u32 ,
554+ visited : & mut HashSet < u32 > ,
555+ ) {
551556 if visited. contains ( & source_index) {
552557 return ;
553558 }
@@ -722,6 +727,7 @@ mod tests {
722727 use indoc:: indoc;
723728 use std:: collections:: HashMap ;
724729
730+ #[ derive( Clone ) ]
725731 struct TestProvider {
726732 map : HashMap < PathBuf , String > ,
727733 }
@@ -789,7 +795,11 @@ mod tests {
789795 stylesheet. to_css ( PrinterOptions :: default ( ) ) . unwrap ( ) . code
790796 }
791797
792- fn bundle_css_module < P : SourceProvider > ( fs : P , entry : & str ) -> ( String , CssModuleExports ) {
798+ fn bundle_css_module < P : SourceProvider > (
799+ fs : P ,
800+ entry : & str ,
801+ project_root : Option < & str > ,
802+ ) -> ( String , CssModuleExports ) {
793803 let mut bundler = Bundler :: new (
794804 & fs,
795805 None ,
@@ -803,7 +813,12 @@ mod tests {
803813 ) ;
804814 let mut stylesheet = bundler. bundle ( Path :: new ( entry) ) . unwrap ( ) ;
805815 stylesheet. minify ( MinifyOptions :: default ( ) ) . unwrap ( ) ;
806- let res = stylesheet. to_css ( PrinterOptions :: default ( ) ) . unwrap ( ) ;
816+ let res = stylesheet
817+ . to_css ( PrinterOptions {
818+ project_root,
819+ ..PrinterOptions :: default ( )
820+ } )
821+ . unwrap ( ) ;
807822 ( res. code , res. exports . unwrap ( ) )
808823 }
809824
@@ -1688,6 +1703,7 @@ mod tests {
16881703 } ,
16891704 } ,
16901705 "/a.css" ,
1706+ None ,
16911707 ) ;
16921708 assert_eq ! (
16931709 code,
@@ -1722,6 +1738,7 @@ mod tests {
17221738 } ,
17231739 } ,
17241740 "/a.css" ,
1741+ None ,
17251742 ) ;
17261743 assert_eq ! (
17271744 code,
@@ -1763,6 +1780,7 @@ mod tests {
17631780 } ,
17641781 } ,
17651782 "/a.css" ,
1783+ None ,
17661784 ) ;
17671785 assert_eq ! (
17681786 code,
@@ -1802,6 +1820,7 @@ mod tests {
18021820 } ,
18031821 } ,
18041822 "/a.css" ,
1823+ None ,
18051824 ) ;
18061825 assert_eq ! (
18071826 code,
@@ -1824,6 +1843,59 @@ mod tests {
18241843 "a" => "_6lixEq_a"
18251844 }
18261845 ) ;
1846+
1847+ // Hashes are stable between project roots.
1848+ let expected = indoc ! { r#"
1849+ .dyGcAa_b {
1850+ background: #ff0;
1851+ }
1852+
1853+ .CK9avG_a {
1854+ background: #fff;
1855+ }
1856+ "# } ;
1857+
1858+ let ( code, _) = bundle_css_module (
1859+ TestProvider {
1860+ map : fs ! {
1861+ "/foo/bar/a.css" : r#"
1862+ @import "b.css";
1863+ .a {
1864+ background: white;
1865+ }
1866+ "# ,
1867+ "/foo/bar/b.css" : r#"
1868+ .b {
1869+ background: yellow;
1870+ }
1871+ "#
1872+ } ,
1873+ } ,
1874+ "/foo/bar/a.css" ,
1875+ Some ( "/foo/bar" ) ,
1876+ ) ;
1877+ assert_eq ! ( code, expected) ;
1878+
1879+ let ( code, _) = bundle_css_module (
1880+ TestProvider {
1881+ map : fs ! {
1882+ "/x/y/z/a.css" : r#"
1883+ @import "b.css";
1884+ .a {
1885+ background: white;
1886+ }
1887+ "# ,
1888+ "/x/y/z/b.css" : r#"
1889+ .b {
1890+ background: yellow;
1891+ }
1892+ "#
1893+ } ,
1894+ } ,
1895+ "/x/y/z/a.css" ,
1896+ Some ( "/x/y/z" ) ,
1897+ ) ;
1898+ assert_eq ! ( code, expected) ;
18271899 }
18281900
18291901 #[ test]
0 commit comments