mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2026-11-27 06:32:42 +00:00
Compare commits
5
Commits
toggleViewMode
...
2.28.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96bd2212c2 | ||
|
|
3d8f312add | ||
|
|
bd40308a83 | ||
|
|
3e13b61c6d | ||
|
|
5da2b452f1 |
No files matched your search
@@ -507,6 +507,12 @@ If a task touches any of the above, read adjacent code first and validate more c
|
||||
|
||||
There is no standard unit-test suite wired into `package.json`.
|
||||
|
||||
### Obsidian CLI runtime lane
|
||||
|
||||
Follow [the runtime testing proxy](docs/OBSIDIAN_RUNTIME_TESTING.md) and its linked fork guide for a native check. `npm run test:obsidian:runner` runs the test-vault guard and harness tests without Obsidian. `npm run verify:obsidian` requires the explicitly configured `excalidraw-test` vault, checks the CLI-selected path before deployment, builds the sibling fork's four Obsidian artifacts and this plugin, stages the exact `main.js`/CSS/manifest, and asserts a live drawing and clean JavaScript error buffer. Review its report and cleanup result.
|
||||
|
||||
Use this lane after fork behavior or packaging changes when Obsidian is available, then exercise the affected workflow using the fork's V03–V11 validation gates. A blank-drawing smoke does not validate raw text, clipboard, font/image assets, saved scenes, custom pens, popout migration, offline behavior, or physical mobile touch. Record what was tested, artifact/source identity, and any pending or unavailable gates. Never deploy a local build to a personal/default vault as a substitute for the named test vault. Keep CLI eval access to internal plugin instances and temporary test controllers out of production modules.
|
||||
|
||||
Repo-wide ESLint currently reports a large backlog of pre-existing issues, so it is not yet a blocking pass/fail gate for every task.
|
||||
|
||||
Primary validation commands:
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# Obsidian runtime testing
|
||||
|
||||
The canonical Excalidraw fork and plugin CLI procedure is [Testing the fork inside Obsidian](https://github.com/zsviczian/excalidraw/blob/master/dev-docs/Obsidian/OBSIDIAN_RUNTIME_TESTING.md) (local sibling path: `../excalidraw/dev-docs/Obsidian/OBSIDIAN_RUNTIME_TESTING.md`). Read its vault guards, exact-build deployment steps, report contract, and feature-gate guidance before running the host lane.
|
||||
|
||||
From this plugin checkout, with the dedicated `excalidraw-test` vault open and the three `EXCALIDRAW_TEST_VAULT_*` variables set as described there:
|
||||
|
||||
```bash
|
||||
npm run test:obsidian:runner
|
||||
npm run verify:obsidian
|
||||
```
|
||||
|
||||
The first command tests the runner without Obsidian. The second builds the sibling fork and this plugin, deploys only to the explicitly checked test vault, exercises one drawing, and writes a report. It is a desktop smoke, so run the change-specific scenarios from the canonical guide as well.
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "2.28.0-beta.4",
|
||||
"version": "2.28.0",
|
||||
"minAppVersion": "1.8.7",
|
||||
"description": "Sketch Your Mind. Edit and view Excalidraw drawings. Enter the world of 4D Visual PKM.",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "2.27.3",
|
||||
"version": "2.28.0",
|
||||
"minAppVersion": "1.8.7",
|
||||
"description": "Sketch Your Mind. Edit and view Excalidraw drawings. Enter the world of 4D Visual PKM.",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
Generated
+4
-4
@@ -13,7 +13,7 @@
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@radix-ui/number": "^1.1.2",
|
||||
"@zsviczian/colormaster": "^1.2.2",
|
||||
"@zsviczian/excalidraw": "0.18.139",
|
||||
"@zsviczian/excalidraw": "0.18.140",
|
||||
"chroma-js": "^3.1.2",
|
||||
"clsx": "^2.0.0",
|
||||
"es6-promise-pool": "2.5.0",
|
||||
@@ -5255,9 +5255,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@zsviczian/excalidraw": {
|
||||
"version": "0.18.139",
|
||||
"resolved": "https://registry.npmjs.org/@zsviczian/excalidraw/-/excalidraw-0.18.139.tgz",
|
||||
"integrity": "sha512-3d31zicckBIK4VMyldgCLuPON5xCWNTxn0vF1r3FdlVbfLXI+OFdeq6Qog8aYO4IXN2W5XKdIF5Byzk17U4Aqg==",
|
||||
"version": "0.18.140",
|
||||
"resolved": "https://registry.npmjs.org/@zsviczian/excalidraw/-/excalidraw-0.18.140.tgz",
|
||||
"integrity": "sha512-DXdxSFVkyVXYBDIlq63IfoegKRZYp71ECSPErSZASxcssKyKOcbiDjI/EjO4nnsvhampnr8mrlLPBjsQyoRTKQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@braintree/sanitize-url": "6.0.2",
|
||||
|
||||
+5
-3
@@ -9,7 +9,9 @@
|
||||
],
|
||||
"scripts": {
|
||||
"dev": "cross-env NODE_ENV=development rollup --config rollup.config.mjs",
|
||||
"build": "cross-env NODE_ENV=production rollup --config rollup.config.mjs",
|
||||
"build": "cross-env NODE_ENV=production rollup --config rollup.config.mjs",
|
||||
"test:obsidian:runner": "node --test scripts/testing/host/runner.test.mjs",
|
||||
"verify:obsidian": "node scripts/testing/host/verify.mjs",
|
||||
"lib": "cross-env NODE_ENV=lib rollup --config rollup.config.mjs",
|
||||
"code": "eslint --max-warnings=0 --ext .ts,.tsx ./src",
|
||||
"code:fix": "eslint --max-warnings=0 --ext .ts,.tsx ./src --fix",
|
||||
@@ -34,7 +36,7 @@
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@radix-ui/number": "^1.1.2",
|
||||
"@zsviczian/colormaster": "^1.2.2",
|
||||
"@zsviczian/excalidraw": "0.18.139",
|
||||
"@zsviczian/excalidraw": "0.18.140",
|
||||
"chroma-js": "^3.1.2",
|
||||
"clsx": "^2.0.0",
|
||||
"es6-promise-pool": "2.5.0",
|
||||
@@ -111,4 +113,4 @@
|
||||
"node": ">=22.0.0",
|
||||
"npm": ">=10.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/** Native Obsidian smoke lane for the exact locally built Excalidraw plugin. */
|
||||
import { createHash, randomUUID } from "node:crypto";
|
||||
import { copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
||||
import { basename, isAbsolute, join, relative, sep } from "node:path";
|
||||
|
||||
export const PLUGIN_ID = "obsidian-excalidraw-plugin";
|
||||
export const ARTIFACTS = ["main.js", "manifest.json", "styles.css"];
|
||||
const REQUIRED_CLI = ["version", "vault", "plugin:enable", "plugin:disable", "commands", "eval", "dev:errors"];
|
||||
const CONTROL = "__excalidrawCliSmoke";
|
||||
const PREFIX = "__excalidraw_cli_smoke_";
|
||||
|
||||
const hash = (path) => createHash("sha256").update(readFileSync(path)).digest("hex");
|
||||
|
||||
function inside(parent, child, label) {
|
||||
const rel = relative(parent, child);
|
||||
if (!rel || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
||||
throw new Error(`${label} must be inside the selected test vault`);
|
||||
}
|
||||
}
|
||||
|
||||
/** Reject ambiguous or redirected vault and plugin paths before any deployment. */
|
||||
export function validateTarget({ vaultName, vaultPath, configDir }) {
|
||||
if (!vaultName || !vaultPath || !configDir) {
|
||||
throw new Error("Set EXCALIDRAW_TEST_VAULT_NAME, EXCALIDRAW_TEST_VAULT_PATH and EXCALIDRAW_TEST_CONFIG_DIR");
|
||||
}
|
||||
if (vaultName !== "excalidraw-test") throw new Error("This runner is restricted to the excalidraw-test vault");
|
||||
if (!isAbsolute(vaultPath) || !isAbsolute(configDir)) throw new Error("Vault and config paths must be absolute");
|
||||
if (!existsSync(vaultPath) || !existsSync(configDir)) throw new Error("Vault or config directory does not exist");
|
||||
const vault = realpathSync(vaultPath);
|
||||
const config = realpathSync(configDir);
|
||||
if (basename(vault) !== vaultName) throw new Error("Vault folder does not match the selected vault name");
|
||||
inside(vault, config, "Config directory");
|
||||
if (!existsSync(join(config, "community-plugins.json"))) {
|
||||
throw new Error("Community plugins must be configured in this test vault");
|
||||
}
|
||||
const plugins = join(config, "plugins");
|
||||
if (existsSync(plugins) && lstatSync(plugins).isSymbolicLink()) throw new Error("Plugin directory cannot be a symlink");
|
||||
const pluginDir = join(plugins, PLUGIN_ID);
|
||||
if (existsSync(pluginDir) && lstatSync(pluginDir).isSymbolicLink()) throw new Error("Target plugin cannot be a symlink");
|
||||
for (const name of ARTIFACTS) {
|
||||
const file = join(pluginDir, name);
|
||||
if (existsSync(file) && lstatSync(file).isSymbolicLink()) throw new Error(`Target artifact cannot be a symlink: ${name}`);
|
||||
}
|
||||
return { vault, config, pluginDir };
|
||||
}
|
||||
|
||||
function cliPath(output) {
|
||||
const path = output.trim();
|
||||
return path.startsWith("path ") ? path.slice(5).trim() : path;
|
||||
}
|
||||
|
||||
function parseEval(output) {
|
||||
const value = output.trim().replace(/^=>\s*/, "");
|
||||
if (value.startsWith("Error:")) throw new Error(`Obsidian eval failed: ${value.slice(0, 500)}`);
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
} catch {
|
||||
throw new Error(`Obsidian eval returned non-JSON: ${value.slice(0, 500)}`);
|
||||
}
|
||||
}
|
||||
|
||||
function artifacts(projectRoot) {
|
||||
const paths = Object.fromEntries(ARTIFACTS.map((name) => [name, join(projectRoot, "dist", name)]));
|
||||
for (const [name, path] of Object.entries(paths)) {
|
||||
if (!existsSync(path)) throw new Error(`Missing built ${name}: ${path}`);
|
||||
}
|
||||
const manifest = JSON.parse(readFileSync(paths["manifest.json"], "utf8"));
|
||||
if (manifest.id !== PLUGIN_ID) throw new Error(`Built manifest ID must be ${PLUGIN_ID}`);
|
||||
return { paths, hashes: Object.fromEntries(ARTIFACTS.map((name) => [name, hash(paths[name])])), version: manifest.version };
|
||||
}
|
||||
|
||||
const startCode = (name) => `(()=>{const p=app.plugins.plugins[${JSON.stringify(PLUGIN_ID)}];if(!p)return JSON.stringify({state:"failed",error:"plugin not loaded"});if(globalThis.${CONTROL})return JSON.stringify({state:"failed",error:"smoke controller already exists"});const c={state:"pending",name:${JSON.stringify(name)},path:null,error:null,cancel:false};globalThis.${CONTROL}=c;const extension=p.settings.compatibilityMode?".excalidraw":p.settings.useExcalidrawExtension?".excalidraw.md":".md";Promise.resolve(p.createAndOpenDrawing(c.name+extension,"new-tab")).then(async path=>{c.path=path;c.state="created";if(c.cancel){const file=app.vault.getFileByPath(path);if(file&&file.name.startsWith(${JSON.stringify(PREFIX)})){app.workspace.getLeavesOfType("excalidraw").find(l=>l.view.file?.path===path)?.detach();await app.vault.delete(file)}c.state="clean"}}).catch(error=>{c.error=String(error);c.state="failed"});return JSON.stringify({state:"started"})})()`;
|
||||
const statusCode = `(()=>{const c=globalThis.${CONTROL};if(!c)return JSON.stringify({state:"missing"});const leaf=c.path&&app.workspace.getLeavesOfType("excalidraw").find(l=>l.view.file?.path===c.path);const view=leaf?.view;return JSON.stringify({state:c.state,path:c.path,error:c.error,ready:!!view?.excalidrawAPI,wrapper:!!view?.containerEl?.querySelector(".excalidraw-wrapper"),ownerMatches:!!view&&view.ownerDocument===view.containerEl.ownerDocument,mainWindow:!!view&&view.ownerDocument===app.workspace.containerEl?.ownerDocument})})()`;
|
||||
const cleanupCode = `(()=>{const c=globalThis.${CONTROL};if(!c)return JSON.stringify({state:"clean"});if(c.state==="pending"){c.cancel=true;return JSON.stringify({state:"pending"})}if(c.state==="cleaning")return JSON.stringify({state:"cleaning"});const path=c.path;const file=path&&app.vault.getFileByPath(path);if(!file){delete globalThis.${CONTROL};return JSON.stringify({state:"clean"})}if(!file.name.startsWith(${JSON.stringify(PREFIX)}))return JSON.stringify({state:"failed",error:"refusing to delete a non-smoke drawing"});const leaf=app.workspace.getLeavesOfType("excalidraw").find(l=>l.view.file?.path===path);leaf?.detach();c.state="cleaning";Promise.resolve(app.vault.delete(file)).then(()=>{c.state="clean"},error=>{c.error=String(error);c.state="failed"});return JSON.stringify({state:"cleaning"})})()`;
|
||||
|
||||
async function poll(read, acceptable, wait, now, timeoutMs = 20_000) {
|
||||
const deadline = now() + timeoutMs;
|
||||
for (;;) {
|
||||
const result = read();
|
||||
if (acceptable(result)) return result;
|
||||
if (result.state === "failed") throw new Error(result.error || "Host scenario failed");
|
||||
if (now() >= deadline) throw new Error(`Host scenario timed out: ${JSON.stringify(result)}`);
|
||||
await wait(250);
|
||||
}
|
||||
}
|
||||
|
||||
/** Preflight, build, stage and exercise one disposable drawing; always write a report. */
|
||||
export async function runObsidianSmoke({ projectRoot, vaultName, vaultPath, configDir, reportDir, runCli, runBuild,
|
||||
wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), now = () => Date.now(), source = {}, unique = () => randomUUID() }) {
|
||||
const report = { schemaVersion: 1, status: "failed", startedAt: new Date(now()).toISOString(), source,
|
||||
target: { vaultName, vaultPath, configDir }, capabilities: {}, artifacts: {}, scenarios: [], cleanup: "not-started" };
|
||||
mkdirSync(reportDir, { recursive: true });
|
||||
let phase = "preflight";
|
||||
let created = false;
|
||||
try {
|
||||
const target = validateTarget({ vaultName, vaultPath, configDir });
|
||||
const cli = (command, ...args) => {
|
||||
const output = runCli(vaultName, command, ...args);
|
||||
if (output.trim().startsWith("Error:")) throw new Error(`${command}: ${output.trim().slice(0, 500)}`);
|
||||
return output;
|
||||
};
|
||||
report.capabilities.version = cli("version").trim();
|
||||
const help = cli("help");
|
||||
const missing = REQUIRED_CLI.filter((command) => !help.includes(command));
|
||||
if (missing.length) throw new Error(`Obsidian CLI lacks: ${missing.join(", ")}`);
|
||||
const selected = cliPath(cli("vault", "info=path"));
|
||||
if (!existsSync(selected) || realpathSync(selected) !== target.vault) {
|
||||
throw new Error(`CLI selected vault ${selected}, expected ${target.vault}`);
|
||||
}
|
||||
report.target.vaultPath = target.vault;
|
||||
report.target.configDir = target.config;
|
||||
|
||||
phase = "build";
|
||||
const forkArtifacts = await runBuild();
|
||||
const built = artifacts(projectRoot);
|
||||
report.artifacts = { forkArtifacts, version: built.version, sourceHashes: built.hashes,
|
||||
mainBytes: readFileSync(built.paths["main.js"]).length };
|
||||
|
||||
phase = "deploy";
|
||||
if (existsSync(target.pluginDir)) cli("plugin:disable", `id=${PLUGIN_ID}`);
|
||||
mkdirSync(target.pluginDir, { recursive: true });
|
||||
for (const name of ARTIFACTS) copyFileSync(built.paths[name], join(target.pluginDir, name));
|
||||
report.artifacts.installedHashes = Object.fromEntries(ARTIFACTS.map((name) => [name, hash(join(target.pluginDir, name))]));
|
||||
if (ARTIFACTS.some((name) => built.hashes[name] !== report.artifacts.installedHashes[name])) {
|
||||
throw new Error("Installed artifacts differ from the local build");
|
||||
}
|
||||
cli("dev:errors", "clear");
|
||||
cli("plugin:enable", `id=${PLUGIN_ID}`);
|
||||
const loaded = await poll(() => parseEval(cli("eval", `code=JSON.stringify({state:app.plugins?.plugins?.[${JSON.stringify(PLUGIN_ID)}]?"loaded":"pending"})`)),
|
||||
(value) => value.state === "loaded", wait, now);
|
||||
if (loaded.state !== "loaded") throw new Error("Plugin did not load");
|
||||
await poll(() => ({ state: cli("commands", `filter=${PLUGIN_ID}`).includes(`${PLUGIN_ID}:excalidraw-autocreate`)
|
||||
? "registered" : "pending" }), (value) => value.state === "registered", wait, now);
|
||||
report.scenarios.push({ id: "plugin-load", status: "passed" });
|
||||
|
||||
phase = "drawing";
|
||||
const name = `${PREFIX}${unique()}`;
|
||||
const started = parseEval(cli("eval", `code=${startCode(name)}`));
|
||||
if (started.state !== "started") throw new Error(started.error || "Could not start drawing smoke");
|
||||
created = true;
|
||||
const drawing = await poll(() => parseEval(cli("eval", `code=${statusCode}`)),
|
||||
(value) => value.state === "created" && value.ready && value.wrapper && value.ownerMatches && value.mainWindow, wait, now);
|
||||
if (!drawing.path || !basename(drawing.path).startsWith(PREFIX)) throw new Error("Unexpected smoke drawing path");
|
||||
report.scenarios.push({ id: "drawing-main-window", status: "passed", assertions: ["Excalidraw API ready", "wrapper mounted", "owner document matches", "main application document"] });
|
||||
const errors = cli("dev:errors").trim();
|
||||
if (errors && !/^No errors captured\.?$/i.test(errors)) throw new Error(`Captured JavaScript errors: ${errors.slice(0, 1000)}`);
|
||||
report.scenarios.push({ id: "javascript-errors", status: "passed" });
|
||||
report.status = "passed";
|
||||
} catch (error) {
|
||||
report.error = error instanceof Error ? error.message : String(error);
|
||||
report.scenarios.push({ id: phase, status: "failed", reason: report.error });
|
||||
} finally {
|
||||
if (created) {
|
||||
try {
|
||||
const cli = (code) => parseEval(runCli(vaultName, "eval", `code=${code}`));
|
||||
const response = cli(cleanupCode);
|
||||
if (response.state === "failed") throw new Error(response.error);
|
||||
await poll(() => cli(`(()=>JSON.stringify({state:globalThis.${CONTROL}?.state||"clean",error:globalThis.${CONTROL}?.error}))()`),
|
||||
(value) => value.state === "clean", wait, now);
|
||||
cli(`(()=>{delete globalThis.${CONTROL};return JSON.stringify({state:"clean"})})()`);
|
||||
report.cleanup = "passed";
|
||||
} catch (error) {
|
||||
report.cleanup = "failed";
|
||||
report.cleanupError = error instanceof Error ? error.message : String(error);
|
||||
report.status = "failed";
|
||||
}
|
||||
}
|
||||
report.completedAt = new Date(now()).toISOString();
|
||||
writeFileSync(join(reportDir, "report.json"), `${JSON.stringify(report, null, 2)}\n`);
|
||||
}
|
||||
return report;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, test } from "node:test";
|
||||
import { rmSync } from "node:fs";
|
||||
import { runObsidianSmoke, validateTarget } from "./runner.mjs";
|
||||
|
||||
const roots = [];
|
||||
afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }); });
|
||||
|
||||
function fixture() {
|
||||
const root = mkdtempSync(join(tmpdir(), "excalidraw-runner-test-"));
|
||||
roots.push(root);
|
||||
const vaultPath = join(root, "excalidraw-test");
|
||||
const configDir = join(vaultPath, ".obsidian");
|
||||
const projectRoot = join(root, "plugin");
|
||||
const reportDir = join(root, "reports");
|
||||
mkdirSync(configDir, { recursive: true });
|
||||
mkdirSync(join(projectRoot, "dist"), { recursive: true });
|
||||
writeFileSync(join(configDir, "community-plugins.json"), "[]");
|
||||
writeFileSync(join(projectRoot, "dist/main.js"), "// smoke build");
|
||||
writeFileSync(join(projectRoot, "dist/styles.css"), "/* smoke */");
|
||||
writeFileSync(join(projectRoot, "dist/manifest.json"), JSON.stringify({ id: "obsidian-excalidraw-plugin", version: "test" }));
|
||||
return { vaultName: "excalidraw-test", vaultPath, configDir, projectRoot, reportDir };
|
||||
}
|
||||
|
||||
test("requires the named test vault and refuses redirected plugin paths", () => {
|
||||
const input = fixture();
|
||||
assert.ok(validateTarget(input).pluginDir.endsWith("obsidian-excalidraw-plugin"));
|
||||
assert.throws(() => validateTarget({ ...input, vaultName: "personal-notes" }), /restricted/);
|
||||
assert.throws(() => validateTarget({ ...input, configDir: input.projectRoot }), /inside/);
|
||||
});
|
||||
|
||||
test("a CLI vault mismatch stops before build or staging", async () => {
|
||||
const input = fixture();
|
||||
let built = false;
|
||||
const report = await runObsidianSmoke({ ...input, runBuild: () => { built = true; },
|
||||
runCli: (_vault, command) => command === "help" ? "version vault plugin:enable plugin:disable commands eval dev:errors" :
|
||||
command === "vault" ? input.projectRoot : "1.13.0" });
|
||||
assert.equal(report.status, "failed");
|
||||
assert.match(report.error, /CLI selected vault/);
|
||||
assert.equal(built, false);
|
||||
assert.equal(JSON.parse(readFileSync(join(input.reportDir, "report.json"))).status, "failed");
|
||||
});
|
||||
|
||||
test("stages exact artifacts, asserts an editor and cleans its test drawing", async () => {
|
||||
const input = fixture();
|
||||
const commands = [];
|
||||
let cleanupStarted = false;
|
||||
let commandReads = 0;
|
||||
const runCli = (_vault, command, ...args) => {
|
||||
commands.push(command);
|
||||
if (command === "version") return "1.13.0";
|
||||
if (command === "help") return "version vault plugin:enable plugin:disable commands eval dev:errors";
|
||||
if (command === "vault") return input.vaultPath;
|
||||
if (command === "commands") {
|
||||
commandReads++;
|
||||
return commandReads > 1 ? "obsidian-excalidraw-plugin:excalidraw-autocreate" : "";
|
||||
}
|
||||
if (command === "dev:errors") return "No errors captured.";
|
||||
if (command === "eval") {
|
||||
const code = args[0];
|
||||
if (code.includes("createAndOpenDrawing")) {
|
||||
assert.ok(code.includes("useExcalidrawExtension"));
|
||||
return '=> {"state":"started"}';
|
||||
}
|
||||
if (code.includes("app.vault.delete")) { cleanupStarted = true; return '{"state":"cleaning"}'; }
|
||||
if (code.includes("?.state||")) return cleanupStarted ? '{"state":"clean"}' : '{"state":"created"}';
|
||||
if (code.includes("delete globalThis.__excalidrawCliSmoke")) return '{"state":"clean"}';
|
||||
if (code.includes("getLeavesOfType")) return '{"state":"created","path":"__excalidraw_cli_smoke_1.excalidraw.md","ready":true,"wrapper":true,"ownerMatches":true,"mainWindow":true}';
|
||||
return '{"state":"loaded"}';
|
||||
}
|
||||
return "";
|
||||
};
|
||||
const report = await runObsidianSmoke({ ...input, runCli, runBuild: () => {}, unique: () => "1", wait: () => {} });
|
||||
assert.equal(report.status, "passed", report.error);
|
||||
assert.equal(report.cleanup, "passed");
|
||||
assert.deepEqual(report.artifacts.sourceHashes, report.artifacts.installedHashes);
|
||||
assert.ok(commands.includes("plugin:enable"));
|
||||
assert.equal(commandReads, 2);
|
||||
assert.equal(report.scenarios.find((item) => item.id === "drawing-main-window").status, "passed");
|
||||
});
|
||||
|
||||
test("an eval Error payload fails even when the CLI process reports success", async () => {
|
||||
const input = fixture();
|
||||
const report = await runObsidianSmoke({ ...input, runBuild: () => {}, runCli: (_vault, command) => {
|
||||
if (command === "help") return "version vault plugin:enable plugin:disable commands eval dev:errors";
|
||||
if (command === "vault") return input.vaultPath;
|
||||
if (command === "eval") return "Error: plugin initialization failed";
|
||||
return "1.13.0";
|
||||
} });
|
||||
assert.equal(report.status, "failed");
|
||||
assert.match(report.error, /Error: plugin initialization failed/);
|
||||
assert.equal(report.cleanup, "not-started");
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
/** Build the local fork and plugin, then run the guarded native test-vault smoke. */
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { copyFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { mkdtempSync } from "node:fs";
|
||||
import { runObsidianSmoke } from "./runner.mjs";
|
||||
|
||||
const pluginRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
|
||||
const forkRoot = resolve(process.env.EXCALIDRAW_FORK_ROOT || join(pluginRoot, "../excalidraw"));
|
||||
const reportDir = process.env.EXCALIDRAW_TEST_REPORT_DIR || mkdtempSync(join(tmpdir(), "excalidraw-obsidian-"));
|
||||
const FORK_ARTIFACTS = ["excalidraw.production.min.js", "excalidraw.production.min.css",
|
||||
"excalidraw.development.js", "excalidraw.development.css"];
|
||||
|
||||
function command(file, args, cwd, timeout = 60_000, inherit = false) {
|
||||
const result = spawnSync(file, args, { cwd, encoding: "utf8", timeout, maxBuffer: 4 * 1024 * 1024,
|
||||
stdio: inherit ? "inherit" : "pipe" });
|
||||
if (result.error) throw new Error(`${file}: ${result.error.message}`);
|
||||
if (result.status !== 0) throw new Error(`${file} ${args.join(" ")} failed (${result.status}): ${(result.stderr || result.stdout || "").trim().slice(0, 1000)}`);
|
||||
return result.stdout || "";
|
||||
}
|
||||
|
||||
const git = (root, args) => command("git", args, root, 10_000).trim();
|
||||
const source = {
|
||||
pluginRevision: git(pluginRoot, ["rev-parse", "HEAD"]),
|
||||
pluginDirty: Boolean(git(pluginRoot, ["status", "--porcelain"])),
|
||||
forkRevision: git(forkRoot, ["rev-parse", "HEAD"]),
|
||||
forkDirty: Boolean(git(forkRoot, ["status", "--porcelain"])),
|
||||
node: process.version,
|
||||
platform: process.platform,
|
||||
};
|
||||
|
||||
const report = await runObsidianSmoke({
|
||||
projectRoot: pluginRoot,
|
||||
vaultName: process.env.EXCALIDRAW_TEST_VAULT_NAME,
|
||||
vaultPath: process.env.EXCALIDRAW_TEST_VAULT_PATH,
|
||||
configDir: process.env.EXCALIDRAW_TEST_CONFIG_DIR,
|
||||
reportDir,
|
||||
source,
|
||||
runCli: (vault, commandName, ...args) => command(process.env.EXCALIDRAW_OBSIDIAN_CLI || "obsidian",
|
||||
[`vault=${vault}`, commandName, ...args], pluginRoot),
|
||||
runBuild: () => {
|
||||
if (Number(process.versions.node.split(".")[0]) < 22) throw new Error("Node.js 22 or newer is required");
|
||||
command("yarn", ["build:obsidian"], join(forkRoot, "packages/excalidraw"), 600_000, true);
|
||||
const sourceDir = join(forkRoot, "packages/excalidraw/dist/obsidian");
|
||||
const installedDir = join(pluginRoot, "node_modules/@zsviczian/excalidraw/dist/obsidian");
|
||||
if (!existsSync(join(pluginRoot, "node_modules/@zsviczian/excalidraw/package.json"))) {
|
||||
throw new Error("Install the plugin's declared dependencies before running the native lane");
|
||||
}
|
||||
for (const name of FORK_ARTIFACTS) {
|
||||
if (!existsSync(join(sourceDir, name))) throw new Error(`Fork build did not produce ${name}`);
|
||||
}
|
||||
mkdirSync(installedDir, { recursive: true });
|
||||
const hashes = {};
|
||||
for (const name of FORK_ARTIFACTS) {
|
||||
const sourcePath = join(sourceDir, name);
|
||||
copyFileSync(sourcePath, join(installedDir, name));
|
||||
const digest = (path) => createHash("sha256").update(readFileSync(path)).digest("hex");
|
||||
const sourceHash = digest(sourcePath);
|
||||
if (sourceHash !== digest(join(installedDir, name))) throw new Error(`Fork artifact handoff changed ${name}`);
|
||||
hashes[name] = sourceHash;
|
||||
}
|
||||
command("npm", ["run", "build"], pluginRoot, 600_000, true);
|
||||
return hashes;
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Obsidian smoke ${report.status}; report: ${join(reportDir, "report.json")}`);
|
||||
if (report.error) console.error(report.error);
|
||||
if (report.cleanupError) console.error(`Cleanup: ${report.cleanupError}`);
|
||||
if (report.status !== "passed") process.exitCode = 1;
|
||||
@@ -18,55 +18,44 @@ I build this plugin as a labor of love. Curious about the philosophy behind it?
|
||||
<div class="ex-coffee-div"><a href="${URLs.KO_FI_COM_ZSOLT}"><img src="${URLs.CDN_KO_FI_COM_CDN_KOFI3_PNG}" border="0" alt="Buy Me a Coffee at ko-fi.com" height=45></a></div>
|
||||
`,
|
||||
"2.28.0": `
|
||||
**Note to ExcaliBrain users:** Update ExcaliBrain. Excalidraw 2.28.0 breaks compatibility with ExcaliBrain v0.2.18.
|
||||
|
||||
## New
|
||||
- The Community Script Store now has a searchable card-based library, a focused update section with **Update all**, and a compact top area for Excalidraw Mastery, support, and creating your own scripts. Script details now support reinstalling, opening local files in a new tab, uninstalling, and moving managed scripts between groups under the **Downloaded** folder. Update detection keeps the existing \`directory-info.json\` modified-time contract, ignores private copies outside **Downloaded**, and handles duplicate managed copies consistently. [#2944](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/2944)
|
||||
- Copied Markdown image SVGs now replace embedded base64 images and fonts with short placeholders, making them smaller and easier to share with AI agents when developing custom CSS.
|
||||
- A brand new and improved Community Script Store. [#2944](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/2944)
|
||||
- When you copy the Markdown Image SVGs for Image CSS AI prompting, the SVG now replace embedded base64 images and fonts with short placeholders, making them smaller and easier to share with agents.
|
||||
|
||||
## New from Excalidraw.com
|
||||
- Create sticky notes with the new **Sticky note** tool or the **N** shortcut. Labels automatically fit and grow with their note, with dedicated colors and a creation-date footer. [#12064](${URLs.GITHUB_COM_EXCALIDRAW_EXCALIDRAW_PULL}/12064)
|
||||
- Right click panning (without enabling a specific "Miro-style" setting) is now supported. [#12110](${URLs.GITHUB_COM_EXCALIDRAW_EXCALIDRAW_PULL}/12110)
|
||||
- Customize font top picks by drag and drop. To set top picks as your default for all new drawings save the file with your toppick choices as a template. [#12160](${URLs.GITHUB_COM_EXCALIDRAW_EXCALIDRAW_PULL}/12160)
|
||||
- Create sticky notes with the new **Sticky note** tool or the **N** shortcut. [#12064](${URLs.GITHUB_COM_EXCALIDRAW_EXCALIDRAW_PULL}/12064)
|
||||
- Right click panning. [#12110](${URLs.GITHUB_COM_EXCALIDRAW_EXCALIDRAW_PULL}/12110)
|
||||
- Customize font toppicks by drag and drop. To set them as default save your toppick choices as a template. [#12160](${URLs.GITHUB_COM_EXCALIDRAW_EXCALIDRAW_PULL}/12160)
|
||||
|
||||
## Fixed / Refactored
|
||||
- Lasso tool was not available in the More Tools menu in Tray Mode [#2937](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_ISSUES}/2937)
|
||||
- \`.excalidraw\` drawings with embedded binary images now render those images when opened into an already-used Excalidraw tab. [#2929](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_ISSUES}/2929)
|
||||
- Descriptions in settings no longer disappear when you revisit a settings page from search results. [#2935](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_ISSUES}/2935)
|
||||
- Drawing persistence is now more reliable during rapid edits across multiple tabs, popout moves, and immediate closing. Backups and automatic exports now track the exact successfully saved revision. [#2933](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/2933)
|
||||
- Rapidly changing Markdown image appearance, selection, or image/embeddable conversion no longer leaves a rejected image-render promise in the console or lets a superseded render overwrite the newer element state.
|
||||
- Improved saving and backupts. [#2933](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/2933)
|
||||
- Fixed a bug where, with *"Render Excalidraw as Image in Obsidian PDF Export"* enabled, exporting a Hybrid Note (an Excalidraw drawing with your own Markdown content alongside it) to PDF could render blank sections wherever a regular image (or other non-Excalidraw) embed appeared on the Markdown side. [#2292](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_ISSUES}/2292), 🙏[bluechallenge](${URLs.GITHUB_COM}/bluechallenge) [#2936](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/2936)
|
||||
- Selection rectangles in popout windows are no longer positioned incorrectly when displays use different DPI settings. [#2940](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_ISSUES}/2940)
|
||||
|
||||
## New/Fixed in Excalidraw Automate
|
||||
- Added a view-targeted representation toggle for integrations. It switches the supplied live Excalidraw-backed view directly between Excalidraw and Markdown without relying on the workspace active leaf or command routing:
|
||||
|
||||
\`\`\`ts
|
||||
public async toggleViewMode(view: View): Promise<View | null>;
|
||||
\`\`\`
|
||||
|
||||
- Integrations can now register a link handler on one target view and receive Excalidraw's resolved pane action without replacing the global hook or copying modifier settings. A new zoom helper fits the complete target scene:
|
||||
|
||||
\`\`\`ts
|
||||
registerViewLinkClickHook(hook: ViewLinkClickHook): () => void;
|
||||
viewZoomToFit(): void;
|
||||
\`\`\`
|
||||
|
||||
- Updated the [ea-script-template](${URLs.GITHUB_COM}/zsviczian/ea-script-template). Read [EA Script prompting with AI is magical](${URLs.COMMUNITY_SKETCH_YOUR_MIND_COM}/t/10977)
|
||||
- Enhancements to support K-Plex and ExcaliBrain integration.
|
||||
\`\`\`ts
|
||||
public async toggleViewMode(view: View): Promise<View | null>;
|
||||
registerViewLinkClickHook(hook: ViewLinkClickHook): () => void;
|
||||
viewZoomToFit(): void;
|
||||
clearViewDirty(): void;
|
||||
registerThisAsViewEA(): boolean;
|
||||
deregisterThisAsViewEA(): boolean;
|
||||
\`\`\`
|
||||
- Excalidraw view state accepts one-shot \`mode: "view" | "edit"\` and \`zoomToFit: true\` options. This lets host integrations open a drawing in its intended mode without polling the React canvas.
|
||||
- Link-open callbacks now receive a usable native event even when an upstream synthesized event omitted it.
|
||||
- Added three view-lifecycle helpers for integrations that use a view-local Excalidraw Automate instance or render generated/transient scene state:
|
||||
\`\`\`ts
|
||||
clearViewDirty(): void;
|
||||
registerThisAsViewEA(): boolean;
|
||||
deregisterThisAsViewEA(): boolean;
|
||||
\`\`\`
|
||||
- \`clearViewDirty()\` clears the target view's current dirty marker without saving it.
|
||||
- \`registerThisAsViewEA()\` registers the EA instance as the hook server for its target view.
|
||||
- \`deregisterThisAsViewEA()\` restores the default plugin-global EA hook server and is safe to use during view teardown.
|
||||
- Scripts can create native sticky notes, including automatically fitted labels:
|
||||
\`\`\`ts
|
||||
addStickyNote(topX: number, topY: number, text: string, formatting?: {width?: number; height?: number; fontSize?: number; fontFamily?: number; textAlign?: "left" | "center" | "right"; textVerticalAlign?: "top" | "middle" | "bottom";}, id?: string): string;
|
||||
\`\`\`
|
||||
\`\`\`ts
|
||||
addStickyNote(topX: number, topY: number, text: string, formatting?: {width?: number; height?: number; fontSize?: number; fontFamily?: number; textAlign?: "left" | "center" | "right"; textVerticalAlign?: "top" | "middle" | "bottom";}, id?: string): string;
|
||||
\`\`\`
|
||||
- Unbound arrows created with Excalidraw Automate's \`addArrow()\` no longer contain incomplete binding data that could cause an error when selected.
|
||||
- Updated the [ea-script-template](${URLs.GITHUB_COM}/zsviczian/ea-script-template). Read [EA Script prompting with AI is magical](${URLs.COMMUNITY_SKETCH_YOUR_MIND_COM}/t/10977)
|
||||
|
||||
`,
|
||||
"2.27.3": `
|
||||
|
||||
Vendored
+1
@@ -202,6 +202,7 @@ export type LocalGraphView = View & {
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
MouseEvent?: typeof MouseEvent;
|
||||
ExcalidrawAutomate: ExcalidrawAutomate;
|
||||
ExcalidrawLib: typeof ExcalidrawLib;
|
||||
pdfjsLib: PdfJsLibrary;
|
||||
|
||||
@@ -6725,9 +6725,7 @@ export default class ExcalidrawView
|
||||
window.setTimeout(() => this.removeLinkTooltip(), 500);
|
||||
|
||||
const nativeEvent = e?.detail?.nativeEvent;
|
||||
const ownerMouseEvent = (
|
||||
this.ownerWindow as (Window & { MouseEvent?: typeof MouseEvent }) | null
|
||||
)?.MouseEvent;
|
||||
const ownerMouseEvent = this.ownerWindow?.MouseEvent;
|
||||
const event = nativeEvent ?? new (ownerMouseEvent ?? MouseEvent)("click", {
|
||||
...emulateKeysForLinkClick("new-tab"),
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user