Skip to content

Commit e1b2438

Browse files
RyanLee-Devclaude
andcommitted
refactor: Node.js only, drop platform binaries
Require Node.js 18+, ship a single minimax.mjs (~112KB). No more cross-compilation for 7 platforms. - build.ts: 50 lines → 20 lines, only produces minimax.mjs + manifest - install.sh: drop OS/arch/musl/Rosetta detection, just check node >= 18 - release.yml: upload only minimax.mjs + manifest.json - package.json: remove bin/files/build:npm/prepublishOnly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 97c34f9 commit e1b2438

4 files changed

Lines changed: 36 additions & 125 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ jobs:
2323
- uses: oven-sh/setup-bun@v2
2424
- run: bun install
2525

26-
- name: Build all targets
26+
- name: Build
2727
run: VERSION=${GITHUB_REF_NAME} bun run build.ts
2828

2929
- name: Create GitHub Release
3030
uses: softprops/action-gh-release@v2
3131
with:
3232
files: |
33-
dist/minimax-*
3433
dist/minimax.mjs
3534
dist/manifest.json
3635
generate_release_notes: true

build.ts

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,27 @@
1-
import { $ } from 'bun';
21
import { createHash } from 'crypto';
32
import { readFileSync, writeFileSync } from 'fs';
43

54
const VERSION = process.env.VERSION ?? 'dev';
6-
7-
const targets = [
8-
{ bunTarget: 'bun-linux-x64', platform: 'linux-x64', output: 'minimax-linux-x64' },
9-
{ bunTarget: 'bun-linux-x64-musl', platform: 'linux-x64-musl', output: 'minimax-linux-x64-musl' },
10-
{ bunTarget: 'bun-linux-arm64', platform: 'linux-arm64', output: 'minimax-linux-arm64' },
11-
{ bunTarget: 'bun-linux-arm64-musl', platform: 'linux-arm64-musl', output: 'minimax-linux-arm64-musl' },
12-
{ bunTarget: 'bun-darwin-x64', platform: 'darwin-x64', output: 'minimax-darwin-x64' },
13-
{ bunTarget: 'bun-darwin-arm64', platform: 'darwin-arm64', output: 'minimax-darwin-arm64' },
14-
{ bunTarget: 'bun-windows-x64', platform: 'windows-x64', output: 'minimax-windows-x64.exe' },
15-
];
5+
const OUT = 'dist/minimax.mjs';
166

177
function sha256(path: string): string {
188
return createHash('sha256').update(readFileSync(path)).digest('hex');
199
}
2010

21-
console.log(`Building minimax-cli ${VERSION}...\n`);
22-
23-
const manifest: {
24-
version: string;
25-
platforms: Record<string, { file: string; checksum: string }>;
26-
} = { version: VERSION, platforms: {} };
27-
28-
// Platform standalones
29-
for (const { bunTarget, platform, output } of targets) {
30-
const outPath = `dist/${output}`;
31-
process.stdout.write(` ${output}...`);
32-
33-
await $`bun build src/main.ts \
34-
--compile \
35-
--minify \
36-
--target ${bunTarget} \
37-
--outfile ${outPath} \
38-
--define "process.env.CLI_VERSION='${VERSION}'"`.quiet();
39-
40-
manifest.platforms[platform] = { file: output, checksum: sha256(outPath) };
41-
console.log(' ✓');
42-
}
43-
44-
// Node.js .mjs bundle (much smaller, requires node >= 18)
45-
process.stdout.write(' minimax.mjs...');
46-
const mjsPath = 'dist/minimax.mjs';
47-
48-
await $`bun build src/main.ts \
49-
--outfile ${mjsPath} \
50-
--target node \
51-
--minify \
52-
--define "process.env.CLI_VERSION='${VERSION}'"`.quiet();
11+
console.log(`Building minimax-cli ${VERSION}...`);
5312

54-
// Prepend shebang so the file is directly executable
55-
const mjsContent = readFileSync(mjsPath);
56-
writeFileSync(mjsPath, Buffer.concat([Buffer.from('#!/usr/bin/env node\n'), mjsContent]));
13+
await Bun.build({
14+
entrypoints: ['src/main.ts'],
15+
outdir: 'dist',
16+
naming: 'minimax.mjs',
17+
target: 'node',
18+
minify: true,
19+
define: { 'process.env.CLI_VERSION': JSON.stringify(VERSION) },
20+
});
5721

58-
manifest.platforms['node'] = { file: 'minimax.mjs', checksum: sha256(mjsPath) };
59-
console.log(' ✓');
22+
// Prepend shebang
23+
const content = readFileSync(OUT);
24+
writeFileSync(OUT, Buffer.concat([Buffer.from('#!/usr/bin/env node\n'), content]));
6025

61-
writeFileSync('dist/manifest.json', JSON.stringify(manifest, null, 2));
62-
console.log(' manifest.json ✓');
63-
console.log(`\nDone. ${targets.length + 1} builds in dist/`);
26+
writeFileSync('dist/manifest.json', JSON.stringify({ version: VERSION, checksum: sha256(OUT) }, null, 2));
27+
console.log(`Done. dist/minimax.mjs ${(content.length / 1024).toFixed(0)}KB`);

install.sh

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ esac
1616
REPO="MiniMax-AI-Dev/cli"
1717
INSTALL_DIR="${MINIMAX_INSTALL_DIR:-$HOME/.local/bin}"
1818

19+
# Require Node.js >= 18
20+
if ! command -v node >/dev/null 2>&1; then
21+
echo "Node.js is required. Install from https://nodejs.org" >&2; exit 1
22+
fi
23+
NODE_MAJOR=$(node --version 2>/dev/null | sed 's/v//' | cut -d. -f1)
24+
if [ -z "$NODE_MAJOR" ] || [ "$NODE_MAJOR" -lt 18 ] 2>/dev/null; then
25+
echo "Node.js 18+ is required (found: $(node --version))" >&2; exit 1
26+
fi
27+
1928
# Dependency check: curl or wget
2029
if command -v curl >/dev/null 2>&1; then
2130
download() { curl -fsSL "$1"; }
@@ -27,48 +36,6 @@ else
2736
echo "curl or wget is required." >&2; exit 1
2837
fi
2938

30-
# Prefer Node.js >= 18 (much smaller download, ~200KB vs ~57MB)
31-
USE_NODE=0
32-
if command -v node >/dev/null 2>&1; then
33-
NODE_MAJOR=$(node --version 2>/dev/null | sed 's/v//' | cut -d. -f1)
34-
if [ -n "$NODE_MAJOR" ] && [ "$NODE_MAJOR" -ge 18 ] 2>/dev/null; then
35-
USE_NODE=1
36-
fi
37-
fi
38-
39-
if [ "$USE_NODE" = "0" ]; then
40-
# Detect OS
41-
case "$(uname -s)" in
42-
Darwin) OS="darwin" ;;
43-
Linux) OS="linux" ;;
44-
*) echo "Unsupported OS: $(uname -s)" >&2; exit 1 ;;
45-
esac
46-
47-
# Detect architecture
48-
case "$(uname -m)" in
49-
x86_64|amd64) ARCH="x64" ;;
50-
arm64|aarch64) ARCH="arm64" ;;
51-
*) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
52-
esac
53-
54-
# Rosetta 2: x64 shell on ARM Mac → use native arm64 binary
55-
if [ "$OS" = "darwin" ] && [ "$ARCH" = "x64" ]; then
56-
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then
57-
ARCH="arm64"
58-
fi
59-
fi
60-
61-
# musl detection on Linux
62-
PLATFORM="${OS}-${ARCH}"
63-
if [ "$OS" = "linux" ]; then
64-
if [ -f /lib/libc.musl-x86_64.so.1 ] || \
65-
[ -f /lib/libc.musl-aarch64.so.1 ] || \
66-
ldd /bin/ls 2>&1 | grep -q musl; then
67-
PLATFORM="${OS}-${ARCH}-musl"
68-
fi
69-
fi
70-
fi
71-
7239
# Resolve version from channel
7340
GH_API="https://api.github.com/repos/${REPO}"
7441
case "$CHANNEL" in
@@ -89,34 +56,23 @@ if [ -z "$VERSION" ]; then
8956
echo "Failed to resolve version." >&2; exit 1
9057
fi
9158

92-
BASE_URL="https://github.com/${REPO}/releases/download/${VERSION}"
93-
94-
# Fetch manifest and extract checksum
95-
MANIFEST=$(download "${BASE_URL}/manifest.json") || {
96-
echo "Failed to fetch manifest.json" >&2; exit 1
97-
}
59+
echo "Installing minimax ${VERSION}..."
9860

99-
if [ "$USE_NODE" = "1" ]; then
100-
PLATFORM="node"
101-
DOWNLOAD_FILE="minimax.mjs"
102-
echo "Installing minimax ${VERSION} (Node.js)..."
103-
else
104-
DOWNLOAD_FILE="minimax-${PLATFORM}"
105-
echo "Installing minimax ${VERSION} for ${PLATFORM}..."
106-
fi
61+
BASE_URL="https://github.com/${REPO}/releases/download/${VERSION}"
10762

108-
CHECKSUM=$(printf '%s' "$MANIFEST" | tr -d '\n' | \
109-
sed "s/.*\"${PLATFORM}\"[^}]*\"checksum\" *: *\"\([a-f0-9]*\)\".*/\1/")
63+
# Fetch checksum from manifest
64+
CHECKSUM=$(download "${BASE_URL}/manifest.json" \
65+
| grep '"checksum"' | sed 's/.*"checksum": *"\([^"]*\)".*/\1/')
11066

11167
if [ -z "$CHECKSUM" ] || [ "${#CHECKSUM}" -ne 64 ]; then
112-
echo "Platform '${PLATFORM}' not found in manifest." >&2; exit 1
68+
echo "Failed to fetch manifest." >&2; exit 1
11369
fi
11470

115-
# Download to temp file
71+
# Download
11672
TMP=$(mktemp)
11773
trap 'rm -f "$TMP"' EXIT
11874

119-
download_to "${BASE_URL}/${DOWNLOAD_FILE}" "$TMP" || {
75+
download_to "${BASE_URL}/minimax.mjs" "$TMP" || {
12076
echo "Download failed." >&2; exit 1
12177
}
12278

package.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,16 @@
22
"name": "minimax-cli",
33
"version": "0.3.1",
44
"private": true,
5-
"description": "CLI for the MiniMax API Platform (Token Plan)",
5+
"description": "CLI for the MiniMax AI Platform",
66
"type": "module",
7-
"bin": {
8-
"minimax": "./dist/minimax.mjs"
9-
},
10-
"files": [
11-
"dist/minimax.mjs"
12-
],
137
"scripts": {
148
"dev": "bun run src/main.ts",
159
"build": "bun run build.ts",
16-
"build:dev": "bun build src/main.ts --compile --minify --outfile dist/minimax --define \"process.env.CLI_VERSION='$(node -p \"require('./package.json').version\")'\"",
10+
"build:dev": "bun build src/main.ts --outfile dist/minimax.mjs --target node --minify --define \"process.env.CLI_VERSION='$(node -p \"require('./package.json').version'\")'\" && printf '#!/usr/bin/env node\\n' | cat - dist/minimax.mjs > dist/tmp && mv dist/tmp dist/minimax.mjs && chmod +x dist/minimax.mjs",
1711
"lint": "eslint src/ test/",
1812
"typecheck": "tsc --noEmit",
1913
"test": "bun test",
20-
"test:watch": "bun test --watch",
21-
"build:npm": "bun build src/main.ts --outfile dist/minimax.mjs --target node --define \"process.env.CLI_VERSION='$npm_package_version'\" && printf '#!/usr/bin/env node\\n' | cat - dist/minimax.mjs > dist/tmp && mv dist/tmp dist/minimax.mjs && chmod +x dist/minimax.mjs",
22-
"prepublishOnly": "bun run build:npm"
14+
"test:watch": "bun test --watch"
2315
},
2416
"dependencies": {
2517
"@clack/prompts": "^0.7.0"

0 commit comments

Comments
 (0)