Skip to content

Commit 054872d

Browse files
authored
chore(NODE-5128): add script to clean dts and dts.map files (#3606)
1 parent cb1ea8a commit 054872d

File tree

3 files changed

+28
-162
lines changed

3 files changed

+28
-162
lines changed

etc/clean_definition_files.cjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#! /usr/bin/env node
2+
/* eslint-disable @typescript-eslint/no-var-requires */
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
function* walk(root) {
7+
const directoryContents = fs.readdirSync(root);
8+
for (const filepath of directoryContents) {
9+
const fullPath = path.join(root, filepath);
10+
const stat = fs.statSync(fullPath);
11+
if (stat.isDirectory()) {
12+
yield* walk(fullPath);
13+
} else if (stat.isFile()) {
14+
yield fullPath;
15+
}
16+
}
17+
}
18+
19+
const libPath = path.resolve(__dirname, '..', 'lib');
20+
if (fs.existsSync(libPath)) {
21+
const definitionFiles = Array.from(walk(libPath)).filter(filePath => {
22+
return filePath.endsWith('.d.ts') || filePath.endsWith('.d.ts.map');
23+
});
24+
for (const definitionFile of definitionFiles) {
25+
fs.unlinkSync(definitionFile);
26+
}
27+
}

package-lock.json

Lines changed: 0 additions & 160 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
"mongodb-legacy": "^5.0.0",
8484
"nyc": "^15.1.0",
8585
"prettier": "^2.8.4",
86-
"rimraf": "^4.4.0",
8786
"semver": "^7.3.8",
8887
"sinon": "^15.0.2",
8988
"sinon-chai": "^3.7.0",
@@ -109,7 +108,7 @@
109108
"scripts": {
110109
"build:evergreen": "node .evergreen/generate_evergreen_tasks.js",
111110
"build:ts": "node ./node_modules/typescript/bin/tsc",
112-
"build:dts": "npm run build:ts && api-extractor run && rimraf 'lib/**/*.d.ts*'",
111+
"build:dts": "npm run build:ts && api-extractor run && node etc/clean_definition_files.cjs",
113112
"build:docs": "./etc/docs/build.ts",
114113
"build:typedoc": "typedoc",
115114
"check:bench": "node test/benchmarks/driverBench",

0 commit comments

Comments
 (0)