From 3f58053f412576c7bcd8f0e5ca72663000c8142a Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Fri, 20 Nov 2026 13:28:06 +0200 Subject: [PATCH] fix(mcp, verify): a type check writes the declarations it reads first, so it passes alone (#261) --- design/build.md | 11 ++++++++++- packages/mcp/package.json | 2 +- packages/verify/package.json | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/design/build.md b/design/build.md index 791ec5a..6a98aa1 100644 --- a/design/build.md +++ b/design/build.md @@ -110,7 +110,7 @@ their documented API ships with declarations generated from it: `tsconfig.json` `site/embed.js`) with `checkJs`, `tsconfig.types.json` emits the entries' declarations into `types/` with `stripInternal`, and each `exports` entry names them under `types`. `pnpm types` writes them, deleting the folder first, since `tsc` never removes a declaration whose source -went; `typecheck` and `prepack` both run it. Three rules, with TypeScript 7: +went; `typecheck` and `prepack` both run it. Four rules, with TypeScript 7: - **A top-level `@typedef` is always exported**, and `@internal` on one does not strip it. Worse, its comment counts among the leading comments of the next declaration, which `stripInternal` @@ -123,6 +123,15 @@ went; `typecheck` and `prepack` both run it. Three rules, with TypeScript 7: `types` condition. Without `types/`, TypeScript falls back to the JavaScript through `default` and finds the internal helper, so the file's `@ts-expect-error` on that import fails: the check cannot pass on anything but the published declarations. +- **A package's `typecheck` writes the declarations it reads first** (#261). The workspace + links a package to its neighbours' folders, where `types/` exists only once something wrote it. + Without it, TypeScript falls back to their JavaScript and checks it under this package's own + `lib`, so the verifier's page code fails mcp's Node-only check for `window` and `document`. + `pnpm -r typecheck` and CI run in dependency order and never showed it; a publish runs only the + packages it releases, and mcp 0.4.0 stopped there when verify was not among them. So mcp's + `typecheck` runs the author's and the verifier's `types` before `tsc`, and every `types` that + reads the player's declarations builds them first (`tsc -b` in packages/player), as the + author's always has. Each package's `typecheck` passes alone with no `types/` anywhere. - **The player's relative imports name their file, `./shared/protocol.js`**, as cmi5's do. `tsc` copies a specifier into the declarations as written, and `node16`/`nodenext` resolution follows only one that names its file, so a specifier without `.js` leaves what came through diff --git a/packages/mcp/package.json b/packages/mcp/package.json index ddcf59a..0198e6e 100644 --- a/packages/mcp/package.json +++ b/packages/mcp/package.json @@ -37,7 +37,7 @@ ], "scripts": { "test": "pnpm --filter @missing-elements/h5p-offline-player build && pnpm --filter @missing-elements/h5p-author exec node scripts/copy-skill.mjs && vitest run", - "typecheck": "tsc -p tsconfig.json", + "typecheck": "pnpm --filter @missing-elements/h5p-verify --filter @missing-elements/h5p-author run types && tsc -p tsconfig.json", "prepack": "node -e \"require('node:fs').copyFileSync('../../LICENSE', 'LICENSE')\"", "prepublishOnly": "node -e \"if (!/^pnpm\\//.test(process.env.npm_config_user_agent || '')) { console.error('Publish with pnpm publish: npm would ship the workspace:^ dependency ranges as they are, and the package would not install.'); process.exit(1) }\" && node ../../scripts/published.mjs && pnpm typecheck && pnpm test" }, diff --git a/packages/verify/package.json b/packages/verify/package.json index 960cf91..974bbe2 100644 --- a/packages/verify/package.json +++ b/packages/verify/package.json @@ -46,7 +46,7 @@ "typecheck": "pnpm types && tsc -p tsconfig.json", "prepack": "node -e \"require('node:fs').copyFileSync('../../LICENSE', 'LICENSE')\" && pnpm types", "prepublishOnly": "node -e \"if (!/^pnpm\\//.test(process.env.npm_config_user_agent || '')) { console.error('Publish with pnpm publish: npm would ship the workspace:^ dependency ranges as they are, and the package would not install.'); process.exit(1) }\" && node ../../scripts/published.mjs && pnpm typecheck && pnpm test", - "types": "node -e \"require('node:fs').rmSync('types', { recursive: true, force: true })\" && tsc -p tsconfig.types.json" + "types": "pnpm --filter @missing-elements/h5p-offline-player exec tsc -b && node -e \"require('node:fs').rmSync('types', { recursive: true, force: true })\" && tsc -p tsconfig.types.json" }, "dependencies": { "@missing-elements/h5p-offline-player": "workspace:^",