Skip to content

Commit

Permalink
enh: allow multiple versions of dependencies (#1528)
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiomedina committed Sep 3, 2023
1 parent 46660a9 commit 2d42e4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/license-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
17 changes: 17 additions & 0 deletions test/license-plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 2d42e4c

Please sign in to comment.