Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Licenses of ES modules in concatenated modules are not emitted #116

Open
iorate opened this issue Jan 21, 2022 · 1 comment
Open

Licenses of ES modules in concatenated modules are not emitted #116

iorate opened this issue Jan 21, 2022 · 1 comment
Assignees

Comments

@iorate
Copy link

iorate commented Jan 21, 2022

Hello, thank you for this useful plugin.

license-webpack-plugin does not extract licenses of ES modules included in module concatenation with the latest version of webpack 5. The repository to reproduce this issue is here: https://github.com/iorate/license-webpack-plugin-concatenated-modules

webpack concatenates ES modules if possible in production mode, and gives them identifiers of form javascript/esm|<path>. The current version of license-webpack-plugin does not handle identifiers of this form:

getActualFilename(filename: string | null | undefined): string | null {
if (
!filename ||
filename.indexOf('delegated ') === 0 ||
filename.indexOf('external ') === 0 ||
filename.indexOf('container entry ') === 0 ||
filename.indexOf('ignored|') === 0 ||
filename.indexOf('remote ') === 0 ||
filename.indexOf('data:') === 0
) {
return null;
}
if (filename.indexOf('webpack/runtime') === 0) {
return this.requireResolve('webpack');
}
if (filename.indexOf('!') > -1) {
// file was procesed by loader, last item after ! is the actual file
const tokens = filename.split('!');
return tokens[tokens.length - 1];
}
if (filename.indexOf('provide module') === 0) {
return filename.split('=')[1].trim();
}
if (filename.indexOf('consume-shared-module') === 0) {
const tokens = filename.split('|');
// 3rd to last item is the filename, see identifier() function in node_modules/webpack/lib/sharing/ConsumeSharedModule.js
const actualFilename = tokens[tokens.length - 3];
if (actualFilename === 'undefined') {
return null;
}
return actualFilename;
}
return filename;
}

... and does not emit licenses of modules with such identifiers.

Versions

node.js 16.13.2
webpack 5.66.0
license-webpack-plugin 4.0.0

@xz64 xz64 self-assigned this Jan 27, 2022
@jayaddison
Copy link

Note: in addition to the workaround listed in the linked repository: webpack v4 and v5 also support an optimization.concatenateModules option that can be disabled and should allow affected licenses to be (re)discovered as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants