fix: run packed bundled postinstall in release check

This commit is contained in:
Peter Steinberger
2026-04-21 09:34:33 +01:00
parent adef75c1e1
commit e57e54e591
4 changed files with 60 additions and 1 deletions

View File

@@ -807,6 +807,20 @@ export function runBundledPluginPostinstall(params = {}) {
});
}
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
export function isDirectPostinstallInvocation(params = {}) {
const entryPath = params.entryPath ?? process.argv[1];
if (!entryPath) {
return false;
}
const modulePath = params.modulePath ?? fileURLToPath(import.meta.url);
const resolveRealPath = params.realpathSync ?? realpathSync;
try {
return resolveRealPath(entryPath) === resolveRealPath(modulePath);
} catch {
return pathToFileURL(entryPath).href === pathToFileURL(modulePath).href;
}
}
if (isDirectPostinstallInvocation()) {
runBundledPluginPostinstall();
}

View File

@@ -204,6 +204,24 @@ function resolveGlobalRoot(prefixDir: string, cwd: string): string {
}).trim();
}
export function createPackedBundledPluginPostinstallEnv(
env: NodeJS.ProcessEnv = process.env,
): NodeJS.ProcessEnv {
return {
...env,
OPENCLAW_DISABLE_BUNDLED_ENTRY_SOURCE_FALLBACK: "1",
OPENCLAW_EAGER_BUNDLED_PLUGIN_DEPS: "1",
};
}
function runPackedBundledPluginPostinstall(packageRoot: string): void {
execFileSync(process.execPath, [join(packageRoot, "scripts/postinstall-bundled-plugins.mjs")], {
cwd: packageRoot,
stdio: "inherit",
env: createPackedBundledPluginPostinstallEnv(),
});
}
function runPackedBundledChannelEntrySmoke(): void {
const tmpRoot = mkdtempSync(join(tmpdir(), "openclaw-release-pack-smoke-"));
try {
@@ -216,6 +234,7 @@ function runPackedBundledChannelEntrySmoke(): void {
installPackedTarball(prefixDir, tarballPath, tmpRoot);
const packageRoot = join(resolveGlobalRoot(prefixDir, tmpRoot), "openclaw");
runPackedBundledPluginPostinstall(packageRoot);
execFileSync(
process.execPath,
[

View File

@@ -14,6 +14,7 @@ import {
collectForbiddenPackPaths,
collectMissingPackPaths,
collectPackUnpackedSizeErrors,
createPackedBundledPluginPostinstallEnv,
packageNameFromSpecifier,
} from "../scripts/release-check.ts";
import { PACKAGE_DIST_INVENTORY_RELATIVE_PATH } from "../src/infra/package-dist-inventory.ts";
@@ -463,3 +464,13 @@ describe("collectPackUnpackedSizeErrors", () => {
]);
});
});
describe("createPackedBundledPluginPostinstallEnv", () => {
it("enables eager bundled dependency repair for packed channel entry smoke", () => {
expect(createPackedBundledPluginPostinstallEnv({ PATH: "/usr/bin" })).toEqual({
PATH: "/usr/bin",
OPENCLAW_DISABLE_BUNDLED_ENTRY_SOURCE_FALLBACK: "1",
OPENCLAW_EAGER_BUNDLED_PLUGIN_DEPS: "1",
});
});
});

View File

@@ -5,6 +5,7 @@ import {
createBundledRuntimeDependencyInstallArgs,
createBundledRuntimeDependencyInstallEnv,
createNestedNpmInstallEnv,
isDirectPostinstallInvocation,
pruneInstalledPackageDist,
discoverBundledPluginRuntimeDeps,
pruneBundledPluginSourceNodeModules,
@@ -82,6 +83,20 @@ describe("bundled plugin postinstall", () => {
});
}
it("recognizes direct invocation through symlinked temp prefixes", () => {
const realpathSync = vi.fn((value: string) =>
value.replace(/^\/var\/folders\//u, "/private/var/folders/"),
);
expect(
isDirectPostinstallInvocation({
entryPath: "/var/folders/tmp/openclaw/scripts/postinstall-bundled-plugins.mjs",
modulePath: "/private/var/folders/tmp/openclaw/scripts/postinstall-bundled-plugins.mjs",
realpathSync,
}),
).toBe(true);
});
async function writeDiscordDaveyOptionalDependencyFixture(
extensionsDir: string,
packageRoot: string,