Skip to content

Commit

Permalink
cli: Fix migrate command not working without global ts-node insta…
Browse files Browse the repository at this point in the history
…llation (#2767)
  • Loading branch information
acheroncrypto authored Jan 11, 2024
1 parent 211982a commit c93b33a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 18 additions & 10 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3882,41 +3882,49 @@ 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")?;
}
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())
.output()?
};

if !exit.status.success() {
println!("Deploy failed.");
eprintln!("Deploy failed.");
std::process::exit(exit.status.code().unwrap());
}

Expand Down
2 changes: 1 addition & 1 deletion lang/syn/src/idl/parse/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
Expand Down

1 comment on commit c93b33a

@vercel
Copy link

@vercel vercel bot commented on c93b33a Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

anchor-docs – ./

anchor-docs-200ms.vercel.app
anchor-docs-git-master-200ms.vercel.app
www.anchor-lang.com
anchor-lang.com

Please sign in to comment.