@@ -92,6 +92,7 @@ pub fn main() -> Result<(), std::io::Error> {
9292 } else {
9393 None
9494 } ;
95+
9596 if let Some ( output_file) = & cli_args. output_file {
9697 let mut code = res. code ;
9798 if cli_args. sourcemap {
@@ -107,7 +108,7 @@ pub fn main() -> Result<(), std::io::Error> {
107108 if cli_args. css_modules {
108109 let css_modules_filename = cli_args
109110 . css_modules_output_file
110- . unwrap_or ( infer_css_modules_filename ( cli_args . output_file ) ?) ;
111+ . unwrap_or ( infer_css_modules_filename ( & output_file) ?) ;
111112 if let Some ( exports) = res. exports {
112113 let css_modules_json = serde_json:: to_string ( & exports) ?;
113114 fs:: write ( css_modules_filename, css_modules_json) ?;
@@ -124,19 +125,15 @@ pub fn main() -> Result<(), std::io::Error> {
124125 Ok ( ( ) )
125126}
126127
127- fn infer_css_modules_filename ( output_file : Option < String > ) -> Result < String , std:: io:: Error > {
128- if let Some ( file) = output_file {
129- let path = path:: Path :: new ( & file) ;
130- if path. extension ( ) == Some ( ffi:: OsStr :: new ( "json" ) ) {
131- Err ( io:: Error :: new (
132- io:: ErrorKind :: Other ,
133- "Cannot infer a css modules json filename, since the output file extension is '.json'" ,
134- ) )
135- } else {
136- // unwrap: the filename option is a String from clap, so is valid utf-8
137- Ok ( path. with_extension ( "json" ) . to_str ( ) . unwrap ( ) . into ( ) )
138- }
128+ fn infer_css_modules_filename ( output_file : & str ) -> Result < String , std:: io:: Error > {
129+ let path = path:: Path :: new ( output_file) ;
130+ if path. extension ( ) == Some ( ffi:: OsStr :: new ( "json" ) ) {
131+ Err ( io:: Error :: new (
132+ io:: ErrorKind :: Other ,
133+ "Cannot infer a css modules json filename, since the output file extension is '.json'" ,
134+ ) )
139135 } else {
140- Ok ( "styles.json" . into ( ) )
136+ // unwrap: the filename option is a String from clap, so is valid utf-8
137+ Ok ( path. with_extension ( "json" ) . to_str ( ) . unwrap ( ) . into ( ) )
141138 }
142139}
0 commit comments