diff --git a/src/api/install.ts b/src/api/install.ts index 686480287c..5a5aad401d 100644 --- a/src/api/install.ts +++ b/src/api/install.ts @@ -148,7 +148,7 @@ async function installInContext (installType: string, packagesToInstall: Depende } } - if (pkgs && pkgs.length && newPkg) { + if (newPkg) { ctx.shrinkwrap.dependencies = ctx.shrinkwrap.dependencies || {} const deps = newPkg.dependencies || {} diff --git a/test/shrinkwrap.ts b/test/shrinkwrap.ts index e57ae86a37..8f718399b9 100644 --- a/test/shrinkwrap.ts +++ b/test/shrinkwrap.ts @@ -85,6 +85,28 @@ test('shrinkwrap not created when no deps in package.json', async t => { t.ok(!await project.loadShrinkwrap(), 'shrinkwrap file not created') }) +test('shrinkwrap removed when no deps in package.json', async t => { + const project = prepare(t) + + await writeYamlFile('shrinkwrap.yaml', { + version: 1, + dependencies: { + 'is-negative@2.1.0': 'localhost+4873/is-negative/2.1.0', + }, + packages: { + 'localhost+4873/is-negative/2.1.0': { + resolution: { + tarball: 'http://localhost:4873/is-negative/-/is-negative-2.1.0.tgz', + }, + }, + }, + }) + + await install(testDefaults()) + + t.ok(!await project.loadShrinkwrap(), 'shrinkwrap file removed') +}) + test('respects shrinkwrap.yaml for top dependencies', async t => { const project = prepare(t)