Skip to content

Commit

Permalink
chore: inject packageVersion at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Dec 12, 2024
1 parent ad8897e commit 6e04e56
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
6 changes: 6 additions & 0 deletions karma.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-env node */

const path = require('path');

const pkg = require('./package.json');

const {
DefinePlugin,
NormalModuleReplacementPlugin
Expand Down Expand Up @@ -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': {}
}),
Expand Down
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: [
Expand Down
5 changes: 3 additions & 2 deletions src/element-templates/ElementTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand Down Expand Up @@ -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
};

Expand Down
9 changes: 6 additions & 3 deletions test/spec/cloud-element-templates/ElementTemplates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -790,7 +791,9 @@ describe('provider/cloud-element-templates - ElementTemplates', function() {
it('should provide default <elementTemplates> engine', inject(function(elementTemplates) {

// then
expect(elementTemplates.getEngines()).to.have.property('elementTemplates', pkg.version);
expect(
elementTemplates.getEngines()
).to.have.property('elementTemplates', packageVersion);
}));


Expand All @@ -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'
});
Expand Down

0 comments on commit 6e04e56

Please sign in to comment.