also looking at this
fix(ci): publish darwin-x86-64 (Intel macOS) — retire macos-13 + fix bun bootstrap
#205
7 files
+427
-348
| @@ -197,6 +197,58 @@ const resolvers: Record<string, PackageResolver> = { | ||
| 197 | 197 | |
| 198 | 198 | // ── Core Install Function ── |
| 199 | 199 | |
| 200 | /** | |
| 201 | * (Re)create the `.bin/<name>` links for an installed package, pointing each at | |
| 202 | * the real binary under `pkgDir` (root or `bin/` subdir). Binaries absent from | |
| 203 | * the archive (e.g. `bunx`, `npx`) are aliased to the primary binary. | |
| 204 | * | |
| 205 | * This is intentionally idempotent and always run — including for already-installed | |
| 206 | * packages — so a real binary reliably *owns* its `.bin` entry. Without this, a | |
| 207 | * second installer writing the same dir (e.g. a registry client that drops a | |
| 208 | * placeholder stub for a platform it lacks) could leave `.bin/<name>` pointing at | |
| 209 | * a broken stub even though the genuine binary is present on disk. | |
| 210 | */ | |
| 211 | function linkBinaries(pkgDir: string, binaries: string[], binDir: string, platform: Platform): void { | |
| 212 | fs.mkdirSync(binDir, { recursive: true }) | |
| 213 | let primaryBin: string | null = null | |
| 214 | ||
| 215 | for (const bin of binaries) { | |
| 216 | // Check both root and bin/ subdirectory | |
| 217 | let srcBin = path.join(pkgDir, bin) | |
| 218 | if (!fs.existsSync(srcBin)) { | |
| 219 | srcBin = path.join(pkgDir, 'bin', bin) | |
| 220 | } | |
| 221 | ||
| 222 | if (!fs.existsSync(srcBin)) { | |
| 223 | // Binary doesn't exist in archive — create as alias to primary binary | |
| 224 | // (e.g. bunx -> bun, npx -> node) | |
| 225 | if (primaryBin) { | |
| 226 | const dstBin = path.join(binDir, bin) | |
| 227 | try { fs.unlinkSync(dstBin) } catch { /* */ } | |
| 228 | if (platform.os === 'windows') { | |
| 229 | fs.copyFileSync(primaryBin, dstBin) | |
| 230 | } | |
| 231 | else { | |
| 232 | fs.symlinkSync(primaryBin, dstBin) | |
| 233 | } | |
| 234 | } | |
| 235 | continue | |
| 236 | } | |
| 237 | ||
| 238 | if (!primaryBin) primaryBin = srcBin | |
| 239 | ||
| 240 | const dstBin = path.join(binDir, bin) | |
| 241 | try { fs.unlinkSync(dstBin) } catch { /* doesn't exist */ } | |
| 242 | ||
| 243 | if (platform.os === 'windows') { | |
| 244 | fs.copyFileSync(srcBin, dstBin) | |
| 245 | } | |
| 246 | else { | |
| 247 | fs.symlinkSync(srcBin, dstBin) | |
| 248 | } | |
| 249 | } | |
| 250 | } | |
| 251 | ||
| 200 | 252 | /** |
| 201 | 253 | * Install a system package by downloading from its official source. |
| 202 | 254 | * Works cross-platform using only Node.js APIs. |
| @@ -246,6 +298,11 @@ export async function installPackage( | ||
| 246 | 298 | const firstBinInSubdir = path.join(pkgDir, 'bin', binaries[0]) |
| 247 | 299 | if (fs.existsSync(firstBin) || fs.existsSync(firstBinInSubdir)) { |
| 248 | 300 | if (!options.quiet) console.log(` ✓ ${domain}@${version} (cached)`) |
| 301 | // Re-assert the .bin links even when already installed, so the genuine | |
| 302 | // binary keeps ownership of `.bin/<name>` if another installer clobbered it. | |
| 303 | if (options.createBinLinks !== false) { | |
| 304 | linkBinaries(pkgDir, binaries, binDir, platform) | |
| 305 | } | |
| 249 | 306 | const globalLinks = maybeLinkToGlobalBin(pkgDir, binaries, platform, options) |
| 250 | 307 | return { name: domain, version, installPath: pkgDir, binaries, globalLinks } |
| 251 | 308 | } |
| @@ -304,44 +361,7 @@ export async function installPackage( | ||
| 304 | 361 | |
| 305 | 362 | // Create .bin/ links |
| 306 | 363 | if (options.createBinLinks !== false) { |
| 307 | fs.mkdirSync(binDir, { recursive: true }) | |
| 308 | let primaryBin: string | null = null | |
| 309 | ||
| 310 | for (const bin of binaries) { | |
| 311 | // Check both root and bin/ subdirectory | |
| 312 | let srcBin = path.join(pkgDir, bin) | |
| 313 | if (!fs.existsSync(srcBin)) { | |
| 314 | srcBin = path.join(pkgDir, 'bin', bin) | |
| 315 | } | |
| 316 | ||
| 317 | if (!fs.existsSync(srcBin)) { | |
| 318 | // Binary doesn't exist in archive — create as alias to primary binary | |
| 319 | // (e.g. bunx -> bun, npx -> node) | |
| 320 | if (primaryBin) { | |
| 321 | const dstBin = path.join(binDir, bin) | |
| 322 | try { fs.unlinkSync(dstBin) } catch { /* */ } | |
| 323 | if (platform.os === 'windows') { | |
| 324 | fs.copyFileSync(primaryBin, dstBin) | |
| 325 | } | |
| 326 | else { | |
| 327 | fs.symlinkSync(primaryBin, dstBin) | |
| 328 | } | |
| 329 | } | |
| 330 | continue | |
| 331 | } | |
| 332 | ||
| 333 | if (!primaryBin) primaryBin = srcBin | |
| 334 | ||
| 335 | const dstBin = path.join(binDir, bin) | |
| 336 | try { fs.unlinkSync(dstBin) } catch { /* doesn't exist */ } | |
| 337 | ||
| 338 | if (platform.os === 'windows') { | |
| 339 | fs.copyFileSync(srcBin, dstBin) | |
| 340 | } | |
| 341 | else { | |
| 342 | fs.symlinkSync(srcBin, dstBin) | |
| 343 | } | |
| 344 | } | |
| 364 | linkBinaries(pkgDir, binaries, binDir, platform) | |
| 345 | 365 | } |
| 346 | 366 | |
| 347 | 367 | if (!options.quiet) console.log(` ✓ ${domain}@${version}`) |