diff --git a/lib/DependencyResolver.ts b/lib/DependencyResolver.ts index 4dcdc41..efd1f65 100644 --- a/lib/DependencyResolver.ts +++ b/lib/DependencyResolver.ts @@ -234,10 +234,8 @@ export class DependencyResolver { }. Using that` ) dependency.targetModule = existingModule - } else if (!this._store.hasPuppetfileRequirementWithTargetModule(dependency.targetModule.getSlug())) { - this._log.debug( - `Dependency ${dependency.targetModule.getSlug()} is not already a base Puppetfile requirement, adding it.` - ) + } else { + this._log.debug(`Adding requirement for dependency to ${dependency.targetModule.getSlug()}`) this._store.addRequirement( new Requirement() .withSource(RequirementSource.Dependency) @@ -245,11 +243,6 @@ export class DependencyResolver { .withTargetModule(dependency.targetModule) .withDependencyRange(dependency.dependencyRange) ) - } else if ( - this._store.hasPuppetfileRequirementWithTargetModule(dependency.targetModule.getSlug()) && - !this._ignoreList.some((slug) => slug === dependency.targetModule?.getSlug()) - ) { - throw new NoVersionFoundError(dependency) } } } diff --git a/test/dependency.resolver.test.ts b/test/dependency.resolver.test.ts index 0f2362c..b5f684c 100644 --- a/test/dependency.resolver.test.ts +++ b/test/dependency.resolver.test.ts @@ -66,6 +66,12 @@ describe('The dependency resolver', function () { ], }, }) + sb.get('/v3/releases/test-wrongdepc-1.2.2').setResponseBody({ + slug: 'test-defaultdependency', + metadata: { + dependencies: [], + }, + }) sb.get('/v3/releases/test-wrongdepc-1.2.3').setResponseBody({ slug: 'test-defaultdependency', metadata: { @@ -124,6 +130,9 @@ describe('The dependency resolver', function () { { version: '1.2.3', }, + { + version: '1.2.2', + }, ], }) sb.get('/v3/modules/test-deprecated').setResponseBody({ @@ -185,6 +194,25 @@ mod 'test-dependency', '1.2.4' expect(subject.dependentModules[0].version).toEqual('1.2.5') }) + it('should create a valid puppetfile when a dependency is in the Puppetfile', async () => { + const subject = await new DependencyResolver() + .withPuppetFile( + await new PuppetFile().fromText(` +forge 'http://localhost:${sb.getPort()}' + +mod 'test-default', '1.2.3' +mod 'test-defaultdependency', '1.2.5' + `) + ) + .resolve() + expect(subject.modules).toHaveLength(2) + expect(subject.modules[0].getSlug()).toEqual('test-default') + expect(subject.modules[0].version).toEqual('1.2.3') + expect(subject.modules[1].getSlug()).toEqual('test-defaultdependency') + expect(subject.modules[1].version).toEqual('1.2.5') + expect(subject.dependentModules).toHaveLength(0) + }) + it('should hide items from the puppetfile', async () => { const subject = await new DependencyResolver() .withPuppetFile( @@ -284,7 +312,7 @@ mod 'test-deprecated', '1.2.3' forge 'http://localhost:${sb.getPort()}' mod 'test-wrongdepa', '1.2.3' -mod 'test-wrongdepc', '1.2.3' +mod 'test-wrongdepc', '1.2.2' `) )