From 6883cf26b6df252aa6744d113536e16d585c10e8 Mon Sep 17 00:00:00 2001 From: Mathieu HATON Date: Tue, 11 May 2021 23:24:33 +0200 Subject: [PATCH] sanitize bsconfig.json and package.json before publish remove dependencie to bisect_ppx because it's not needed in the published package --- package.json | 1 + scripts/prepack.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 scripts/prepack.js diff --git a/package.json b/package.json index c20e30a9..d5696a5c 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "cleanwatch": "npm run clean && npm run watch", "cleantest": "npm run cleanbuild && npm run test", "cleancoverage": "npm run cleanbisect && BISECT_ENABLE=yes npm run cleanbuild && npm run coverage", + "prepack": "node scripts/prepack.js", "releasebuild": "npm run cleancoverage" }, "keywords": [ diff --git a/scripts/prepack.js b/scripts/prepack.js new file mode 100644 index 00000000..04d8c7b6 --- /dev/null +++ b/scripts/prepack.js @@ -0,0 +1,38 @@ +const fs = require("fs"); +const path = require("path"); +const pkg = require("../package.json"); +const bsConfig = require("../bsconfig.json"); + +const bsConfigWriter = json => { + const bsConfigPath = path.join(__dirname, "..", "bsconfig.json"); + fs.writeFileSync(bsConfigPath, JSON.stringify(json, null, 2)); +}; + +const packageWriter = json => { + const packagePath = path.join(__dirname, "..", "package.json"); + fs.writeFileSync(packagePath, JSON.stringify(json, null, 2)); +} + +const dependenciesNotNeededForPkg = ["bisect_ppx"]; +const hasToBeRemoved = (dep) => !dependenciesNotNeededForPkg.includes(dep) + +const filteredDependencies = Object.entries(pkg.dependencies).filter( + ([dep]) => hasToBeRemoved(dep) +); + +const newPkg = { + ...pkg, + dependencies: Object.fromEntries(filteredDependencies) +}; + +packageWriter(newPkg) + +const bsDependencies = bsConfig["bs-dependencies"].filter(hasToBeRemoved); + +const { ["ppx-flags"]: _, ...rest } = bsConfig; +const newBsConfig = { + ...rest, + "bs-dependencies": bsDependencies +}; + +bsConfigWriter(newBsConfig)