Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Fix migrate command not working without global ts-node installation #2767

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading