Skip to content

Fix TypeScript metadata bundling for serverless tracing#362

Merged
jeremy merged 2 commits into
basecamp:mainfrom
robzolkos:fix-ts-metadata-esm
Jul 13, 2026
Merged

Fix TypeScript metadata bundling for serverless tracing#362
jeremy merged 2 commits into
basecamp:mainfrom
robzolkos:fix-ts-metadata-esm

Conversation

@robzolkos

@robzolkos robzolkos commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

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.json at runtime with createRequire from both dist/client.js and dist/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 with MODULE_NOT_FOUND.

This change:

  • generates metadata as src/generated/metadata.ts
  • imports metadata statically from client.ts and services/base.ts
  • removes the runtime createRequire JSON loading path
  • emits dist/generated/metadata.js, which bundlers and file tracers can follow normally

Basecamp card: https://app.basecamp.com/2914079/buckets/46292715/card_tables/cards/10074337245

Fixes #361.

Validation

  • npm run typecheck
  • npm run lint
  • npm test — 616 passing
  • npm run build
  • npm pack + @vercel/nft@0.30.4 smoke test confirmed:
    • dist/generated/metadata.js is traced
    • dist/generated/metadata.json is no longer required
    • the pruned artifact starts successfully (client 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.

  • Bug Fixes
    • Generate a typed ESM module at src/generated/metadata.ts (unions for backoff, etc.) and emit dist/generated/metadata.js as a default export.
    • Import the module in client.ts and services/base.ts; remove createRequire and local metadata type definitions.
    • Update 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.

Review in cubic

Copilot AI review requested due to automatic review settings July 8, 2026 12:12
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file typescript Pull requests that update TypeScript code bug Something isn't working labels Jul 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 from generated/metadata.js in the client and base service.
  • Generate metadata as src/generated/metadata.ts via extract-metadata.ts, and update the TypeScript generate script 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.

Comment thread typescript/scripts/extract-metadata.ts Outdated
Copilot AI review requested due to automatic review settings July 8, 2026 12:25
@robzolkos

Copy link
Copy Markdown
Collaborator Author

Fixed — narrowed the generated metadata types to match the extractor output and pushed the update.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 13, 2026 13:46
@robzolkos robzolkos force-pushed the fix-ts-metadata-esm branch from 6c2ad30 to 8343568 Compare July 13, 2026 13:46
@github-actions github-actions Bot added the breaking Breaking change to public API label Jul 13, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Potential breaking changes detected:

  • Removal of the OperationMetadata interface, which is an exported type.
  • Change from using createRequire to directly importing metadata from ./generated/metadata.js, which could alter runtime behavior.
  • Removal of the createRequire-based import mechanism for metadata.json. If consumers were relying on the previous JSON import behavior, this could break their code.

Review carefully before merging. Consider a major version bump.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated no new comments.

@jeremy jeremy merged commit 99ff10d into basecamp:main Jul 13, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaking change to public API bug Something isn't working dependencies Pull requests that update a dependency file typescript Pull requests that update TypeScript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createRequire JSON load in dist breaks bundlers / serverless file tracing

3 participants