diff --git a/crates/moon/tests/test_cases/mod.rs b/crates/moon/tests/test_cases/mod.rs index 8f201769..f82c5709 100644 --- a/crates/moon/tests/test_cases/mod.rs +++ b/crates/moon/tests/test_cases/mod.rs @@ -8030,39 +8030,47 @@ fn test_moon_query() { } #[test] +#[allow(clippy::just_underscores_and_digits)] fn test_moon_install_bin() { - let dir = TestDir::new("moon_install_bin.in"); - let dir = dir.join("user.in"); + let top_dir = TestDir::new("moon_install_bin.in"); + let dir = top_dir.join("user.in"); - let mooncakes_path = dir.join(moonutil::common::DEP_PATH); - if mooncakes_path.exists() { - std::fs::remove_dir_all(&mooncakes_path).unwrap(); - } - - let bin_dir = mooncakes_path.join(moonutil::common::MOON_BIN_DIR); + let _1 = top_dir.join("author2.in").join("author2-native.exe"); + let _2 = top_dir.join("author2.in").join("author2-js.js"); + let _3 = top_dir.join("author2.in").join("author2-wasm.wasm"); + let _4 = top_dir.join("author1.in").join("this-is-wasm.wasm"); + let _5 = top_dir.join("author1.in").join("main-js.js"); // moon check should auto install bin deps get_stdout(&dir, ["check"]); - assert!(bin_dir.exists()); - assert!(bin_dir.join("author2-native.exe").exists()); - assert!(bin_dir.join("author2-js.js").exists()); - assert!(bin_dir.join("author2-wasm.wasm").exists()); - assert!(bin_dir.join("m-wasm.wasm").exists()); - assert!(bin_dir.join("main-js.js").exists()); - - std::fs::remove_dir_all(&mooncakes_path).unwrap(); + assert!(_1.exists()); + assert!(_2.exists()); + assert!(_3.exists()); + assert!(_4.exists()); + assert!(_5.exists()); - assert!(!bin_dir.exists()); + { + // delete all bin files + std::fs::remove_file(&_1).unwrap(); + std::fs::remove_file(&_2).unwrap(); + std::fs::remove_file(&_3).unwrap(); + std::fs::remove_file(&_4).unwrap(); + std::fs::remove_file(&_5).unwrap(); + assert!(!_1.exists()); + assert!(!_2.exists()); + assert!(!_3.exists()); + assert!(!_4.exists()); + assert!(!_5.exists()); + } // moon install should install bin deps get_stdout(&dir, ["install"]); - assert!(bin_dir.exists()); - assert!(bin_dir.join("author2-native.exe").exists()); - assert!(bin_dir.join("author2-js.js").exists()); - assert!(bin_dir.join("author2-wasm.wasm").exists()); - assert!(bin_dir.join("m-wasm.wasm").exists()); - assert!(bin_dir.join("main-js.js").exists()); + assert!(_1.exists()); + assert!(_2.exists()); + assert!(_3.exists()); + assert!(_4.exists()); + assert!(_5.exists()); check( get_stderr(&dir, ["build"]), diff --git a/crates/moon/tests/test_cases/moon_install_bin.in/user.in/main/moon.pkg.json b/crates/moon/tests/test_cases/moon_install_bin.in/user.in/main/moon.pkg.json index 661f5b10..1cae2c2c 100644 --- a/crates/moon/tests/test_cases/moon_install_bin.in/user.in/main/moon.pkg.json +++ b/crates/moon/tests/test_cases/moon_install_bin.in/user.in/main/moon.pkg.json @@ -7,7 +7,7 @@ { "input": [], "output": ["1.txt"], - "command": "node $mooncake_bin/main-js.js" + "command": "node ../author1.in/main-js.js" } ] } diff --git a/crates/moon/tests/test_cases/moon_install_bin.in/user.in/moon.mod.json b/crates/moon/tests/test_cases/moon_install_bin.in/user.in/moon.mod.json index 692cd055..77ddf5ba 100644 --- a/crates/moon/tests/test_cases/moon_install_bin.in/user.in/moon.mod.json +++ b/crates/moon/tests/test_cases/moon_install_bin.in/user.in/moon.mod.json @@ -11,10 +11,7 @@ "path": "../author1.in", "bin_pkg": [ "main-js", - { - "name": "main-wasm", - "alias": "m-wasm" - } + "main-wasm" ] }, "author2/flash": { diff --git a/crates/mooncake/src/pkg/install.rs b/crates/mooncake/src/pkg/install.rs index 67757561..c113070e 100644 --- a/crates/mooncake/src/pkg/install.rs +++ b/crates/mooncake/src/pkg/install.rs @@ -62,10 +62,6 @@ pub(crate) fn install_impl( } if let Some(ref bin_deps) = m.bin_deps { - let install_path = source_dir - .join(moonutil::common::DEP_PATH) - .join(moonutil::common::MOON_BIN_DIR); - let moon_path = std::env::current_exe() .map_or_else(|_| "moon".into(), |x| x.to_string_lossy().into_owned()); @@ -86,14 +82,7 @@ pub(crate) fn install_impl( let module_db = get_module_db(&bin_mod_path, &res, &dep_dir)?; if let Some(ref bin_pkg) = info.bin_pkg { - for bin_pkg_to_install in bin_pkg { - let (pkg_name, bin_alias) = match bin_pkg_to_install { - moonutil::dependency::BinPkgItem::Simple(pkg_name) => (pkg_name, None), - moonutil::dependency::BinPkgItem::Detailed { name, alias } => { - (name, alias.as_ref()) - } - }; - + for pkg_name in bin_pkg { let full_pkg_name = format!("{bin_mod_to_install}/{pkg_name}"); let pkg = module_db.get_package_by_name_safe(&full_pkg_name); @@ -103,9 +92,8 @@ pub(crate) fn install_impl( &moon_path, &bin_mod_path, &full_pkg_name, - &install_path, + &bin_mod_path, pkg.bin_target.to_backend_ext(), - bin_alias, verbose, )?; } @@ -122,28 +110,13 @@ pub(crate) fn install_impl( &moon_path, &bin_mod_path, full_pkg_name, - &install_path, + &bin_mod_path, pkg.bin_target.to_backend_ext(), - None, verbose, )?; } } } - - // remove all files except .exe, .wasm, .js - if install_path.exists() { - for entry in std::fs::read_dir(&install_path)? { - let entry = entry?; - let path = entry.path(); - if path.is_file() { - let ext = path.extension().and_then(|s| s.to_str()); - if !matches!(ext, Some("exe" | "wasm" | "js")) { - std::fs::remove_file(path)?; - } - } - } - } } Ok((res, dep_dir)) @@ -155,7 +128,6 @@ fn build_and_install_bin_package( full_pkg_name: &str, install_path: &Path, bin_target: impl AsRef, - bin_alias: Option<&String>, verbose: bool, ) -> anyhow::Result<()> { let mut build_args = vec![ @@ -170,11 +142,6 @@ fn build_and_install_bin_package( full_pkg_name.to_string(), ]; - if let Some(bin_alias) = bin_alias { - build_args.push("--bin-alias".to_string()); - build_args.push(bin_alias.to_string()); - } - if !verbose { build_args.push("--quiet".to_string()); } diff --git a/crates/moonutil/src/dependency.rs b/crates/moonutil/src/dependency.rs index 91859095..002918d9 100644 --- a/crates/moonutil/src/dependency.rs +++ b/crates/moonutil/src/dependency.rs @@ -165,18 +165,7 @@ pub struct BinaryDependencyInfo { /// Binary packages to compile. #[serde(skip_serializing_if = "Option::is_none", alias = "bin-pkg")] - pub bin_pkg: Option>, -} - -#[derive(Clone, Serialize, Deserialize, Debug)] -#[serde(untagged)] -pub enum BinPkgItem { - Simple(String), - Detailed { - name: String, - #[serde(skip_serializing_if = "Option::is_none")] - alias: Option, - }, + pub bin_pkg: Option>, } impl BinaryDependencyInfo {