Skip to content

test(packaging): verify consumer TypeScript declarations across all entrypoints - #1971

Merged
shettyvarun268 merged 7 commits into
masterfrom
shettyvarun268/verify-package-types
Oct 7, 2026
Merged

shettyvarun268 merged 7 commits into
masterfrom
shettyvarun268/verify-package-types

Conversation

@shettyvarun268

Copy link
Copy Markdown
Contributor

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 without skipLibCheck: true.

Previously, scripts/verify-exports.mjs only validated Node.js runtime loading (require() and import()), allowing broken or stripped @internal .d.ts imports (TS2724) or mismatched typesVersions paths (TS2307) to slip through CI undetected.

This PR:

  1. Adds scripts/verify-types.mjs, which dynamically generates imports across all public entrypoints in package.json and runs npx tsc --noEmit --skipLibCheck false under both:
    • CommonJS / Legacy resolution (--module commonjs --moduleResolution node --esModuleInterop) to validate typesVersions
    • ESM / Dual resolution (--module nodenext --moduleResolution nodenext) to validate exports["..."]["types"]
  2. Updates scripts/test-packaging.sh to install consumer TypeScript dependencies (typescript@5, @types/node, firebase-admin) and execute verify-types.mjs after verify-exports.mjs (and defaults $1 to ${1:-} so npm run test:packaging works locally without arguments).
  3. Fixes 6 missing /index suffixes under typesVersions in package.json for ai and v2/ai subpaths caught by the new check.

Scenarios Tested

  • Ran npm run test:packaging locally (passes all 62 entrypoints across CJS runtime, ESM runtime, CJS tsc, and NodeNext tsc).
  • Verified negative test case: marking WireParamSpec as @internal immediately fails npm run test:packaging with error TS2724.
  • Ran npm run lint (0 errors).

Release Notes

relnote: none

…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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread scripts/verify-types.mjs Outdated
Comment thread scripts/verify-types.mjs Outdated
Comment thread scripts/verify-types.mjs Outdated
@shettyvarun268

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread scripts/verify-types.mjs Outdated
Comment thread scripts/verify-types.mjs Outdated
@shettyvarun268
shettyvarun268 marked this pull request as ready for review October 7, 2026 16:27
@shettyvarun268 shettyvarun268 changed the title test(packaging): verify consumer TypeScript declarations across all e… test(packaging): verify consumer TypeScript declarations across all entrypoints Oct 7, 2026
Comment thread scripts/test-packaging.sh
Comment thread scripts/verify-types.mjs
Comment thread scripts/verify-types.mjs
Comment thread scripts/verify-types.mjs Outdated
Comment thread scripts/verify-types.mjs Outdated
Comment thread scripts/verify-types.mjs Outdated
Comment thread scripts/verify-types.mjs Outdated
Comment thread scripts/test-packaging.sh Outdated

@ajperel ajperel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread package.json
Comment thread scripts/test-packaging.sh Outdated
Comment thread scripts/verify-types.mjs Outdated
Comment thread scripts/verify-types.mjs Outdated
Comment thread scripts/verify-types.mjs Outdated
Comment thread scripts/verify-types.mjs
importLines.push(`import * as m${i} from '${importPath}';`);
}

const tscPath = path.resolve(process.cwd(), 'node_modules/typescript/bin/tsc');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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:

Suggested change
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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this. Just 4 lines and helps with an early exit without printing long stack traces

Comment thread scripts/verify-types.mjs
Comment thread tsconfig.dts.json
@shettyvarun268
shettyvarun268 merged commit 8490c3d into master Oct 7, 2026
26 checks passed
@shettyvarun268
shettyvarun268 deleted the shettyvarun268/verify-package-types branch October 7, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants