diff --git a/src/modules/nodejs.rs b/src/modules/nodejs.rs index e1717a0a..100717f8 100644 --- a/src/modules/nodejs.rs +++ b/src/modules/nodejs.rs @@ -18,7 +18,12 @@ pub fn module<'a>(context: &'a Context) -> Option> { .set_folders(&["node_modules"]) .is_match(); - if !is_js_project { + let is_esy_project = context + .try_begin_scan()? + .set_folders(&["esy.lock"]) + .is_match(); + + if !is_js_project || is_esy_project { return None; } @@ -63,6 +68,19 @@ mod tests { dir.close() } + #[test] + fn folder_with_package_json_and_esy_lock() -> io::Result<()> { + let dir = tempfile::tempdir()?; + File::create(dir.path().join("package.json"))?.sync_all()?; + let esy_lock = dir.path().join("esy.lock"); + fs::create_dir_all(&esy_lock)?; + + let actual = render_module("nodejs", dir.path(), None); + let expected = None; + assert_eq!(expected, actual); + dir.close() + } + #[test] fn folder_with_node_version() -> io::Result<()> { let dir = tempfile::tempdir()?; diff --git a/src/modules/ocaml.rs b/src/modules/ocaml.rs index ad61305c..be132b0e 100644 --- a/src/modules/ocaml.rs +++ b/src/modules/ocaml.rs @@ -24,7 +24,17 @@ pub fn module<'a>(context: &'a Context) -> Option> { return None; } - let ocaml_version = utils::exec_cmd("ocaml", &["-vnum"])?.stdout; + let is_esy_project = context + .try_begin_scan()? + .set_folders(&["esy.lock"]) + .is_match(); + + let ocaml_version = if is_esy_project { + utils::exec_cmd("esy", &["ocaml", "-vnum"])?.stdout + } else { + utils::exec_cmd("ocaml", &["-vnum"])?.stdout + }; + let formatted_version = format!("v{}", &ocaml_version); let mut module = context.new_module("ocaml"); @@ -79,9 +89,13 @@ mod tests { fn folder_with_esy_lock_directory() -> io::Result<()> { let dir = tempfile::tempdir()?; fs::create_dir_all(dir.path().join("esy.lock"))?; - + File::create(dir.path().join("package.json"))?.sync_all()?; + fs::write( + dir.path().join("package.lock"), + "{\"dependencies\": {\"ocaml\": \"4.8.1000\"}}", + )?; let actual = render_module("ocaml", dir.path(), None); - let expected = Some(format!("via {} ", Color::Yellow.bold().paint("🐫 v4.10.0"))); + let expected = Some(format!("via {} ", Color::Yellow.bold().paint("🐫 v4.08.1"))); assert_eq!(expected, actual); dir.close() } diff --git a/src/utils.rs b/src/utils.rs index ee7af608..79b8d883 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -87,6 +87,10 @@ active boot switches: -d:release\n", stdout: String::from("4.10.0"), stderr: String::default(), }), + "esy ocaml -vnum" => Some(CommandOutput { + stdout: String::from("4.08.1"), + stderr: String::default(), + }), "php -nr echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.'.'.PHP_RELEASE_VERSION;" => { Some(CommandOutput { stdout: String::from("7.3.8"),