|
1 | 1 | #!/usr/bin/env python3 |
2 | | -"""Stage and optionally package the @openai/codex npm module.""" |
| 2 | +"""Stage and optionally package the @leonw24/open-codex npm module.""" |
| 3 | + |
| 4 | +from __future__ import annotations |
3 | 5 |
|
4 | 6 | import argparse |
5 | 7 | import json |
| 8 | +import os |
6 | 9 | import shutil |
7 | 10 | import subprocess |
8 | 11 | import sys |
|
14 | 17 | REPO_ROOT = CODEX_CLI_ROOT.parent |
15 | 18 | RESPONSES_API_PROXY_NPM_ROOT = REPO_ROOT / "codex-rs" / "responses-api-proxy" / "npm" |
16 | 19 | CODEX_SDK_ROOT = REPO_ROOT / "sdk" / "typescript" |
17 | | -CODEX_NPM_NAME = "@openai/codex" |
| 20 | +CODEX_NPM_NAME = "@leonw24/open-codex" |
18 | 21 |
|
19 | 22 | # `npm_name` is the local optional-dependency alias consumed by `bin/codex.js`. |
20 | | -# The underlying package published to npm is always `@openai/codex`. |
| 23 | +# The underlying package published to npm is always `@leonw24/open-codex`. |
21 | 24 | CODEX_PLATFORM_PACKAGES: dict[str, dict[str, str]] = { |
22 | 25 | "codex-linux-x64": { |
23 | | - "npm_name": "@openai/codex-linux-x64", |
| 26 | + "npm_name": "@leonw24/open-codex-linux-x64", |
24 | 27 | "npm_tag": "linux-x64", |
25 | | - "target_triple": "x86_64-unknown-linux-musl", |
| 28 | + "target_triple": "x86_64-unknown-linux-gnu", |
26 | 29 | "os": "linux", |
27 | 30 | "cpu": "x64", |
28 | 31 | }, |
29 | 32 | "codex-linux-arm64": { |
30 | | - "npm_name": "@openai/codex-linux-arm64", |
| 33 | + "npm_name": "@leonw24/open-codex-linux-arm64", |
31 | 34 | "npm_tag": "linux-arm64", |
32 | | - "target_triple": "aarch64-unknown-linux-musl", |
| 35 | + "target_triple": "aarch64-unknown-linux-gnu", |
33 | 36 | "os": "linux", |
34 | 37 | "cpu": "arm64", |
35 | 38 | }, |
36 | 39 | "codex-darwin-x64": { |
37 | | - "npm_name": "@openai/codex-darwin-x64", |
| 40 | + "npm_name": "@leonw24/open-codex-darwin-x64", |
38 | 41 | "npm_tag": "darwin-x64", |
39 | 42 | "target_triple": "x86_64-apple-darwin", |
40 | 43 | "os": "darwin", |
41 | 44 | "cpu": "x64", |
42 | 45 | }, |
43 | 46 | "codex-darwin-arm64": { |
44 | | - "npm_name": "@openai/codex-darwin-arm64", |
| 47 | + "npm_name": "@leonw24/open-codex-darwin-arm64", |
45 | 48 | "npm_tag": "darwin-arm64", |
46 | 49 | "target_triple": "aarch64-apple-darwin", |
47 | 50 | "os": "darwin", |
48 | 51 | "cpu": "arm64", |
49 | 52 | }, |
50 | 53 | "codex-win32-x64": { |
51 | | - "npm_name": "@openai/codex-win32-x64", |
| 54 | + "npm_name": "@leonw24/open-codex-win32-x64", |
52 | 55 | "npm_tag": "win32-x64", |
53 | 56 | "target_triple": "x86_64-pc-windows-msvc", |
54 | 57 | "os": "win32", |
55 | 58 | "cpu": "x64", |
56 | 59 | }, |
57 | 60 | "codex-win32-arm64": { |
58 | | - "npm_name": "@openai/codex-win32-arm64", |
| 61 | + "npm_name": "@leonw24/open-codex-win32-arm64", |
59 | 62 | "npm_tag": "win32-arm64", |
60 | 63 | "target_triple": "aarch64-pc-windows-msvc", |
61 | 64 | "os": "win32", |
|
95 | 98 | } |
96 | 99 |
|
97 | 100 |
|
| 101 | +def platform_packages_for_meta() -> list[str]: |
| 102 | + requested = os.environ.get("CODEX_NPM_PLATFORM_PACKAGES") |
| 103 | + if not requested: |
| 104 | + return [ |
| 105 | + platform_package |
| 106 | + for platform_package in PACKAGE_EXPANSIONS["codex"] |
| 107 | + if platform_package != "codex" |
| 108 | + ] |
| 109 | + |
| 110 | + packages = [package.strip() for package in requested.split(",") if package.strip()] |
| 111 | + unknown = [package for package in packages if package not in CODEX_PLATFORM_PACKAGES] |
| 112 | + if unknown: |
| 113 | + unknown_list = ", ".join(sorted(unknown)) |
| 114 | + raise RuntimeError(f"Unknown CODEX_NPM_PLATFORM_PACKAGES entries: {unknown_list}") |
| 115 | + return packages |
| 116 | + |
| 117 | + |
98 | 118 | def parse_args() -> argparse.Namespace: |
99 | 119 | parser = argparse.ArgumentParser(description="Build or stage the Codex CLI npm package.") |
100 | 120 | parser.add_argument( |
@@ -308,8 +328,7 @@ def stage_sources(staging_dir: Path, version: str, package: str) -> None: |
308 | 328 | f"npm:{CODEX_NPM_NAME}@" |
309 | 329 | f"{compute_platform_package_version(version, CODEX_PLATFORM_PACKAGES[platform_package]['npm_tag'])}" |
310 | 330 | ) |
311 | | - for platform_package in PACKAGE_EXPANSIONS["codex"] |
312 | | - if platform_package != "codex" |
| 331 | + for platform_package in platform_packages_for_meta() |
313 | 332 | } |
314 | 333 |
|
315 | 334 | elif package == "codex-sdk": |
@@ -419,7 +438,9 @@ def run_npm_pack(staging_dir: Path, output_path: Path) -> Path: |
419 | 438 | output_path = output_path.resolve() |
420 | 439 | output_path.parent.mkdir(parents=True, exist_ok=True) |
421 | 440 |
|
422 | | - with tempfile.TemporaryDirectory(prefix="codex-npm-pack-") as pack_dir_str: |
| 441 | + runner_temp = Path(os.environ.get("RUNNER_TEMP", tempfile.gettempdir())) |
| 442 | + runner_temp.mkdir(parents=True, exist_ok=True) |
| 443 | + with tempfile.TemporaryDirectory(prefix="codex-npm-pack-", dir=runner_temp) as pack_dir_str: |
423 | 444 | pack_dir = Path(pack_dir_str) |
424 | 445 | stdout = subprocess.check_output( |
425 | 446 | ["npm", "pack", "--json", "--pack-destination", str(pack_dir)], |
|
0 commit comments