diff --git a/src/api/uninstall.ts b/src/api/uninstall.ts index 32f65b9936..263dac7c1e 100644 --- a/src/api/uninstall.ts +++ b/src/api/uninstall.ts @@ -46,14 +46,6 @@ export async function uninstallInContext (pkgsToUninstall: string[], ctx: PnpmCo const pkgJsonPath = path.join(ctx.root, 'package.json') const saveType = getSaveType(opts) const pkg = await removeDeps(pkgJsonPath, pkgsToUninstall, saveType) - if (ctx.shrinkwrap.dependencies) { - for (let depName in ctx.shrinkwrap.dependencies) { - if (!isDependentOn(pkg, depName)) { - delete ctx.shrinkwrap.dependencies[depName] - delete ctx.shrinkwrap.specifiers[depName] - } - } - } const newShr = await pruneShrinkwrap(ctx.shrinkwrap, pkg) const removedPkgIds = await removeOrphanPkgs(ctx.privateShrinkwrap, newShr, ctx.root, ctx.storePath) await saveShrinkwrap(ctx.root, newShr) @@ -67,15 +59,6 @@ export async function uninstallInContext (pkgsToUninstall: string[], ctx: PnpmCo await removeOuterLinks(pkgsToUninstall, path.join(ctx.root, 'node_modules'), {storePath: ctx.storePath}) } -function isDependentOn (pkg: Package, depName: string): boolean { - return [ - 'dependencies', - 'devDependencies', - 'optionalDependencies', - ] - .some(deptype => pkg[deptype] && pkg[deptype][depName]) -} - async function removeOuterLinks ( pkgsToUninstall: string[], modules: string, diff --git a/src/getSaveType.ts b/src/getSaveType.ts index afe9bbc9db..eee4fda540 100644 --- a/src/getSaveType.ts +++ b/src/getSaveType.ts @@ -6,6 +6,6 @@ export const dependenciesTypes: DependenciesType[] = ['dependencies', 'devDepend export default function getSaveType (opts: PnpmOptions): DependenciesType | undefined { if (opts.saveDev) return 'devDependencies' if (opts.saveOptional) return 'optionalDependencies' - if (opts.save) return 'dependencies' + if (opts.saveProd) return 'dependencies' return undefined } diff --git a/src/types.ts b/src/types.ts index 9f862ff247..bb3210989f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -8,6 +8,7 @@ export type PnpmOptions = { bin?: string, ignoreScripts?: boolean save?: boolean, + saveProd?: boolean, saveDev?: boolean, saveOptional?: boolean, production?: boolean, @@ -63,6 +64,7 @@ export type StrictPnpmOptions = { bin: string, ignoreScripts: boolean save: boolean, + saveProd: boolean, saveDev: boolean, saveOptional: boolean, production: boolean, diff --git a/test/install/updatingPkgJson.ts b/test/install/updatingPkgJson.ts index dd6051af47..c0d99437ae 100644 --- a/test/install/updatingPkgJson.ts +++ b/test/install/updatingPkgJson.ts @@ -135,7 +135,7 @@ test('dependency should be removed from the old field when installing it as a di }, }) await installPkgs(['foo'], testDefaults({saveOptional: true})) - await installPkgs(['bar'], testDefaults({save: true})) + await installPkgs(['bar'], testDefaults({saveProd: true})) await installPkgs(['qar'], testDefaults({saveDev: true})) const pkgJson = await readPkg({normalize: false}) diff --git a/test/uninstall.ts b/test/uninstall.ts index d83701da0f..65f942a481 100644 --- a/test/uninstall.ts +++ b/test/uninstall.ts @@ -19,6 +19,7 @@ import { link, } from '../src' import thenify = require('thenify') +import pnpmCli from '../src/bin/pnpm' const ncp = thenify(ncpCB.ncp) @@ -37,15 +38,18 @@ test('uninstall package with no dependencies', async function (t) { test('uninstall package and remove from appropriate property', async function (t: tape.Test) { const project = prepare(t) - await installPkgs(['is-negative@2.1.0'], testDefaults({ saveDev: true })) - await uninstall(['is-negative'], testDefaults()) + await installPkgs(['is-positive@3.1.0'], testDefaults({ saveOptional: true })) - await project.storeHasNot('is-negative', '2.1.0') + // testing the CLI directly as there was an issue where `npm.config` started to set save = true by default + // npm@5 introduced --save-prod that bahaves the way --save worked in pre 5 versions + await pnpmCli(['uninstall', 'is-positive']) - await project.hasNot('is-negative') + await project.storeHasNot('is-positive', '3.1.0') + + await project.hasNot('is-positive') const pkgJson = await readPkg() - t.equal(pkgJson.dependencies, undefined, 'is-negative has been removed from dependencies') + t.equal(pkgJson.optionalDependencies, undefined, 'is-negative has been removed from optionalDependencies') }) test('uninstall scoped package', async function (t) {