Skip to content

Commit a4e3129

Browse files
committed
add typecheck
1 parent 93da990 commit a4e3129

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
with:
2828
cache: npm
2929
- run: npm ci
30+
- name: Type Definition Check
31+
run: npm run ci:typecheck
3032
- name: Test Types
3133
run: npm run test:types 2>&1 | tee silent.txt;
3234
check-docs:

ci/typecheck.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const fs = require('fs').promises;
2+
const { exec } = require('child_process');
3+
const util = require('util');
4+
5+
async function getTypes(files) {
6+
const types = {};
7+
const promise = files.map((file) => {
8+
if (file.includes('.d.ts')) {
9+
return fs.readFile(`./types/${file}`, 'utf8').then((content) => {
10+
types[file] = content;
11+
});
12+
}
13+
});
14+
await Promise.all(promise);
15+
return types;
16+
}
17+
18+
(async () => {
19+
const execute = util.promisify(exec);
20+
const currentFiles = await fs.readdir('./types');
21+
const currentTypes = await getTypes(currentFiles);
22+
await execute('npm run build:types');
23+
const newFiles = await fs.readdir('./types');
24+
const newTypes = await getTypes(newFiles);
25+
for (const file of newFiles) {
26+
if (currentTypes[file] !== newTypes[file]) {
27+
console.error(
28+
'\x1b[31m%s\x1b[0m',
29+
'Type definitions files cannot be updated manually. Use `npm run build:types` to generate type definitions.'
30+
);
31+
process.exit(1);
32+
}
33+
}
34+
process.exit(0);
35+
})();

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"scripts": {
9999
"build": "node build_releases.js",
100100
"build:types": "tsc && prettier --write 'types/{**/*,*}.ts'",
101+
"ci:typecheck": "node ./ci/typecheck.js",
101102
"release": "node build_releases.js && npm publish",
102103
"test": "cross-env PARSE_BUILD=node jest",
103104
"test:mongodb": "npm run test:mongodb:runnerstart && npm run integration",

0 commit comments

Comments
 (0)