From 426151d49ed1e928e9733bc25578330f9bf41b3d Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Sun, 27 Jun 2021 22:39:17 +0300 Subject: [PATCH 1/3] cli: use npx for local mocha/ts-mocha --- cli/src/main.rs | 74 +++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 4c526bdb6d..96411aad47 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1013,57 +1013,35 @@ fn test( // Run the tests. let test_result: Result<_> = { + let runner = if use_yarn { "yarn" } else { "npx" }; + let ts_config_exist = Path::new("tsconfig.json").exists(); - let mut args = vec!["-t", "1000000"]; - if let Some(ref file) = file { - args.push(file); - } else if ts_config_exist { - args.push("tests/**/*.spec.ts"); + let cmd = if ts_config_exist { "ts-mocha" } else { "mocha" }; + let mut args = if ts_config_exist { + vec![cmd, "-p", "./tsconfig.json"] } else { - args.push("tests/"); - } - let exit = match (ts_config_exist, use_yarn) { - (true, true) => std::process::Command::new("yarn") - .arg("ts-mocha") - .arg("-p") - .arg("./tsconfig.json") - .args(args) - .env("ANCHOR_PROVIDER_URL", cfg.provider.cluster.url()) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .output() - .map_err(anyhow::Error::from) - .with_context(|| "ts-mocha"), - (false, true) => std::process::Command::new("yarn") - .arg("mocha") - .args(args) - .env("ANCHOR_PROVIDER_URL", cfg.provider.cluster.url()) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .output() - .map_err(anyhow::Error::from) - .with_context(|| "mocha"), - (true, false) => std::process::Command::new("ts-mocha") - .arg("-p") - .arg("./tsconfig.json") - .args(args) - .env("ANCHOR_PROVIDER_URL", cfg.provider.cluster.url()) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .output() - .map_err(anyhow::Error::from) - .with_context(|| "ts-mocha"), - (false, false) => std::process::Command::new("mocha") - .args(args) - .env("ANCHOR_PROVIDER_URL", cfg.provider.cluster.url()) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .output() - .map_err(anyhow::Error::from) - .with_context(|| "mocha"), + vec![cmd] }; - - exit + args.extend_from_slice(&[ + "-t", + "1000000", + if let Some(ref file) = file { + file + } else if ts_config_exist { + "tests/**/*.spec.ts" + } else { + "tests/" + }, + ]); + + std::process::Command::new(runner) + .args(args) + .env("ANCHOR_PROVIDER_URL", cfg.provider.cluster.url()) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .output() + .map_err(anyhow::Error::from) + .context(cmd) }; // Check all errors and shut down. From b888b03133c5dd12cfed2403107b41e4a20abe81 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Sun, 27 Jun 2021 23:25:10 +0300 Subject: [PATCH 2/3] remove `--yarn` flag --- Cargo.lock | 11 ----------- cli/Cargo.toml | 1 - cli/src/main.rs | 15 +-------------- 3 files changed, 1 insertion(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b293464c6..029345e1b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -148,7 +148,6 @@ dependencies = [ "solana-sdk", "syn 1.0.67", "toml", - "which", ] [[package]] @@ -4213,16 +4212,6 @@ dependencies = [ "webpki", ] -[[package]] -name = "which" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b55551e42cbdf2ce2bedd2203d0cc08dba002c27510f86dab6d0ce304cba3dfe" -dependencies = [ - "either", - "libc", -] - [[package]] name = "winapi" version = "0.2.8" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index f429999136..f82b8be2a7 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -31,4 +31,3 @@ dirs = "3.0" heck = "0.3.1" flate2 = "1.0.19" rand = "0.7.3" -which = "4.1.0" diff --git a/cli/src/main.rs b/cli/src/main.rs index 96411aad47..4a085f45d6 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -96,9 +96,6 @@ pub enum Command { /// use this to save time when running test and the program code is not altered. #[clap(long)] skip_build: bool, - /// Use this flag if you want to use yarn as your package manager. - #[clap(long)] - yarn: bool, file: Option, }, /// Creates a new program. @@ -253,14 +250,12 @@ fn main() -> Result<()> { skip_deploy, skip_local_validator, skip_build, - yarn, file, } => test( &opts.cfg_override, skip_deploy, skip_local_validator, skip_build, - yarn, file, ), #[cfg(feature = "dev")] @@ -972,7 +967,6 @@ fn test( skip_deploy: bool, skip_local_validator: bool, skip_build: bool, - use_yarn: bool, file: Option, ) -> Result<()> { with_workspace(cfg_override, |cfg, _path, _cargo| { @@ -1006,15 +1000,8 @@ fn test( // Setup log reader. let log_streams = stream_logs(&cfg.provider.cluster.url()); - // Check to see if yarn is installed, panic if not. - if use_yarn { - which::which("yarn").unwrap(); - } - // Run the tests. let test_result: Result<_> = { - let runner = if use_yarn { "yarn" } else { "npx" }; - let ts_config_exist = Path::new("tsconfig.json").exists(); let cmd = if ts_config_exist { "ts-mocha" } else { "mocha" }; let mut args = if ts_config_exist { @@ -1034,7 +1021,7 @@ fn test( }, ]); - std::process::Command::new(runner) + std::process::Command::new("npx") .args(args) .env("ANCHOR_PROVIDER_URL", cfg.provider.cluster.url()) .stdout(Stdio::inherit()) From 944b34bb9086eaa8c046db92b50224355f999dbc Mon Sep 17 00:00:00 2001 From: armaniferrante Date: Sun, 27 Jun 2021 13:43:33 -0700 Subject: [PATCH 3/3] Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 388fc390e7..842f262c1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ incremented for features. ## [Unreleased] +### Breaking Changes + +* cli: Remove `--yarn` flag in favor of using `npx` ([#432](https://github.com/project-serum/anchor/pull/432)). + ## [0.9.0] - 2021-06-15 ### Features