Skip to content

Commit 088cab5

Browse files
committed
fix(macos): prefer repo pnpm for packaging
1 parent bd74a62 commit 088cab5

4 files changed

Lines changed: 143 additions & 8 deletions

File tree

scripts/package-mac-app.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ sparkle_framework_for_arch() {
6868
PNPM_CMD=()
6969

7070
resolve_pnpm_cmd() {
71-
if command -v pnpm >/dev/null 2>&1; then
72-
PNPM_CMD=(pnpm)
71+
if command -v corepack >/dev/null 2>&1 && (cd "$ROOT_DIR" && corepack pnpm --version >/dev/null 2>&1); then
72+
PNPM_CMD=(corepack pnpm)
7373
return 0
7474
fi
7575

76-
if command -v corepack >/dev/null 2>&1 && (cd "$ROOT_DIR" && corepack pnpm --version >/dev/null 2>&1); then
77-
PNPM_CMD=(corepack pnpm)
76+
if command -v pnpm >/dev/null 2>&1; then
77+
PNPM_CMD=(pnpm)
7878
return 0
7979
fi
8080

scripts/package-mac-dist.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ DIST_PNPM_CMD=()
3333
SPARKLE_BUILD_DEPS_RETRIED=0
3434

3535
resolve_dist_pnpm_cmd() {
36-
if command -v pnpm >/dev/null 2>&1; then
37-
DIST_PNPM_CMD=(pnpm)
36+
if command -v corepack >/dev/null 2>&1 && (cd "$ROOT_DIR" && corepack pnpm --version >/dev/null 2>&1); then
37+
DIST_PNPM_CMD=(corepack pnpm)
3838
return 0
3939
fi
4040

41-
if command -v corepack >/dev/null 2>&1 && (cd "$ROOT_DIR" && corepack pnpm --version >/dev/null 2>&1); then
42-
DIST_PNPM_CMD=(corepack pnpm)
41+
if command -v pnpm >/dev/null 2>&1; then
42+
DIST_PNPM_CMD=(pnpm)
4343
return 0
4444
fi
4545

test/scripts/package-mac-app.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,68 @@ describe("package-mac-app plist stamping", () => {
205205
]);
206206
});
207207

208+
it("prefers repo Corepack pnpm over a global pnpm shim", () => {
209+
const helperBlock = getPackageManagerHelperBlock();
210+
const tempRoot = mkdtempSync(path.join(tmpdir(), "openclaw-package-pnpm-root-"));
211+
const outerRoot = mkdtempSync(path.join(tmpdir(), "openclaw-package-pnpm-outer-"));
212+
const toolsDir = mkdtempSync(path.join(tmpdir(), "openclaw-package-pnpm-tools-"));
213+
const logPath = path.join(tempRoot, "pnpm.log");
214+
tempDirs.push(tempRoot, outerRoot, toolsDir);
215+
216+
writeFileSync(
217+
path.join(tempRoot, "package.json"),
218+
'{\n "packageManager": "pnpm@11.2.2+sha512.test"\n}\n',
219+
);
220+
writeFileSync(
221+
path.join(outerRoot, "package.json"),
222+
'{\n "packageManager": "pnpm@11.8.0+sha512.test"\n}\n',
223+
);
224+
writeFileSync(
225+
path.join(toolsDir, "pnpm"),
226+
[
227+
"#!/usr/bin/env bash",
228+
"set -euo pipefail",
229+
'printf "global|%s|%s\\n" "$PWD" "$*" >> "$OPENCLAW_TEST_LOG"',
230+
'if [[ "${1:-}" == "--version" ]]; then echo "11.8.0"; fi',
231+
"",
232+
].join("\n"),
233+
"utf8",
234+
);
235+
writeFileSync(
236+
path.join(toolsDir, "corepack"),
237+
[
238+
"#!/usr/bin/env bash",
239+
"set -euo pipefail",
240+
'printf "corepack|%s|%s\\n" "$PWD" "$*" >> "$OPENCLAW_TEST_LOG"',
241+
'if [[ "${1:-}" == "pnpm" && "${2:-}" == "--version" ]]; then',
242+
' if grep -q "pnpm@11.2.2" package.json 2>/dev/null; then echo "11.2.2"; else echo "11.8.0"; fi',
243+
"fi",
244+
"",
245+
].join("\n"),
246+
"utf8",
247+
);
248+
chmodSync(path.join(toolsDir, "pnpm"), 0o755);
249+
chmodSync(path.join(toolsDir, "corepack"), 0o755);
250+
251+
const result = runHelper(`
252+
set -euo pipefail
253+
ROOT_DIR=${JSON.stringify(tempRoot)}
254+
OPENCLAW_TEST_LOG=${JSON.stringify(logPath)}
255+
export OPENCLAW_TEST_LOG
256+
PATH=${JSON.stringify(`${toolsDir}:/usr/bin:/bin`)}
257+
cd ${JSON.stringify(outerRoot)}
258+
${helperBlock}
259+
run_pnpm --version
260+
`);
261+
262+
expect(result.status).toBe(0);
263+
expect(result.stdout).toBe("11.2.2\n");
264+
expect(readFileSync(logPath, "utf8").trim().split("\n")).toEqual([
265+
`corepack|${tempRoot}|pnpm --version`,
266+
`corepack|${tempRoot}|pnpm --version`,
267+
]);
268+
});
269+
208270
it("fails with an actionable error when neither pnpm nor corepack pnpm is available", () => {
209271
const helperBlock = getPackageManagerHelperBlock();
210272
const tempRoot = mkdtempSync(path.join(tmpdir(), "openclaw-package-pnpm-root-"));

test/scripts/package-mac-dist.test.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ function runHelper(script: string) {
3737
});
3838
}
3939

40+
function getPackageManagerHelperBlock(): string {
41+
const script = readFileSync(scriptPath, "utf8");
42+
const start = script.indexOf("DIST_PNPM_CMD=()");
43+
const end = script.indexOf("ensure_sparkle_build_deps()");
44+
45+
expect(start).toBeGreaterThanOrEqual(0);
46+
expect(end).toBeGreaterThan(start);
47+
48+
return script.slice(start, end);
49+
}
50+
4051
afterEach(() => {
4152
for (const dir of tempDirs.splice(0)) {
4253
rmSync(dir, { recursive: true, force: true });
@@ -102,6 +113,68 @@ describe("package-mac-dist plist validation", () => {
102113
expect(script).not.toContain('canonical_sparkle_build "$VERSION" 2>/dev/null || true');
103114
});
104115

116+
it("prefers repo Corepack pnpm over a global pnpm shim", () => {
117+
const helperBlock = getPackageManagerHelperBlock();
118+
const tempRoot = mkdtempSync(path.join(tmpdir(), "openclaw-dist-pnpm-root-"));
119+
const outerRoot = mkdtempSync(path.join(tmpdir(), "openclaw-dist-pnpm-outer-"));
120+
const toolsDir = mkdtempSync(path.join(tmpdir(), "openclaw-dist-pnpm-tools-"));
121+
const logPath = path.join(tempRoot, "pnpm.log");
122+
tempDirs.push(tempRoot, outerRoot, toolsDir);
123+
124+
writeFileSync(
125+
path.join(tempRoot, "package.json"),
126+
'{\n "packageManager": "pnpm@11.2.2+sha512.test"\n}\n',
127+
);
128+
writeFileSync(
129+
path.join(outerRoot, "package.json"),
130+
'{\n "packageManager": "pnpm@11.8.0+sha512.test"\n}\n',
131+
);
132+
writeFileSync(
133+
path.join(toolsDir, "pnpm"),
134+
[
135+
"#!/usr/bin/env bash",
136+
"set -euo pipefail",
137+
'printf "global|%s|%s\\n" "$PWD" "$*" >> "$OPENCLAW_TEST_LOG"',
138+
'if [[ "${1:-}" == "--version" ]]; then echo "11.8.0"; fi',
139+
"",
140+
].join("\n"),
141+
"utf8",
142+
);
143+
writeFileSync(
144+
path.join(toolsDir, "corepack"),
145+
[
146+
"#!/usr/bin/env bash",
147+
"set -euo pipefail",
148+
'printf "corepack|%s|%s\\n" "$PWD" "$*" >> "$OPENCLAW_TEST_LOG"',
149+
'if [[ "${1:-}" == "pnpm" && "${2:-}" == "--version" ]]; then',
150+
' if grep -q "pnpm@11.2.2" package.json 2>/dev/null; then echo "11.2.2"; else echo "11.8.0"; fi',
151+
"fi",
152+
"",
153+
].join("\n"),
154+
"utf8",
155+
);
156+
chmodSync(path.join(toolsDir, "pnpm"), 0o755);
157+
chmodSync(path.join(toolsDir, "corepack"), 0o755);
158+
159+
const result = runHelper(`
160+
set -euo pipefail
161+
ROOT_DIR=${JSON.stringify(tempRoot)}
162+
OPENCLAW_TEST_LOG=${JSON.stringify(logPath)}
163+
export OPENCLAW_TEST_LOG
164+
PATH=${JSON.stringify(`${toolsDir}:/usr/bin:/bin`)}
165+
cd ${JSON.stringify(outerRoot)}
166+
${helperBlock}
167+
run_dist_pnpm --version
168+
`);
169+
170+
expect(result.status).toBe(0);
171+
expect(result.stdout).toBe("11.2.2\n");
172+
expect(readFileSync(logPath, "utf8").trim().split("\n")).toEqual([
173+
`corepack|${tempRoot}|pnpm --version`,
174+
`corepack|${tempRoot}|pnpm --version`,
175+
]);
176+
});
177+
105178
it("keeps dependency bootstrap output out of captured Sparkle build values", () => {
106179
const script = readFileSync(scriptPath, "utf8");
107180
const helpers = script.slice(

0 commit comments

Comments
 (0)