diff --git a/scripts/runtime-postbuild.mjs b/scripts/runtime-postbuild.mjs index 238f1f8360e..9b1c4973206 100644 --- a/scripts/runtime-postbuild.mjs +++ b/scripts/runtime-postbuild.mjs @@ -10,6 +10,12 @@ import { writeOfficialChannelCatalog } from "./write-official-channel-catalog.mj const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const ROOT_RUNTIME_ALIAS_PATTERN = /^(?.+\.(?:runtime|contract))-[A-Za-z0-9_-]+\.js$/u; +export const LEGACY_CLI_EXIT_COMPAT_CHUNKS = [ + { + dest: "dist/memory-state-CcqRgDZU.js", + contents: "export function hasMemoryRuntime() {\n return false;\n}\n", + }, +]; /** * Copy static (non-transpiled) runtime assets that are referenced by their @@ -81,6 +87,14 @@ export function writeStableRootRuntimeAliases(params = {}) { } } +export function writeLegacyCliExitCompatChunks(params = {}) { + const rootDir = params.rootDir ?? ROOT; + const chunks = params.chunks ?? LEGACY_CLI_EXIT_COMPAT_CHUNKS; + for (const { dest, contents } of chunks) { + writeTextFileIfChanged(path.join(rootDir, dest), contents); + } +} + export function runRuntimePostBuild(params = {}) { copyPluginSdkRootAlias(params); copyBundledPluginMetadata(params); @@ -88,6 +102,7 @@ export function runRuntimePostBuild(params = {}) { stageBundledPluginRuntimeDeps(params); stageBundledPluginRuntime(params); writeStableRootRuntimeAliases(params); + writeLegacyCliExitCompatChunks(params); copyStaticExtensionAssets(params); } diff --git a/test/scripts/runtime-postbuild.test.ts b/test/scripts/runtime-postbuild.test.ts index 7c10c779927..b430d00e8a1 100644 --- a/test/scripts/runtime-postbuild.test.ts +++ b/test/scripts/runtime-postbuild.test.ts @@ -4,6 +4,7 @@ import { describe, expect, it, vi } from "vitest"; import { copyStaticExtensionAssets, listStaticExtensionAssetOutputs, + writeLegacyCliExitCompatChunks, writeStableRootRuntimeAliases, } from "../../scripts/runtime-postbuild.mjs"; import { createScriptTestHarness } from "./test-helpers.js"; @@ -79,4 +80,14 @@ describe("runtime postbuild static assets", () => { ); await expect(fs.stat(path.join(distDir, "library.js"))).rejects.toThrow(); }); + + it("writes legacy CLI exit compatibility chunks", async () => { + const rootDir = createTempDir("openclaw-runtime-postbuild-"); + + writeLegacyCliExitCompatChunks({ rootDir }); + + await expect( + fs.readFile(path.join(rootDir, "dist", "memory-state-CcqRgDZU.js"), "utf8"), + ).resolves.toContain("function hasMemoryRuntime()"); + }); });