openclaw/scripts/openclaw-postpack.mjs
RoboClaw 9d5c37cf80
fix(release): seal worker chunks in npm packages (#163985)
Co-authored-by: RomneyDa <6581799+RomneyDa@users.noreply.github.com>
2026-10-02 22:22:21 -07:00

36 lines
1.4 KiB
JavaScript
Executable file

#!/usr/bin/env node
import { rm } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import {
LEGACY_PACKAGE_INSTALL_GUARD_RELATIVE_PATH,
PACKAGE_LIFECYCLE_PENDING_RELATIVE_PATH,
} from "./lib/package-lifecycle-marker.mjs";
// Restores every source artifact temporarily rewritten for npm packaging.
import { restorePackageChangelog } from "./package-changelog.mjs";
import { restorePackageDocsMap } from "./package-docs-map.mjs";
import { restorePackageManifest } from "./package-manifest.mjs";
import { restorePackagedWorkerBundle } from "./package-worker-bundle-lifecycle.mjs";
export async function restorePrepackArtifacts(cwd = process.cwd()) {
await restorePackageChangelog(cwd);
await restorePackageManifest(cwd);
await restorePackagedWorkerBundle(cwd);
await Promise.all(
[PACKAGE_LIFECYCLE_PENDING_RELATIVE_PATH, LEGACY_PACKAGE_INSTALL_GUARD_RELATIVE_PATH].map(
(relativePath) => rm(path.join(cwd, relativePath), { force: true }),
),
);
// Release the lifecycle receipt only after every other source mutation settles.
await restorePackageDocsMap(cwd);
}
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
try {
await restorePrepackArtifacts();
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
}
}