BPMN.js Differ

3.2.0 · active · verified Sun Apr 19

bpmn-js-differ is a semantic diffing utility specifically designed for comparing two BPMN 2.0 files programmatically. It analyzes the structural and semantic differences between two BPMN definitions, producing a detailed report of added, removed, changed, and layout-modified elements. The current stable version is 3.2.0. The library maintains a steady release cadence, often aligning with updates to its core dependencies like `bpmn-moddle` and `bpmn-js`. Its key differentiator lies in providing a structured, semantic diff output, which is crucial for building visual diff tools or automated change detection workflows for BPMN diagrams, as opposed to simple text-based comparisons.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `bpmn-js-differ` to compare two BPMN 2.0 XML strings by first parsing them with `bpmn-moddle` and then feeding the resulting definitions into the `diff` function. It then logs the detected additions, removals, modifications, and layout changes.

import { diff } from 'bpmn-js-differ';
import { BpmnModdle } from 'bpmn-moddle';

// Example BPMN XML strings (replace with your actual diagrams)
const diagramAXML = `<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" id="Definitions_1">
  <bpmn:process id="Process_1" isExecutable="false">
    <bpmn:startEvent id="StartEvent_1" name="Start"></bpmn:startEvent>
    <bpmn:task id="Task_1" name="Original Task"></bpmn:task>
    <bpmn:sequenceFlow id="Flow_1" sourceRef="StartEvent_1" targetRef="Task_1"></bpmn:sequenceFlow>
  </bpmn:process>
</bpmn:definitions>`;

const diagramBXML = `<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" id="Definitions_1">
  <bpmn:process id="Process_1" isExecutable="false">
    <bpmn:startEvent id="StartEvent_1" name="Start"></bpmn:startEvent>
    <bpmn:task id="Task_1" name="Modified Task"></bpmn:task>
    <bpmn:endEvent id="EndEvent_1" name="End"></bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_1" sourceRef="StartEvent_1" targetRef="Task_1"></bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_2" sourceRef="Task_1" targetRef="EndEvent_1"></bpmn:sequenceFlow>
  </bpmn:process>
</bpmn:definitions>`;

async function compareBpmnDiagrams(xmlA, xmlB) {
  const bpmnModdle = new BpmnModdle();

  const { rootElement: definitionsA } = await bpmnModdle.fromXML(xmlA);
  const { rootElement: definitionsB } = await bpmnModdle.fromXML(xmlB);

  const changes = diff(definitionsA, definitionsB);

  console.log('Detected Changes:');
  console.log('  Added:', Object.keys(changes._added));
  console.log('  Removed:', Object.keys(changes._removed));
  console.log('  Changed:', Object.keys(changes._changed));
  console.log('  Layout Changed:', Object.keys(changes._layoutChanged));

  return changes;
}

compareBpmnDiagrams(diagramAXML, diagramBXML)
  .catch(console.error);

view raw JSON →