Skip to content

Commit 233aed8

Browse files
author
Roland Peelen
committed
🎨 - Allow arbitrary suffix
1 parent 860d66c commit 233aed8

File tree

4 files changed

+13
-31
lines changed

4 files changed

+13
-31
lines changed

src/bsconfig.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use serde::{Deserialize, Serialize};
1+
use serde::Deserialize;
2+
use std::fs;
23
use std::path::{Path, PathBuf};
3-
use std::{fmt, fs};
4+
5+
pub static DEFAULT_SUFFIX: &str = ".mjs";
46

57
#[derive(Deserialize, Debug, Clone)]
68
#[serde(untagged)]
@@ -121,28 +123,6 @@ pub enum JsxModule {
121123
React,
122124
}
123125

124-
#[derive(Deserialize, Serialize, Debug, Clone)]
125-
pub enum Suffix {
126-
#[serde(rename = ".js")]
127-
Js,
128-
#[serde(rename = ".mjs")]
129-
Mjs,
130-
#[serde(rename = ".cjs")]
131-
Cjs,
132-
#[serde(rename = ".bs.js")]
133-
BsJs,
134-
#[serde(rename = ".bs.mjs")]
135-
BsMjs,
136-
#[serde(rename = ".bs.cjs")]
137-
BsCjs,
138-
}
139-
140-
impl fmt::Display for Suffix {
141-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
142-
write!(f, "{}", serde_json::to_value(self).unwrap().as_str().unwrap())
143-
}
144-
}
145-
146126
#[derive(Deserialize, Debug, Clone)]
147127
pub struct JsxSpecs {
148128
pub version: Option<i32>,
@@ -161,7 +141,7 @@ pub struct T {
161141
#[serde(rename = "package-specs")]
162142
pub package_specs: Option<OneOrMore<PackageSpec>>,
163143
pub warnings: Option<Warnings>,
164-
pub suffix: Option<Suffix>,
144+
pub suffix: Option<String>,
165145
#[serde(rename = "pinned-dependencies")]
166146
pub pinned_dependencies: Option<Vec<String>>,
167147
#[serde(rename = "bs-dependencies")]

src/build/build_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub struct AstModule {
117117
pub last_modified: SystemTime,
118118
pub ast_file_path: String,
119119
pub is_root: bool,
120-
pub suffix: Option<crate::bsconfig::Suffix>,
120+
pub suffix: Option<String>,
121121
}
122122

123123
pub struct CompileAssetsState {

src/build/clean.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn remove_iast(source_file: &str, package_path: &str, root_path: &str, is_root:
3131
));
3232
}
3333

34-
fn remove_mjs_file(source_file: &str, suffix: &bsconfig::Suffix) {
34+
fn remove_mjs_file(source_file: &str, suffix: &String) {
3535
let _ = std::fs::remove_file(helpers::change_extension(
3636
source_file,
3737
// suffix.to_string includes the ., so we need to remove it
@@ -107,12 +107,12 @@ pub fn clean_mjs_files(build_state: &BuildState) {
107107
.bsconfig
108108
.suffix
109109
.to_owned()
110-
.unwrap_or(bsconfig::Suffix::Mjs),
110+
.unwrap_or(String::from(bsconfig::DEFAULT_SUFFIX)),
111111
))
112112
}
113113
_ => None,
114114
})
115-
.collect::<Vec<(String, bsconfig::Suffix)>>();
115+
.collect::<Vec<(String, String)>>();
116116

117117
rescript_file_locations
118118
.par_iter()
@@ -168,7 +168,9 @@ pub fn cleanup_previous_build(
168168
);
169169
remove_mjs_file(
170170
&res_file_location,
171-
&suffix.to_owned().unwrap_or(bsconfig::Suffix::Mjs),
171+
&suffix
172+
.to_owned()
173+
.unwrap_or(String::from(bsconfig::DEFAULT_SUFFIX)),
172174
);
173175
remove_iast(
174176
res_file_location,

src/build/compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ fn compile_file(
499499
// TODO: Also read suffix from package-spec.
500500
let suffix = match root_package.bsconfig.suffix.to_owned() {
501501
Some(suffix) => suffix,
502-
None => bsconfig::Suffix::Mjs,
502+
None => String::from(bsconfig::DEFAULT_SUFFIX)
503503
};
504504

505505
vec![

0 commit comments

Comments
 (0)