1
- // @ts -check
2
-
3
1
import fs from 'node:fs'
4
2
import path from 'node:path'
5
3
import license from 'rollup-plugin-license'
6
4
import colors from 'picocolors'
7
5
import fg from 'fast-glob'
8
6
import resolve from 'resolve'
7
+ import type { Plugin } from 'rollup'
9
8
10
- /**
11
- * @param {string } licenseFilePath
12
- * @param {string } licenseTitle
13
- * @param {string } packageName
14
- */
15
- function licensePlugin ( licenseFilePath , licenseTitle , packageName ) {
9
+ export default function licensePlugin (
10
+ licenseFilePath : string ,
11
+ licenseTitle : string ,
12
+ packageName : string ,
13
+ ) : Plugin {
16
14
return license ( {
17
15
thirdParty ( dependencies ) {
18
16
// https://github.com/rollup/rollup/blob/master/build-plugins/generate-license-file.js
19
17
// MIT Licensed https://github.com/rollup/rollup/blob/master/LICENSE-CORE.md
20
18
const coreLicense = fs . readFileSync (
21
- new URL ( '../LICENSE' , import . meta. url ) ,
19
+ new URL ( '../../ LICENSE' , import . meta. url ) ,
22
20
)
23
- function sortLicenses ( licenses ) {
24
- let withParenthesis = [ ]
25
- let noParenthesis = [ ]
21
+ function sortLicenses ( licenses : Set < string > ) {
22
+ let withParenthesis : string [ ] = [ ]
23
+ let noParenthesis : string [ ] = [ ]
26
24
licenses . forEach ( ( license ) => {
27
25
if ( / ^ \( / . test ( license ) ) {
28
26
withParenthesis . push ( license )
@@ -34,12 +32,10 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) {
34
32
noParenthesis = noParenthesis . sort ( )
35
33
return [ ...noParenthesis , ...withParenthesis ]
36
34
}
37
- const licenses = new Set ( )
35
+ const licenses = new Set < string > ( )
38
36
const dependencyLicenseTexts = dependencies
39
- . sort ( ( { name : _nameA } , { name : _nameB } ) => {
40
- const nameA = /** @type {string } */ ( _nameA )
41
- const nameB = /** @type {string } */ ( _nameB )
42
- return nameA > nameB ? 1 : nameB > nameA ? - 1 : 0
37
+ . sort ( ( { name : nameA } , { name : nameB } ) => {
38
+ return nameA ! > nameB ! ? 1 : nameB ! > nameA ! ? - 1 : 0
43
39
} )
44
40
. map (
45
41
( {
@@ -96,7 +92,7 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) {
96
92
. join ( '\n' ) +
97
93
'\n'
98
94
}
99
- licenses . add ( license )
95
+ licenses . add ( license ! )
100
96
return text
101
97
} ,
102
98
)
@@ -122,5 +118,3 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) {
122
118
} ,
123
119
} )
124
120
}
125
-
126
- export default licensePlugin
0 commit comments