MCPcopy
hub / github.com/vitejs/vite / licensePlugin

Function licensePlugin

packages/vite/rollupLicensePlugin.ts:7–128  ·  view source on GitHub ↗
(
  licenseFilePath: string,
  licenseTitle: string,
  packageName: string,
  additionalSection?: string,
)

Source from the content-addressed store, hash-verified

5import type { Plugin, PluginContext } from 'rollup'
6
7export default function licensePlugin(
8 licenseFilePath: string,
9 licenseTitle: string,
10 packageName: string,
11 additionalSection?: string,
12): Plugin {
13 const originalPlugin = license({
14 thirdParty(dependencies) {
15 // https://github.com/rollup/rollup/blob/master/build-plugins/generate-license-file.js
16 // MIT Licensed https://github.com/rollup/rollup/blob/master/LICENSE-CORE.md
17 const coreLicense = fs.readFileSync(
18 new URL('../../LICENSE', import.meta.url),
19 'utf-8',
20 )
21
22 const deps = sortDependencies(dependencies)
23 const licenses = sortLicenses(
24 new Set(
25 dependencies.map((dep) => dep.license).filter(Boolean) as string[],
26 ),
27 )
28
29 let dependencyLicenseTexts = ''
30 for (let i = 0; i < deps.length; i++) {
31 // Find dependencies with the same license text so it can be shared
32 const licenseText = deps[i].licenseText
33 const sameDeps = [deps[i]]
34 if (licenseText) {
35 for (let j = i + 1; j < deps.length; j++) {
36 if (licenseText === deps[j].licenseText) {
37 sameDeps.push(...deps.splice(j, 1))
38 j--
39 }
40 }
41 }
42
43 let text = `## ${sameDeps.map((d) => d.name).join(', ')}\n`
44 const depInfos = sameDeps.map((d) => getDependencyInformation(d))
45
46 // If all same dependencies have the same license and contributor names, show them only once
47 if (
48 depInfos.length > 1 &&
49 depInfos.every(
50 (info) =>
51 info.license === depInfos[0].license &&
52 info.names === depInfos[0].names,
53 )
54 ) {
55 const { license, names } = depInfos[0]
56 const repositoryText = depInfos
57 .map((info) => info.repository)
58 .filter(Boolean)
59 .join(', ')
60
61 if (license) text += `License: ${license}\n`
62 if (names) text += `By: ${names}\n`
63 if (repositoryText) text += `Repositories: ${repositoryText}\n`
64 }

Callers 2

rolldown.config.tsFile · 0.70
tsdown.config.tsFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected