Skip to content

Commit db14e6a

Browse files
committed
upstream new version of rewatch
1 parent c83f80c commit db14e6a

File tree

5 files changed

+151
-17
lines changed

5 files changed

+151
-17
lines changed

rewatch/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/target
2-
/docs
32
.DS_Store
3+
/docs

rewatch/src/build/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn clean_mjs_files(build_state: &BuildState) {
8383
.join(&source_file.implementation.path)
8484
.to_string_lossy()
8585
.to_string(),
86-
spec.get_suffix(),
86+
root_package.config.get_suffix(spec),
8787
))
8888
} else {
8989
None

rewatch/src/build/compile.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ pub fn compiler_args(
460460
vec![]
461461
} else {
462462
debug!("Compiling file: {}", &module_name);
463-
let specs = config.get_package_specs();
463+
let specs = root_config.get_package_specs();
464464

465465
specs
466466
.iter()
@@ -488,7 +488,7 @@ pub fn compiler_args(
488488
.unwrap()
489489
)
490490
},
491-
spec.get_suffix()
491+
root_config.get_suffix(spec),
492492
),
493493
];
494494
})
@@ -680,11 +680,11 @@ fn compile_file(
680680
}) => {
681681
let source = helpers::get_source_file_from_rescript_file(
682682
&std::path::Path::new(&package.path).join(path),
683-
&spec.get_suffix(),
683+
&root_package.config.get_suffix(spec),
684684
);
685685
let destination = helpers::get_source_file_from_rescript_file(
686686
&std::path::Path::new(&package.get_build_path()).join(path),
687-
&spec.get_suffix(),
687+
&root_package.config.get_suffix(spec),
688688
);
689689

690690
if source.exists() {

rewatch/src/build/read_compile_state.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ pub fn read(build_state: &mut BuildState) -> CompileAssetsState {
105105
is_root: *package_is_root,
106106
suffix: root_package
107107
.config
108-
.get_package_specs()
109-
.first()
110-
.map(|spec| spec.get_suffix())
111-
.unwrap(),
108+
.get_suffix(root_package.config.get_package_specs().first().unwrap()),
112109
},
113110
);
114111
let _ = ast_rescript_file_locations.insert(res_file_path);

rewatch/src/config.rs

Lines changed: 144 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ impl PackageSpec {
127127
}
128128
}
129129

130-
pub fn get_suffix(&self) -> String {
131-
self.suffix.to_owned().unwrap_or(".js".to_string())
130+
pub fn get_suffix(&self) -> Option<String> {
131+
self.suffix.to_owned()
132132
}
133133
}
134134

@@ -203,13 +203,13 @@ pub struct Config {
203203
pub suffix: Option<String>,
204204
#[serde(rename = "pinned-dependencies")]
205205
pub pinned_dependencies: Option<Vec<String>>,
206-
#[serde(rename = "bs-dependencies")]
206+
#[serde(rename = "dependencies", alias = "bs-dependencies")]
207207
pub bs_dependencies: Option<Vec<String>>,
208-
#[serde(rename = "bs-dev-dependencies")]
208+
#[serde(rename = "bs-dev-dependencies", alias = "dev-dependencies")]
209209
pub bs_dev_dependencies: Option<Vec<String>>,
210210
#[serde(rename = "ppx-flags")]
211211
pub ppx_flags: Option<Vec<OneOrMore<String>>>,
212-
#[serde(rename = "bsc-flags")]
212+
#[serde(rename = "bsc-flags", alias = "compiler-flags")]
213213
pub bsc_flags: Option<Vec<OneOrMore<String>>>,
214214
pub reason: Option<Reason>,
215215
pub namespace: Option<NamespaceConfig>,
@@ -435,6 +435,12 @@ impl Config {
435435
Some(OneOrMore::Multiple(vec)) => vec,
436436
}
437437
}
438+
439+
pub fn get_suffix(&self, spec: &PackageSpec) -> String {
440+
spec.get_suffix()
441+
.or(self.suffix.clone())
442+
.unwrap_or(".js".to_string())
443+
}
438444
}
439445

440446
#[cfg(test)]
@@ -455,8 +461,11 @@ mod tests {
455461
"#;
456462

457463
let config = serde_json::from_str::<Config>(json).unwrap();
458-
assert_eq!(config.get_suffix(), ".mjs");
459-
assert_eq!(config.get_module(), "es6");
464+
let specs = config.get_package_specs();
465+
assert_eq!(specs.len(), 1);
466+
let spec = specs.first().unwrap();
467+
assert_eq!(spec.module, "es6");
468+
assert_eq!(config.get_suffix(spec), ".mjs");
460469
}
461470

462471
#[test]
@@ -543,6 +552,134 @@ mod tests {
543552
);
544553
}
545554

555+
#[test]
556+
fn test_get_suffix() {
557+
let json = r#"
558+
{
559+
"name": "testrepo",
560+
"sources": {
561+
"dir": "src",
562+
"subdirs": true
563+
},
564+
"package-specs": [
565+
{
566+
"module": "es6",
567+
"in-source": true
568+
}
569+
],
570+
"suffix": ".mjs"
571+
}
572+
"#;
573+
574+
let config = serde_json::from_str::<Config>(json).unwrap();
575+
assert_eq!(
576+
config.get_suffix(&config.get_package_specs().first().unwrap()),
577+
".mjs"
578+
);
579+
}
580+
581+
#[test]
582+
fn test_dependencies() {
583+
let json = r#"
584+
{
585+
"name": "testrepo",
586+
"sources": {
587+
"dir": "src",
588+
"subdirs": true
589+
},
590+
"package-specs": [
591+
{
592+
"module": "es6",
593+
"in-source": true
594+
}
595+
],
596+
"suffix": ".mjs",
597+
"bs-dependencies": [ "@testrepo/main" ]
598+
}
599+
"#;
600+
601+
let config = serde_json::from_str::<Config>(json).unwrap();
602+
assert_eq!(config.bs_dependencies, Some(vec!["@testrepo/main".to_string()]));
603+
}
604+
605+
#[test]
606+
fn test_dependencies_alias() {
607+
let json = r#"
608+
{
609+
"name": "testrepo",
610+
"sources": {
611+
"dir": "src",
612+
"subdirs": true
613+
},
614+
"package-specs": [
615+
{
616+
"module": "es6",
617+
"in-source": true
618+
}
619+
],
620+
"suffix": ".mjs",
621+
"dependencies": [ "@testrepo/main" ]
622+
}
623+
"#;
624+
625+
let config = serde_json::from_str::<Config>(json).unwrap();
626+
assert_eq!(config.bs_dependencies, Some(vec!["@testrepo/main".to_string()]));
627+
}
628+
629+
#[test]
630+
fn test_dev_dependencies() {
631+
let json = r#"
632+
{
633+
"name": "testrepo",
634+
"sources": {
635+
"dir": "src",
636+
"subdirs": true
637+
},
638+
"package-specs": [
639+
{
640+
"module": "es6",
641+
"in-source": true
642+
}
643+
],
644+
"suffix": ".mjs",
645+
"bs-dev-dependencies": [ "@testrepo/main" ]
646+
}
647+
"#;
648+
649+
let config = serde_json::from_str::<Config>(json).unwrap();
650+
assert_eq!(
651+
config.bs_dev_dependencies,
652+
Some(vec!["@testrepo/main".to_string()])
653+
);
654+
}
655+
656+
#[test]
657+
fn test_dev_dependencies_alias() {
658+
let json = r#"
659+
{
660+
"name": "testrepo",
661+
"sources": {
662+
"dir": "src",
663+
"subdirs": true
664+
},
665+
"package-specs": [
666+
{
667+
"module": "es6",
668+
"in-source": true
669+
}
670+
],
671+
"suffix": ".mjs",
672+
"dev-dependencies": [ "@testrepo/main" ]
673+
}
674+
"#;
675+
676+
let config = serde_json::from_str::<Config>(json).unwrap();
677+
assert_eq!(
678+
config.bs_dev_dependencies,
679+
Some(vec!["@testrepo/main".to_string()])
680+
);
681+
}
682+
546683
#[test]
547684
fn test_check_if_rescript11_or_higher() {
548685
assert_eq!(check_if_rescript11_or_higher("11.0.0"), Ok(true));

0 commit comments

Comments
 (0)