diff --git a/cspell.json b/cspell.json index 6b9a2c064..dc0c23ca4 100644 --- a/cspell.json +++ b/cspell.json @@ -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" ] } diff --git a/scripts/build/build.mjs b/scripts/build/build.mjs index 65f147e11..f5ca1f495 100644 --- a/scripts/build/build.mjs +++ b/scripts/build/build.mjs @@ -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( diff --git a/scripts/utils/index.mjs b/scripts/utils/index.mjs index 46438ac31..9e9e1c5a5 100644 --- a/scripts/utils/index.mjs +++ b/scripts/utils/index.mjs @@ -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 { diff --git a/scripts/vendors/bundle-vendors.mjs b/scripts/vendors/bundle-vendors.mjs index 80392e3b6..8a82f8cbc 100644 --- a/scripts/vendors/bundle-vendors.mjs +++ b/scripts/vendors/bundle-vendors.mjs @@ -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(); diff --git a/scripts/vendors/utils.mjs b/scripts/vendors/utils.mjs new file mode 100644 index 000000000..b579fd05b --- /dev/null +++ b/scripts/vendors/utils.mjs @@ -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); +} diff --git a/scripts/vendors/validate-vendor-versions.mjs b/scripts/vendors/validate-vendor-versions.mjs index 3f4033d4d..d5a408af7 100644 --- a/scripts/vendors/validate-vendor-versions.mjs +++ b/scripts/vendors/validate-vendor-versions.mjs @@ -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); diff --git a/scripts/vendors/vendor-meta.json b/scripts/vendors/vendor-meta.json new file mode 100644 index 000000000..acd4925ac --- /dev/null +++ b/scripts/vendors/vendor-meta.json @@ -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 (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 (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 (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 \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 (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 (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.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 (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 (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" + } +} diff --git a/scripts/vendors/vendor-versions.json b/scripts/vendors/vendor-versions.json deleted file mode 100644 index 37af8fec9..000000000 --- a/scripts/vendors/vendor-versions.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "string-width": "5.0.1", - "mem": "9.0.2" -} diff --git a/scripts/vendors/vendor-versions.mjs b/scripts/vendors/vendor-versions.mjs deleted file mode 100644 index 37ae16521..000000000 --- a/scripts/vendors/vendor-versions.mjs +++ /dev/null @@ -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" - ); -}