mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-28 20:11:48 -04:00
fix: remove bins when uninstalling global packages
Ref https://github.com/pnpm/pnpm/issues/749
This commit is contained in:
@@ -53,6 +53,7 @@ export async function prune(maybeOpts?: PnpmOptions): Promise<void> {
|
||||
store: ctx.storePath,
|
||||
storeIndex: ctx.storeIndex,
|
||||
pruneStore: true,
|
||||
bin: opts.bin,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ export default async function removeOrphanPkgs (
|
||||
opts: {
|
||||
oldShrinkwrap: Shrinkwrap,
|
||||
newShrinkwrap: Shrinkwrap,
|
||||
bin: string,
|
||||
prefix: string,
|
||||
store: string,
|
||||
storeIndex: Store,
|
||||
@@ -29,7 +30,10 @@ export default async function removeOrphanPkgs (
|
||||
name: depName[0],
|
||||
dev: Boolean(opts.oldShrinkwrap.devDependencies && opts.oldShrinkwrap.devDependencies[depName[0]]),
|
||||
optional: Boolean(opts.oldShrinkwrap.optionalDependencies && opts.oldShrinkwrap.optionalDependencies[depName[0]]),
|
||||
}, rootModules)
|
||||
}, {
|
||||
modules: rootModules,
|
||||
bin: opts.bin,
|
||||
})
|
||||
}))
|
||||
|
||||
const oldPkgIds = R.keys(opts.oldShrinkwrap.packages).map(depPath => dp.resolve(opts.oldShrinkwrap.registry, depPath))
|
||||
|
||||
@@ -72,6 +72,7 @@ export async function uninstallInContext (pkgsToUninstall: string[], ctx: PnpmCo
|
||||
prefix: ctx.root,
|
||||
store: ctx.storePath,
|
||||
storeIndex: ctx.storeIndex,
|
||||
bin: opts.bin,
|
||||
})
|
||||
const privateShrinkwrap = makePartialPrivateShrinkwrap
|
||||
? pruneShrinkwrap(ctx.privateShrinkwrap, pkg)
|
||||
@@ -84,7 +85,10 @@ export async function uninstallInContext (pkgsToUninstall: string[], ctx: PnpmCo
|
||||
layoutVersion: LAYOUT_VERSION,
|
||||
independentLeaves: opts.independentLeaves,
|
||||
})
|
||||
await removeOuterLinks(pkgsToUninstall, path.join(ctx.root, 'node_modules'), {storePath: ctx.storePath})
|
||||
await removeOuterLinks(pkgsToUninstall, path.join(ctx.root, 'node_modules'), {
|
||||
storePath: ctx.storePath,
|
||||
bin: opts.bin,
|
||||
})
|
||||
|
||||
logger('summary').info()
|
||||
}
|
||||
@@ -94,6 +98,7 @@ async function removeOuterLinks (
|
||||
modules: string,
|
||||
opts: {
|
||||
storePath: string,
|
||||
bin: string,
|
||||
}
|
||||
) {
|
||||
// These packages are not in package.json, they were just linked in not installed
|
||||
@@ -103,7 +108,10 @@ async function removeOuterLinks (
|
||||
name: pkgToUninstall,
|
||||
dev: false,
|
||||
optional: false,
|
||||
}, modules)
|
||||
}, {
|
||||
modules,
|
||||
bin: opts.bin,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ export default async function (
|
||||
prefix: opts.root,
|
||||
store: opts.storePath,
|
||||
storeIndex: opts.storeIndex,
|
||||
bin: opts.bin,
|
||||
})
|
||||
|
||||
let flatResolvedDeps = R.values(pkgsToLink).filter(dep => !opts.skipped.has(dep.id))
|
||||
|
||||
@@ -10,11 +10,14 @@ export default async function removeTopDependency (
|
||||
dev: boolean,
|
||||
optional: boolean,
|
||||
},
|
||||
modules: string
|
||||
opts: {
|
||||
modules: string,
|
||||
bin: string,
|
||||
}
|
||||
) {
|
||||
const results = await Promise.all([
|
||||
removeBins(dependency.name, modules),
|
||||
rimraf(path.join(modules, dependency.name)),
|
||||
removeBins(dependency.name, opts),
|
||||
rimraf(path.join(opts.modules, dependency.name)),
|
||||
])
|
||||
|
||||
const uninstalledPkg = results[0]
|
||||
@@ -27,14 +30,20 @@ export default async function removeTopDependency (
|
||||
})
|
||||
}
|
||||
|
||||
async function removeBins (uninstalledPkg: string, modules: string) {
|
||||
const uninstalledPkgPath = path.join(modules, uninstalledPkg)
|
||||
async function removeBins (
|
||||
uninstalledPkg: string,
|
||||
opts: {
|
||||
modules: string,
|
||||
bin: string,
|
||||
}
|
||||
) {
|
||||
const uninstalledPkgPath = path.join(opts.modules, uninstalledPkg)
|
||||
const uninstalledPkgJson = await safeReadPkgFromDir(uninstalledPkgPath)
|
||||
|
||||
if (!uninstalledPkgJson) return
|
||||
const cmds = await binify(uninstalledPkgJson, uninstalledPkgPath)
|
||||
await Promise.all(
|
||||
cmds.map(cmd => path.join(modules, '.bin', cmd.name)).map(rimraf)
|
||||
cmds.map(cmd => path.join(opts.bin, cmd.name)).map(rimraf)
|
||||
)
|
||||
|
||||
return uninstalledPkgJson
|
||||
|
||||
Reference in New Issue
Block a user