chore: adjust webpack plugin to also extract inline asset licenses

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/54497/head
Ferdinand Thiessen 2025-08-19 11:11:58 +07:00 committed by nextcloud-command
parent 4b2fcac882
commit f933a41a5a
2 changed files with 27 additions and 7 deletions

@ -137,13 +137,8 @@ class WebpackSPDXPlugin {
.filter((s) => !!s)
.map((s) => s.split('?', 2)[0])
// Skip assets without modules, these are emitted by webpack plugins
if (sources.length === 0) {
logger.warn(`Skipping ${asset} because it does not contain any source information`)
continue
}
/** packages used by the current asset
/**
* packages used by the current asset
* @type {Set<string>}
*/
const packages = new Set()
@ -198,6 +193,29 @@ class WebpackSPDXPlugin {
output += `- ${pkg.name}\n\t- version: ${pkg.version}\n\t- license: ${license}\n`
}
output = `\n\n${output}`
if (sources.length === 0) {
logger.info(`Checking content of asset ${asset}`)
const sources = [...modules].map((module) => module.identifier())
for (const source of sources) {
const match = source.match(/asset\/inline\|data:image\/svg\+xml,(.+)/)
if (match) {
const content = decodeURI(match[1])
const [, license] = content.match(/SPDX-License-Identifier:\s*([^\s]+)/) ?? []
const [, author] = content.match(/SPDX-FileCopyrightText:\s*([^-]+)/) ?? []
if (author && license) {
authors.add(author)
licenses.add(license)
}
}
}
if (authors.size === 0) {
logger.warn(`Asset ${asset} does not contain any source information`)
continue
}
output = ''
}
for (const author of [...authors].sort()) {
output = `SPDX-FileCopyrightText: ${author}\n${output}`
}

@ -0,0 +1,2 @@
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: 2020 Google Inc.