fix: support scope override for platform packages on internal registry

Internal npm registry (anpm) only allows specific scopes like @ali,
not @alibaba-group. Derive scope from OCR_PKG_NAME and apply it to
platform subpackage names during publish. Also make platform.js read
package names from optionalDependencies dynamically instead of relying
solely on the hardcoded scope.
This commit is contained in:
kite 2026-06-17 12:52:43 +08:00
parent f76d4266ed
commit 62ec5e7d4f
3 changed files with 36 additions and 3 deletions

View file

@ -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() {

View file

@ -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)

View file

@ -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