codepunkt/webpack-license-plugin

Handle packages with nested package.json

mikejpeters opened this issue · 3 comments

Some npm packages are structured with a nested package.json that only contains basic info without the license, but the root package.json has the license info.

For example, socket.io-client:

├── build/esm/package.json
└── package.json

The root package.json looks like this:

{
  "name": "socket.io-client",
  "version": "4.4.0",
  "main": "./build/cjs/index.js",
  "module": "./build/esm/index.js",
  "license": "MIT",

And the nested package.json looks like this:

{
  "name": "socket.io-client",
  "version": "4.4.0",
  "type": "module"
}

This plugin currently picks up the nested package.json, which doesn't contain any license info, causing the error "Could not find license info for socket.io-client@4.4.0".

Would it make sense for ModuleDirectoryLocator to check the parent directory in case the package license and licenses properties are both undefined? I'd be happy to try my hand at a pull request if you agree this makes sense. Thanks!

+1, currently have basically the same error with

image

but it's still visible on HEAD/main over there: https://github.com/BuilderIO/partytown

there's a valid license in the root package.json:

https://github.com/BuilderIO/partytown/blob/main/package.json#L5

but the "sub-packages" have only a basic package.json, for example this one:

https://github.com/BuilderIO/partytown/blob/main/src/integration/package.json

GitHub
Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉 - GitHub - BuilderIO/partytown: Relocate resource intensive third-party scripts off of the main threa...
GitHub
Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉 - partytown/package.json at main · BuilderIO/partytown
GitHub
Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉 - partytown/package.json at main · BuilderIO/partytown

@Schweinepriester in case you want to try my fork where I made some changes to support this, you can install @boundstate/webpack-license-plugin.

(Ideally I don't plan to maintain that fork forever, it's just for now in case it takes a while for my pull request to get merged)

@mikejpeters Thank you, esp. for the PR as well, but for now I went with a license override for the sub package like so:

licenseOverrides: {
  '@builder.io/partytown/integration@0.5.4': 'MIT',
},

But I continue to agree that this shouldn't be necessary, i.e. the changes in your PR are very desirable!