Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Remove unnecessary bun-types directives
Closes #478
- Loading branch information
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, '')); | ||
} | ||
} | ||
})(); |