diff --git a/codex-cli/scripts/build_npm_package.py b/codex-cli/scripts/build_npm_package.py index eda6c26152..c9c77cba05 100755 --- a/codex-cli/scripts/build_npm_package.py +++ b/codex-cli/scripts/build_npm_package.py @@ -2,6 +2,7 @@ """Stage and optionally package the @openai/codex npm module.""" import argparse +import importlib.util import json import shutil import subprocess @@ -15,76 +16,18 @@ REPO_ROOT = CODEX_CLI_ROOT.parent RESPONSES_API_PROXY_NPM_ROOT = REPO_ROOT / "codex-rs" / "responses-api-proxy" / "npm" CODEX_SDK_ROOT = REPO_ROOT / "sdk" / "typescript" CODEX_NPM_NAME = "@openai/codex" +PACKAGE_METADATA = SCRIPT_DIR / "package_metadata.py" -# `npm_name` is the local optional-dependency alias consumed by `bin/codex.js`. -# The underlying package published to npm is always `@openai/codex`. -CODEX_PLATFORM_PACKAGES: dict[str, dict[str, str]] = { - "codex-linux-x64": { - "npm_name": "@openai/codex-linux-x64", - "npm_tag": "linux-x64", - "target_triple": "x86_64-unknown-linux-musl", - "os": "linux", - "cpu": "x64", - }, - "codex-linux-arm64": { - "npm_name": "@openai/codex-linux-arm64", - "npm_tag": "linux-arm64", - "target_triple": "aarch64-unknown-linux-musl", - "os": "linux", - "cpu": "arm64", - }, - "codex-darwin-x64": { - "npm_name": "@openai/codex-darwin-x64", - "npm_tag": "darwin-x64", - "target_triple": "x86_64-apple-darwin", - "os": "darwin", - "cpu": "x64", - }, - "codex-darwin-arm64": { - "npm_name": "@openai/codex-darwin-arm64", - "npm_tag": "darwin-arm64", - "target_triple": "aarch64-apple-darwin", - "os": "darwin", - "cpu": "arm64", - }, - "codex-win32-x64": { - "npm_name": "@openai/codex-win32-x64", - "npm_tag": "win32-x64", - "target_triple": "x86_64-pc-windows-msvc", - "os": "win32", - "cpu": "x64", - }, - "codex-win32-arm64": { - "npm_name": "@openai/codex-win32-arm64", - "npm_tag": "win32-arm64", - "target_triple": "aarch64-pc-windows-msvc", - "os": "win32", - "cpu": "arm64", - }, -} - -PACKAGE_EXPANSIONS: dict[str, list[str]] = { - "codex": ["codex", *CODEX_PLATFORM_PACKAGES], -} - -PACKAGE_NATIVE_COMPONENTS: dict[str, list[str]] = { - "codex": [], - "codex-linux-x64": ["codex", "rg"], - "codex-linux-arm64": ["codex", "rg"], - "codex-darwin-x64": ["codex", "rg"], - "codex-darwin-arm64": ["codex", "rg"], - "codex-win32-x64": ["codex", "rg", "codex-windows-sandbox-setup", "codex-command-runner"], - "codex-win32-arm64": ["codex", "rg", "codex-windows-sandbox-setup", "codex-command-runner"], - "codex-responses-api-proxy": ["codex-responses-api-proxy"], - "codex-sdk": [], -} - -PACKAGE_TARGET_FILTERS: dict[str, str] = { - package_name: package_config["target_triple"] - for package_name, package_config in CODEX_PLATFORM_PACKAGES.items() -} - -PACKAGE_CHOICES = tuple(PACKAGE_NATIVE_COMPONENTS) +_SPEC = importlib.util.spec_from_file_location("codex_package_metadata", PACKAGE_METADATA) +if _SPEC is None or _SPEC.loader is None: + raise RuntimeError(f"Unable to load module from {PACKAGE_METADATA}") +_METADATA_MODULE = importlib.util.module_from_spec(_SPEC) +_SPEC.loader.exec_module(_METADATA_MODULE) +CODEX_PLATFORM_PACKAGES = getattr(_METADATA_MODULE, "CODEX_PLATFORM_PACKAGES", {}) +PACKAGE_CHOICES = getattr(_METADATA_MODULE, "PACKAGE_CHOICES", ()) +PACKAGE_EXPANSIONS = getattr(_METADATA_MODULE, "PACKAGE_EXPANSIONS", {}) +PACKAGE_NATIVE_COMPONENTS = getattr(_METADATA_MODULE, "PACKAGE_NATIVE_COMPONENTS", {}) +PACKAGE_TARGET_FILTERS = getattr(_METADATA_MODULE, "PACKAGE_TARGET_FILTERS", {}) COMPONENT_DEST_DIR: dict[str, str] = { "codex": "codex", diff --git a/codex-cli/scripts/package_metadata.py b/codex-cli/scripts/package_metadata.py new file mode 100644 index 0000000000..8ac98acfb4 --- /dev/null +++ b/codex-cli/scripts/package_metadata.py @@ -0,0 +1,71 @@ +"""Shared package metadata for Codex release packaging scripts.""" + +# `npm_name` is the local optional-dependency alias consumed by `bin/codex.js`. +# The underlying package published to npm is always `@openai/codex`. +CODEX_PLATFORM_PACKAGES: dict[str, dict[str, str]] = { + "codex-linux-x64": { + "npm_name": "@openai/codex-linux-x64", + "npm_tag": "linux-x64", + "target_triple": "x86_64-unknown-linux-musl", + "os": "linux", + "cpu": "x64", + }, + "codex-linux-arm64": { + "npm_name": "@openai/codex-linux-arm64", + "npm_tag": "linux-arm64", + "target_triple": "aarch64-unknown-linux-musl", + "os": "linux", + "cpu": "arm64", + }, + "codex-darwin-x64": { + "npm_name": "@openai/codex-darwin-x64", + "npm_tag": "darwin-x64", + "target_triple": "x86_64-apple-darwin", + "os": "darwin", + "cpu": "x64", + }, + "codex-darwin-arm64": { + "npm_name": "@openai/codex-darwin-arm64", + "npm_tag": "darwin-arm64", + "target_triple": "aarch64-apple-darwin", + "os": "darwin", + "cpu": "arm64", + }, + "codex-win32-x64": { + "npm_name": "@openai/codex-win32-x64", + "npm_tag": "win32-x64", + "target_triple": "x86_64-pc-windows-msvc", + "os": "win32", + "cpu": "x64", + }, + "codex-win32-arm64": { + "npm_name": "@openai/codex-win32-arm64", + "npm_tag": "win32-arm64", + "target_triple": "aarch64-pc-windows-msvc", + "os": "win32", + "cpu": "arm64", + }, +} + +PACKAGE_EXPANSIONS: dict[str, list[str]] = { + "codex": ["codex", *CODEX_PLATFORM_PACKAGES], +} + +PACKAGE_NATIVE_COMPONENTS: dict[str, list[str]] = { + "codex": [], + "codex-linux-x64": ["codex", "rg"], + "codex-linux-arm64": ["codex", "rg"], + "codex-darwin-x64": ["codex", "rg"], + "codex-darwin-arm64": ["codex", "rg"], + "codex-win32-x64": ["codex", "rg", "codex-windows-sandbox-setup", "codex-command-runner"], + "codex-win32-arm64": ["codex", "rg", "codex-windows-sandbox-setup", "codex-command-runner"], + "codex-responses-api-proxy": ["codex-responses-api-proxy"], + "codex-sdk": [], +} + +PACKAGE_TARGET_FILTERS: dict[str, str] = { + package_name: package_config["target_triple"] + for package_name, package_config in CODEX_PLATFORM_PACKAGES.items() +} + +PACKAGE_CHOICES = tuple(PACKAGE_NATIVE_COMPONENTS) diff --git a/scripts/stage_npm_packages.py b/scripts/stage_npm_packages.py index 3f75efc3ab..9109608e63 100755 --- a/scripts/stage_npm_packages.py +++ b/scripts/stage_npm_packages.py @@ -16,12 +16,13 @@ from pathlib import Path REPO_ROOT = Path(__file__).resolve().parent.parent BUILD_SCRIPT = REPO_ROOT / "codex-cli" / "scripts" / "build_npm_package.py" INSTALL_NATIVE_DEPS = REPO_ROOT / "codex-cli" / "scripts" / "install_native_deps.py" +PACKAGE_METADATA = REPO_ROOT / "codex-cli" / "scripts" / "package_metadata.py" WORKFLOW_NAME = ".github/workflows/rust-release.yml" GITHUB_REPO = "openai/codex" -_SPEC = importlib.util.spec_from_file_location("codex_build_npm_package", BUILD_SCRIPT) +_SPEC = importlib.util.spec_from_file_location("codex_package_metadata", PACKAGE_METADATA) if _SPEC is None or _SPEC.loader is None: - raise RuntimeError(f"Unable to load module from {BUILD_SCRIPT}") + raise RuntimeError(f"Unable to load module from {PACKAGE_METADATA}") _BUILD_MODULE = importlib.util.module_from_spec(_SPEC) _SPEC.loader.exec_module(_BUILD_MODULE) PACKAGE_NATIVE_COMPONENTS = getattr(_BUILD_MODULE, "PACKAGE_NATIVE_COMPONENTS", {}) diff --git a/scripts/stage_standalone_installer_archives.py b/scripts/stage_standalone_installer_archives.py index e4d3cbc6c9..c98a611e22 100755 --- a/scripts/stage_standalone_installer_archives.py +++ b/scripts/stage_standalone_installer_archives.py @@ -15,13 +15,13 @@ from pathlib import Path REPO_ROOT = Path(__file__).resolve().parent.parent -BUILD_SCRIPT = REPO_ROOT / "codex-cli" / "scripts" / "build_npm_package.py" INSTALL_NATIVE_DEPS = REPO_ROOT / "codex-cli" / "scripts" / "install_native_deps.py" +PACKAGE_METADATA = REPO_ROOT / "codex-cli" / "scripts" / "package_metadata.py" WORKFLOW_NAME = ".github/workflows/rust-release.yml" -_SPEC = importlib.util.spec_from_file_location("codex_build_npm_package", BUILD_SCRIPT) +_SPEC = importlib.util.spec_from_file_location("codex_package_metadata", PACKAGE_METADATA) if _SPEC is None or _SPEC.loader is None: - raise RuntimeError(f"Unable to load module from {BUILD_SCRIPT}") + raise RuntimeError(f"Unable to load module from {PACKAGE_METADATA}") _BUILD_MODULE = importlib.util.module_from_spec(_SPEC) _SPEC.loader.exec_module(_BUILD_MODULE) CODEX_PLATFORM_PACKAGES = getattr(_BUILD_MODULE, "CODEX_PLATFORM_PACKAGES", {})