| 176 | function licensePlugin() { |
| 177 | return license({ |
| 178 | thirdParty(dependencies) { |
| 179 | // https://github.com/rollup/rollup/blob/master/build-plugins/generate-license-file.js |
| 180 | // MIT Licensed https://github.com/rollup/rollup/blob/master/LICENSE-CORE.md |
| 181 | const coreLicense = fs.readFileSync(resolve(dir, '../../LICENSE')) |
| 182 | const licenses = new Set() |
| 183 | const dependencyLicenseTexts = dependencies |
| 184 | .filter(({ name }) => !name?.startsWith('@vitest/')) |
| 185 | .sort(({ name: nameA }, { name: nameB }) => |
| 186 | nameA > nameB ? 1 : nameB > nameA ? -1 : 0, |
| 187 | ) |
| 188 | .map( |
| 189 | ({ |
| 190 | name, |
| 191 | license, |
| 192 | licenseText, |
| 193 | author, |
| 194 | maintainers, |
| 195 | contributors, |
| 196 | repository, |
| 197 | }) => { |
| 198 | let text = `## ${name}\n` |
| 199 | if (license) { |
| 200 | text += `License: ${license}\n` |
| 201 | } |
| 202 | |
| 203 | const names = new Set() |
| 204 | if (author && author.name) { |
| 205 | names.add(author.name) |
| 206 | } |
| 207 | |
| 208 | for (const person of maintainers.concat(contributors)) { |
| 209 | if (person && person.name) { |
| 210 | names.add(person.name) |
| 211 | } |
| 212 | } |
| 213 | if (names.size > 0) { |
| 214 | text += `By: ${Array.from(names).join(', ')}\n` |
| 215 | } |
| 216 | |
| 217 | if (repository) { |
| 218 | text += `Repository: ${repository.url || repository}\n` |
| 219 | } |
| 220 | |
| 221 | if (!licenseText) { |
| 222 | try { |
| 223 | const pkgDir = dirname( |
| 224 | resolve(join(name, 'package.json'), { |
| 225 | preserveSymlinks: false, |
| 226 | }), |
| 227 | ) |
| 228 | const [licenseFile] = globSync(`${pkgDir}/LICENSE*`, { |
| 229 | caseSensitiveMatch: false, |
| 230 | expandDirectories: false, |
| 231 | }) |
| 232 | if (licenseFile) { |
| 233 | licenseText = fs.readFileSync(licenseFile, 'utf-8') |
| 234 | } |
| 235 | } |