From e9a56f788177dde19ebf9d44d2fc8bbe20d2f6ac Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Mon, 15 May 2023 12:07:50 +0200 Subject: [PATCH] fix: Remove unnecessary bun-types directives Closes #478 --- package.json | 3 ++- scripts/fix-declaration-directives.mjs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 scripts/fix-declaration-directives.mjs diff --git a/package.json b/package.json index 759499d2..b6972973 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,8 @@ "build:esm": "tsc -b tsconfig.esm.json && node scripts/esm-post-process.mjs", "build:cjs": "tsc -b tsconfig.cjs.json", "build:umd": "rollup --bundleConfigAsCjs --config rollup.config.ts --configPlugin typescript && gzip umd/graphql-ws.min.js -c > umd/graphql-ws.min.js.gz", - "build": "yarn build:esm && yarn build:cjs && yarn build:umd", + "build": "yarn build:esm && yarn build:cjs && yarn build:umd && yarn postbuild", + "postbuild": "node scripts/fix-declaration-directives.mjs", "release": "semantic-release" }, "peerDependencies": { diff --git a/scripts/fix-declaration-directives.mjs b/scripts/fix-declaration-directives.mjs new file mode 100644 index 00000000..4d0dfa44 --- /dev/null +++ b/scripts/fix-declaration-directives.mjs @@ -0,0 +1,22 @@ +/** + * Adding Bun's typings through the tripple-slash directive adds it everywhere + * where Node primitives are used (probably because Bun and Node share interfaces). + * + * This script removes the bun-typings directive everywhere except for Bun. + */ +import { glob } from 'glob'; +import fs from 'fs/promises'; + +(async () => { + const matches = await glob('lib/**/*.d.?(m)ts'); + const notBunMatches = matches.filter((match) => !match.includes('bun.d')); + + const directive = '/// \n'; + + for (const path of notBunMatches) { + const src = (await fs.readFile(path)).toString(); + if (src.includes(src)) { + await fs.writeFile(path, src.replace(directive, '')); + } + } +})();