Files
fusion/packages/cli/scripts/prepare-publish-manifest.mjs
gsxdsm af6e5b5eaf FN-5842: publish plugin SDK subpath export
Expose the plugin SDK as a published CLI subpath while preserving existing workspace behavior.

- add a prepack transform helper that injects the ./plugin-sdk and ./package.json exports only in packed manifests
- split tsup config into dedicated CLI and plugin-sdk builds so dist/plugin-sdk JS and DTS are emitted with @fusion deps inlined
- add coverage for definePlugin/validatePluginManifest behavior and manifest/build export guarantees
- document the new published @runfusion/fusion/plugin-sdk surface for plugin authors

Files changed:
 docs/agents.md                                     |  2 +
 packages/cli/scripts/prepare-publish-manifest.mjs  | 61 +++++++++++++++-------
 packages/cli/src/__tests__/plugin-sdk-export.test.ts| 50 ++++++++++++++++++
 packages/cli/tsup.config.ts                        | 31 +++++++++--
 4 files changed, 121 insertions(+), 23 deletions(-)

Fusion-Task-Id: FN-5842

Fusion-Task-Lineage: b6b481ae-aaac-46c0-a6f7-8cc1e9eed1ce
2026-06-01 16:09:35 -07:00

68 lines
2.0 KiB
JavaScript

/* global process, URL, console */
import { existsSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
import { pathToFileURL } from "node:url";
export function applyPrepackTransform(pkg) {
const devDependencies = { ...(pkg.devDependencies || {}) };
delete devDependencies["@fusion/core"];
delete devDependencies["@fusion/dashboard"];
delete devDependencies["@fusion/engine"];
delete devDependencies["@fusion/pi-claude-cli"];
delete devDependencies["@fusion/pi-llama-cpp"];
delete devDependencies["@fusion-plugin-examples/roadmap"];
return {
...pkg,
devDependencies,
// Inject exports only for the packed manifest so workspace/dev resolution
// remains unchanged (postpack restore reverts this file to original state).
exports: {
...(pkg.exports || {}),
"./plugin-sdk": {
types: "./dist/plugin-sdk/index.d.ts",
import: "./dist/plugin-sdk/index.js",
},
"./package.json": "./package.json",
},
};
}
function run() {
const mode = process.argv[2];
const packageJsonPath = new URL("../package.json", import.meta.url);
const backupPath = new URL("../package.json.pack-backup", import.meta.url);
if (mode === "prepack") {
if (existsSync(backupPath)) {
unlinkSync(backupPath);
}
const original = readFileSync(packageJsonPath, "utf8");
writeFileSync(backupPath, original, "utf8");
const pkg = JSON.parse(original);
const transformed = applyPrepackTransform(pkg);
writeFileSync(packageJsonPath, `${JSON.stringify(transformed, null, 2)}\n`, "utf8");
process.exit(0);
}
if (mode === "postpack") {
if (!existsSync(backupPath)) {
process.exit(0);
}
const backup = readFileSync(backupPath, "utf8");
writeFileSync(packageJsonPath, backup, "utf8");
unlinkSync(backupPath);
process.exit(0);
}
console.error("Usage: node ./scripts/prepare-publish-manifest.mjs <prepack|postpack>");
process.exit(1);
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
run();
}