diff --git a/crates/moon/tests/test_cases/mod.rs b/crates/moon/tests/test_cases/mod.rs index 2f5eb047..44db8451 100644 --- a/crates/moon/tests/test_cases/mod.rs +++ b/crates/moon/tests/test_cases/mod.rs @@ -4835,7 +4835,7 @@ fn test_moon_run_with_cli_args() { check( get_stdout(&dir, ["run", "main", "--dry-run"]), expect![[r#" - moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/main:./main -target wasm-gc + moonc build-package ./main/main_wasm.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/main:./main -target wasm-gc moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/release/build/main/main.core -main username/hello/main -o ./target/wasm-gc/release/build/main/main.wasm -pkg-config-path ./main/moon.pkg.json -pkg-sources username/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc moonrun ./target/wasm-gc/release/build/main/main.wasm "#]], @@ -4856,16 +4856,33 @@ fn test_moon_run_with_cli_args() { ], ), expect![[r#" - moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/main:./main -target wasm-gc + moonc build-package ./main/main_wasm.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/main:./main -target wasm-gc moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/release/build/main/main.core -main username/hello/main -o ./target/wasm-gc/release/build/main/main.wasm -pkg-config-path ./main/moon.pkg.json -pkg-sources username/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc moonrun ./target/wasm-gc/release/build/main/main.wasm -- δΈ­ζ–‡ πŸ˜„πŸ‘ hello 1242 "#]], ); check( - get_stdout(&dir, ["run", "main", "--", "δΈ­ζ–‡", "πŸ˜„πŸ‘", "hello", "1242"]), + get_stdout( + &dir, + [ + "run", "main", "--", "δΈ­ζ–‡", "πŸ˜„πŸ‘", "hello", "1242", "--flag", + ], + ), + expect![[r#" + ["δΈ­ζ–‡", "πŸ˜„πŸ‘", "hello", "1242", "--flag"] + "#]], + ); + + check( + get_stdout( + &dir, + [ + "run", "main", "--target", "js", "--", "δΈ­ζ–‡", "πŸ˜„πŸ‘", "hello", "1242", "--flag", + ], + ), expect![[r#" - ["δΈ­ζ–‡", "πŸ˜„πŸ‘", "hello", "1242"] + ["--", "δΈ­ζ–‡", "πŸ˜„πŸ‘", "hello", "1242", "--flag"] "#]], ); } diff --git a/crates/moon/tests/test_cases/moo_run_with_cli_args.in/main/main_js.mbt b/crates/moon/tests/test_cases/moo_run_with_cli_args.in/main/main_js.mbt new file mode 100644 index 00000000..6dfb3a35 --- /dev/null +++ b/crates/moon/tests/test_cases/moo_run_with_cli_args.in/main/main_js.mbt @@ -0,0 +1,12 @@ +pub fn get_args() -> Array[String] { + get_cli_args_internal() +} + +extern "js" fn get_cli_args_internal() -> Array[String] = + #| function() { + #| return process.argv.slice(2); + #| } + +fn main { + get_args() |> println +} \ No newline at end of file diff --git a/crates/moon/tests/test_cases/moo_run_with_cli_args.in/main/main.mbt b/crates/moon/tests/test_cases/moo_run_with_cli_args.in/main/main_wasm.mbt similarity index 100% rename from crates/moon/tests/test_cases/moo_run_with_cli_args.in/main/main.mbt rename to crates/moon/tests/test_cases/moo_run_with_cli_args.in/main/main_wasm.mbt diff --git a/crates/moon/tests/test_cases/moo_run_with_cli_args.in/main/moon.pkg.json b/crates/moon/tests/test_cases/moo_run_with_cli_args.in/main/moon.pkg.json index fcc86bad..eccca3f2 100644 --- a/crates/moon/tests/test_cases/moo_run_with_cli_args.in/main/moon.pkg.json +++ b/crates/moon/tests/test_cases/moo_run_with_cli_args.in/main/moon.pkg.json @@ -1,3 +1,7 @@ { - "is-main": true + "is-main": true, + "targets": { + "main_wasm.mbt": ["wasm", "wasm-gc"], + "main_js.mbt": ["js"] + } } \ No newline at end of file diff --git a/crates/moonbuild/src/build.rs b/crates/moonbuild/src/build.rs index f2b6a3c1..3f872573 100644 --- a/crates/moonbuild/src/build.rs +++ b/crates/moonbuild/src/build.rs @@ -56,6 +56,7 @@ fn run(command: &str, path: &Path, args: &[String], verbose: bool) -> anyhow::Re } let mut execution = Command::new(command) .arg(path) + .arg("--") .args(args) .stdout(Stdio::inherit()) .stderr(Stdio::inherit())