From fdb7ef3612366469d1af392161493ecb56d112be Mon Sep 17 00:00:00 2001 From: Jesper Pedersen Date: Tue, 21 Apr 2026 19:54:02 +0200 Subject: [PATCH] fix: resolve plugin dependencies from data directory via SessionStart hook The Claude plugin system installs plugins into a read-only root directory, so npm dependencies need to be installed separately into the plugin data directory. This adds a SessionStart hook that runs npm install into CLAUDE_PLUGIN_DATA when package.json changes, sets NODE_PATH so Node can find the modules, and switches html2canvas resolution to createRequire instead of hardcoded relative paths. Co-authored-by: Claude --- .claude-plugin/plugin.json | 17 ++++++++++++++++- CHANGELOG.md | 4 ++++ src/server.js | 6 ++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index f005f27..07f7732 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -15,10 +15,25 @@ "feedback", "annotation" ], + "hooks": { + "SessionStart": [ + { + "hooks": [ + { + "type": "command", + "command": "diff -q \"${CLAUDE_PLUGIN_ROOT}/package.json\" \"${CLAUDE_PLUGIN_DATA}/package.json\" >/dev/null 2>&1 || (cd \"${CLAUDE_PLUGIN_DATA}\" && cp \"${CLAUDE_PLUGIN_ROOT}/package.json\" . && npm install --production) || rm -f \"${CLAUDE_PLUGIN_DATA}/package.json\"" + } + ] + } + ] + }, "mcpServers": { "browser-feedback": { "command": "node", - "args": ["${CLAUDE_PLUGIN_ROOT}/src/server.js"] + "args": ["${CLAUDE_PLUGIN_ROOT}/src/server.js"], + "env": { + "NODE_PATH": "${CLAUDE_PLUGIN_DATA}/node_modules" + } } } } diff --git a/CHANGELOG.md b/CHANGELOG.md index c091c32..59798b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Install plugin dependencies via `SessionStart` hook into the plugin data directory, and resolve `html2canvas` using `createRequire` so it works when `node_modules` lives outside the plugin root + ## [0.6.3] - 2026-04-21 ### Fixed diff --git a/src/server.js b/src/server.js index 5bdbded..4b4f0f3 100644 --- a/src/server.js +++ b/src/server.js @@ -11,7 +11,8 @@ import http from "http"; import fs from "fs"; import path from "path"; import crypto from "node:crypto"; -import { fileURLToPath } from "url"; +import { fileURLToPath, pathToFileURL } from "url"; +import { createRequire } from "module"; import { execFile } from "child_process"; import { isValidSessionId, getPendingSummary, detectProjectUrl, formatFeedbackAsContent } from "./utils.js"; @@ -247,7 +248,8 @@ const httpServer = http.createServer((req, res) => { } if (urlObj.pathname === "/html2canvas.min.js") { - const html2canvasPath = path.join(__dirname, "..", "node_modules", "html2canvas", "dist", "html2canvas.min.js"); + const require = createRequire(import.meta.url); + const html2canvasPath = path.join(path.dirname(require.resolve("html2canvas/package.json")), "dist", "html2canvas.min.js"); fs.readFile(html2canvasPath, "utf8", (err, content) => { if (err) { res.writeHead(404);