Skip to content

Commit 0fcd5db

Browse files
authored
Separate license and third-party licenses (#17073)
* Separate license and third-party licenses * Minor tweak * Line break * Add a dot * DEBUG pkg-pr-new * Revert "DEBUG pkg-pr-new" This reverts commit ade850d.
1 parent 0c2b4bb commit 0fcd5db

File tree

2 files changed

+27
-45
lines changed

2 files changed

+27
-45
lines changed

Diff for: scripts/build/build-license.js renamed to scripts/build/build-dependencies-license.js

+19-43
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { outdent } from "outdent";
44
import rollupPluginLicense from "rollup-plugin-license";
55
import { 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");
97
const separator = `\n${"-".repeat(40)}\n\n`;
108

119
function 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;

Diff for: scripts/build/config.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import url from "node:url";
44
import createEsmUtils from "esm-utils";
55
import { outdent } from "outdent";
66
import { copyFile, DIST_DIR, PROJECT_ROOT } from "../utils/index.js";
7+
import buildDependenciesLicense from "./build-dependencies-license.js";
78
import buildJavascriptModule from "./build-javascript-module.js";
8-
import buildLicense from "./build-license.js";
99
import buildPackageJson from "./build-package-json.js";
1010
import buildTypes from "./build-types.js";
1111
import esmifyTypescriptEslint from "./esmify-typescript-eslint.js";
@@ -859,7 +859,13 @@ const metaFiles = [
859859
},
860860
{
861861
input: "LICENSE",
862-
build: buildLicense,
862+
build: copyFileBuilder,
863+
},
864+
{
865+
output: {
866+
file: "THIRD-PARTY-NOTICES.md",
867+
},
868+
build: buildDependenciesLicense,
863869
},
864870
].map((file) => ({
865871
...file,

0 commit comments

Comments
 (0)