fix(excalidraw): resolve canvas module path and add canonical file location convention

Fix convert.mjs to resolve canvas from .export-runtime via createRequire
instead of bare import (which resolves relative to script location, not CWD).
Add File Location Convention section to SKILL.md — diagrams save .excalidraw
source alongside PNGs in the project's image directory for easy re-export.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
John Lamb
2026-02-27 09:07:10 -06:00
parent f524c1b9d8
commit 442bdc45dd
2 changed files with 27 additions and 6 deletions

View File

@@ -4,13 +4,20 @@
* Filters pseudo-elements, adds required defaults, expands labels into bound text.
*/
import { readFileSync, writeFileSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { createRequire } from 'module';
const __dirname = dirname(fileURLToPath(import.meta.url));
const runtimeRequire = createRequire(join(__dirname, '.export-runtime', 'package.json'));
// Canvas-based text measurement with graceful fallback to heuristic.
// Excalidraw renders with Virgil (hand-drawn font); system sans-serif
// is a reasonable proxy. The 1.1x multiplier accounts for Virgil being wider.
let measureText;
try {
const { createCanvas } = await import('canvas');
const canvas = runtimeRequire('canvas');
const { createCanvas } = canvas;
const cvs = createCanvas(1, 1);
const ctx = cvs.getContext('2d');
measureText = (text, fontSize) => {