diff --git a/karma.config.js b/karma.config.js index ead36993..9db925dc 100644 --- a/karma.config.js +++ b/karma.config.js @@ -1,6 +1,9 @@ /* eslint-env node */ const path = require('path'); + +const pkg = require('./package.json'); + const { DefinePlugin, NormalModuleReplacementPlugin @@ -93,6 +96,9 @@ module.exports = function(karma) { plugins: [ new DefinePlugin({ + // @nikku needs to be defined + 'process.env.PKG_VERSION': JSON.stringify(pkg.version), + // @barmac: process.env has to be defined to make @testing-library/preact work 'process.env': {} }), diff --git a/package-lock.json b/package-lock.json index c91a9140..4fcf02c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "@rollup/plugin-commonjs": "^28.0.1", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^15.3.0", + "@rollup/plugin-replace": "^6.0.1", "@testing-library/preact": "^2.0.1", "@testing-library/preact-hooks": "^1.1.0", "assert": "^2.1.0", @@ -1357,6 +1358,28 @@ } } }, + "node_modules/@rollup/plugin-replace": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-6.0.1.tgz", + "integrity": "sha512-2sPh9b73dj5IxuMmDAsQWVFT7mR+yoHweBaXG2W/R8vQ+IWZlnaI7BR7J6EguVQUp1hd8Z7XuozpDjEKQAAC2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "magic-string": "^0.30.3" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, "node_modules/@rollup/pluginutils": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.0.tgz", @@ -11234,6 +11257,16 @@ "resolve": "^1.22.1" } }, + "@rollup/plugin-replace": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-6.0.1.tgz", + "integrity": "sha512-2sPh9b73dj5IxuMmDAsQWVFT7mR+yoHweBaXG2W/R8vQ+IWZlnaI7BR7J6EguVQUp1hd8Z7XuozpDjEKQAAC2Q==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^5.0.1", + "magic-string": "^0.30.3" + } + }, "@rollup/pluginutils": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.0.tgz", diff --git a/package.json b/package.json index d72cf44e..01b329bf 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "@rollup/plugin-commonjs": "^28.0.1", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^15.3.0", + "@rollup/plugin-replace": "^6.0.1", "@testing-library/preact": "^2.0.1", "@testing-library/preact-hooks": "^1.1.0", "assert": "^2.1.0", diff --git a/rollup.config.mjs b/rollup.config.mjs index df420c17..74f091e7 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -4,6 +4,7 @@ import commonjs from '@rollup/plugin-commonjs'; import copy from 'rollup-plugin-copy'; import json from '@rollup/plugin-json'; import resolve from '@rollup/plugin-node-resolve'; +import replace from '@rollup/plugin-replace'; import { readFileSync @@ -81,6 +82,12 @@ function pgl(plugins = []) { function corePlugins(plugins = []) { return [ ...plugins, + replace({ + preventAssignment: true, + values: { + 'process.env.PKG_VERSION': JSON.stringify(pkg.version) + } + }), json(), resolve({ mainFields: [ diff --git a/src/element-templates/ElementTemplates.js b/src/element-templates/ElementTemplates.js index 3a32037b..8e92e474 100644 --- a/src/element-templates/ElementTemplates.js +++ b/src/element-templates/ElementTemplates.js @@ -24,7 +24,8 @@ import { coerce } from 'semver'; -import pkg from '../../package.json'; +// eslint-disable-next-line no-undef +const packageVersion = process.env.PKG_VERSION; /** @@ -177,7 +178,7 @@ export default class ElementTemplates { // package version; templates may use that engine to declare // compatibility with this library engines = { - elementTemplates: pkg.version, + elementTemplates: packageVersion, ...engines }; diff --git a/test/spec/cloud-element-templates/ElementTemplates.spec.js b/test/spec/cloud-element-templates/ElementTemplates.spec.js index 26a3c78a..69bcb0e6 100644 --- a/test/spec/cloud-element-templates/ElementTemplates.spec.js +++ b/test/spec/cloud-element-templates/ElementTemplates.spec.js @@ -34,7 +34,8 @@ import { findExtensions, findExtension } from 'src/cloud-element-templates/Helpe import { getLabel } from 'bpmn-js/lib/features/label-editing/LabelUtil'; import { findMessage } from 'src/cloud-element-templates/Helper'; -import pkg from '../../../package.json'; +// eslint-disable-next-line no-undef +const packageVersion = process.env.PKG_VERSION; describe('provider/cloud-element-templates - ElementTemplates', function() { @@ -790,7 +791,9 @@ describe('provider/cloud-element-templates - ElementTemplates', function() { it('should provide default engine', inject(function(elementTemplates) { // then - expect(elementTemplates.getEngines()).to.have.property('elementTemplates', pkg.version); + expect( + elementTemplates.getEngines() + ).to.have.property('elementTemplates', packageVersion); })); @@ -804,7 +807,7 @@ describe('provider/cloud-element-templates - ElementTemplates', function() { // then expect(elementTemplates.getEngines()).to.eql({ - 'elementTemplates': pkg.version, + 'elementTemplates': packageVersion, 'camunda': '8.0.0', 'other': '100.5.0' });