mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-11-13 12:15:48 +08:00
[feat] bundle MCP and DSH into one installable package
This commit is contained in:
1 parent
02a25a759f
commit
2a9faf1eb1
15 files changed
+875
-590
No files matched your search
@@ -3,9 +3,16 @@ import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), "../integrations/deepseek-harness");
|
||||
const dist = resolve(root, "../../dist");
|
||||
await build({ entryPoints: [resolve(root, "src/plugin.js")], outfile: resolve(dist, "harness.js"),
|
||||
bundle: true, format: "esm", platform: "node", target: "node22",
|
||||
packages: "external" });
|
||||
await build({ entryPoints: [resolve(root, "src/host.js")], outfile: resolve(root, "dist/host.js"),
|
||||
bundle: true, format: "esm", platform: "node", target: "node22" });
|
||||
await build({ entryPoints: [resolve(root, "src/client.js")], outfile: resolve(root, "dist/client.js"),
|
||||
bundle: true, format: "cjs", platform: "browser", target: "es2022",
|
||||
banner: { js: 'window.__ModuleLoader__.load({ id: "@chunkdash/dsh-crossdesk-sidebar", factory: (require) => { var module = { exports: {} }; var exports = module.exports;' },
|
||||
footer: { js: "return module.exports; } });" } });
|
||||
for (const [id, outfile] of [
|
||||
["@chunkdash/crossdesk-mcp", resolve(dist, "harness-client.js")],
|
||||
["@chunkdash/dsh-crossdesk-sidebar", resolve(root, "dist/client.js")],
|
||||
]) await build({ entryPoints: [resolve(root, "src/client.js")], outfile,
|
||||
bundle: true, format: "cjs", platform: "browser", target: "es2022",
|
||||
banner: { js: `window.__ModuleLoader__.load({ id: ${JSON.stringify(id)}, factory: (require) => { var module = { exports: {} }; var exports = module.exports;` },
|
||||
footer: { js: "return module.exports; } });" } });
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user