浏览代码

cli: make ts idl equal json idl (#1609)

Paul 3 年之前
父节点
当前提交
3face237fb
共有 2 个文件被更改,包括 6 次插入6 次删除
  1. 1 0
      CHANGELOG.md
  2. 5 6
      cli/src/template.rs

+ 1 - 0
CHANGELOG.md

@@ -28,6 +28,7 @@ incremented for features.
 * spl: Update `spl/governance` to use new errors ([#1582](https://github.com/project-serum/anchor/pull/1582)).
 * client: Fix `Cluster`'s `FromStr` implementation ([#1362](https://github.com/project-serum/anchor/pull/1362)).
 * lang: implement `Key` for `Pubkey` again, so `associated_token::*` constraints can use pubkey targets again ([#1601](https://github.com/project-serum/anchor/pull/1601)).
+* cli/ts: generated `IDL` variable in `types/<project-name.ts>` should equal the `<project-name>.json` idl file ([#1609](https://github.com/project-serum/anchor/pull/1609)) 
 
 ### Breaking
 

+ 5 - 6
cli/src/template.rs

@@ -29,20 +29,19 @@ token = "{}"
 }
 
 pub fn idl_ts(idl: &Idl) -> Result<String> {
-    let mut idl = idl.clone();
-    for acc in idl.accounts.iter_mut() {
+    let mut idl_types = idl.clone();
+    for acc in idl_types.accounts.iter_mut() {
         acc.name = acc.name.to_mixed_case();
     }
-    let idl_json = serde_json::to_string_pretty(&idl)?;
     Ok(format!(
         r#"export type {} = {};
 
 export const IDL: {} = {};
 "#,
+        idl_types.name.to_camel_case(),
+        serde_json::to_string_pretty(&idl_types)?,
         idl.name.to_camel_case(),
-        idl_json,
-        idl.name.to_camel_case(),
-        idl_json
+        serde_json::to_string_pretty(&idl)?
     ))
 }