feat: auto-install acpx deps via npm postinstall on global install

This commit is contained in:
khhjoe
2026-03-28 20:30:54 +08:00
committed by Peter Steinberger
parent 5f628c0bf8
commit 3151eb5b48
2 changed files with 45 additions and 1 deletions

View File

@@ -30,7 +30,8 @@
"docs/",
"!docs/.generated/**",
"!docs/.i18n/zh-CN.tm.jsonl",
"skills/"
"skills/",
"scripts/postinstall-bundled-plugins.mjs"
],
"type": "module",
"main": "dist/index.js",
@@ -1093,6 +1094,7 @@
"plugin-sdk:sync-exports": "node scripts/sync-plugin-sdk-exports.mjs",
"plugin-sdk:usage": "node --import tsx scripts/analyze-plugin-sdk-usage.ts",
"plugins:sync": "node --import tsx scripts/sync-plugin-versions.ts",
"postinstall": "node scripts/postinstall-bundled-plugins.mjs",
"prepack": "pnpm build && pnpm ui:build",
"prepare": "command -v git >/dev/null 2>&1 && git rev-parse --is-inside-work-tree >/dev/null 2>&1 && git config core.hooksPath git-hooks || exit 0",
"protocol:check": "pnpm protocol:gen && pnpm protocol:gen:swift && git diff --exit-code -- dist/protocol.schema.json apps/macos/Sources/OpenClawProtocol/GatewayModels.swift apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift",

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env node
// Runs after `npm i -g` to install runtime deps for bundled extensions
// that cannot be pre-bundled (e.g. platform-specific binaries like acpx).
// All other extension deps are already bundled into dist/ JS files.
// This script is a no-op outside of a global npm install context.
import { execSync } from "node:child_process";
import { existsSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const isGlobal = process.env.npm_config_global === "true";
if (!isGlobal) {
process.exit(0);
}
const __dirname = dirname(fileURLToPath(import.meta.url));
const extensionsDir = join(__dirname, "..", "dist", "extensions");
// Extensions whose runtime deps include platform-specific binaries and therefore
// cannot be pre-bundled. Add entries here if new extensions share this pattern.
const NEEDS_INSTALL = ["acpx"];
for (const ext of NEEDS_INSTALL) {
const extDir = join(extensionsDir, ext);
if (!existsSync(join(extDir, "package.json"))) {
continue;
}
// Skip if already installed (node_modules/.bin present).
if (existsSync(join(extDir, "node_modules", ".bin"))) {
continue;
}
try {
execSync("npm install --omit=dev --no-save --package-lock=false", {
cwd: extDir,
stdio: "pipe",
});
console.log(`[postinstall] installed bundled plugin deps: ${ext}`);
} catch (e) {
// Non-fatal: gateway will surface the missing dep via doctor.
console.warn(`[postinstall] could not install deps for ${ext}: ${String(e)}`);
}
}