fix(update): reject openclaw source package targets

This commit is contained in:
Vincent Koc
2026-05-22 07:20:49 +08:00
parent fad1c8a071
commit 15a0156a8c
19 changed files with 254 additions and 36 deletions

View File

@@ -364,6 +364,27 @@ run_pnpm() {
"${PNPM_CMD[@]}" "$@"
}
to_lowercase_ascii() {
printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]'
}
is_openclaw_source_package_install_spec() {
local value="${1:-}"
local normalized_value=""
normalized_value="$(to_lowercase_ascii "$value")"
normalized_value="${normalized_value#openclaw@}"
[[ "$normalized_value" == "main" ]] && return 0
[[ "$normalized_value" =~ ^github:openclaw/openclaw($|[#/]) ]] && return 0
normalized_value="${normalized_value#git+}"
[[ "$normalized_value" =~ ^https?://github\.com/openclaw/openclaw(\.git)?($|[?#]) ]] && return 0
[[ "$normalized_value" =~ ^ssh://git@github\.com[:/]openclaw/openclaw(\.git)?($|[?#]) ]] && return 0
[[ "$normalized_value" =~ ^git://github\.com/openclaw/openclaw(\.git)?($|[?#]) ]] && return 0
[[ "$normalized_value" =~ ^git@github\.com:openclaw/openclaw(\.git)?($|[?#]) ]] && return 0
return 1
}
resolve_git_openclaw_ref() {
local requested="${OPENCLAW_VERSION:-latest}"
local resolved_version=""
@@ -624,6 +645,9 @@ fix_npm_prefix_if_needed() {
install_openclaw() {
local requested="${OPENCLAW_VERSION:-latest}"
if is_openclaw_source_package_install_spec "$requested"; then
fail "npm installs do not support OpenClaw GitHub source targets like '${requested}'. Use --install-method git --version main, latest, beta, an exact version, or a built .tgz package."
fi
local freshness_flag="--min-release-age=0"
local min_release_age=""
min_release_age="$(env -u NPM_CONFIG_BEFORE -u npm_config_before "$(npm_bin)" config get min-release-age 2>/dev/null || true)"

View File

@@ -511,10 +511,45 @@ function Resolve-NpmOpenClawInstallSpec {
return "$PackageName@$trimmedTag"
}
function Test-OpenClawSourcePackageInstallSpec {
param([string]$RequestedTag)
if ([string]::IsNullOrWhiteSpace($RequestedTag)) {
return $false
}
$normalizedTag = $RequestedTag.Trim().ToLowerInvariant()
if ($normalizedTag.StartsWith("openclaw@")) {
$normalizedTag = $normalizedTag.Substring("openclaw@".Length)
}
if ($normalizedTag -eq "main") {
return $true
}
if ($normalizedTag -match '^github:openclaw/openclaw($|[#/])') {
return $true
}
if ($normalizedTag.StartsWith("git+")) {
$normalizedTag = $normalizedTag.Substring("git+".Length)
}
return (
$normalizedTag -match '^https?://github\.com/openclaw/openclaw(\.git)?($|[?#])' -or
$normalizedTag -match '^ssh://git@github\.com[:/]openclaw/openclaw(\.git)?($|[?#])' -or
$normalizedTag -match '^git://github\.com/openclaw/openclaw(\.git)?($|[?#])' -or
$normalizedTag -match '^git@github\.com:openclaw/openclaw(\.git)?($|[?#])'
)
}
function Install-OpenClaw {
if ([string]::IsNullOrWhiteSpace($Tag)) {
$Tag = "latest"
}
if (Test-OpenClawSourcePackageInstallSpec -RequestedTag $Tag) {
Write-Host "Error: npm installs do not support OpenClaw GitHub source targets like '$Tag'." -ForegroundColor Red
Write-Host "Use -InstallMethod git -Tag main for the moving main checkout, or use latest, beta, an exact version, or a built .tgz package." -ForegroundColor Yellow
return $false
}
if (-not (Ensure-Git)) {
return $false
}

View File

@@ -1047,7 +1047,7 @@ Options:
--install-method, --method npm|git Install via npm (default) or from a git checkout
--npm Shortcut for --install-method npm
--git, --github Shortcut for --install-method git
--version <version|dist-tag|spec> npm install target (default: latest; use "main" for GitHub main)
--version <version|dist-tag|spec> npm install target (default: latest)
--beta Use beta if available, else latest
--git-dir, --dir <path> Checkout directory (default: ~/openclaw)
--no-git-update Skip git pull for existing checkout
@@ -1060,7 +1060,7 @@ Options:
Environment variables:
OPENCLAW_INSTALL_METHOD=git|npm
OPENCLAW_VERSION=latest|next|main|<semver>|<spec>
OPENCLAW_VERSION=latest|next|<semver>|<spec>
OPENCLAW_BETA=0|1
OPENCLAW_GIT_DIR=...
OPENCLAW_GIT_UPDATE=0|1
@@ -1076,7 +1076,7 @@ Examples:
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash -s -- --no-onboard
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash -s -- --no-onboard --verify
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash -s -- --version main
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash -s -- --install-method git --version main
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash -s -- --install-method git --no-onboard
EOF
}
@@ -2444,6 +2444,23 @@ is_explicit_package_install_spec() {
[[ "$value" == *"://"* || "$value" == *"#"* || "$value" =~ ^(file|github|git\+ssh|git\+https|git\+http|git\+file|npm): ]]
}
is_openclaw_source_package_install_spec() {
local value="${1:-}"
local normalized_value=""
normalized_value="$(to_lowercase_ascii "$value")"
normalized_value="${normalized_value#openclaw@}"
[[ "$normalized_value" == "main" ]] && return 0
[[ "$normalized_value" =~ ^github:openclaw/openclaw($|[#/]) ]] && return 0
normalized_value="${normalized_value#git+}"
[[ "$normalized_value" =~ ^https?://github\.com/openclaw/openclaw(\.git)?($|[?#]) ]] && return 0
[[ "$normalized_value" =~ ^ssh://git@github\.com[:/]openclaw/openclaw(\.git)?($|[?#]) ]] && return 0
[[ "$normalized_value" =~ ^git://github\.com/openclaw/openclaw(\.git)?($|[?#]) ]] && return 0
[[ "$normalized_value" =~ ^git@github\.com:openclaw/openclaw(\.git)?($|[?#]) ]] && return 0
return 1
}
can_resolve_registry_package_version() {
local value="${1:-}"
local normalized_value=""
@@ -2499,6 +2516,12 @@ install_openclaw() {
OPENCLAW_VERSION="latest"
fi
if is_openclaw_source_package_install_spec "${OPENCLAW_VERSION}"; then
ui_error "npm installs do not support OpenClaw GitHub source targets like '${OPENCLAW_VERSION}'."
ui_info "Use --install-method git --version main for the moving main checkout, or use latest, beta, an exact version, or a built .tgz package."
return 1
fi
local resolved_version=""
if can_resolve_registry_package_version "${OPENCLAW_VERSION}"; then
resolved_version="$(npm view "${package_name}@${OPENCLAW_VERSION}" version 2>/dev/null || true)"