





















@@ -1,46 +1,102 @@
11import { spawnSync } from "node:child_process";
2-import { resolve } from "node:path";
3-import { describe, expect, it } from "vitest";
2+import { mkdirSync, writeFileSync } from "node:fs";
3+import { join, resolve } from "node:path";
4+import { afterEach, describe, expect, it } from "vitest";
5+import { cleanupTempDirs, makeTempRepoRoot } from "../helpers/temp-repo.js";
4657const scriptPath = resolve("scripts/list-prod-store-packages.mjs");
8+const tempDirs: string[] = [];
697-function runListProdStorePackages(input: unknown) {
10+function runListProdStorePackages(input: unknown, cwd = process.cwd()) {
811return spawnSync(process.execPath, [scriptPath], {
12+ cwd,
913encoding: "utf8",
1014input: JSON.stringify(input),
1115});
1216}
13171418describe("list-prod-store-packages", () => {
19+afterEach(() => {
20+cleanupTempDirs(tempDirs);
21+});
22+1523it("accepts pnpm list array output", () => {
16-const result = runListProdStorePackages([
17-{
18-dependencies: {
19-sourceMap: {
20-from: "source-map",
21-resolved: "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
22-version: "0.6.1",
24+const cwd = makeTempRepoRoot(tempDirs, "openclaw-prod-store-packages-");
25+const result = runListProdStorePackages(
26+[
27+{
28+dependencies: {
29+sourceMap: {
30+from: "source-map",
31+resolved: "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
32+version: "0.6.1",
33+},
2334},
2435},
25-},
26-]);
36+],
37+cwd,
38+);
27392840expect(result.status).toBe(0);
2941expect(result.stdout).toBe("source-map@0.6.1");
3042});
31433244it("accepts pnpm list object output", () => {
33-const result = runListProdStorePackages({
34-dependencies: {
35-litSignals: {
36-from: "@lit-labs/signals",
37-resolved: "https://registry.npmjs.org/@lit-labs/signals/-/signals-0.1.3.tgz",
38-version: "0.1.3",
45+const cwd = makeTempRepoRoot(tempDirs, "openclaw-prod-store-packages-");
46+const result = runListProdStorePackages(
47+{
48+dependencies: {
49+litSignals: {
50+from: "@lit-labs/signals",
51+resolved: "https://registry.npmjs.org/@lit-labs/signals/-/signals-0.1.3.tgz",
52+version: "0.1.3",
53+},
3954},
4055},
41-});
56+cwd,
57+);
42584359expect(result.status).toBe(0);
4460expect(result.stdout).toBe("@lit-labs/signals@0.1.3");
4561});
62+63+it("adds lockfile snapshot dependencies missing from pnpm list output", () => {
64+const cwd = makeTempRepoRoot(tempDirs, "openclaw-prod-store-packages-");
65+mkdirSync(join(cwd, "scripts"));
66+writeFileSync(
67+join(cwd, "pnpm-lock.yaml"),
68+[
69+"lockfileVersion: '10.0'",
70+"",
71+"packages:",
72+" source-map-support@0.5.21:",
73+" resolution: {integrity: sha512-test}",
74+" source-map@0.6.1:",
75+" resolution: {integrity: sha512-test}",
76+"",
77+"snapshots:",
78+" source-map-support@0.5.21:",
79+" dependencies:",
80+" source-map: 0.6.1",
81+" source-map@0.6.1: {}",
82+"",
83+].join("\n"),
84+);
85+const result = runListProdStorePackages(
86+{
87+dependencies: {
88+sourceMapSupport: {
89+from: "source-map-support",
90+resolved:
91+"https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz",
92+version: "0.5.21",
93+},
94+},
95+},
96+cwd,
97+);
98+99+expect(result.status).toBe(0);
100+expect(result.stdout).toBe("source-map-support@0.5.21\nsource-map@0.6.1");
101+});
46102});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。