Fix TypeScript metadata bundling for serverless tracing#362
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes the TypeScript SDK’s serverless tracing/bundling failure by moving runtime operation metadata from a dynamically-required JSON file into a generated ESM module that is statically imported, so file tracers (e.g. @vercel/nft) can reliably include it in deployment artifacts (Fixes #361).
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Changes:
- Replace
createRequire(...metadata.json)runtime loading with static ESM imports fromgenerated/metadata.jsin the client and base service. - Generate metadata as
src/generated/metadata.tsviaextract-metadata.ts, and update the TypeScriptgeneratescript accordingly. - Clean up related types/comments/imports impacted by the metadata change.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| typescript/src/services/base.ts | Switch metadata loading to a static ESM import for tracer/bundler visibility. |
| typescript/src/generated/metadata.ts | New generated metadata ESM module (typed) replacing the prior JSON artifact. |
| typescript/src/download.ts | Remove now-unused hook type import after related refactors. |
| typescript/src/client.ts | Replace runtime JSON loading with static import of the metadata module. |
| typescript/scripts/generate-path-mapping.ts | Update comments to reflect the metadata module (not JSON) as the source of truth. |
| typescript/scripts/extract-metadata.ts | Emit a TypeScript ESM module instead of JSON; update schema/types. |
| typescript/package.json | Update generate script to write metadata.ts instead of metadata.json. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Fixed — narrowed the generated metadata types to match the extractor output and pushed the update. |
6c2ad30 to
8343568
Compare
Review carefully before merging. Consider a major version bump. |
Summary
Fixes the TypeScript SDK metadata packaging issue reported in #361 by making runtime operation metadata part of the static ESM import graph.
The SDK previously loaded
generated/metadata.jsonat runtime withcreateRequirefrom bothdist/client.jsanddist/services/base.js. Some serverless file tracers can miss that JSON file, leaving it out of the deployed artifact and causing cold starts to fail withMODULE_NOT_FOUND.This change:
src/generated/metadata.tsclient.tsandservices/base.tscreateRequireJSON loading pathdist/generated/metadata.js, which bundlers and file tracers can follow normallyBasecamp card: https://app.basecamp.com/2914079/buckets/46292715/card_tables/cards/10074337245
Fixes #361.
Validation
npm run typechecknpm run lintnpm test— 616 passingnpm run buildnpm pack+@vercel/nft@0.30.4smoke test confirmed:dist/generated/metadata.jsis traceddist/generated/metadata.jsonis no longer requiredclient constructed)Summary by cubic
Moves the SDK’s runtime metadata from a JSON file to a generated, typed ESM module that’s statically imported, so serverless file tracers include it and cold starts no longer fail with MODULE_NOT_FOUND. Narrows metadata types for stronger compile-time checks. Fixes #361.
src/generated/metadata.ts(unions for backoff, etc.) and emitdist/generated/metadata.jsas a default export.client.tsandservices/base.ts; removecreateRequireand local metadata type definitions.generate/build to write and copy the module; the JSON file is no longer needed.Written for commit 8343568. Summary will update on new commits.