diff --git a/src/bsconfig.rs b/src/bsconfig.rs index 813a399..38beb22 100644 --- a/src/bsconfig.rs +++ b/src/bsconfig.rs @@ -1,6 +1,8 @@ -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use std::fs; use std::path::{Path, PathBuf}; -use std::{fmt, fs}; + +pub static DEFAULT_SUFFIX: &str = ".mjs"; #[derive(Deserialize, Debug, Clone)] #[serde(untagged)] @@ -121,28 +123,6 @@ pub enum JsxModule { React, } -#[derive(Deserialize, Serialize, Debug, Clone)] -pub enum Suffix { - #[serde(rename = ".js")] - Js, - #[serde(rename = ".mjs")] - Mjs, - #[serde(rename = ".cjs")] - Cjs, - #[serde(rename = ".bs.js")] - BsJs, - #[serde(rename = ".bs.mjs")] - BsMjs, - #[serde(rename = ".bs.cjs")] - BsCjs, -} - -impl fmt::Display for Suffix { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", serde_json::to_value(self).unwrap().as_str().unwrap()) - } -} - #[derive(Deserialize, Debug, Clone)] pub struct JsxSpecs { pub version: Option, @@ -161,7 +141,7 @@ pub struct T { #[serde(rename = "package-specs")] pub package_specs: Option>, pub warnings: Option, - pub suffix: Option, + pub suffix: Option, #[serde(rename = "pinned-dependencies")] pub pinned_dependencies: Option>, #[serde(rename = "bs-dependencies")] diff --git a/src/build/build_types.rs b/src/build/build_types.rs index 6713ad2..37a551e 100644 --- a/src/build/build_types.rs +++ b/src/build/build_types.rs @@ -117,7 +117,7 @@ pub struct AstModule { pub last_modified: SystemTime, pub ast_file_path: String, pub is_root: bool, - pub suffix: Option, + pub suffix: Option, } pub struct CompileAssetsState { diff --git a/src/build/clean.rs b/src/build/clean.rs index 63f24e3..8ee3249 100644 --- a/src/build/clean.rs +++ b/src/build/clean.rs @@ -31,7 +31,7 @@ fn remove_iast(source_file: &str, package_path: &str, root_path: &str, is_root: )); } -fn remove_mjs_file(source_file: &str, suffix: &bsconfig::Suffix) { +fn remove_mjs_file(source_file: &str, suffix: &String) { let _ = std::fs::remove_file(helpers::change_extension( source_file, // suffix.to_string includes the ., so we need to remove it @@ -107,12 +107,12 @@ pub fn clean_mjs_files(build_state: &BuildState) { .bsconfig .suffix .to_owned() - .unwrap_or(bsconfig::Suffix::Mjs), + .unwrap_or(String::from(bsconfig::DEFAULT_SUFFIX)), )) } _ => None, }) - .collect::>(); + .collect::>(); rescript_file_locations .par_iter() @@ -168,7 +168,9 @@ pub fn cleanup_previous_build( ); remove_mjs_file( &res_file_location, - &suffix.to_owned().unwrap_or(bsconfig::Suffix::Mjs), + &suffix + .to_owned() + .unwrap_or(String::from(bsconfig::DEFAULT_SUFFIX)), ); remove_iast( res_file_location, diff --git a/src/build/compile.rs b/src/build/compile.rs index a0b9ba6..64ab73d 100644 --- a/src/build/compile.rs +++ b/src/build/compile.rs @@ -499,7 +499,7 @@ fn compile_file( // TODO: Also read suffix from package-spec. let suffix = match root_package.bsconfig.suffix.to_owned() { Some(suffix) => suffix, - None => bsconfig::Suffix::Mjs, + None => String::from(bsconfig::DEFAULT_SUFFIX) }; vec![