Skip to content

Commit

Permalink
fix: do not delete the typechain "commons.ts" file
Browse files Browse the repository at this point in the history
test: check that the "common.ts" file exists
  • Loading branch information
PaulRBerg committed Aug 3, 2021
1 parent 3b2e928 commit 6da98b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ subtask(TASK_PREPARE_PACKAGE_TYPECHAIN).setAction(async function (taskArgs: Task
throw new HardhatPluginError(PLUGIN_NAME, "Please generate the TypeChain bindings before running this plugin");
}

// TypeChain generates some files that are shared across all bindings.
const excludedFiles: string[] = ["commons"];

// Delete all bindings that were not allowlisted.
// CAVEAT: this will delete the "factories" folder.
const bindings: string[] = await fsExtra.readdir(pathToBindings);
for (const binding of bindings) {
const contract: string = binding.replace(".d.ts", "");
if (!config.packager.contracts.includes(contract)) {
const fileName: string = binding.replace(".d.ts", "").replace(".ts", "");
if (excludedFiles.includes(fileName)) {
continue;
}
if (!config.packager.contracts.includes(fileName)) {
const fullPath: string = path.join(pathToBindings, binding);
await fsExtra.remove(fullPath);
}
Expand Down
1 change: 1 addition & 0 deletions test/packager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe("Hardhat Packager", function () {

expect(fsExtra.existsSync(pathToArtifacts)).toEqual(true);
expect(fsExtra.existsSync(pathToBindings)).toEqual(true);
expect(fsExtra.existsSync(path.join(pathToBindings, "commons.ts"))).toEqual(true);

expect(consoleLogMock).toHaveBeenCalledWith(["Preparing 2 contracts ..."]);
expect(consoleLogMock).toHaveBeenCalledWith([`Successfully prepared 2 contracts for registry deployment!`]);
Expand Down

0 comments on commit 6da98b4

Please sign in to comment.