mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
fix(install): use repo pnpm for git installs
This commit is contained in:
@@ -580,6 +580,15 @@ EOF
|
||||
}
|
||||
|
||||
run_pnpm() {
|
||||
if [[ ${#PNPM_CMD[@]} -eq 2 && "${PNPM_CMD[1]}" == "pnpm" ]] && [[ "${1:-}" == "-C" && -n "${2:-}" ]]; then
|
||||
local repo_dir="$2"
|
||||
shift 2
|
||||
if ! (cd "$repo_dir" && "${PNPM_CMD[@]}" --version >/dev/null 2>&1); then
|
||||
ensure_pnpm
|
||||
fi
|
||||
(cd "$repo_dir" && "${PNPM_CMD[@]}" "$@")
|
||||
return
|
||||
fi
|
||||
if ! pnpm_cmd_is_ready; then
|
||||
ensure_pnpm
|
||||
fi
|
||||
@@ -739,6 +748,10 @@ activate_repo_pnpm_version() {
|
||||
if [[ -n "$corepack_cmd" ]]; then
|
||||
log "Activating repo pnpm ${version}"
|
||||
"$corepack_cmd" prepare "pnpm@${version}" --activate >/dev/null 2>&1 || true
|
||||
if [[ "$(cd "$repo_dir" && "$corepack_cmd" pnpm --version 2>/dev/null || true)" == "$version" ]]; then
|
||||
set_pnpm_cmd "$corepack_cmd" pnpm
|
||||
return 0
|
||||
fi
|
||||
detect_pnpm_cmd || true
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -2128,6 +2128,15 @@ EOF
|
||||
}
|
||||
|
||||
run_pnpm() {
|
||||
if [[ "${PNPM_CMD[*]}" == "corepack pnpm" && "${1:-}" == "-C" && -n "${2:-}" ]]; then
|
||||
local repo_dir="$2"
|
||||
shift 2
|
||||
if ! (cd "$repo_dir" && "${PNPM_CMD[@]}" --version >/dev/null 2>&1); then
|
||||
ensure_pnpm
|
||||
fi
|
||||
(cd "$repo_dir" && "${PNPM_CMD[@]}" "$@")
|
||||
return
|
||||
fi
|
||||
if ! pnpm_cmd_is_ready; then
|
||||
ensure_pnpm
|
||||
fi
|
||||
@@ -2260,6 +2269,10 @@ activate_repo_pnpm_version() {
|
||||
ui_info "Activating repo pnpm ${version}"
|
||||
corepack prepare "pnpm@${version}" --activate >/dev/null 2>&1 || true
|
||||
refresh_shell_command_cache
|
||||
if [[ "$(cd "$repo_dir" && corepack pnpm --version 2>/dev/null || true)" == "$version" ]]; then
|
||||
set_pnpm_cmd corepack pnpm
|
||||
return 0
|
||||
fi
|
||||
detect_pnpm_cmd || true
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -158,6 +158,63 @@ describe("install-cli.sh", () => {
|
||||
expect(script).toContain('activate_repo_pnpm_version "$repo_dir"');
|
||||
});
|
||||
|
||||
it("uses the repo Corepack pnpm when a global pnpm version is already present", () => {
|
||||
const tmp = mkdtempSync(join(tmpdir(), "openclaw-install-cli-pnpm-version-"));
|
||||
const bin = join(tmp, "bin");
|
||||
const outer = join(tmp, "outer");
|
||||
const repo = join(tmp, "repo");
|
||||
mkdirSync(bin, { recursive: true });
|
||||
mkdirSync(outer, { recursive: true });
|
||||
mkdirSync(repo, { recursive: true });
|
||||
writeFileSync(
|
||||
join(outer, "package.json"),
|
||||
'{\n "packageManager": "yarn@4.5.0"\n}\n',
|
||||
);
|
||||
writeFileSync(
|
||||
join(repo, "package.json"),
|
||||
'{\n "packageManager": "pnpm@11.2.2+sha512.test"\n}\n',
|
||||
);
|
||||
writeFileSync(
|
||||
join(bin, "pnpm"),
|
||||
["#!/bin/bash", '[[ "${1:-}" == "--version" ]] && echo "11.8.0"', ""].join("\n"),
|
||||
);
|
||||
writeFileSync(
|
||||
join(bin, "corepack"),
|
||||
[
|
||||
"#!/bin/bash",
|
||||
'if [[ "${1:-}" == "prepare" ]]; then exit 0; fi',
|
||||
'if [[ "${1:-}" == "pnpm" && "${2:-}" == "--version" ]]; then',
|
||||
' if grep -q "pnpm@11.2.2" package.json 2>/dev/null; then echo "11.2.2"; else exit 1; fi',
|
||||
" exit 0",
|
||||
"fi",
|
||||
"exit 1",
|
||||
"",
|
||||
].join("\n"),
|
||||
);
|
||||
chmodSync(join(bin, "pnpm"), 0o755);
|
||||
chmodSync(join(bin, "corepack"), 0o755);
|
||||
|
||||
try {
|
||||
const result = runInstallCliShell(
|
||||
[
|
||||
`cd ${JSON.stringify(process.cwd())}`,
|
||||
`source ${JSON.stringify(SCRIPT_PATH)}`,
|
||||
`cd ${JSON.stringify(outer)}`,
|
||||
`activate_repo_pnpm_version ${JSON.stringify(repo)}`,
|
||||
'printf "cmd=%s\\n" "${PNPM_CMD[*]}"',
|
||||
`printf "run=%s\\n" "$(run_pnpm -C ${JSON.stringify(repo)} --version)"`,
|
||||
].join("\n"),
|
||||
{ PATH: `${bin}:${process.env.PATH ?? ""}` },
|
||||
);
|
||||
|
||||
expect(result.status).toBe(0);
|
||||
expect(result.stdout).toContain(`cmd=${join(bin, "corepack")} pnpm`);
|
||||
expect(result.stdout).toContain("run=11.2.2");
|
||||
} finally {
|
||||
rmSync(tmp, { force: true, recursive: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("links an existing usable Alpine/musl Node runtime without sudo", () => {
|
||||
const tmp = mkdtempSync(join(tmpdir(), "openclaw-install-cli-alpine-"));
|
||||
const bin = join(tmp, "bin");
|
||||
|
||||
@@ -1350,6 +1350,63 @@ describe("install.sh", () => {
|
||||
expect(script).toContain('activate_repo_pnpm_version "$repo_dir"');
|
||||
});
|
||||
|
||||
it("uses the repo Corepack pnpm when a global pnpm version is already present", () => {
|
||||
const tmp = mkdtempSync(join(tmpdir(), "openclaw-install-pnpm-version-"));
|
||||
const bin = join(tmp, "bin");
|
||||
const outer = join(tmp, "outer");
|
||||
const repo = join(tmp, "repo");
|
||||
mkdirSync(bin, { recursive: true });
|
||||
mkdirSync(outer, { recursive: true });
|
||||
mkdirSync(repo, { recursive: true });
|
||||
writeFileSync(
|
||||
join(outer, "package.json"),
|
||||
'{\n "packageManager": "yarn@4.5.0"\n}\n',
|
||||
);
|
||||
writeFileSync(
|
||||
join(repo, "package.json"),
|
||||
'{\n "packageManager": "pnpm@11.2.2+sha512.test"\n}\n',
|
||||
);
|
||||
writeFileSync(
|
||||
join(bin, "pnpm"),
|
||||
["#!/bin/bash", '[[ "${1:-}" == "--version" ]] && echo "11.8.0"', ""].join("\n"),
|
||||
);
|
||||
writeFileSync(
|
||||
join(bin, "corepack"),
|
||||
[
|
||||
"#!/bin/bash",
|
||||
'if [[ "${1:-}" == "prepare" ]]; then exit 0; fi',
|
||||
'if [[ "${1:-}" == "pnpm" && "${2:-}" == "--version" ]]; then',
|
||||
' if grep -q "pnpm@11.2.2" package.json 2>/dev/null; then echo "11.2.2"; else exit 1; fi',
|
||||
" exit 0",
|
||||
"fi",
|
||||
"exit 1",
|
||||
"",
|
||||
].join("\n"),
|
||||
);
|
||||
chmodSync(join(bin, "pnpm"), 0o755);
|
||||
chmodSync(join(bin, "corepack"), 0o755);
|
||||
|
||||
try {
|
||||
const result = runInstallShell(
|
||||
[
|
||||
`cd ${JSON.stringify(process.cwd())}`,
|
||||
`source ${JSON.stringify(SCRIPT_PATH)}`,
|
||||
`cd ${JSON.stringify(outer)}`,
|
||||
`activate_repo_pnpm_version ${JSON.stringify(repo)}`,
|
||||
'printf "cmd=%s\\n" "${PNPM_CMD[*]}"',
|
||||
`printf "run=%s\\n" "$(run_pnpm -C ${JSON.stringify(repo)} --version)"`,
|
||||
].join("\n"),
|
||||
{ PATH: `${bin}:${process.env.PATH ?? ""}` },
|
||||
);
|
||||
|
||||
expect(result.status).toBe(0);
|
||||
expect(result.stdout).toContain("cmd=corepack pnpm");
|
||||
expect(result.stdout).toContain("run=11.2.2");
|
||||
} finally {
|
||||
rmSync(tmp, { force: true, recursive: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("does not treat /dev/tty permissions as a controlling terminal", () => {
|
||||
const result = runInstallShell(`
|
||||
set -euo pipefail
|
||||
|
||||
Reference in New Issue
Block a user