diff --git a/CHANGELOG.md b/CHANGELOG.md index 8838c67455..f05a5d0c38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ The minor version will be incremented upon a breaking change and the patch versi - lang: Remove `try_to_vec` usage while setting the return data in order to reduce heap memory usage ([#2744](https://github.com/coral-xyz/anchor/pull/2744)) - cli: Show installation progress if Solana tools are not installed when using toolchain overrides ([#2757](https://github.com/coral-xyz/anchor/pull/2757)). - ts: Fix formatting enums ([#2763](https://github.com/coral-xyz/anchor/pull/2763)). +- cli: Fix `migrate` command not working without global `ts-node` installation ([#2767](https://github.com/coral-xyz/anchor/pull/2767)). ### Breaking diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 050af212af..93784d013d 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -3882,9 +3882,10 @@ fn migrate(cfg_override: &ConfigOverride) -> Result<()> { let url = cluster_url(cfg, &cfg.test_validator); let cur_dir = std::env::current_dir()?; + let migrations_dir = cur_dir.join("migrations"); + let deploy_ts = Path::new("deploy.ts"); - let use_ts = - Path::new("tsconfig.json").exists() && Path::new("migrations/deploy.ts").exists(); + let use_ts = Path::new("tsconfig.json").exists() && migrations_dir.join(deploy_ts).exists(); if !Path::new(".anchor").exists() { fs::create_dir(".anchor")?; @@ -3892,23 +3893,30 @@ fn migrate(cfg_override: &ConfigOverride) -> Result<()> { std::env::set_current_dir(".anchor")?; let exit = if use_ts { - let module_path = cur_dir.join("migrations/deploy.ts"); + let module_path = migrations_dir.join(deploy_ts); let deploy_script_host_str = rust_template::deploy_ts_script_host(&url, &module_path.display().to_string()); - fs::write("deploy.ts", deploy_script_host_str)?; - std::process::Command::new("ts-node") - .arg("deploy.ts") + fs::write(deploy_ts, deploy_script_host_str)?; + + std::process::Command::new("yarn") + .args([ + "run", + "ts-node", + &fs::canonicalize(deploy_ts)?.to_string_lossy(), + ]) .env("ANCHOR_WALLET", cfg.provider.wallet.to_string()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .output()? } else { - let module_path = cur_dir.join("migrations/deploy.js"); + let deploy_js = deploy_ts.with_extension("js"); + let module_path = migrations_dir.join(&deploy_js); let deploy_script_host_str = rust_template::deploy_js_script_host(&url, &module_path.display().to_string()); - fs::write("deploy.js", deploy_script_host_str)?; + fs::write(&deploy_js, deploy_script_host_str)?; + std::process::Command::new("node") - .arg("deploy.js") + .arg(&deploy_js) .env("ANCHOR_WALLET", cfg.provider.wallet.to_string()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) @@ -3916,7 +3924,7 @@ fn migrate(cfg_override: &ConfigOverride) -> Result<()> { }; if !exit.status.success() { - println!("Deploy failed."); + eprintln!("Deploy failed."); std::process::exit(exit.status.code().unwrap()); } diff --git a/lang/syn/src/idl/parse/file.rs b/lang/syn/src/idl/parse/file.rs index a2a9dd7140..14ebdf2018 100644 --- a/lang/syn/src/idl/parse/file.rs +++ b/lang/syn/src/idl/parse/file.rs @@ -107,7 +107,7 @@ pub fn parse( .named .iter() .map(|f: &syn::Field| { - let index = match f.attrs.get(0) { + let index = match f.attrs.first() { None => false, Some(i) => parser::tts_to_string(&i.path) == "index", };