diff --git a/scripts/platform.js b/scripts/platform.js index 0fafae0..3972669 100644 --- a/scripts/platform.js +++ b/scripts/platform.js @@ -16,7 +16,21 @@ const PLATFORM_PKG = { }; function getPlatformPackageName() { - return PLATFORM_PKG[`${process.platform}-${process.arch}`] || null; + const key = `${process.platform}-${process.arch}`; + + try { + const parentPkg = JSON.parse( + fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8") + ); + const optDeps = parentPkg.optionalDependencies || {}; + for (const name of Object.keys(optDeps)) { + if (name.endsWith(`-${key}`)) { + return name; + } + } + } catch (_) {} + + return PLATFORM_PKG[key] || null; } function resolveNativeBinary() { diff --git a/scripts/publish/publish-platform.sh b/scripts/publish/publish-platform.sh index 4a3cd15..4bbd964 100755 --- a/scripts/publish/publish-platform.sh +++ b/scripts/publish/publish-platform.sh @@ -31,6 +31,12 @@ if [ -n "${OCR_PUBLISH_REGISTRY:-}" ]; then REGISTRY_ARGS=(--registry "$OCR_PUBLISH_REGISTRY") fi +# Derive scope override from OCR_PKG_NAME (e.g. @ali/open-code-review → @ali) +SCOPE_OVERRIDE="" +if [ -n "${OCR_PKG_NAME:-}" ]; then + SCOPE_OVERRIDE="${OCR_PKG_NAME%%/*}" +fi + # Pre-check all binaries exist before publishing anything for entry in "${PLATFORMS[@]}"; do IFS=':' read -r _ dist_binary _ <<< "$entry" @@ -75,7 +81,13 @@ for entry in "${PLATFORMS[@]}"; do CURRENT_BIN_DIR="$bin_dir" cp "$pkg_json" "$CURRENT_BACKUP" - jq --arg v "$NPM_VERSION" '.version = $v' "$pkg_json" > "${pkg_json}.tmp" && mv "${pkg_json}.tmp" "$pkg_json" || { rm -f "${pkg_json}.tmp"; false; } + if [ -n "$SCOPE_OVERRIDE" ]; then + jq --arg v "$NPM_VERSION" --arg s "$SCOPE_OVERRIDE" \ + '.version = $v | .name = (.name | sub("^@[^/]+"; $s))' \ + "$pkg_json" > "${pkg_json}.tmp" && mv "${pkg_json}.tmp" "$pkg_json" || { rm -f "${pkg_json}.tmp"; false; } + else + jq --arg v "$NPM_VERSION" '.version = $v' "$pkg_json" > "${pkg_json}.tmp" && mv "${pkg_json}.tmp" "$pkg_json" || { rm -f "${pkg_json}.tmp"; false; } + fi pkg_name=$(jq -r '.name' "$pkg_json") already=$(npm view "${pkg_name}@${NPM_VERSION}" version ${REGISTRY_ARGS[@]+"${REGISTRY_ARGS[@]}"} 2>/dev/null || true) diff --git a/scripts/publish/publish.sh b/scripts/publish/publish.sh index 100274a..d8953a1 100755 --- a/scripts/publish/publish.sh +++ b/scripts/publish/publish.sh @@ -201,8 +201,15 @@ patch_package_json() { fi if [ -n "${OCR_PKG_NAME:-}" ]; then - jq --arg n "$OCR_PKG_NAME" '.name = $n' "$tmp" > "${tmp}.new" && mv "${tmp}.new" "$tmp" + local new_scope="${OCR_PKG_NAME%%/*}" + jq --arg n "$OCR_PKG_NAME" --arg s "$new_scope" ' + .name = $n | + if .optionalDependencies then + .optionalDependencies |= with_entries(.key |= sub("^@[^/]+"; $s)) + else . end + ' "$tmp" > "${tmp}.new" && mv "${tmp}.new" "$tmp" info " name → ${OCR_PKG_NAME}" + info " optionalDependencies scope → ${new_scope}" fi if [ -n "${OCR_PUBLISH_REGISTRY:-}" ]; then