Skip to content
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
11 changes: 6 additions & 5 deletions hw-graphviz.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
</head>

<body>
<h2 id="placeholder_version"></h2>
<div id="placeholder"></div>
<script type="module">
// Prefer local version (if available) ---
const GraphvizLocal = await import("./dist/index.js").then(m => m.Graphviz).catch(() => undefined);
import { Graphviz as GraphvizExternal } from "https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist/index.js";

const Graphviz = GraphvizLocal ?? GraphvizExternal;
const Graphviz = await import("./packages/graphviz/dist/index.js").then(m => m.Graphviz).catch(() => undefined) ??
await import("https://cdn.jsdelivr.net/npm/@hpcc-js/wasm-graphviz/dist/index.js").then(m => m.Graphviz);
Comment on lines +14 to +15
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ?? chain only catches failures of the first import; if the CDN import on the next line fails, it will throw an unhandled rejection. Consider wrapping the combined import logic in a try/catch or adding a .catch() to the second import.

Suggested change
const Graphviz = await import("./packages/graphviz/dist/index.js").then(m => m.Graphviz).catch(() => undefined) ??
await import("https://cdn.jsdelivr.net/npm/@hpcc-js/wasm-graphviz/dist/index.js").then(m => m.Graphviz);
let Graphviz;
try {
Graphviz = await import("./packages/graphviz/dist/index.js").then(m => m.Graphviz);
} catch (localError) {
console.error("Failed to load local Graphviz module:", localError);
try {
Graphviz = await import("https://cdn.jsdelivr.net/npm/@hpcc-js/wasm-graphviz/dist/index.js").then(m => m.Graphviz);
} catch (cdnError) {
console.error("Failed to load Graphviz from CDN:", cdnError);
Graphviz = undefined;
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +15
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The nested await import with chained .then() and ?? reduces readability. Consider splitting this into separate try/catch or sequential if blocks for clarity.

Suggested change
const Graphviz = await import("./packages/graphviz/dist/index.js").then(m => m.Graphviz).catch(() => undefined) ??
await import("https://cdn.jsdelivr.net/npm/@hpcc-js/wasm-graphviz/dist/index.js").then(m => m.Graphviz);
let Graphviz;
try {
const localModule = await import("./packages/graphviz/dist/index.js");
Graphviz = localModule.Graphviz;
} catch (error) {
console.warn("Failed to load local Graphviz module, falling back to remote module:", error);
}
if (!Graphviz) {
const remoteModule = await import("https://cdn.jsdelivr.net/npm/@hpcc-js/wasm-graphviz/dist/index.js");
Graphviz = remoteModule.Graphviz;
}

Copilot uses AI. Check for mistakes.

const dot = `
digraph G {
Expand Down Expand Up @@ -48,7 +47,9 @@
`;

const graphviz = await Graphviz.load();
const div = document.getElementById("placeholder");
let div = document.getElementById("placeholder_version");
div.innerText = `Version: ${graphviz.version()}`;
div = document.getElementById("placeholder");
div.innerHTML = graphviz.layout(dot, "svg", "dot");
</script>

Expand Down
72 changes: 36 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/cpp-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ if [ ! -d "./build" ]
then
cmake -S . -B ./build --preset vcpkg-emscripten-MinSizeRel
fi
cmake -S . -B ./build --preset vcpkg-emscripten-Debug
# cmake -S . -B ./build --preset vcpkg-emscripten-Debug

cmake --build ./build --parallel
Loading