diff --git a/jest.config.js b/jest.config.js index f1147e27..343a47e7 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,10 @@ +const lernaJson = require('./lerna.json') + module.exports = { preset: 'ts-jest', globals: { __DEV__: true, + __VERSION__: lernaJson.version, __BROWSER__: false, __JSDOM__: true, __RUNTIME_COMPILE__: true, diff --git a/packages/global.d.ts b/packages/global.d.ts index c7e0779a..d84d24ac 100644 --- a/packages/global.d.ts +++ b/packages/global.d.ts @@ -4,6 +4,7 @@ declare var __JSDOM__: boolean declare var __BROWSER__: boolean declare var __RUNTIME_COMPILE__: boolean declare var __COMMIT__: string +declare var __VERSION__: string // Feature flags declare var __FEATURE_OPTIONS__: boolean diff --git a/packages/runtime-core/__tests__/version.spec.ts b/packages/runtime-core/__tests__/version.spec.ts new file mode 100644 index 00000000..f3cbe5f3 --- /dev/null +++ b/packages/runtime-core/__tests__/version.spec.ts @@ -0,0 +1,6 @@ +import { version } from '../src' +import lernaJson from '../../../lerna.json' + +test('version', () => { + expect(version).toBe(lernaJson.version) +}) diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index ae3f6d8f..3df49680 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -84,3 +84,5 @@ export { DirectiveArguments } from './directives' export { SuspenseBoundary } from './suspense' + +export const version = __VERSION__ diff --git a/rollup.config.js b/rollup.config.js index 9eeca408..3c6bd04e 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -4,6 +4,7 @@ import ts from 'rollup-plugin-typescript2' import replace from 'rollup-plugin-replace' import alias from 'rollup-plugin-alias' import json from 'rollup-plugin-json' +import lernaJson from './lerna.json' if (!process.env.TARGET) { throw new Error('TARGET package must be specified via --environment flag.') @@ -143,6 +144,7 @@ function createReplacePlugin( ) { return replace({ __COMMIT__: `"${process.env.COMMIT}"`, + __VERSION__: `"${lernaJson.version}"`, __DEV__: isBundlerESMBuild ? // preserve to be handled by bundlers `process.env.NODE_ENV !== 'production'`