Files
fusion/packages/cli/scripts/prepare-publish-manifest.mjs
2026-06-10 18:06:51 -07:00

76 lines
2.4 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/i18n"];
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).
//
// Declaring any `exports` field flips Node into strict subpath mode, which
// would otherwise hide every other `./dist/*` file. The runfusion.ai alias
// imports `@runfusion/fusion/dist/bin.js` and the pi loader reads
// `./dist/extension.js`, so a `./dist/*` passthrough is required to keep
// those subpaths resolvable post-pack.
exports: {
...(pkg.exports || {}),
"./plugin-sdk": {
types: "./dist/plugin-sdk/index.d.ts",
import: "./dist/plugin-sdk/index.js",
},
"./dist/*": "./dist/*",
"./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();
}