Skip to content

Commit

Permalink
fix: Remove unnecessary bun-types directives
Browse files Browse the repository at this point in the history
Closes #478
  • Loading branch information
enisdenjo committed May 15, 2023
1 parent 6d57a71 commit e9a56f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -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": {
Expand Down
22 changes: 22 additions & 0 deletions 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 = '/// <reference types="bun-types" />\n';

for (const path of notBunMatches) {
const src = (await fs.readFile(path)).toString();
if (src.includes(src)) {
await fs.writeFile(path, src.replace(directive, ''));
}
}
})();

0 comments on commit e9a56f7

Please sign in to comment.