Repository navigation
test(packaging): verify consumer TypeScript declarations across all entrypoints - #1971
Conversation
…ntrypoints - Add scripts/verify-types.mjs to validate packaged .d.ts files from a downstream consumer perspective under both CJS (moduleResolution: node / typesVersions) and ESM/Dual (moduleResolution: nodenext / exports.types) with skipLibCheck: false. - Run TypeScript consumer verification in scripts/test-packaging.sh after runtime export verification and default optional tarball arg for local runs. - Fix missing /index suffixes in package.json typesVersions for ai and v2/ai subpaths caught by the new check.
There was a problem hiding this comment.
Code Review
This pull request updates package exports in package.json to point to explicit index paths and introduces a new TypeScript declaration verification script (verify-types.mjs) to the packaging test pipeline. Feedback on the new verification script includes: executing the local tsc compiler directly with node instead of npx to ensure compatibility on Windows, using an anchored regular expression to safely strip leading ./ prefixes from export paths, and cleaning up the temporary verify-types.ts file before the script exits.
…and GraphQL type checks
… with graphql installed upfront
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates export paths in package.json to explicitly point to index files, cleans up build artifacts in the packaging script, and introduces a new verification script (verify-types.mjs) to validate TypeScript declarations and package exports. The review feedback suggests improving the robustness of the verification script by adding type checks for export targets and types paths to prevent potential runtime errors during string operations and path resolution.
ajperel
left a comment
There was a problem hiding this comment.
I will admit this is touching things that I am not an expert in. But AI think this is a great end-to-end test approach. Working with it a lot I have a few small suggestions to improve how it's done and one suggestion that we also introduce a fast fail case on build that should catch most (but maybe not all) problems so devs don't only catch this late in CI.
| importLines.push(`import * as m${i} from '${importPath}';`); | ||
| } | ||
|
|
||
| const tscPath = path.resolve(process.cwd(), 'node_modules/typescript/bin/tsc'); |
There was a problem hiding this comment.
🟡 Nit: Add upfront existence guard for tsc binary
If typescript fails to install or is hoisted unexpectedly, execFileSync throws a generic child process error. An upfront guard mirroring the pkgPath check on line 28 makes the diagnostic immediate and clear:
| const tscPath = path.resolve(process.cwd(), 'node_modules/typescript/bin/tsc'); | |
| const tscPath = path.resolve(process.cwd(), "node_modules/typescript/bin/tsc"); | |
| if (!fs.existsSync(tscPath)) { | |
| console.error(`❌ Could not find TypeScript compiler binary at ${tscPath}`); | |
| process.exit(1); | |
| } |
There was a problem hiding this comment.
This is maybe getting too edge casey? AI does like to handle everything under the sun. Not sure though... we have had npm issues before.
There was a problem hiding this comment.
Added this. Just 4 lines and helps with an early exit without printing long stack traces
Description
Adds consumer TypeScript declaration (
.d.ts) verification to the packaging CI test (scripts/test-packaging.sh/npm run test:packaging) to ensure the published package compiles cleanly withoutskipLibCheck: true.Previously,
scripts/verify-exports.mjsonly validated Node.js runtime loading (require()andimport()), allowing broken or stripped@internal.d.tsimports (TS2724) or mismatchedtypesVersionspaths (TS2307) to slip through CI undetected.This PR:
scripts/verify-types.mjs, which dynamically generates imports across all public entrypoints inpackage.jsonand runsnpx tsc --noEmit --skipLibCheck falseunder both:--module commonjs --moduleResolution node --esModuleInterop) to validatetypesVersions--module nodenext --moduleResolution nodenext) to validateexports["..."]["types"]scripts/test-packaging.shto install consumer TypeScript dependencies (typescript@5,@types/node,firebase-admin) and executeverify-types.mjsafterverify-exports.mjs(and defaults$1to${1:-}sonpm run test:packagingworks locally without arguments)./indexsuffixes undertypesVersionsinpackage.jsonforaiandv2/aisubpaths caught by the new check.Scenarios Tested
npm run test:packaginglocally (passes all 62 entrypoints across CJS runtime, ESM runtime, CJStsc, and NodeNexttsc).WireParamSpecas@internalimmediately failsnpm run test:packagingwitherror TS2724.npm run lint(0 errors).Release Notes
relnote: none