@@ -4,8 +4,6 @@ import { outdent } from "outdent";
4
4
import rollupPluginLicense from "rollup-plugin-license" ;
5
5
import { DIST_DIR , PROJECT_ROOT } from "../utils/index.js" ;
6
6
7
- const PROJECT_LICENSE_FILE = path . join ( PROJECT_ROOT , "LICENSE" ) ;
8
- const LICENSE_FILE = path . join ( DIST_DIR , "LICENSE" ) ;
9
7
const separator = `\n${ "-" . repeat ( 40 ) } \n\n` ;
10
8
11
9
function toBlockQuote ( text ) {
@@ -44,7 +42,7 @@ function getDependencies(results) {
44
42
return dependencies ;
45
43
}
46
44
47
- async function getLicenseText ( dependencies ) {
45
+ function getLicenseText ( dependencies ) {
48
46
dependencies = dependencies . filter (
49
47
( dependency , index ) =>
50
48
// Exclude ourself
@@ -63,8 +61,6 @@ async function getLicenseText(dependencies) {
63
61
dependencyA . version . localeCompare ( dependencyB . version ) ,
64
62
) ;
65
63
66
- const prettierLicense = await fs . readFile ( PROJECT_LICENSE_FILE , "utf8" ) ;
67
-
68
64
const licenses = [
69
65
...new Set (
70
66
dependencies
@@ -73,31 +69,16 @@ async function getLicenseText(dependencies) {
73
69
) ,
74
70
] ;
75
71
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
80
74
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 ) } .
82
77
` ;
83
78
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
-
98
79
const content = dependencies
99
80
. map ( ( dependency ) => {
100
- let text = `### ${ dependency . name } @v${ dependency . version } \n` ;
81
+ let text = `## ${ dependency . name } @v${ dependency . version } \n` ;
101
82
102
83
const meta = [ ] ;
103
84
@@ -106,16 +87,16 @@ async function getLicenseText(dependencies) {
106
87
}
107
88
108
89
if ( dependency . license ) {
109
- meta . push ( `License: ${ dependency . license } ` ) ;
90
+ meta . push ( `License: ${ dependency . license } ` ) ;
110
91
}
111
92
if ( dependency . homepage ) {
112
- meta . push ( `Homepage: <${ dependency . homepage } >` ) ;
93
+ meta . push ( `Homepage: <${ dependency . homepage } > ` ) ;
113
94
}
114
95
if ( dependency . repository ?. url ) {
115
- meta . push ( `Repository: <${ dependency . repository . url } >` ) ;
96
+ meta . push ( `Repository: <${ dependency . repository . url } > ` ) ;
116
97
}
117
98
if ( dependency . author ) {
118
- meta . push ( `Author: ${ dependency . author . text ( ) } ` ) ;
99
+ meta . push ( `Author: ${ dependency . author . text ( ) } ` ) ;
119
100
}
120
101
if ( dependency . contributors ?. length > 0 ) {
121
102
const contributors = dependency . contributors
@@ -136,19 +117,14 @@ async function getLicenseText(dependencies) {
136
117
} )
137
118
. join ( separator ) ;
138
119
139
- return [
140
- ...parts ,
141
- outdent `
142
- ## Bundled dependencies
143
-
144
- ${ content }
145
- ` ,
146
- ] . join ( "\n\n" ) ;
120
+ return [ head , content ] . join ( "\n\n" ) ;
147
121
}
148
122
149
- async function buildLicense ( { file, files, results, cliOptions } ) {
123
+ async function buildDependenciesLicense ( { file, files, results, cliOptions } ) {
124
+ const fileName = file . output . file ;
125
+
150
126
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.` ) ;
152
128
}
153
129
154
130
const shouldBuildLicense =
@@ -157,7 +133,7 @@ async function buildLicense({ file, files, results, cliOptions }) {
157
133
typeof cliOptions . minify !== "boolean" ;
158
134
159
135
if ( ! shouldBuildLicense ) {
160
- return ;
136
+ return { skipped : true } ;
161
137
}
162
138
163
139
const dependencies = getDependencies ( results ) ;
@@ -166,9 +142,9 @@ async function buildLicense({ file, files, results, cliOptions }) {
166
142
throw new Error ( "Fail to collect dependencies." ) ;
167
143
}
168
144
169
- const text = await getLicenseText ( dependencies ) ;
145
+ const text = getLicenseText ( dependencies ) ;
170
146
171
- await fs . writeFile ( LICENSE_FILE , text ) ;
147
+ await fs . writeFile ( path . join ( DIST_DIR , fileName ) , text ) ;
172
148
}
173
149
174
- export default buildLicense ;
150
+ export default buildDependenciesLicense ;
0 commit comments