From 93da9900326c60a1cf0ef1a91649bf0e18b70680 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Thu, 20 Feb 2025 10:40:26 -0600 Subject: [PATCH 1/4] ci: Remove building types --- .github/workflows/ci.yml | 2 -- package.json | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81c922c3b..99e2997aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,8 +27,6 @@ jobs: with: cache: npm - run: npm ci - - name: Build Types - run: npm run build:types - name: Test Types run: npm run test:types 2>&1 | tee silent.txt; check-docs: diff --git a/package.json b/package.json index 2acbc5a43..13e10bc63 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,7 @@ }, "scripts": { "build": "node build_releases.js", - "build:types": "tsc && prettier --write 'types/{**/*,*}.ts' && npm run lint:fix", + "build:types": "tsc && prettier --write 'types/{**/*,*}.ts'", "release": "node build_releases.js && npm publish", "test": "cross-env PARSE_BUILD=node jest", "test:mongodb": "npm run test:mongodb:runnerstart && npm run integration", From a4e31296bb40a8f62d1c70a199d463f5c9b4a2d7 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 25 Feb 2025 13:55:34 -0600 Subject: [PATCH 2/4] add typecheck --- .github/workflows/ci.yml | 2 ++ ci/typecheck.js | 35 +++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 38 insertions(+) create mode 100644 ci/typecheck.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99e2997aa..4034be1c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,8 @@ jobs: with: cache: npm - run: npm ci + - name: Type Definition Check + run: npm run ci:typecheck - name: Test Types run: npm run test:types 2>&1 | tee silent.txt; check-docs: diff --git a/ci/typecheck.js b/ci/typecheck.js new file mode 100644 index 000000000..50fe8877d --- /dev/null +++ b/ci/typecheck.js @@ -0,0 +1,35 @@ +const fs = require('fs').promises; +const { exec } = require('child_process'); +const util = require('util'); + +async function getTypes(files) { + const types = {}; + const promise = files.map((file) => { + if (file.includes('.d.ts')) { + return fs.readFile(`./types/${file}`, 'utf8').then((content) => { + types[file] = content; + }); + } + }); + await Promise.all(promise); + return types; +} + +(async () => { + const execute = util.promisify(exec); + const currentFiles = await fs.readdir('./types'); + const currentTypes = await getTypes(currentFiles); + await execute('npm run build:types'); + const newFiles = await fs.readdir('./types'); + const newTypes = await getTypes(newFiles); + for (const file of newFiles) { + if (currentTypes[file] !== newTypes[file]) { + console.error( + '\x1b[31m%s\x1b[0m', + 'Type definitions files cannot be updated manually. Use `npm run build:types` to generate type definitions.' + ); + process.exit(1); + } + } + process.exit(0); +})(); diff --git a/package.json b/package.json index 13e10bc63..43c621a72 100644 --- a/package.json +++ b/package.json @@ -98,6 +98,7 @@ "scripts": { "build": "node build_releases.js", "build:types": "tsc && prettier --write 'types/{**/*,*}.ts'", + "ci:typecheck": "node ./ci/typecheck.js", "release": "node build_releases.js && npm publish", "test": "cross-env PARSE_BUILD=node jest", "test:mongodb": "npm run test:mongodb:runnerstart && npm run integration", From ef892e0df9ed1844e510381304b6095fbd81b038 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 25 Feb 2025 14:01:26 -0600 Subject: [PATCH 3/4] should break --- types/ParseOp.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/ParseOp.d.ts b/types/ParseOp.d.ts index a7ad4a411..d3a35a33a 100644 --- a/types/ParseOp.d.ts +++ b/types/ParseOp.d.ts @@ -17,7 +17,7 @@ export declare class UnsetOp extends Op { applyTo(): any; mergeWith(): UnsetOp; toJSON(): { - __op: string; + __op: any; }; } export declare class IncrementOp extends Op { From 15dae5e2983362d4933812b5ff26a1072a651c4d Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 25 Feb 2025 14:03:35 -0600 Subject: [PATCH 4/4] Revert "should break" This reverts commit ef892e0df9ed1844e510381304b6095fbd81b038. --- types/ParseOp.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/ParseOp.d.ts b/types/ParseOp.d.ts index d3a35a33a..a7ad4a411 100644 --- a/types/ParseOp.d.ts +++ b/types/ParseOp.d.ts @@ -17,7 +17,7 @@ export declare class UnsetOp extends Op { applyTo(): any; mergeWith(): UnsetOp; toJSON(): { - __op: any; + __op: string; }; } export declare class IncrementOp extends Op {