mirror of
https://github.com/NanmiCoder/claude-code-haha.git
synced 2026-10-10 20:03:13 +08:00
fix(desktop): install adapter dependencies for macOS builds
This commit is contained in:
@@ -5,6 +5,7 @@ set -euo pipefail
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
DESKTOP_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
REPO_ROOT="$(cd "${DESKTOP_DIR}/.." && pwd)"
|
||||
ADAPTERS_DIR="${REPO_ROOT}/adapters"
|
||||
|
||||
TARGET_TRIPLE="aarch64-apple-darwin"
|
||||
CANONICAL_OUTPUT_DIR="${DESKTOP_DIR}/build-artifacts/macos-arm64"
|
||||
@@ -19,7 +20,7 @@ Usage:
|
||||
./desktop/scripts/build-macos-arm64.sh [extra electron-builder args...]
|
||||
|
||||
Environment:
|
||||
SKIP_INSTALL=1 Skip `bun install` in the repo root and desktop app.
|
||||
SKIP_INSTALL=1 Skip `bun install` in the repo root, desktop app, and adapters package.
|
||||
SIGN_BUILD=0 Force an unsigned (ad-hoc) build. Signing is ON by default
|
||||
when a stable identity exists in the keychain, because
|
||||
Computer Use requires host + sidecar + helper to share one
|
||||
@@ -92,6 +93,9 @@ if [[ "${SKIP_INSTALL:-0}" != "1" ]]; then
|
||||
|
||||
echo "[build-macos-arm64] Installing desktop dependencies..."
|
||||
(cd "${DESKTOP_DIR}" && bun install)
|
||||
|
||||
echo "[build-macos-arm64] Installing adapter dependencies..."
|
||||
(cd "${ADAPTERS_DIR}" && bun install)
|
||||
fi
|
||||
|
||||
echo "[build-macos-arm64] Cleaning stale Electron outputs..."
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
// @vitest-environment node
|
||||
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { copyFile, chmod, mkdir, mkdtemp, rm, stat, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import path from 'node:path'
|
||||
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
async function exists(pathname: string): Promise<boolean> {
|
||||
return stat(pathname).then(() => true, () => false)
|
||||
}
|
||||
|
||||
async function writeExecutable(pathname: string, source: string): Promise<void> {
|
||||
await writeFile(pathname, source, 'utf8')
|
||||
await chmod(pathname, 0o755)
|
||||
}
|
||||
|
||||
describe('macOS arm64 build dependency installation', () => {
|
||||
it('installs every package needed by the compiled sidecar in a clean worktree', async () => {
|
||||
const fixtureRoot = await mkdtemp(path.join(tmpdir(), 'cc-haha-macos-build-'))
|
||||
const desktopDir = path.join(fixtureRoot, 'desktop')
|
||||
const adaptersDir = path.join(fixtureRoot, 'adapters')
|
||||
const scriptsDir = path.join(desktopDir, 'scripts')
|
||||
const fakeBinDir = path.join(fixtureRoot, 'fake-bin')
|
||||
const buildScript = path.join(scriptsDir, 'build-macos-arm64.sh')
|
||||
|
||||
try {
|
||||
await Promise.all([
|
||||
mkdir(scriptsDir, { recursive: true }),
|
||||
mkdir(adaptersDir, { recursive: true }),
|
||||
mkdir(fakeBinDir, { recursive: true }),
|
||||
])
|
||||
await copyFile(
|
||||
path.resolve(import.meta.dirname, 'build-macos-arm64.sh'),
|
||||
buildScript,
|
||||
)
|
||||
await chmod(buildScript, 0o755)
|
||||
|
||||
await writeExecutable(path.join(fakeBinDir, 'uname'), `#!/bin/bash
|
||||
if [[ "\${1:-}" == "-s" ]]; then
|
||||
echo Darwin
|
||||
elif [[ "\${1:-}" == "-m" ]]; then
|
||||
echo arm64
|
||||
fi
|
||||
`)
|
||||
await writeExecutable(path.join(fakeBinDir, 'bun'), `#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ "\${1:-}" == "install" ]]; then
|
||||
mkdir -p "\${PWD}/node_modules"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "\${*}" == *"build:sidecars"* ]]; then
|
||||
for package_dir in "\${TEST_REPO_ROOT}" "\${TEST_REPO_ROOT}/desktop" "\${TEST_REPO_ROOT}/adapters"; do
|
||||
[[ -d "\${package_dir}/node_modules" ]] || exit 42
|
||||
done
|
||||
exit 86
|
||||
fi
|
||||
|
||||
exit 0
|
||||
`)
|
||||
for (const command of ['node', 'codesign', 'hdiutil']) {
|
||||
await writeExecutable(path.join(fakeBinDir, command), '#!/bin/bash\nexit 0\n')
|
||||
}
|
||||
|
||||
expect(await Promise.all([
|
||||
exists(path.join(fixtureRoot, 'node_modules')),
|
||||
exists(path.join(desktopDir, 'node_modules')),
|
||||
exists(path.join(adaptersDir, 'node_modules')),
|
||||
])).toEqual([false, false, false])
|
||||
|
||||
const result = spawnSync('/bin/bash', [buildScript], {
|
||||
cwd: desktopDir,
|
||||
encoding: 'utf8',
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: `${fakeBinDir}:${process.env.PATH ?? ''}`,
|
||||
MAC_TARGETS: 'zip',
|
||||
SIGN_BUILD: '0',
|
||||
TEST_REPO_ROOT: fixtureRoot,
|
||||
},
|
||||
})
|
||||
|
||||
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(86)
|
||||
expect(await Promise.all([
|
||||
exists(path.join(fixtureRoot, 'node_modules')),
|
||||
exists(path.join(desktopDir, 'node_modules')),
|
||||
exists(path.join(adaptersDir, 'node_modules')),
|
||||
])).toEqual([true, true, true])
|
||||
} finally {
|
||||
await rm(fixtureRoot, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user