[feat] bundle MCP and DSH into one installable package

This commit is contained in:
dijunkun committed 2026-11-12 12:36:53 +08:00
1 parent 02a25a759f
commit 2a9faf1eb1
15 files changed
+875 -590

No files matched your search

+35 -5
View File
@@ -16,19 +16,20 @@ import { parseArgs } from "node:util";
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const repository = resolve(root, "../..");
const { values } = parseArgs({ options: { "out-dir": { type: "string" } } });
const { values } = parseArgs({ options: {
"out-dir": { type: "string" },
"native-package-dir": { type: "string" },
} });
const output = resolve(values["out-dir"] ?? join(repository, "build/npm-mcp"));
const project = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
const cli = JSON.parse(
await readFile(join(root, "../cli/package.json"), "utf8"),
);
const cli = JSON.parse(await readFile(join(root, "../cli/package.json"), "utf8"));
const platforms = JSON.parse(
await readFile(join(root, "../cli/npm/platforms.json"), "utf8"),
);
const native = await import(new URL("../dist/native.js", import.meta.url));
if (native.NATIVE_VERSION !== cli.version)
throw new Error("MCP and CLI native versions must match.");
for (const file of ["main.js", "viewer-browser.html", "viewer-apps.html"])
for (const file of ["main.js", "viewer-browser.html", "viewer-apps.html", "harness.js", "harness-client.js"])
await access(join(root, "dist", file));
const staging = await mkdtemp(join(tmpdir(), "crossdesk-mcp-pack-"));
try {
@@ -38,10 +39,12 @@ try {
"ui",
"scripts",
"integrations",
"cordis.patch.yml",
"tsconfig.json",
"tsconfig.ui.json",
"package-lock.json",
"README.md",
"DEVELOPMENT.md",
])
await cp(join(root, entry), join(staging, entry), { recursive: true });
await cp(join(repository, "LICENSE"), join(staging, "LICENSE"));
@@ -59,11 +62,13 @@ try {
"scripts/build-ui.mjs",
"scripts/build-harness.mjs",
"integrations",
"cordis.patch.yml",
"tsconfig.json",
"tsconfig.ui.json",
"build-package.json",
"package-lock.json",
"README.md",
"DEVELOPMENT.md",
"LICENSE",
],
optionalDependencies: Object.fromEntries(
@@ -73,6 +78,31 @@ try {
};
delete manifest.scripts;
delete manifest.devDependencies;
// Platform bundles are installable before the native version reaches npm.
// Preserve the native package's source, notices and build provenance too.
if (values["native-package-dir"]) {
const directory = resolve(values["native-package-dir"]);
const bundled = JSON.parse(await readFile(join(directory, "package.json"), "utf8"));
const platform = Object.values(platforms).find(p => p.packageName === bundled.name);
if (!platform || bundled.version !== native.NATIVE_VERSION ||
JSON.stringify(bundled.os) !== JSON.stringify([platform.os]) ||
JSON.stringify(bundled.cpu) !== JSON.stringify([platform.cpu]) ||
(platform.libc && JSON.stringify(bundled.libc) !== JSON.stringify([platform.libc])))
throw new Error("Expected a compatible CrossDesk native platform package.");
for (const entry of ["bin", "source", "LICENSE", "build-info.json"])
await access(join(directory, entry));
const binary = join(directory, "bin", platform.os === "win32" ? "crossdesk-cli.exe" : "crossdesk-cli");
await access(binary);
if (platform.os === process.platform && platform.cpu === process.arch)
await native.nativeBinary(binary);
const target = `${platform.os === "win32" ? "windows" : platform.os}-${platform.cpu}`;
await cp(directory, join(staging, "native", target), { recursive: true });
manifest.files.push("native");
manifest.os = [platform.os];
manifest.cpu = [platform.cpu];
if (platform.libc) manifest.libc = [platform.libc];
delete manifest.optionalDependencies;
}
await writeFile(
join(staging, "package.json"),
JSON.stringify(manifest, null, 2) + "\n",