Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce a dedicated function to get the version #2965

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions dev/ts/shared/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import type {
Overlay,
PoolFilter,
StyleUpdate,
Version,
ZoomType,
} from '../../../src/bpmn-visualization';
import type { mxCell } from 'mxgraph';
Expand Down Expand Up @@ -354,12 +353,6 @@ export function downloadPng(): void {
downloadAsPng(new SvgExporter(bpmnVisualization.graph).exportSvgForPng());
}

export function getVersion(): Version {
const version = bpmnVisualization.getVersion();
log('Version:', version);
return version;
}

export function updateStyle(bpmnElementIds: string | string[], style: StyleUpdate): void {
log('Applying style using the style API: %O', style);
bpmnVisualization.bpmnElementsRegistry.updateStyle(bpmnElementIds, style);
Expand Down
2 changes: 1 addition & 1 deletion src/bpmn-visualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ limitations under the License.
export * from './component/options';
export { BpmnVisualization } from './component/BpmnVisualization';
export * from './component/registry';
export type { Version } from './component/version';
export * from './component/version';
export type { Navigation } from './component/navigation';
export * from './model/bpmn/internal';

Expand Down
8 changes: 6 additions & 2 deletions src/component/BpmnVisualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Navigation } from './navigation';
import { newBpmnParser } from './parser/BpmnParser';
import { createNewBpmnElementsRegistry } from './registry/bpmn-elements-registry';
import { BpmnModelRegistry } from './registry/bpmn-model-registry';
import { version, type Version } from './version';
import { getVersion, type Version } from './version';

/**
* Let initialize `bpmn-visualization`. It requires at minimum to pass the HTMLElement in the page where the BPMN diagram is rendered.
Expand Down Expand Up @@ -96,7 +96,11 @@ export class BpmnVisualization {
newBpmnRenderer(this.graph, this.rendererOptions).render(renderedModel, options?.fit);
}

/**
* Returns the version of `bpmn-visualization` and the version of its dependencies.
* @deprecated As of `0.43.0`, use {@link getVersion} instead. This method will be removed in `0.45.0`.
*/
getVersion(): Version {
return version();
return getVersion();
}
}
8 changes: 4 additions & 4 deletions src/component/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import { mxClient } from './mxgraph/initializer';
const libraryVersion = '0.42.0-post';

/**
* @internal
* Returns the version of `bpmn-visualization` and the version of its dependencies.
* @since 0.43.0
*/
export const version = (): Version => {
export const getVersion = (): Version => {
return { lib: libraryVersion, dependencies: new Map([['mxGraph', mxClient.VERSION]]) };
};

/**
* Version of `bpmn-visualization` and its dependencies.
* @category Initialization & Configuration
* The version of `bpmn-visualization` and the version of its dependencies.
*/
export interface Version {
/** The `bpmn-visualization` version. */
Expand Down
2 changes: 2 additions & 0 deletions test/integration/BpmnVisualization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ describe('BpmnVisualization API', () => {
});
});

// Note: the tests here are duplicated with test/unit/component/version.test.ts
// They will be removed when the deprecated `BpmnVisualization.getVersion` method is removed
describe('Version', () => {
it('lib version', () => {
expect(bpmnVisualization.getVersion().lib).toBe(getLibraryVersionFromPackageJson());
Expand Down
47 changes: 47 additions & 0 deletions test/unit/component/version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @jest-environment jsdom
*/
/*
Copyright 2023 Bonitasoft S.A.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { getVersion } from '@lib/component/version';
import { readFileSync } from '@test/shared/file-helper';

const getLibraryVersionFromPackageJson = (): string => {
const json = readFileSync('../../package.json');
const packageJson = JSON.parse(json);
return packageJson.version;
};

describe('Version', () => {
test('lib version', () => {
expect(getVersion().lib).toBe(getLibraryVersionFromPackageJson());
});

test('mxGraph version', () => {
expect(getVersion().dependencies.get('mxGraph')).toBeDefined();
});

test('not modifiable version', () => {
const initialVersion = getVersion();
initialVersion.lib = 'set by test';
initialVersion.dependencies.set('extra', 'added in test');

const newVersion = getVersion();
expect(newVersion.lib).not.toBe(initialVersion.lib);
expect(newVersion.dependencies).not.toBe(initialVersion.dependencies);
});
});
3 changes: 3 additions & 0 deletions tsconfig.typedoc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*"
]
}