Save vendor licenses for build script (#12258)

This commit is contained in:
fisker Cheung authored and GitHub committed 2022-02-08 10:33:09 +08:00
1 parent 331d278a3a
commit b1e59dd70a
9 files changed
+227 -29

No files matched your search

+2 -1
View File
@@ -391,6 +391,7 @@
"website/playground/codeSamples.js",
"website/pages/googlefe164a33bda4034b.html",
"website/static/lib/**",
"website/static/playground.js"
"website/static/playground.js",
"scripts/vendors/vendor-meta.json"
]
}
+5
View File
@@ -253,6 +253,11 @@ async function run(params) {
}
if (shouldSaveBundledPackagesLicenses) {
const vendorMeta = await readJson(
new URL("../vendors/vendor-meta.json", import.meta.url)
);
licenses.push(...vendorMeta.licenses);
await saveLicenses(licenses.filter(({ name }) => name !== "prettier"));
} else {
console.warn(
+4 -2
View File
@@ -2,13 +2,15 @@ import fs from "node:fs/promises";
import url from "node:url";
import path from "node:path";
const toPath = (path) => (path instanceof URL ? url.fileURLToPath(path) : path);
async function readJson(file) {
const data = await fs.readFile(file);
return JSON.parse(data);
}
function writeJson(file, content) {
content = JSON.stringify(content, null, 2);
content = JSON.stringify(content, null, 2) + "\n";
return writeFile(file, content);
}
@@ -18,7 +20,7 @@ async function copyFile(from, to) {
}
async function writeFile(file, content) {
const directory = path.dirname(file);
const directory = path.dirname(toPath(file));
try {
await fs.mkdir(directory, { recursive: true });
} catch {
+28 -6
View File
@@ -5,8 +5,10 @@ import path from "node:path";
import createEsmUtils from "esm-utils";
import esbuild from "esbuild";
import { readPackageUp } from "read-pkg-up";
import { PROJECT_ROOT } from "../utils/index.mjs";
import esbuildPluginLicense from "../build/esbuild-plugins/license.mjs";
import vendors from "./vendors.mjs";
import { writeVendorVersions } from "./vendor-versions.mjs";
import { saveVendorVersions, saveVendorLicenses } from "./utils.mjs";
import esbuildPluginTsNocheck from "./esbuild-plugin-ts-nocheck.mjs";
const { __dirname, require } = createEsmUtils(import.meta);
@@ -26,7 +28,7 @@ async function lockVersions(vendors) {
const vendorVersion = vendorPackage.version;
vendorVersions[vendor] = vendorVersion;
}
await writeVendorVersions(vendorVersions);
await saveVendorVersions(vendorVersions);
}
async function fileExists(filePath) {
@@ -46,18 +48,28 @@ async function cleanExistsBundledJS() {
}
}
async function bundle(vendor) {
async function bundle(vendor, options) {
const outfile = getVendorFilePath(vendor);
if (await fileExists(outfile)) {
await fs.rm(outfile);
}
/** @type {import("esbuild").CommonOptions} */
const esbuildOption = {
entryPoints: [require.resolve(vendor)],
bundle: true,
target: ["node12.17.0"],
platform: "node",
plugins: [esbuildPluginTsNocheck()],
plugins: [
esbuildPluginTsNocheck(),
esbuildPluginLicense({
cwd: PROJECT_ROOT,
thirdParty: {
includePrivate: true,
output: options.onLicenseFound,
},
}),
],
outfile,
};
await esbuild.build(esbuildOption);
@@ -76,12 +88,22 @@ async function bundle(vendor) {
async function main() {
await cleanExistsBundledJS();
const licenses = [];
for (const vendor of vendors) {
await bundle(vendor);
await bundle(vendor, {
onLicenseFound(dependencies) {
licenses.push(...dependencies);
},
});
console.log(`Bundled: ${vendor}`);
}
await lockVersions(vendors);
console.log("Locked: vendor-versions.json");
console.log("Vendor versions saved");
await saveVendorLicenses(licenses);
console.log("Vendor licenses saved");
}
main();
+23
View File
@@ -0,0 +1,23 @@
import fs from "node:fs";
import { readJson, writeJson } from "../utils/index.mjs";
const vendorMetaFile = new URL("./vendor-meta.json", import.meta.url);
const getMeta = () =>
fs.existsSync(vendorMetaFile) ? readJson(vendorMetaFile) : {};
export async function getVendorVersions() {
const meta = await getMeta();
return meta.versions;
}
export async function saveVendorVersions(versions) {
const meta = await getMeta();
meta.versions = versions;
await writeJson(vendorMetaFile, meta);
}
export async function saveVendorLicenses(licenses) {
const meta = await getMeta();
meta.licenses = licenses;
await writeJson(vendorMetaFile, meta);
}
+1 -1
View File
@@ -2,7 +2,7 @@
import createEsmUtils from "esm-utils";
import { readPackageUp } from "read-pkg-up";
import { getVendorVersions } from "./vendor-versions.mjs";
import { getVendorVersions } from "./utils.mjs";
import vendors from "./vendors.mjs";
const { require } = createEsmUtils(import.meta);
+164
View File
@@ -0,0 +1,164 @@
{
"licenses": [
{
"name": "ansi-regex",
"maintainers": [],
"version": "6.0.1",
"description": "Regular expression for matching ANSI escape codes",
"repository": "chalk/ansi-regex",
"homepage": null,
"private": false,
"license": "MIT",
"licenseText": "MIT License\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"contributors": []
},
{
"name": "strip-ansi",
"maintainers": [],
"version": "7.0.1",
"description": "Strip ANSI escape codes from a string",
"repository": "chalk/strip-ansi",
"homepage": null,
"private": false,
"license": "MIT",
"licenseText": "MIT License\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"contributors": []
},
{
"name": "is-fullwidth-code-point",
"maintainers": [],
"version": "4.0.0",
"description": "Check if the character represented by a given Unicode code point is fullwidth",
"repository": "sindresorhus/is-fullwidth-code-point",
"homepage": null,
"private": false,
"license": "MIT",
"licenseText": "MIT License\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"contributors": []
},
{
"name": "emoji-regex",
"maintainers": [],
"version": "9.2.2",
"description": "A regular expression to match all Emoji-only symbols as per the Unicode Standard.",
"repository": {
"type": "git",
"url": "https://github.com/mathiasbynens/emoji-regex.git"
},
"homepage": "https://mths.be/emoji-regex",
"private": false,
"license": "MIT",
"licenseText": "Copyright Mathias Bynens <https://mathiasbynens.be/>\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"author": {
"name": "Mathias Bynens",
"email": null,
"url": "https://mathiasbynens.be/"
},
"contributors": []
},
{
"name": "string-width",
"maintainers": [],
"version": "5.0.1",
"description": "Get the visual width of a string - the number of columns required to display it",
"repository": "sindresorhus/string-width",
"homepage": null,
"private": false,
"license": "MIT",
"licenseText": "MIT License\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"contributors": []
},
{
"name": "mimic-fn",
"maintainers": [],
"version": "4.0.0",
"description": "Make a function mimic another one",
"repository": "sindresorhus/mimic-fn",
"homepage": null,
"private": false,
"license": "MIT",
"licenseText": "MIT License\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"contributors": []
},
{
"name": "p-defer",
"maintainers": [],
"version": "1.0.0",
"description": "Create a deferred promise",
"repository": "sindresorhus/p-defer",
"homepage": null,
"private": false,
"license": "MIT",
"licenseText": "The MIT License (MIT)\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"contributors": []
},
{
"name": "map-age-cleaner",
"maintainers": [],
"version": "0.1.3",
"description": "Automatically cleanup expired items in a Map",
"repository": "SamVerschueren/map-age-cleaner",
"homepage": null,
"private": false,
"license": "MIT",
"licenseText": "MIT License\n\nCopyright (c) Sam Verschueren <sam.verschueren@gmail.com> (github.com/SamVerschueren)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"author": {
"name": "Sam Verschueren",
"email": "sam.verschueren@gmail.com",
"url": "github.com/SamVerschueren"
},
"contributors": []
},
{
"name": "mem",
"maintainers": [],
"version": "9.0.2",
"description": "Memoize functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input",
"repository": "sindresorhus/mem",
"homepage": null,
"private": false,
"license": "MIT",
"licenseText": "MIT License\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"contributors": []
}
],
"versions": {
"string-width": "5.0.1",
"mem": "9.0.2"
}
}
-4
View File
@@ -1,4 +0,0 @@
{
"string-width": "5.0.1",
"mem": "9.0.2"
}
-15
View File
@@ -1,15 +0,0 @@
import fs from "node:fs/promises";
const vendorVersionsPath = new URL("./vendor-versions.json", import.meta.url);
export async function getVendorVersions() {
return JSON.parse(await fs.readFile(vendorVersionsPath));
}
export async function writeVendorVersions(data) {
await fs.writeFile(
vendorVersionsPath,
JSON.stringify(data, null, 2) + "\n",
"utf-8"
);
}