diff --git a/src/cli/commands/licenses.js b/src/cli/commands/licenses.js index 1d95c73bf7..8ca86e5bc5 100644 --- a/src/cli/commands/licenses.js +++ b/src/cli/commands/licenses.js @@ -121,16 +121,23 @@ export const {run, examples} = buildSubCommands('licenses', { // the same license text are grouped together. const manifestsByLicense: Map> = new Map(); for (const manifest of manifests) { - const {licenseText} = manifest; + const {licenseText, noticeText} = manifest; + let licenseKey; if (!licenseText) { continue; } - if (!manifestsByLicense.has(licenseText)) { - manifestsByLicense.set(licenseText, new Map()); + if (!noticeText) { + licenseKey = licenseText; + } else { + licenseKey = `${licenseText}\n\nNOTICE\n\n${noticeText}`; + } + + if (!manifestsByLicense.has(licenseKey)) { + manifestsByLicense.set(licenseKey, new Map()); } - const byLicense = manifestsByLicense.get(licenseText); + const byLicense = manifestsByLicense.get(licenseKey); invariant(byLicense, 'expected value'); byLicense.set(manifest.name, manifest); } @@ -141,7 +148,7 @@ export const {run, examples} = buildSubCommands('licenses', { ); console.log(); - for (const [licenseText, manifests] of manifestsByLicense) { + for (const [licenseKey, manifests] of manifestsByLicense) { console.log('-----'); console.log(); @@ -164,8 +171,8 @@ export const {run, examples} = buildSubCommands('licenses', { console.log(heading.join(' ')); console.log(); - if (licenseText) { - console.log(licenseText.trim()); + if (licenseKey) { + console.log(licenseKey.trim()); } else { // what do we do here? base it on `license`? } diff --git a/src/types.js b/src/types.js index 63b3a459e2..1f5a800617 100644 --- a/src/types.js +++ b/src/types.js @@ -68,6 +68,7 @@ export type Manifest = { flat?: boolean, license?: string, licenseText?: string, + noticeText?: string, readme?: string, readmeFilename?: string, diff --git a/src/util/normalize-manifest/fix.js b/src/util/normalize-manifest/fix.js index 8ce398e6b6..53845efead 100644 --- a/src/util/normalize-manifest/fix.js +++ b/src/util/normalize-manifest/fix.js @@ -308,6 +308,19 @@ export default (async function( } } + // get notice file + const noticeFile = files.find((filename): boolean => { + const lower = filename.toLowerCase(); + return lower === 'notice' || lower.startsWith('notice.'); + }); + if (noticeFile) { + const noticeFilepath = path.join(moduleLoc, noticeFile); + const noticeFileStats = await fs.stat(noticeFilepath); + if (noticeFileStats.isFile()) { + info.noticeText = await fs.readFile(noticeFilepath); + } + } + for (const dependencyType of MANIFEST_FIELDS) { const dependencyList = info[dependencyType]; if (dependencyList && typeof dependencyList === 'object') {