fix(flowchart): expose pure modules as window globals for standalone window; v4.9.7

Each pure module's UMD wrapper assigned window.FlowchartXxx only in the else branch — when 'module' was undefined. But the renderer runs with nodeIntegration:true, so 'module' is always truthy and the else branch never ran. The standalone Flowchart Generator window then aborted with 'Flowchart pure modules not loaded'.

Fix: append 'if (typeof window !== undefined) window.FlowchartXxx = exported;' after the CommonJS branch in all 4 pure modules (store, shapes, mermaid, canvas). Both branches can run now; the legacy sidebar panel still loads them via require() and the renderer unconditionally exposes the global.

Regression guard: 4 new source-grep tests in tests/flowchart-controller.test.js assert each module's source contains the 'window.FlowchartXxx = exported' assignment.

Attribution: Amit Haridas
This commit is contained in:
2026-09-14 23:59:50 +05:30
parent 5f846d1e5f
commit 86d4c0d23a
8 changed files with 53 additions and 2 deletions
+1 -1
View File
@@ -257,4 +257,4 @@ Amit Haridas (amit.wh@gmail.com)
## Version
v4.9.6
v4.9.7
+7
View File
@@ -1,5 +1,12 @@
# PanConverter - Updates & Changelog
## Version 4.9.7 (2026-09-14)
### Fix
- **Standalone Flowchart Generator window now loads (was: 'modules not loaded' fatal error).** Each of the four pure modules (`flowchart-shapes.js`, `flowchart-mermaid.js`, `flowchart-store.js`, `flowchart-canvas.js`) ships with a UMD wrapper. The original wrapper assigned `window.FlowchartXxx` only in the `else` branch — i.e. when `module` was undefined. But the renderer runs with `nodeIntegration: true`, so `module` is always truthy in that environment and the `else` branch never ran, leaving `window.FlowchartShapes` / `window.FlowchartMermaid` / `window.FlowchartStore` / `window.FlowchartCanvas` undefined. The standalone window's controller (`src/renderer/flowchart-controller.js`) then aborted with `fatal('Flowchart pure modules not loaded — verify script tags in src/flowchart-generator.html')`.
- Fix: every pure module's UMD wrapper now has a second `if (typeof window !== 'undefined') { window.FlowchartXxx = exported; }` block appended AFTER the CommonJS branch. Both branches can run (the CommonJS branch keeps the legacy sidebar panel working under `require()`; the new branch unconditionally exposes the global in the renderer). The factory IIFE is unchanged, so the public surface of every module is identical to v4.9.6 — no behavioural change.
- New regression guard: 4 source-grep tests in `tests/flowchart-controller.test.js` assert each module's source file contains the `window.FlowchartXxx = exported` assignment so a future refactor can't silently drop the global again.
## Version 4.9.6 (2026-09-14)
### Refactor
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "markdown-converter",
"version": "4.9.6",
"version": "4.9.7",
"description": "Professional Markdown editor and universal file converter with PDF editing, batch processing, and syntax highlighting",
"main": "src/main.js",
"scripts": {
+6
View File
@@ -337,6 +337,12 @@ function createCanvas(container, store, opts = {}) {
} else {
root.FlowchartCanvas = exported;
}
// v4.9.7 — also expose as window global when running in Electron renderer
// (nodeIntegration:true makes `module` truthy so the else branch above never
// runs; the controller still expects window.FlowchartCanvas).
if (typeof window !== 'undefined') {
window.FlowchartCanvas = exported;
}
})(typeof window !== 'undefined' ? window : globalThis, function () {
return { createCanvas, SHAPE_KINDS };
});
+6
View File
@@ -100,6 +100,12 @@ function toMermaid(graph) {
} else {
root.FlowchartMermaid = exported;
}
// v4.9.7 — also expose as window global when running in Electron renderer
// (nodeIntegration:true makes `module` truthy so the else branch above never
// runs; the controller still expects window.FlowchartMermaid).
if (typeof window !== 'undefined') {
window.FlowchartMermaid = exported;
}
})(typeof window !== 'undefined' ? window : globalThis, function () {
return { toMermaid, escapeLabel, nodeDeclaration, edgeDeclaration };
});
+6
View File
@@ -69,6 +69,12 @@ function shapeSvg(kind, x, y, width, height) {
} else {
root.FlowchartShapes = exported;
}
// v4.9.7 — also expose as window global when running in Electron renderer
// (nodeIntegration:true makes `module` truthy so the else branch above never
// runs; the controller still expects window.FlowchartShapes).
if (typeof window !== 'undefined') {
window.FlowchartShapes = exported;
}
})(typeof window !== 'undefined' ? window : globalThis, function () {
return {
shapeSvg,
+6
View File
@@ -268,6 +268,12 @@ function create(io) {
} else {
root.FlowchartStore = exported;
}
// v4.9.7 — also expose as window global when running in Electron renderer
// (nodeIntegration:true makes `module` truthy so the else branch above never
// runs; the controller still expects window.FlowchartStore).
if (typeof window !== 'undefined') {
window.FlowchartStore = exported;
}
})(typeof window !== 'undefined' ? window : globalThis, function () {
return { create, NODE_KINDS, EDGE_KINDS };
});
+20
View File
@@ -214,3 +214,23 @@ describe('flowchart-controller: renderer.js sidebar registration is disabled', (
expect(liveMatch).toBeNull();
});
});
// v4.9.7 regression — pure modules MUST expose themselves as window globals
// so the standalone Flowchart Generator window can load them via <script>
// tags. In Electron renderer with nodeIntegration:true, `module` is truthy,
// which used to make the UMD wrapper skip its browser-global assignment;
// this guard is now mandatory. We assert the source contains the
// `window.FlowchartXxx = exported;` line so a future refactor can't silently
// drop it again.
describe('flowchart pure modules — UMD browser-global assignment (v4.9.7)', () => {
const cases = [
['flowchart/flowchart-store.js', 'FlowchartStore'],
['flowchart/flowchart-shapes.js', 'FlowchartShapes'],
['flowchart/flowchart-mermaid.js', 'FlowchartMermaid'],
['flowchart/flowchart-canvas.js', 'FlowchartCanvas'],
];
test.each(cases)('%s assigns window.%s = exported', (rel, globalName) => {
const src = fs.readFileSync(path.join(__dirname, '..', 'src', rel), 'utf-8');
expect(src).toMatch(new RegExp(`window\\.${globalName}\\s*=\\s*exported`));
});
});