From 2a5fc3e1de0cbb08d34f56ef37e6dd69a364250f Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 26 Oct 2018 23:17:54 +0300 Subject: [PATCH] fix: uninstall on a project with shared shrinkwrap.yaml ref #1366 --- packages/shrinkwrap/src/write.ts | 4 +- packages/supi/test/uninstall.ts | 86 +++++++++++++++++++++++++++++--- 2 files changed, 81 insertions(+), 9 deletions(-) diff --git a/packages/shrinkwrap/src/write.ts b/packages/shrinkwrap/src/write.ts index 3c0b210577..1dc37a176a 100644 --- a/packages/shrinkwrap/src/write.ts +++ b/packages/shrinkwrap/src/write.ts @@ -102,9 +102,7 @@ function normalizeShrinkwrap (shr: Shrinkwrap, forceSharedFormat: boolean) { if (R.isEmpty(shrToSave.packages)) { delete shrToSave.packages } - if (shrToSave.registry) { - delete shrToSave.registry - } + delete shrToSave.registry return normalizeShrinkwrapVersion(shrToSave) } } diff --git a/packages/supi/test/uninstall.ts b/packages/supi/test/uninstall.ts index 03336c4e9d..e57430fc38 100644 --- a/packages/supi/test/uninstall.ts +++ b/packages/supi/test/uninstall.ts @@ -1,14 +1,14 @@ -import prepare from '@pnpm/prepare' -import tape = require('tape') -import promisifyTape from 'tape-promise' -const test = promisifyTape(tape) +import prepare, { preparePackages } from '@pnpm/prepare' +import exists = require('path-exists') import existsSymlink = require('exists-link') import ncpCB = require('ncp') +import loadYamlFile = require('load-yaml-file') import path = require('path') -import exists = require('path-exists') +import promisifyTape from 'tape-promise' import readPkg = require('read-pkg') -import sinon = require('sinon') +import tape = require('tape') import { + install, installPkgs, link, PackageJsonLog, @@ -17,12 +17,15 @@ import { storePrune, uninstall, } from 'supi' +import sinon = require('sinon') import promisify = require('util.promisify') import { pathToLocalPkg, testDefaults, } from './utils' +const test = promisifyTape(tape) +const testOnly = promisifyTape(tape.only) const ncp = promisify(ncpCB.ncp) test('uninstall package with no dependencies', async (t: tape.Test) => { @@ -179,3 +182,74 @@ test('pendingBuilds gets updated after uninstall', async (t: tape.Test) => { t.ok(modules2) t.equal(modules2!.pendingBuilds.length, 1, 'uninstall should update pendingBuilds') }) + +test('uninstalling a dependency from package that uses shared shrinkwrap', async (t) => { + const projects = preparePackages(t, [ + { + name: 'project-1', + version: '1.0.0', + dependencies: { + 'is-positive': '1.0.0', + }, + }, + { + name: 'project-2', + version: '1.0.0', + dependencies: { + 'is-negative': '1.0.0', + }, + }, + ]) + + const importers = [ + { + prefix: path.resolve('project-1'), + }, + { + prefix: path.resolve('project-2'), + }, + ] + + await install(await testDefaults({ importers })) + + await projects['project-1'].has('is-positive') + await projects['project-2'].has('is-negative') + + await uninstall(['is-positive'], await testDefaults({ + prefix: importers[0].prefix, + shrinkwrapDirectory: process.cwd(), + })) + + await projects['project-1'].hasNot('is-positive') + await projects['project-2'].has('is-negative') + + const shr = await loadYamlFile('shrinkwrap.yaml') + + t.deepEqual(shr, { + importers: { + 'project-1': { + specifiers: {}, + }, + 'project-2': { + dependencies: { + 'is-negative': '1.0.0', + }, + specifiers: { + 'is-negative': '1.0.0', + }, + }, + }, + packages: { + '/is-negative/1.0.0': { + dev: false, + engines: { + node: '>=0.10.0', + }, + resolution: { + integrity: 'sha1-clmHeoPIAKwxkd17nZ+80PdS1P4=', + }, + }, + }, + shrinkwrapVersion: 4, + }) +})