diff --git a/src/index.ts b/src/index.ts index 8b3f469529..b3cdadb903 100644 --- a/src/index.ts +++ b/src/index.ts @@ -146,7 +146,7 @@ export default async (opts: HeadlessOptions) => { const filteredShrinkwrap = filterShrinkwrap(wantedShrinkwrap, filterOpts) stageLogger.debug('importing_started') - const depGraph = await shrinkwrapToDepGraph(filteredShrinkwrap, currentShrinkwrap, opts) + const depGraph = await shrinkwrapToDepGraph(filteredShrinkwrap, opts.force ? null : currentShrinkwrap, opts) statsLogger.debug({added: Object.keys(depGraph).length}) diff --git a/test/index.ts b/test/index.ts index 3f95d46493..b111cf7697 100644 --- a/test/index.ts +++ b/test/index.ts @@ -233,6 +233,44 @@ test('available packages are used when node_modules is not clean', async (t) => t.end() }) +test('available packages are relinked during forced install', async (t) => { + const projectDir = tempy.directory() + t.comment(projectDir) + + const destPackageJsonPath = path.join(projectDir, 'package.json') + const destShrinkwrapYamlPath = path.join(projectDir, 'shrinkwrap.yaml') + + const hasGlobDir = path.join(fixtures, 'has-glob') + const hasGlobAndRimrafDir = path.join(fixtures, 'has-glob-and-rimraf') + fse.copySync(path.join(hasGlobDir, 'package.json'), destPackageJsonPath) + fse.copySync(path.join(hasGlobDir, 'shrinkwrap.yaml'), destShrinkwrapYamlPath) + + await headless(await testDefaults({prefix: projectDir})) + + fse.copySync(path.join(hasGlobAndRimrafDir, 'package.json'), destPackageJsonPath) + fse.copySync(path.join(hasGlobAndRimrafDir, 'shrinkwrap.yaml'), destShrinkwrapYamlPath) + + const reporter = sinon.spy() + await headless(await testDefaults({prefix: projectDir, reporter, force: true})) + + const project = assertProject(t, projectDir) + await project.has('rimraf') + await project.has('glob') + + t.ok(reporter.calledWithMatch({ + level: 'debug', + pkgId: 'localhost+4873/balanced-match/1.0.0', + status: 'resolving_content', + } as ProgressLog), 'does not resolve already available package') + t.ok(reporter.calledWithMatch({ + level: 'debug', + pkgId: 'localhost+4873/rimraf/2.6.2', + status: 'resolving_content', + } as ProgressLog), 'resolves rimraf') + + t.end() +}) + test('fail when shrinkwrap.yaml is not up-to-date with package.json', async (t) => { const projectDir = tempy.directory() t.comment(projectDir)