Skip to content

fix: inline SDK version instead of reading package.json at runtime - #294

Merged
Zaimwa9 merged 1 commit into
mainfrom
fix/user-agent-version-lookup
Sep 2, 2026
Merged

fix: inline SDK version instead of reading package.json at runtime#294
Zaimwa9 merged 1 commit into
mainfrom
fix/user-agent-version-lookup

Conversation

@Zaimwa9

@Zaimwa9 Zaimwa9 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

getUserAgent() read the SDK version with require('../package.json') at request time. This never worked in the published package (the relative path resolves to build/esm/package.json or the build/cjs/package.json stub, so the header always reported unknown), and under bundlers such as Vite the require can be rewritten into a form that escapes the try/catch and crashes the host application.

  • Inline the version in a committed sdk/version.ts constant; no filesystem or require access at runtime.
  • Register sdk/version.ts as a release-please extra-files entry so the constant is bumped on every release.
  • Un-skip the ESM user-agent test, which now passes against the real package version.

How did you test this code?

  • npm test and npm run test:esm-build pass.
  • Built and packed the SDK, bundled a Fastify server with vite build --ssr (Vite 8), ran the bundle from a separate directory: the request sends User-Agent: flagsmith-nodejs-sdk/9.0.1 and the bundle contains no package.json reference.

@Zaimwa9
Zaimwa9 requested a review from a team as a code owner September 2, 2026 09:20
@Zaimwa9
Zaimwa9 requested review from emyller and removed request for a team September 2, 2026 09:20
@Zaimwa9
Zaimwa9 merged commit 2afee6c into main Sep 2, 2026
4 checks passed
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.

2 participants