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

This commit is contained in:
John Rees 2021-12-31 01:26:11 +00:00 committed by GitHub
parent b6cbdb257e
commit 69299fb723
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 13 deletions

View File

@ -47,19 +47,21 @@ const workspace = new Proxy({} as any, {
}
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.
const anchorToml = toml.parse(