Migrating to 2.0
sfn-diagram 2.0 removes what 1.10 deprecated, ships ES modules only, needs Node 22.12 or
later, and moves the interactive viewer to sfn-diagram/html. From 2.0 on, the
Compatibility policy defines what a version number promises. 1.10.0 is
the last 1.x release (below).
What to check
Section titled “What to check”- Every project: the Node version.
- Library code:
- imports of the interactive viewer and its internals;
- the removed options:
width/height,pngQualityandengine; LayoutCachemethods;- exhaustive switches over the execution status;
- CSS or scripts that target
#arrowhead-*; - Jest and TypeScript config;
- hand-built graph objects.
- CLI, Docker image and binaries:
- the Node version, for
npxandnpm i -g; - jobs that pull the Docker image as
latestor:1:latestmoves to 2.0, and:1stops getting rebuilds (below); - images built
FROMthe Docker image; - SVG marker ids, which the CLI can’t opt out of yet;
abortedin execution overlays and in the--executionsummary.
- the Node version, for
- GitHub Action and VS Code extension: nothing to change (below).
Breaking changes
Section titled “Breaking changes”Each section shows the 1.x code and its 2.0 replacement.
Node 22.12 or later (#285)
Section titled “Node 22.12 or later (#285)”What changes: engines.node is >=22.12.0. Node 22 itself reaches end of life on
2027-04-30, and from 2.0 an end-of-life Node line may be dropped in a minor release (see
Runtime support).
Before (1.x):
- uses: actions/setup-node@v4 with: node-version: 20After (2.0):
- uses: actions/setup-node@v4 with: node-version: 22 # 22.12 or later, or 24ESM only (#524)
Section titled “ESM only (#524)”What changes: the package ships ES modules only, and drops main and
typesVersions. import is unchanged, and CommonJS require('sfn-diagram') keeps
working on Node 22.12+, which can require ES modules. Tooling that ignores the
exports map and reads main needs an update.
Before (1.x):
module.exports = { transformIgnorePatterns: ['/node_modules/(?!(d3-shape|d3-path)/)'],};{ "compilerOptions": { "module": "commonjs", "moduleResolution": "node" }}After (2.0):
module.exports = { transformIgnorePatterns: [ '/node_modules/(?!(sfn-diagram|sfn-diagram-react|d3-shape|d3-path)/)', ],};{ "compilerOptions": { "module": "nodenext", "moduleResolution": "nodenext" }}- Jest: exempt
sfn-diagram(andsfn-diagram-react) fromtransformIgnorePatternsso Jest transforms them, for exampletransformIgnorePatterns: ['/node_modules/(?!(sfn-diagram|sfn-diagram-react|d3-shape|d3-path)/)']. 2.0.0 and 2.0.1 also need thed3-shapeandd3-pathexemption; later releases no longer depend on them, so it can go once you upgrade past 2.0.1. - TypeScript: with
typesVersionsgone,moduleResolution: "node"("node10") loses the subpath types (sfn-diagram/pngand the rest). Use"node16","nodenext"or"bundler". Projects that compile to CommonJS need TypeScript 5.8+ withmodule: "nodenext"(current TypeScript also offers"node20").
Interactive viewer moved to sfn-diagram/html (#615)
Section titled “Interactive viewer moved to sfn-diagram/html (#615)”What changes: generateHtml, generateHtmlAsync, generateExecutionHtml,
generateExecutionHtmlAsync and generateViewerUpdate move from sfn-diagram to
sfn-diagram/html. generateDiagram, generateFromAwsResponse and
SfnDiagramGenerator.generate no longer accept format: 'html': they throw an error
that names the new import, and their return types narrow to MermaidOutput | SvgOutput.
Before (1.x):
import { generateDiagram } from 'sfn-diagram';
const { html } = generateDiagram({ aslDefinition, format: 'html' });After (2.0):
import { generateHtml } from 'sfn-diagram/html';
const { html } = generateHtml({ aslDefinition });For generateFromAwsResponse({ response, ...options, format: 'html' }), pass the
definition yourself, checking it first as generateFromAwsResponse did:
if (!response.definition) throw new Error('No definition found in AWS response');const { html } = generateHtml({ ...options, aslDefinition: response.definition });The HTML types (HtmlOutput, GenerateHtmlParams and the rest) are still exported from
the root as well, and the CLI’s --format html is unchanged. A cache from
createLayoutCache works with both entries.
1.10 could have flagged this change in advance and didn’t. It ships in 2.0 anyway
because the viewer is about half of the root entry. Without it, sfn-diagram goes from
369 kB to 163 kB minified (120 kB to 57 kB gzipped). That saving reaches every caller of
generateDiagram and every unbundled import, which tree-shaking can’t help.
Viewer internals no longer exported (#528)
Section titled “Viewer internals no longer exported (#528)”What changes: buildViewerContent and resolveViewerTheme are no longer exported.
generateViewerUpdate (from sfn-diagram/html) replaces buildViewerContent: its
contentHtml is the same markup for a rendered diagram. It renders from the definition,
so there is no replacement that takes an svg you rendered or edited yourself.
Before (1.x):
import { buildViewerContent } from 'sfn-diagram';
const contentHtml = buildViewerContent({ minimapCollapsed: true, svg });After (2.0):
import { generateViewerUpdate } from 'sfn-diagram/html';
const { contentHtml, relayoutModel } = generateViewerUpdate({ aslDefinition });resolveViewerThemehas no public replacement:'light','dark'and'auto'map to themselves; classify a custom theme by itsbackgroundcolour.ViewerUpdate.relayoutModelis now typedunknown. Its 1.x fields (RelayoutModel.callerOverrides,RelayoutModel.collapseTargets,RelayoutModel.diffChangedIds,RelayoutModel.edges,RelayoutModel.executionStatusByNodeId,RelayoutModel.nodesandRelayoutModel.options) are internal. Pass it through unchanged together withcontentHtml.
DiagramOptions.width and height removed (#408)
Section titled “DiagramOptions.width and height removed (#408)”What changes: DiagramOptions.width and DiagramOptions.height are removed. They
never affected the output.
Before (1.x):
const { svg } = generateSvg({ aslDefinition, height: 600, width: 800 });After (2.0):
const { svg } = generateSvg({ aslDefinition });/* The SVG's viewBox scales freely: size it with CSS. */.diagram svg { height: auto; max-width: 100%;}For PNG resolution, use scale (below).
DiagramOptions.pngQuality removed (#321)
Section titled “DiagramOptions.pngQuality removed (#321)”What changes: DiagramOptions.pngQuality is removed. It never affected PNG output;
PngExportOptions.scale sets the resolution.
Before (1.x):
await exportPng({ aslDefinition, pngQuality: 90 });After (2.0):
await exportPng({ aslDefinition, scale: 2 });html-to-image PNG engine removed (#525)
Section titled “html-to-image PNG engine removed (#525)”What changes: the html-to-image engine and its node-html-to-image peer are gone;
uninstall node-html-to-image. The default resvg engine is the only one, and
engine: 'html-to-image' now throws.
Before (1.x):
npm install sfn-diagram node-html-to-imageawait exportPng({ aslDefinition, engine: 'html-to-image' });await new PngExporter({}).convert({ height, svg, width });After (2.0):
npm uninstall node-html-to-imagenpm install @resvg/resvg-jsawait exportPng({ aslDefinition });await new PngExporter({}).convert({ svg, width });PngExporter.convert stops taking height (ConvertParams.height; no entry point
exports the type), since only that engine used it. The PNG’s aspect ratio comes from the
SVG.
LayoutCache narrowed (#526)
Section titled “LayoutCache narrowed (#526)”What changes: LayoutCache.get, LayoutCache.set and LayoutCache.keyFor are
removed. Only clear() and stats() stay. Pass the cache as cache to a render
function such as generateSvg and let it do the lookup. An SVG, HTML or PNG render
throws a TypeError for a cache that createLayoutCache did not create.
Before (1.x):
import type { LayoutCache } from 'sfn-diagram';
// A hand-written cache, or code that calls get, set or keyFor itself.const cache: LayoutCache = { clear, get, keyFor, set, stats };generateSvg({ aslDefinition, cache });After (2.0):
import { createLayoutCache, generateSvg } from 'sfn-diagram';
const cache = createLayoutCache({ maxEntries: 64 });generateSvg({ aslDefinition, cache });cache.stats();Graph types tightened (#526)
Section titled “Graph types tightened (#526)”What changes: StateNode.type becomes NodeType (a StateType, or one of the
synthetic BranchEnd, IteratorEnd, ItemReader and ResultWriter nodes) instead
of string, and GraphEdge.type becomes required. Nothing changes unless your code
builds these objects by hand.
Before (1.x):
const edge: GraphEdge = { from: 'A', id: 'A->B', to: 'B' };After (2.0):
const edge: GraphEdge = { from: 'A', id: 'A->B', to: 'B', type: 'normal' };aborted execution status (#309)
Section titled “aborted execution status (#309)”What changes: ExecutionStateStatus and TimelineEntryStatus gain an aborted
member, and ExecutionMetadataSummary gains an aborted list. A Parallel branch or Map
iteration stopped because another one failed, a container AWS aborted, and every state
still open when an execution is stopped now report aborted (blue-grey; Mermaid class
execAborted) instead of failed. The branch or iteration that actually errored stays
failed.
Before (1.x):
switch (status) { case 'caught': case 'failed': case 'notReached': case 'running': case 'succeeded': return label(status);}After (2.0):
switch (status) { case 'aborted': case 'caught': case 'failed': case 'notReached': case 'running': case 'succeeded': return label(status); default: return label('unknown');}Code that reads metadata.failed to find every state that did not finish should read
metadata.aborted too. The compatibility policy
lets this union grow in a minor release, so a default: branch keeps working.
Marker ids prefixed by default (#527)
Section titled “Marker ids prefixed by default (#527)”What changes: each SVG render prefixes its marker ids with sfn- and eight hex
digits hashed from the rest of the SVG (sfn-1a2b3c4d-arrowhead-normal), so CSS or
scripts that reference #arrowhead-* stop matching. The hash changes whenever the
output does, so don’t hard-code it. <sfn-diagram> elements change from
arrowhead-<n>-<type> to sfn-el<n>-arrowhead-<type>. The collapsed view that
generateViewerUpdate embeds gets its own hash, or <idPrefix>collapsed-arrowhead-<type>
under an explicit idPrefix (1.10 wrote <idPrefix>arrowhead-collapsed-<type>).
Before (1.x):
#arrowhead-normal path { fill: rebeccapurple;}After (2.0):
const { svg } = generateSvg({ aslDefinition, idPrefix: 'orders-' });#orders-arrowhead-normal path { fill: rebeccapurple;}Pass idPrefix: '' to keep the bare 1.x ids. The CLI and config file have no idPrefix
setting yet (#564, not scheduled),
so CLI output gets the 2.0 default with no opt-out until that lands.
Docker image base (#555)
Section titled “Docker image base (#555)”What changes: the image is built on node:24-alpine (Alpine Linux, musl libc)
instead of the Debian-based node:24-slim. The CLI, its entrypoint, the node user
(uid 1000) and the /app layout don’t change. The Debian image carried 35 high and
critical OS findings with no Debian fix; the Alpine image has none. Nothing changes
unless you build FROM the image.
Before (1.x):
FROM ghcr.io/yusufaf/sfn-diagram:1USER rootRUN apt-get update && apt-get install -y --no-install-recommends git \ && rm -rf /var/lib/apt/lists/*USER nodeAfter (2.0):
FROM ghcr.io/yusufaf/sfn-diagram:2USER rootRUN apk add --no-cache gitUSER node- Install packages with
apk add --no-cache <package>instead ofapt-get install, as root. Package names can differ. - Binaries linked against glibc don’t run on musl. Use Alpine builds of them, or build
your own image from
node:24-slim. /bin/shis BusyBoxash, and there is nobashunless you add it.- Liberation Sans is at
/usr/share/fonts/liberation/. IfSFN_DIAGRAM_PNG_FONT_DIRSpoints at/usr/share/fonts/truetype/liberation, update it.
Not changing
Section titled “Not changing”- Bare
From->Tokeys inedgeOverrideskeep working. They are the only key form that survives reordering a Choice state’s rules. See per-edge overrides. - CLI flags, exit codes and config keys.
--format htmlfrom the CLI.- The GitHub Action’s inputs.
Releases and other packages
Section titled “Releases and other packages”- 2.0.0 is
lateston npm and JSR. Dockerlatestand:2(on ghcr.io and Docker Hub), the Homebrew formula and the standalone binaries move to 2.0 in the same release. - 1.10.0 is the last 1.x release: there are no 1.x fixes after 2.0.
:1image tags stop getting the weekly base-image rebuild. To stay on 1.x for now, pinsfn-diagram@1or the:1image. sfn-diagram-react1.0.0 requires sfn-diagram 2 (#540).- The VS Code extension bundles 2.0 from its 0.4.0 release (#542); there is nothing to do.
- The GitHub Action stays on
v1with unchanged inputs, and bundles the 2.0 core, so its execution overlays can showaborted.