fix: force reinstall in which() when .bin is missing

When the lockfile exists but .bin is empty or absent, add() would
read the lockfile via loadVirtual() and return early without calling
reify(). Delete the lockfile before calling add() so it proceeds
with a full install.
pr-18308
Dax Raad 2026-03-19 21:54:53 -04:00
parent 34c676ba7a
commit c075a5d694
1 changed files with 2 additions and 1 deletions

View File

@ -16,7 +16,7 @@ import { Global } from "../global"
import { Lock } from "../util/lock"
import { Log } from "../util/log"
import path from "path"
import { readdir } from "fs/promises"
import { readdir, rm } from "fs/promises"
import { Filesystem } from "@/util/filesystem"
const { Arborist } = await import("@npmcli/arborist")
@ -172,6 +172,7 @@ export namespace Npm {
const bin = await pick()
if (bin) return path.join(binDir, bin)
await rm(path.join(dir, "package-lock.json"), { force: true })
await add(pkg)
const resolved = await pick()
if (!resolved) throw new Error(`No binary found for package "${pkg}" after install`)