diff --git a/src/license-plugin.js b/src/license-plugin.js index caeb14f0..293d06c5 100644 --- a/src/license-plugin.js +++ b/src/license-plugin.js @@ -280,7 +280,9 @@ class LicensePlugin { * @return {void} */ addDependency(pkg) { - const name = pkg.name; + const name = (this._options.thirdParty && this._options.thirdParty.multipleVersions) ? + `${pkg.name}@${pkg.version}` : + pkg.name; if (!name) { this.warn('Trying to add dependency without any name, skipping it.'); } else if (!_.has(this._dependencies, name)) { diff --git a/test/license-plugin.spec.js b/test/license-plugin.spec.js index 98d75eaf..02ede1b8 100644 --- a/test/license-plugin.spec.js +++ b/test/license-plugin.spec.js @@ -133,6 +133,23 @@ describe('LicensePlugin', () => { }); }); + it('should load pkg with version in key when multipleVersions option is truthy', () => { + const id = path.join(__dirname, 'fixtures', 'fake-package-1', 'src', 'index.js'); + + plugin._options = { + thirdParty: { + multipleVersions: true, + }, + }; + + plugin.scanDependency(id); + + expect(addDependency).toHaveBeenCalled(); + expect(plugin._dependencies).toEqual({ + [`${fakePackage.name}@${fakePackage.version}`]: fakePackage, + }); + }); + it('should load pkg and going up directories until a package name is found', () => { const id = path.join(__dirname, 'fixtures', 'fake-package-5', 'esm', 'index.js');