소스 검색

ts: only read .json files when parsing IDLs (#1214)

John Rees 3 년 전
부모
커밋
69299fb723
1개의 변경된 파일15개의 추가작업 그리고 13개의 파일을 삭제
  1. 15 13
      ts/src/workspace.ts

+ 15 - 13
ts/src/workspace.ts

@@ -47,19 +47,21 @@ const workspace = new Proxy({} as any, {
       }
       }
 
 
       const idlMap = new Map<string, Idl>();
       const idlMap = new Map<string, Idl>();
-      fs.readdirSync(idlFolder).forEach((file) => {
-        const filePath = `${idlFolder}/${file}`;
-        const idlStr = fs.readFileSync(filePath);
-        const idl = JSON.parse(idlStr);
-        idlMap.set(idl.name, idl);
-        const name = camelCase(idl.name, { pascalCase: true });
-        if (idl.metadata && idl.metadata.address) {
-          workspaceCache[name] = new Program(
-            idl,
-            new PublicKey(idl.metadata.address)
-          );
-        }
-      });
+      fs.readdirSync(idlFolder)
+        .filter((file) => file.endsWith(".json"))
+        .forEach((file) => {
+          const filePath = `${idlFolder}/${file}`;
+          const idlStr = fs.readFileSync(filePath);
+          const idl = JSON.parse(idlStr);
+          idlMap.set(idl.name, idl);
+          const name = camelCase(idl.name, { pascalCase: true });
+          if (idl.metadata && idl.metadata.address) {
+            workspaceCache[name] = new Program(
+              idl,
+              new PublicKey(idl.metadata.address)
+            );
+          }
+        });
 
 
       // Override the workspace programs if the user put them in the config.
       // Override the workspace programs if the user put them in the config.
       const anchorToml = toml.parse(
       const anchorToml = toml.parse(