From 34092ec19324d3d573de9b88f3cca9c37158c513 Mon Sep 17 00:00:00 2001 From: leeguooooo Date: Tue, 3 Mar 2026 17:12:17 +0900 Subject: [PATCH] fix: prevent stale native version and skip npm-bin rewrite on pnpm --- package.json | 5 +++-- scripts/postinstall.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 091f7b6..14b90a4 100644 --- a/package.json +++ b/package.json @@ -18,10 +18,11 @@ "prepare": "husky", "version:sync": "node scripts/sync-version.js", "version": "npm run version:sync && git add cli/Cargo.toml", + "native:clean": "cargo clean --manifest-path cli/Cargo.toml -p agent-browser-stealth", "build": "tsc", - "build:native": "npm run version:sync && cargo build --release --manifest-path cli/Cargo.toml && node scripts/copy-native.js", + "build:native": "npm run version:sync && npm run native:clean && cargo build --release --manifest-path cli/Cargo.toml && node scripts/copy-native.js", "build:linux": "npm run version:sync && docker compose -f docker/docker-compose.yml run --rm build-linux", - "build:macos": "npm run version:sync && (cargo build --release --manifest-path cli/Cargo.toml --target aarch64-apple-darwin & cargo build --release --manifest-path cli/Cargo.toml --target x86_64-apple-darwin & wait) && cp cli/target/aarch64-apple-darwin/release/agent-browser bin/agent-browser-darwin-arm64 && cp cli/target/x86_64-apple-darwin/release/agent-browser bin/agent-browser-darwin-x64", + "build:macos": "npm run version:sync && npm run native:clean && (cargo build --release --manifest-path cli/Cargo.toml --target aarch64-apple-darwin & cargo build --release --manifest-path cli/Cargo.toml --target x86_64-apple-darwin & wait) && cp cli/target/aarch64-apple-darwin/release/agent-browser bin/agent-browser-darwin-arm64 && cp cli/target/x86_64-apple-darwin/release/agent-browser bin/agent-browser-darwin-x64", "build:windows": "npm run version:sync && docker compose -f docker/docker-compose.yml run --rm build-windows", "build:all-platforms": "npm run version:sync && (npm run build:linux & npm run build:windows & wait) && npm run build:macos", "build:docker": "docker build -t agent-browser-builder -f docker/Dockerfile.build .", diff --git a/scripts/postinstall.js b/scripts/postinstall.js index fed8e80..2f4ff10 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -161,7 +161,19 @@ function showPlaywrightReminder() { * Fix npm's bin entry on global installs to use the native binary directly. * This provides zero-overhead CLI execution for global installs. */ +function isPnpmGlobalInstall() { + const ua = process.env.npm_config_user_agent || ''; + return ua.includes('pnpm/'); +} + async function fixGlobalInstallBin() { + // pnpm already manages global shims in its own bin dir. + // Rewriting links via `npm prefix -g` can create stale links in unrelated paths + // (e.g. /opt/homebrew/bin), which then shadow pnpm's up-to-date shims. + if (isPnpmGlobalInstall()) { + return; + } + if (platform() === 'win32') { await fixWindowsShims(); } else {