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 ade850d708c97dd9aee89cf94e1ed9b18ef465ae.
This commit is contained in:
1 parent
0c2b4bb3aa
commit
0fcd5db0aa
2 files changed
+27
-45
No files matched your search
@@ -4,8 +4,6 @@ import { outdent } from "outdent";
|
||||
import rollupPluginLicense from "rollup-plugin-license";
|
||||
import { DIST_DIR, PROJECT_ROOT } from "../utils/index.js";
|
||||
|
||||
const PROJECT_LICENSE_FILE = path.join(PROJECT_ROOT, "LICENSE");
|
||||
const LICENSE_FILE = path.join(DIST_DIR, "LICENSE");
|
||||
const separator = `\n${"-".repeat(40)}\n\n`;
|
||||
|
||||
function toBlockQuote(text) {
|
||||
@@ -44,7 +42,7 @@ function getDependencies(results) {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
async function getLicenseText(dependencies) {
|
||||
function getLicenseText(dependencies) {
|
||||
dependencies = dependencies.filter(
|
||||
(dependency, index) =>
|
||||
// Exclude ourself
|
||||
@@ -63,8 +61,6 @@ async function getLicenseText(dependencies) {
|
||||
dependencyA.version.localeCompare(dependencyB.version),
|
||||
);
|
||||
|
||||
const prettierLicense = await fs.readFile(PROJECT_LICENSE_FILE, "utf8");
|
||||
|
||||
const licenses = [
|
||||
...new Set(
|
||||
dependencies
|
||||
@@ -73,31 +69,16 @@ async function getLicenseText(dependencies) {
|
||||
),
|
||||
];
|
||||
|
||||
const text = outdent`
|
||||
# Prettier license
|
||||
const head = outdent`
|
||||
# Licenses of bundled dependencies
|
||||
|
||||
Prettier is released under the MIT license:
|
||||
|
||||
${prettierLicense.trim()}
|
||||
The published Prettier artifact additionally contains code with the following licenses:
|
||||
${new Intl.ListFormat("en-US", { type: "conjunction" }).format(licenses)}.
|
||||
`;
|
||||
|
||||
if (licenses.length === 0) {
|
||||
return text;
|
||||
}
|
||||
|
||||
const parts = [
|
||||
text,
|
||||
outdent`
|
||||
## Licenses of bundled dependencies
|
||||
|
||||
The published Prettier artifact additionally contains code with the following licenses:
|
||||
${licenses.join(", ")}
|
||||
`,
|
||||
];
|
||||
|
||||
const content = dependencies
|
||||
.map((dependency) => {
|
||||
let text = `### ${dependency.name}@v${dependency.version}\n`;
|
||||
let text = `## ${dependency.name}@v${dependency.version}\n`;
|
||||
|
||||
const meta = [];
|
||||
|
||||
@@ -106,16 +87,16 @@ async function getLicenseText(dependencies) {
|
||||
}
|
||||
|
||||
if (dependency.license) {
|
||||
meta.push(`License: ${dependency.license}`);
|
||||
meta.push(`License: ${dependency.license} `);
|
||||
}
|
||||
if (dependency.homepage) {
|
||||
meta.push(`Homepage: <${dependency.homepage}>`);
|
||||
meta.push(`Homepage: <${dependency.homepage}> `);
|
||||
}
|
||||
if (dependency.repository?.url) {
|
||||
meta.push(`Repository: <${dependency.repository.url}>`);
|
||||
meta.push(`Repository: <${dependency.repository.url}> `);
|
||||
}
|
||||
if (dependency.author) {
|
||||
meta.push(`Author: ${dependency.author.text()}`);
|
||||
meta.push(`Author: ${dependency.author.text()} `);
|
||||
}
|
||||
if (dependency.contributors?.length > 0) {
|
||||
const contributors = dependency.contributors
|
||||
@@ -136,19 +117,14 @@ async function getLicenseText(dependencies) {
|
||||
})
|
||||
.join(separator);
|
||||
|
||||
return [
|
||||
...parts,
|
||||
outdent`
|
||||
## Bundled dependencies
|
||||
|
||||
${content}
|
||||
`,
|
||||
].join("\n\n");
|
||||
return [head, content].join("\n\n");
|
||||
}
|
||||
|
||||
async function buildLicense({ file, files, results, cliOptions }) {
|
||||
async function buildDependenciesLicense({ file, files, results, cliOptions }) {
|
||||
const fileName = file.output.file;
|
||||
|
||||
if (files.at(-1) !== file) {
|
||||
throw new Error("license should be last file to build.");
|
||||
throw new Error(`${fileName} should be last file to build.`);
|
||||
}
|
||||
|
||||
const shouldBuildLicense =
|
||||
@@ -157,7 +133,7 @@ async function buildLicense({ file, files, results, cliOptions }) {
|
||||
typeof cliOptions.minify !== "boolean";
|
||||
|
||||
if (!shouldBuildLicense) {
|
||||
return;
|
||||
return { skipped: true };
|
||||
}
|
||||
|
||||
const dependencies = getDependencies(results);
|
||||
@@ -166,9 +142,9 @@ async function buildLicense({ file, files, results, cliOptions }) {
|
||||
throw new Error("Fail to collect dependencies.");
|
||||
}
|
||||
|
||||
const text = await getLicenseText(dependencies);
|
||||
const text = getLicenseText(dependencies);
|
||||
|
||||
await fs.writeFile(LICENSE_FILE, text);
|
||||
await fs.writeFile(path.join(DIST_DIR, fileName), text);
|
||||
}
|
||||
|
||||
export default buildLicense;
|
||||
export default buildDependenciesLicense;
|
||||
@@ -4,8 +4,8 @@ import url from "node:url";
|
||||
import createEsmUtils from "esm-utils";
|
||||
import { outdent } from "outdent";
|
||||
import { copyFile, DIST_DIR, PROJECT_ROOT } from "../utils/index.js";
|
||||
import buildDependenciesLicense from "./build-dependencies-license.js";
|
||||
import buildJavascriptModule from "./build-javascript-module.js";
|
||||
import buildLicense from "./build-license.js";
|
||||
import buildPackageJson from "./build-package-json.js";
|
||||
import buildTypes from "./build-types.js";
|
||||
import esmifyTypescriptEslint from "./esmify-typescript-eslint.js";
|
||||
@@ -859,7 +859,13 @@ const metaFiles = [
|
||||
},
|
||||
{
|
||||
input: "LICENSE",
|
||||
build: buildLicense,
|
||||
build: copyFileBuilder,
|
||||
},
|
||||
{
|
||||
output: {
|
||||
file: "THIRD-PARTY-NOTICES.md",
|
||||
},
|
||||
build: buildDependenciesLicense,
|
||||
},
|
||||
].map((file) => ({
|
||||
...file,
|
||||
|
||||
Reference in new issue
Block a user