1- // @ts -check
2-
31import fs from 'node:fs'
42import path from 'node:path'
53import license from 'rollup-plugin-license'
64import colors from 'picocolors'
75import fg from 'fast-glob'
86import resolve from 'resolve'
7+ import type { Plugin } from 'rollup'
98
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 {
1614 return license ( {
1715 thirdParty ( dependencies ) {
1816 // https://github.com/rollup/rollup/blob/master/build-plugins/generate-license-file.js
1917 // MIT Licensed https://github.com/rollup/rollup/blob/master/LICENSE-CORE.md
2018 const coreLicense = fs . readFileSync (
21- new URL ( '../LICENSE' , import . meta. url ) ,
19+ new URL ( '../../ LICENSE' , import . meta. url ) ,
2220 )
23- function sortLicenses ( licenses ) {
24- let withParenthesis = [ ]
25- let noParenthesis = [ ]
21+ function sortLicenses ( licenses : Set < string > ) {
22+ let withParenthesis : string [ ] = [ ]
23+ let noParenthesis : string [ ] = [ ]
2624 licenses . forEach ( ( license ) => {
2725 if ( / ^ \( / . test ( license ) ) {
2826 withParenthesis . push ( license )
@@ -34,12 +32,10 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) {
3432 noParenthesis = noParenthesis . sort ( )
3533 return [ ...noParenthesis , ...withParenthesis ]
3634 }
37- const licenses = new Set ( )
35+ const licenses = new Set < string > ( )
3836 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
4339 } )
4440 . map (
4541 ( {
@@ -96,7 +92,7 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) {
9692 . join ( '\n' ) +
9793 '\n'
9894 }
99- licenses . add ( license )
95+ licenses . add ( license ! )
10096 return text
10197 } ,
10298 )
@@ -122,5 +118,3 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) {
122118 } ,
123119 } )
124120}
125-
126- export default licensePlugin
0 commit comments