diff --git a/packages/common/src/__tests__/test-sdk-version.ts b/packages/common/src/__tests__/test-sdk-version.ts new file mode 100644 index 0000000000..97924a5985 --- /dev/null +++ b/packages/common/src/__tests__/test-sdk-version.ts @@ -0,0 +1,11 @@ +import { readFileSync } from 'fs'; +import { join } from 'path'; +import test from 'ava'; +import { sdkVersion } from '../index'; + +const pkg = JSON.parse(readFileSync(join(__dirname, '../../package.json'), 'utf8')) as { version: string }; + +test('sdkVersion exposes the package version', (t) => { + t.is(sdkVersion, pkg.version); + t.regex(sdkVersion, /^\d+\.\d+\.\d+/); +}); diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index a501b23d02..1384462c4d 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -6,6 +6,12 @@ import * as encoding from './encoding'; import * as helpers from './type-helpers'; +import { version as sdkVersion } from './pkg'; + +/** + * Version of the Temporal TypeScript SDK. + */ +export { sdkVersion }; export * from './activity-options'; export { ActivityCancellationDetailsOptions, ActivityCancellationDetails } from './activity-cancellation-details'; diff --git a/packages/common/src/pkg.ts b/packages/common/src/pkg.ts new file mode 100644 index 0000000000..4fe0f53c78 --- /dev/null +++ b/packages/common/src/pkg.ts @@ -0,0 +1,7 @@ +// ../package.json is outside of the TS project rootDir which causes TS to complain about this import. +// We do not want to change the rootDir because it messes up the output structure. +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore +import pkg from '../package.json'; + +export const version = pkg.version as string;