@@ -4,8 +4,6 @@ import { outdent } from "outdent";
44import rollupPluginLicense from "rollup-plugin-license" ;
55import { DIST_DIR , PROJECT_ROOT } from "../utils/index.js" ;
66
7- const PROJECT_LICENSE_FILE = path . join ( PROJECT_ROOT , "LICENSE" ) ;
8- const LICENSE_FILE = path . join ( DIST_DIR , "LICENSE" ) ;
97const separator = `\n${ "-" . repeat ( 40 ) } \n\n` ;
108
119function toBlockQuote ( text ) {
@@ -44,7 +42,7 @@ function getDependencies(results) {
4442 return dependencies ;
4543}
4644
47- async function getLicenseText ( dependencies ) {
45+ function getLicenseText ( dependencies ) {
4846 dependencies = dependencies . filter (
4947 ( dependency , index ) =>
5048 // Exclude ourself
@@ -63,8 +61,6 @@ async function getLicenseText(dependencies) {
6361 dependencyA . version . localeCompare ( dependencyB . version ) ,
6462 ) ;
6563
66- const prettierLicense = await fs . readFile ( PROJECT_LICENSE_FILE , "utf8" ) ;
67-
6864 const licenses = [
6965 ...new Set (
7066 dependencies
@@ -73,31 +69,16 @@ async function getLicenseText(dependencies) {
7369 ) ,
7470 ] ;
7571
76- const text = outdent `
77- # Prettier license
78-
79- Prettier is released under the MIT license:
72+ const head = outdent `
73+ # Licenses of bundled dependencies
8074
81- ${ prettierLicense . trim ( ) }
75+ The published Prettier artifact additionally contains code with the following licenses:
76+ ${ new Intl . ListFormat ( "en-US" , { type : "conjunction" } ) . format ( licenses ) } .
8277 ` ;
8378
84- if ( licenses . length === 0 ) {
85- return text ;
86- }
87-
88- const parts = [
89- text ,
90- outdent `
91- ## Licenses of bundled dependencies
92-
93- The published Prettier artifact additionally contains code with the following licenses:
94- ${ licenses . join ( ", " ) }
95- ` ,
96- ] ;
97-
9879 const content = dependencies
9980 . map ( ( dependency ) => {
100- let text = `### ${ dependency . name } @v${ dependency . version } \n` ;
81+ let text = `## ${ dependency . name } @v${ dependency . version } \n` ;
10182
10283 const meta = [ ] ;
10384
@@ -106,16 +87,16 @@ async function getLicenseText(dependencies) {
10687 }
10788
10889 if ( dependency . license ) {
109- meta . push ( `License: ${ dependency . license } ` ) ;
90+ meta . push ( `License: ${ dependency . license } ` ) ;
11091 }
11192 if ( dependency . homepage ) {
112- meta . push ( `Homepage: <${ dependency . homepage } >` ) ;
93+ meta . push ( `Homepage: <${ dependency . homepage } > ` ) ;
11394 }
11495 if ( dependency . repository ?. url ) {
115- meta . push ( `Repository: <${ dependency . repository . url } >` ) ;
96+ meta . push ( `Repository: <${ dependency . repository . url } > ` ) ;
11697 }
11798 if ( dependency . author ) {
118- meta . push ( `Author: ${ dependency . author . text ( ) } ` ) ;
99+ meta . push ( `Author: ${ dependency . author . text ( ) } ` ) ;
119100 }
120101 if ( dependency . contributors ?. length > 0 ) {
121102 const contributors = dependency . contributors
@@ -136,19 +117,14 @@ async function getLicenseText(dependencies) {
136117 } )
137118 . join ( separator ) ;
138119
139- return [
140- ...parts ,
141- outdent `
142- ## Bundled dependencies
143-
144- ${ content }
145- ` ,
146- ] . join ( "\n\n" ) ;
120+ return [ head , content ] . join ( "\n\n" ) ;
147121}
148122
149- async function buildLicense ( { file, files, results, cliOptions } ) {
123+ async function buildDependenciesLicense ( { file, files, results, cliOptions } ) {
124+ const fileName = file . output . file ;
125+
150126 if ( files . at ( - 1 ) !== file ) {
151- throw new Error ( "license should be last file to build." ) ;
127+ throw new Error ( ` ${ fileName } should be last file to build.` ) ;
152128 }
153129
154130 const shouldBuildLicense =
@@ -157,7 +133,7 @@ async function buildLicense({ file, files, results, cliOptions }) {
157133 typeof cliOptions . minify !== "boolean" ;
158134
159135 if ( ! shouldBuildLicense ) {
160- return ;
136+ return { skipped : true } ;
161137 }
162138
163139 const dependencies = getDependencies ( results ) ;
@@ -166,9 +142,9 @@ async function buildLicense({ file, files, results, cliOptions }) {
166142 throw new Error ( "Fail to collect dependencies." ) ;
167143 }
168144
169- const text = await getLicenseText ( dependencies ) ;
145+ const text = getLicenseText ( dependencies ) ;
170146
171- await fs . writeFile ( LICENSE_FILE , text ) ;
147+ await fs . writeFile ( path . join ( DIST_DIR , fileName ) , text ) ;
172148}
173149
174- export default buildLicense ;
150+ export default buildDependenciesLicense ;
0 commit comments