@@ -11,6 +11,7 @@ import {
1111 setScriptTaskData ,
1212 getStartFormFileNameMapping ,
1313 setStartFormFileName ,
14+ getDefinitionsId ,
1415} from '@proceed/bpmn-helper' ;
1516import { asyncForEach } from './javascriptHelpers' ;
1617
@@ -36,39 +37,57 @@ const { diff } = require('bpmn-js-differ');
3637// should be refactored to reflect the fact this runs on the server now.
3738
3839export async function areVersionsEqual ( bpmn : string , otherBpmn : string ) {
39- const bpmnObj = await toBpmnObject ( bpmn ) ;
40- const otherBpmnObj = await toBpmnObject ( otherBpmn ) ;
40+ // compare the bpmn of both versions excluding the differences that would come from one being
41+ // versioned and the other not being versioned
42+ const unversionedOther = await convertToEditableBpmn ( otherBpmn ) ;
4143
42- const {
43- versionId,
44- name : versionName ,
45- description : versionDescription ,
46- versionBasedOn,
47- versionCreatedOn,
48- } = await getDefinitionsVersionInformation ( otherBpmnObj ) ;
49-
50- if ( versionId ) {
51- // check if the two bpmns were the same if they had the same version information
52- await setDefinitionsVersionInformation ( bpmnObj , {
53- versionId,
54- versionName,
55- versionDescription,
56- versionBasedOn,
57- versionCreatedOn,
58- } ) ;
44+ const bpmnObj = await toBpmnObject ( bpmn ) ;
45+ const unversionedOtherObj = await toBpmnObject ( unversionedOther . bpmn ) ;
46+
47+ // compare the two bpmns in a way that is not affected by the ordering of elements in the text
48+ // file
49+ const changes = diff ( unversionedOtherObj , bpmnObj ) ;
50+ const hasChanges =
51+ Object . keys ( changes . _changed ) . length ||
52+ Object . keys ( changes . _removed ) . length ||
53+ Object . keys ( changes . _added ) . length ||
54+ Object . keys ( changes . _layoutChanged ) . length ;
55+
56+ if ( hasChanges ) return false ;
57+
58+ const definitionsId = await getDefinitionsId ( bpmnObj ) ;
59+
60+ // compare the assets used in the bpmns
61+ // (we expect that the "same" asset names are referenced since the comparison above would find differences otherwise)
62+
63+ // compare start forms
64+ for ( const [ versioned , unversioned ] of Object . entries (
65+ unversionedOther . changedStartFormTaskFileNames ,
66+ ) ) {
67+ const versionedHtmlForm = await getHtmlForm ( definitionsId , versioned ) ;
68+ const unversionedHtmlForm = await getHtmlForm ( definitionsId , unversioned ) ;
69+ if ( versionedHtmlForm !== unversionedHtmlForm ) return false ;
70+ }
5971
60- // compare the two bpmns
61- const changes = diff ( otherBpmnObj , bpmnObj ) ;
62- const hasChanges =
63- Object . keys ( changes . _changed ) . length ||
64- Object . keys ( changes . _removed ) . length ||
65- Object . keys ( changes . _added ) . length ||
66- Object . keys ( changes . _layoutChanged ) . length ;
72+ // compare user tasks
73+ for ( const [ versioned , unversioned ] of Object . entries (
74+ unversionedOther . changedUserTaskFileNames ,
75+ ) ) {
76+ const versionedHtmlForm = await getHtmlForm ( definitionsId , versioned ) ;
77+ const unversionedHtmlForm = await getHtmlForm ( definitionsId , unversioned ) ;
78+ if ( versionedHtmlForm !== unversionedHtmlForm ) return false ;
79+ }
6780
68- return ! hasChanges ;
81+ // compare script tasks
82+ for ( const [ versioned , unversioned ] of Object . entries (
83+ unversionedOther . changedScriptTaskFileNames ,
84+ ) ) {
85+ const versionedScript = await getProcessScriptTaskScript ( definitionsId , versioned + '.js' ) ;
86+ const unversionedScript = await getProcessScriptTaskScript ( definitionsId , unversioned + '.js' ) ;
87+ if ( versionedScript !== unversionedScript ) return false ;
6988 }
7089
71- return false ;
90+ return true ;
7291}
7392
7493export async function convertToEditableBpmn ( bpmn : string ) {
0 commit comments