Skip to content

Commit b4c311e

Browse files
authored
fix(release): keep frozen package inventory self-contained (#106886)
* fix(release): keep frozen package inventory self-contained * fix(release): declare frozen inventory helper
1 parent 1bdb7b8 commit b4c311e

3 files changed

Lines changed: 53 additions & 17 deletions

File tree

scripts/package-openclaw-for-docker.d.mts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ export function packOpenClawPackageForDocker(
2828
outputDir: unknown,
2929
options?: Record<string, unknown>,
3030
): Promise<string>;
31+
export function writePackageInventoryForDocker(
32+
sourceDir: string,
33+
runImpl?: (
34+
command: string,
35+
args: string[],
36+
cwd: string,
37+
options?: Record<string, unknown>,
38+
) => Promise<unknown>,
39+
): Promise<void>;
3140
export function runCommandForTest(
3241
command: unknown,
3342
args: unknown,

scripts/package-openclaw-for-docker.mjs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,22 @@ export async function packOpenClawPackageForDocker(sourceDir, outputDir, options
721721
return tarball;
722722
}
723723

724+
export async function writePackageInventoryForDocker(sourceDir, runImpl = run) {
725+
// Frozen release refs own their inventory shape; run their writer instead of importing current-main helpers.
726+
const tsxModuleUrl = import.meta.resolve("tsx");
727+
await runImpl(
728+
"node",
729+
["--import", tsxModuleUrl, path.join(sourceDir, "scripts/write-package-dist-inventory.ts")],
730+
sourceDir,
731+
{
732+
timeoutMs: resolveTimeoutMs(
733+
"OPENCLAW_DOCKER_PACKAGE_INVENTORY_TIMEOUT_MS",
734+
DEFAULT_PACKAGE_INVENTORY_TIMEOUT_MS,
735+
),
736+
},
737+
);
738+
}
739+
724740
async function main() {
725741
const options = parseArgs(process.argv.slice(2));
726742
const sourceDir = path.resolve(ROOT_DIR, options.sourceDir || ROOT_DIR);
@@ -735,23 +751,7 @@ async function main() {
735751
}
736752

737753
console.error("==> Writing OpenClaw package inventory");
738-
await run(
739-
"node",
740-
[
741-
"--import",
742-
"tsx",
743-
"--input-type=module",
744-
"-e",
745-
"const { writePackageDistInventory } = await import('./scripts/lib/package-dist-inventory.ts'); await writePackageDistInventory(process.cwd());",
746-
],
747-
sourceDir,
748-
{
749-
timeoutMs: resolveTimeoutMs(
750-
"OPENCLAW_DOCKER_PACKAGE_INVENTORY_TIMEOUT_MS",
751-
DEFAULT_PACKAGE_INVENTORY_TIMEOUT_MS,
752-
),
753-
},
754-
);
754+
await writePackageInventoryForDocker(sourceDir);
755755

756756
const tarball = await packOpenClawPackageForDocker(sourceDir, outputDir, {
757757
allowUnreleasedChangelog: options.allowUnreleasedChangelog,

test/e2e/qa-lab/runtime/package-openclaw-for-docker.e2e.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
parseArgs,
1414
prepareBundledAiRuntimePackage,
1515
runCommandForTest,
16+
writePackageInventoryForDocker,
1617
} from "../../../../scripts/package-openclaw-for-docker.mjs";
1718
import { useAutoCleanupTempDirTracker } from "../../../helpers/temp-dir.js";
1819

@@ -175,6 +176,32 @@ describe("package-openclaw-for-docker", () => {
175176
}
176177
});
177178

179+
it("writes inventory for a frozen source checkout without the trusted helper", async () => {
180+
const sourceDir = tempDirs.make("openclaw-package-frozen-source-");
181+
fs.mkdirSync(path.join(sourceDir, "dist"), { recursive: true });
182+
fs.mkdirSync(path.join(sourceDir, "scripts"), { recursive: true });
183+
fs.writeFileSync(path.join(sourceDir, "package.json"), '{"name":"openclaw"}\n');
184+
fs.writeFileSync(path.join(sourceDir, "dist", "entry.js"), "export {};\n");
185+
fs.writeFileSync(
186+
path.join(sourceDir, "scripts", "write-package-dist-inventory.ts"),
187+
[
188+
'import fs from "node:fs";',
189+
'fs.writeFileSync("dist/postinstall-inventory.json", JSON.stringify(["dist/entry.js"]));',
190+
].join("\n"),
191+
);
192+
193+
await writePackageInventoryForDocker(sourceDir);
194+
195+
expect(
196+
JSON.parse(
197+
fs.readFileSync(path.join(sourceDir, "dist", "postinstall-inventory.json"), "utf8"),
198+
),
199+
).toEqual(["dist/entry.js"]);
200+
expect(fs.existsSync(path.join(sourceDir, "scripts", "lib", "package-dist-inventory.ts"))).toBe(
201+
false,
202+
);
203+
});
204+
178205
it("rejects pnpm pack with npm metadata output", () => {
179206
expect(parseArgs(["--pnpm-pack"]).pnpmPack).toBe(true);
180207
expect(() => parseArgs(["--pnpm-pack", "--pack-json", "pack.json"])).toThrow(

0 commit comments

Comments
 (0)