Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function uninstallInContext (
pkgsToUninstall: string[],
ctx: PnpmSingleContext,
opts: StrictUninstallOptions,
) {
const makePartialCurrentLockfile = !lockfilesEqual(ctx.currentLockfile, ctx.wantedLockfile)
const saveType = getSaveType(opts)
const pkg = await removeDeps(ctx.manifest, pkgsToUninstall, { prefix: opts.prefix, saveType })
const newLockfile = pruneLockfile(ctx.wantedLockfile, pkg, ctx.importerId, {
defaultRegistry: ctx.registries.default,
warn: (message) => logger.warn({ message, prefix: ctx.prefix }),
})
const removedPkgIds = await prune({
importers: [
{
bin: opts.bin,
hoistedAliases: ctx.hoistedAliases,
id: ctx.importerId,
modulesDir: ctx.modulesDir,
prefix: ctx.prefix,
removePackages: pkgsToUninstall,
shamefullyFlatten: opts.shamefullyFlatten,
},
],
lockfileDirectory: opts.lockfileDirectory,
prefix: ctx.prefix,
removePackages: pkgsToUninstall,
shamefullyFlatten: opts.shamefullyFlatten,
},
],
lockfileDirectory: opts.lockfileDirectory,
newLockfile,
oldLockfile: ctx.currentLockfile,
registries: ctx.registries,
storeController: opts.storeController,
virtualStoreDir: ctx.virtualStoreDir,
})
ctx.pendingBuilds = ctx.pendingBuilds.filter((pkgId) => !removedPkgIds.has(dp.resolve(ctx.registries, pkgId)))
await opts.storeController.close()
const currentLockfile = makePartialCurrentLockfile
? pruneLockfile(ctx.currentLockfile, pkg, ctx.importerId, { defaultRegistry: ctx.registries.default })
: newLockfile
const lockfileOpts = { forceSharedFormat: opts.forceSharedLockfile }
if (opts.useLockfile) {
await writeLockfiles(ctx.lockfileDirectory, newLockfile, currentLockfile, lockfileOpts)
} else {
await writeCurrentLockfile(ctx.lockfileDirectory, currentLockfile, lockfileOpts)
}
if (opts.shamefullyFlatten) {
ctx.hoistedAliases = await shamefullyFlattenByLockfile(currentLockfile, ctx.importerId, {
getIndependentPackageLocation: opts.independentLeaves
? async (packageId: string, packageName: string) => {
const { directory } = await opts.storeController.getPackageLocation(packageId, packageName, {
lockfileDirectory: ctx.lockfileDirectory,
targetEngine: opts.sideEffectsCacheRead && ENGINE_NAME || undefined,
})