From 0a442ee2da98a09dccba7d55e39690822396d599 Mon Sep 17 00:00:00 2001 From: Daniel Simon Date: Wed, 7 Apr 2021 15:38:51 +0700 Subject: [PATCH] fix: fix `MODULE_NOT_FOUND` error due to missing `dev.json` --- packages/lib-ethers/.npmignore | 1 - packages/lib-ethers/package.json | 1 + .../scripts/delete-dev-deployments.ts | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 packages/lib-ethers/scripts/delete-dev-deployments.ts diff --git a/packages/lib-ethers/.npmignore b/packages/lib-ethers/.npmignore index 016e6d939..2cd20eff1 100644 --- a/packages/lib-ethers/.npmignore +++ b/packages/lib-ethers/.npmignore @@ -1,4 +1,3 @@ /live /accounts.json -/dist/deployments/dev.json /temp diff --git a/packages/lib-ethers/package.json b/packages/lib-ethers/package.json index 806670cf3..7dcf43304 100644 --- a/packages/lib-ethers/package.json +++ b/packages/lib-ethers/package.json @@ -17,6 +17,7 @@ "scripts": { "hardhat": "hardhat", "check-live-version": "ts-node scripts/check-live-version.ts", + "prepublishOnly": "ts-node scripts/delete-dev-deployments.ts", "prepare": "run-s prepare:*", "prepare:deployments": "ts-node scripts/copy-deployments.ts", "prepare:types": "ts-node scripts/generate-types.ts", diff --git a/packages/lib-ethers/scripts/delete-dev-deployments.ts b/packages/lib-ethers/scripts/delete-dev-deployments.ts new file mode 100644 index 000000000..c9dd57b1d --- /dev/null +++ b/packages/lib-ethers/scripts/delete-dev-deployments.ts @@ -0,0 +1,17 @@ +import fs from "fs"; +import path from "path"; + +const deploymentsDir = "deployments"; +const devDeploymentName = "dev.json"; + +const exists = (file: string) => fs.existsSync(file) && fs.lstatSync(file).isFile(); + +const devDeployments = () => + fs + .readdirSync(deploymentsDir, { withFileTypes: true }) + .filter(dirent => dirent.isDirectory() && dirent.name !== "backfill") + .map(deploymentDir => path.join(deploymentsDir, deploymentDir.name, devDeploymentName)) + .concat(path.join(deploymentsDir, devDeploymentName)) + .filter(exists); + +devDeployments().forEach(devDeployment => fs.unlinkSync(devDeployment));