diff --git a/release-please-config.json b/release-please-config.json index f473b24..fc1a9dd 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -8,7 +8,8 @@ "bump-patch-for-minor-pre-major": false, "draft": false, "prerelease": false, - "include-component-in-tag": false + "include-component-in-tag": false, + "extra-files": ["sdk/version.ts"] } }, "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", diff --git a/sdk/utils.ts b/sdk/utils.ts index 016e274..660249e 100644 --- a/sdk/utils.ts +++ b/sdk/utils.ts @@ -1,11 +1,11 @@ import { createHash } from 'crypto'; import { Fetch, FlagsmithTraitValue, TraitConfig } from './types.js'; import { Dispatcher } from 'undici-types'; +import { SDK_VERSION } from './version.js'; type Traits = { [key: string]: TraitConfig | FlagsmithTraitValue }; const FLAGSMITH_USER_AGENT = 'flagsmith-nodejs-sdk'; -const FLAGSMITH_UNKNOWN_VERSION = 'unknown'; export function isTraitConfig( traitValue: TraitConfig | FlagsmithTraitValue @@ -130,11 +130,5 @@ export class Deferred { } export function getUserAgent(): string { - try { - const packageJson = require('../package.json'); - const version = packageJson?.version; - return version ? `${FLAGSMITH_USER_AGENT}/${version}` : FLAGSMITH_UNKNOWN_VERSION; - } catch { - return FLAGSMITH_UNKNOWN_VERSION; - } + return `${FLAGSMITH_USER_AGENT}/${SDK_VERSION}`; } diff --git a/sdk/version.ts b/sdk/version.ts new file mode 100644 index 0000000..8e9cf2d --- /dev/null +++ b/sdk/version.ts @@ -0,0 +1 @@ +export const SDK_VERSION = '9.0.1'; // x-release-please-version diff --git a/tests/sdk/flagsmith.test.ts b/tests/sdk/flagsmith.test.ts index 766367c..acaf939 100644 --- a/tests/sdk/flagsmith.test.ts +++ b/tests/sdk/flagsmith.test.ts @@ -512,8 +512,7 @@ test('getIdentityFlags succeeds if initial fetch failed then succeeded', async ( expect(flags2.isFeatureEnabled('some_feature')).toBe(true); }); -// Skip in ESM build: require() path resolution differs -test.skipIf(isEsmBuild)('get_user_agent_extracts_version_from_package_json', async () => { +test('get_user_agent_matches_package_version', async () => { const userAgent = getUserAgent(); const packageJson = require('../../package.json');