From dfe9059c7c0ea5422eccf02148c85eb8e0931e50 Mon Sep 17 00:00:00 2001 From: "Daniel D. Beck" Date: Tue, 16 Jul 2024 18:32:39 +0200 Subject: [PATCH 1/2] Turn on type checks --- package.json | 1 + packages/compute-baseline/package.json | 5 +++-- tsconfig.json | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e0c92abba37..f9dc64193c9 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "test:lint": "npx eslint .", "test:schema": "tsx scripts/schema.ts", "test:specs": "tsx scripts/specs.ts", + "test:types": "npm run --workspaces test:types && tsc", "test": "npm run test:caniuse -- --quiet && npm run test:schema && npm run test:specs && npm run test:format && npm run test:dist && npm run test --workspaces && npm run test:lint", "update-drafts": "tsx scripts/update-drafts.ts" }, diff --git a/packages/compute-baseline/package.json b/packages/compute-baseline/package.json index 3ce8147e56a..9a895111d38 100644 --- a/packages/compute-baseline/package.json +++ b/packages/compute-baseline/package.json @@ -14,9 +14,10 @@ "types": "./dist/index.d.ts", "type": "module", "scripts": { - "test": "mocha -r tsx 'src/**/*.test.ts'", + "prepare": "cp ../../LICENSE.txt . && tsc", "test:coverage": "c8 npm run test", - "prepare": "cp ../../LICENSE.txt . && tsc" + "test:types": "tsc --noEmit", + "test": "mocha -r tsx 'src/**/*.test.ts'" }, "license": "Apache-2.0", "devDependencies": { diff --git a/tsconfig.json b/tsconfig.json index ec1afe07cf6..a0b1184ae4f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,5 +5,7 @@ "moduleResolution": "Bundler", "esModuleInterop": true, "resolveJsonModule": true, - } + "noEmit": true + }, + "exclude": ["packages/"] } From ae7d3c5f3e4698e729f04fbabef0d9952da77b25 Mon Sep 17 00:00:00 2001 From: "Daniel D. Beck" Date: Tue, 16 Jul 2024 18:32:49 +0200 Subject: [PATCH 2/2] Fix type errors --- scripts/dist.ts | 8 ++++---- scripts/update-drafts.ts | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/dist.ts b/scripts/dist.ts index 1dacfeb447f..78c36bc7dcc 100644 --- a/scripts/dist.ts +++ b/scripts/dist.ts @@ -1,13 +1,13 @@ import { computeBaseline, getStatus, setLogger } from "compute-baseline"; import { Compat, Feature } from "compute-baseline/browser-compat-data"; +import { fdir } from "fdir"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { isDeepStrictEqual } from "node:util"; import winston from "winston"; -import YAML, { Document, YAMLSeq, Scalar } from "yaml"; +import YAML, { Document, Scalar, YAMLSeq } from "yaml"; import yargs from "yargs"; -import { fdir } from "fdir"; const compat = new Compat(); @@ -101,7 +101,7 @@ function compareStatus(a: SupportStatus, b: SupportStatus) { const bVersions = Object.values(b.support); for (let i = 0; i < aVersions.length; i++) { if (aVersions[i] !== bVersions[i]) { - return aVersions[i] - bVersions[i]; + return Number(aVersions[i]) - Number(bVersions[i]); } } return 0; @@ -230,7 +230,7 @@ function insertCompatFeatures(yaml: Document, groups: Map) { return; } - const list = new YAMLSeq(); + const list = new YAMLSeq>(); for (const [comment, keys] of groups.entries()) { let first = true; for (const key of keys) { diff --git a/scripts/update-drafts.ts b/scripts/update-drafts.ts index a7e3d6b384b..22ecc966415 100644 --- a/scripts/update-drafts.ts +++ b/scripts/update-drafts.ts @@ -1,11 +1,13 @@ import { Compat } from "compute-baseline/browser-compat-data"; import fs from "node:fs/promises"; import { fileURLToPath } from "node:url"; -import { Document } from "yaml"; import webSpecs from "web-specs" assert { type: "json" }; +import { Document } from "yaml"; import { features } from "../index.js"; +type WebSpecsSpec = (typeof webSpecs)[number]; + function* getPages(spec): Generator { yield spec.url; if (spec.nightly?.url) { @@ -53,7 +55,7 @@ async function main() { }); // Build a map from URLs to spec. - const pageToSpec = new Map(); + const pageToSpec = new Map(); for (const spec of webSpecs) { for (const page of getPages(spec)) { pageToSpec.set(normalize(page), spec); @@ -61,7 +63,7 @@ async function main() { } // Iterate BCD and group compat features by spec. - const specToCompatFeatures = new Map>(); + const specToCompatFeatures = new Map>(); for (const feature of compat.walk()) { // Skip deprecated and non-standard features. if (feature.deprecated || !feature.standard_track) {