|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * Build a self-contained .mcpb bundle for pdf-server. |
| 4 | + * |
| 5 | + * `mcpb pack` zips whatever is on disk; in this monorepo all runtime deps |
| 6 | + * are hoisted to the root node_modules, so packing in-place produces a |
| 7 | + * bundle with no pdfjs-dist/ajv/etc. that crashes in Claude Desktop. |
| 8 | + * |
| 9 | + * This script stages dist/ + manifest into a clean temp dir, runs a fresh |
| 10 | + * non-workspace `npm install --omit=dev --omit=optional` (the polyfill in |
| 11 | + * dist/pdfjs-polyfill.js makes @napi-rs/canvas's ~130MB of native binaries |
| 12 | + * unnecessary), syncs the manifest version to package.json, then packs. |
| 13 | + */ |
| 14 | + |
| 15 | +import { |
| 16 | + cpSync, |
| 17 | + rmSync, |
| 18 | + mkdirSync, |
| 19 | + readFileSync, |
| 20 | + writeFileSync, |
| 21 | +} from "node:fs"; |
| 22 | +import { execSync } from "node:child_process"; |
| 23 | +import { fileURLToPath } from "node:url"; |
| 24 | +import path from "node:path"; |
| 25 | + |
| 26 | +const here = path.dirname(fileURLToPath(import.meta.url)); |
| 27 | +const stage = path.join(here, ".mcpb-stage"); |
| 28 | +const out = path.join(here, "pdf-server.mcpb"); |
| 29 | + |
| 30 | +const pkg = JSON.parse(readFileSync(path.join(here, "package.json"), "utf8")); |
| 31 | +const manifest = JSON.parse( |
| 32 | + readFileSync(path.join(here, "manifest.json"), "utf8"), |
| 33 | +); |
| 34 | +manifest.version = pkg.version; |
| 35 | + |
| 36 | +rmSync(stage, { recursive: true, force: true }); |
| 37 | +mkdirSync(stage); |
| 38 | + |
| 39 | +for (const f of ["dist", "icon.png", "README.md", ".mcpbignore"]) { |
| 40 | + cpSync(path.join(here, f), path.join(stage, f), { recursive: true }); |
| 41 | +} |
| 42 | +writeFileSync( |
| 43 | + path.join(stage, "manifest.json"), |
| 44 | + JSON.stringify(manifest, null, 2), |
| 45 | +); |
| 46 | +writeFileSync(path.join(stage, "package.json"), JSON.stringify(pkg, null, 2)); |
| 47 | + |
| 48 | +const run = (cmd) => execSync(cmd, { cwd: stage, stdio: "inherit" }); |
| 49 | +run( |
| 50 | + "npm install --omit=dev --omit=optional --no-audit --no-fund --no-package-lock " + |
| 51 | + "--registry=https://registry.npmjs.org/", |
| 52 | +); |
| 53 | +run(`npx -y @anthropic-ai/mcpb pack . ${JSON.stringify(out)}`); |
| 54 | + |
| 55 | +rmSync(stage, { recursive: true, force: true }); |
| 56 | +console.log(`\n✅ ${path.relative(process.cwd(), out)}`); |
0 commit comments