From a562fb284b4716033996fda01ac124d9c6932a53 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 5 Apr 2024 12:40:47 +0100 Subject: [PATCH 1/5] Compile dependent licenses --- scripts/rollup.config.mjs | 45 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/scripts/rollup.config.mjs b/scripts/rollup.config.mjs index 9c0baabb..fb7844f0 100644 --- a/scripts/rollup.config.mjs +++ b/scripts/rollup.config.mjs @@ -1,6 +1,8 @@ import fs from 'node:fs/promises'; import path from 'node:path/posix'; +import { fileURLToPath } from 'node:url'; import { readFileSync } from 'node:fs'; +import { createRequire } from 'node:module'; import * as prettier from 'prettier'; import commonjs from '@rollup/plugin-commonjs'; @@ -10,6 +12,8 @@ import terser from '@rollup/plugin-terser'; import cjsCheck from 'rollup-plugin-cjs-check'; import dts from 'rollup-plugin-dts'; +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + const normalize = name => [] .concat(name) .join(' ') @@ -34,7 +38,8 @@ const externalModules = [ ...Object.keys(meta.peerDependencies || {}), ]; -const external = new RegExp(`^(${externalModules.join('|')})($|/)`); +const moduleRe = /^(?!node:|[.{1,2}\/])(@[\w.-]+\/)?[\w.-]+/; +const externalRe = new RegExp(`^(${externalModules.join('|')})($|/)`); const exports = {}; for (const key in meta.exports) { @@ -49,6 +54,8 @@ for (const key in meta.exports) { } } +const externals = new Set(); + const commonConfig = { input: Object.entries(exports).reduce((input, [exportName, entry]) => { input[exportName] = entry.source; @@ -56,7 +63,10 @@ const commonConfig = { }, {}), onwarn: () => {}, external(id) { - return external.test(id); + const isExternal = externalRe.test(id); + if (!isExternal && moduleRe.test(id)) + externals.add(id); + return isExternal; }, treeshake: { unknownGlobalSideEffects: false, @@ -129,6 +139,37 @@ const outputPlugins = [ }, }, + { + name: 'outputBundledLicenses', + async writeBundle() { + const { resolve } = createRequire(import.meta.url); + const rootLicense = await fs.readFile(path.join(__dirname, '../LICENSE.md'), 'utf8'); + const licenses = new Map(); + for (const packageName of externals) { + let license; + const metaPath = resolve(packageName + '/package.json'); + const packagePath = path.dirname(metaPath); + let licenseName = (await fs.readdir(packagePath)) + .find((name) => /^licen[sc]e/i.test(name)); + if (!licenseName) { + const meta = require(metaPath); + const match = /^SEE LICENSE IN (.*)/i.exec(meta.license || ''); + licenseName = match ? match[1] : meta.license; + } + try { + license = await fs.readFile(path.join(packagePath, licenseName), 'utf8'); + } catch (_error) { + license = `${licenseName}, Copyright (c) ${meta.author}`; + } + licenses.set(packageName, license); + } + let output = rootLicense.trim(); + for (const [packageName, licenseText] of licenses) + output += `\n\n## ${packageName}\n\n${licenseText.trim()}`; + await fs.writeFile('LICENSE.md', output); + }, + }, + cjsCheck(), terser({ From aae474f66b0cda16b4e14bd046cc358ed4421b55 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 5 Apr 2024 12:41:46 +0100 Subject: [PATCH 2/5] Fix built-ins not externalising --- scripts/rollup.config.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/rollup.config.mjs b/scripts/rollup.config.mjs index fb7844f0..2d56d591 100644 --- a/scripts/rollup.config.mjs +++ b/scripts/rollup.config.mjs @@ -2,7 +2,7 @@ import fs from 'node:fs/promises'; import path from 'node:path/posix'; import { fileURLToPath } from 'node:url'; import { readFileSync } from 'node:fs'; -import { createRequire } from 'node:module'; +import { createRequire, isBuiltin } from 'node:module'; import * as prettier from 'prettier'; import commonjs from '@rollup/plugin-commonjs'; @@ -63,7 +63,7 @@ const commonConfig = { }, {}), onwarn: () => {}, external(id) { - const isExternal = externalRe.test(id); + const isExternal = isBuiltin(id) || externalRe.test(id); if (!isExternal && moduleRe.test(id)) externals.add(id); return isExternal; From 3d129b66026dc25c51b87cb0b66afb7654b813c6 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 5 Apr 2024 13:00:03 +0100 Subject: [PATCH 3/5] Update licenses --- LICENSE.md | 2 +- packages/cli-utils/LICENSE.md | 74 ++++++++++++++++++++ packages/internal/LICENSE.md | 125 ++++++++++++++++++++++++++++++++++ 3 files changed, 200 insertions(+), 1 deletion(-) diff --git a/LICENSE.md b/LICENSE.md index 25ce8b2c..adef8fd1 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -18,4 +18,4 @@ 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. +SOFTWARE. \ No newline at end of file diff --git a/packages/cli-utils/LICENSE.md b/packages/cli-utils/LICENSE.md index 25ce8b2c..1ca4f4fd 100644 --- a/packages/cli-utils/LICENSE.md +++ b/packages/cli-utils/LICENSE.md @@ -19,3 +19,77 @@ 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. + +## sade + +The MIT License (MIT) + +Copyright (c) Luke Edwards (https://lukeed.com) + +Permission 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: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE 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. + +## json5 + +MIT License + +Copyright (c) 2012-2018 Aseem Kishore, and [others]. + +Permission 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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE 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. + +[others]: https://github.com/json5/json5/contributors + +## mri + +The MIT License (MIT) + +Copyright (c) Luke Edwards (lukeed.com) + +Permission 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: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE 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. \ No newline at end of file diff --git a/packages/internal/LICENSE.md b/packages/internal/LICENSE.md index 25ce8b2c..a54208d5 100644 --- a/packages/internal/LICENSE.md +++ b/packages/internal/LICENSE.md @@ -19,3 +19,128 @@ 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. + +## json5 + +MIT License + +Copyright (c) 2012-2018 Aseem Kishore, and [others]. + +Permission 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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE 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. + +[others]: https://github.com/json5/json5/contributors + +## @urql/introspection + +MIT License + +Copyright (c) 2018–2020 Formidable, +Copyright (c) urql GraphQL Team and other contributors + +Permission 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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE 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. + +## @urql/core + +MIT License + +Copyright (c) 2018–2020 Formidable, +Copyright (c) urql GraphQL Team and other contributors + +Permission 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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE 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. + +## @urql/exchange-retry + +MIT License + +Copyright (c) 2018–2020 Formidable, +Copyright (c) urql GraphQL Team and other contributors + +Permission 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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE 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. + +## wonka + +MIT License + +Copyright (c) 0no.co + +Permission 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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE 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. \ No newline at end of file From ddf9feb38ee743b47eca2267d589f59560010a13 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 5 Apr 2024 13:09:23 +0100 Subject: [PATCH 4/5] Prevent root license from being overwritten --- scripts/rollup.config.mjs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/rollup.config.mjs b/scripts/rollup.config.mjs index 2d56d591..512446b2 100644 --- a/scripts/rollup.config.mjs +++ b/scripts/rollup.config.mjs @@ -143,7 +143,9 @@ const outputPlugins = [ name: 'outputBundledLicenses', async writeBundle() { const { resolve } = createRequire(import.meta.url); - const rootLicense = await fs.readFile(path.join(__dirname, '../LICENSE.md'), 'utf8'); + const rootLicense = path.join(__dirname, '../LICENSE.md'); + const outputLicense = path.resolve('LICENSE.md'); + if (rootLicense === outputLicense) return; const licenses = new Map(); for (const packageName of externals) { let license; @@ -163,10 +165,10 @@ const outputPlugins = [ } licenses.set(packageName, license); } - let output = rootLicense.trim(); + let output = (await fs.readFile(rootLicense, 'utf8')).trim(); for (const [packageName, licenseText] of licenses) output += `\n\n## ${packageName}\n\n${licenseText.trim()}`; - await fs.writeFile('LICENSE.md', output); + await fs.writeFile(outputLicense, output); }, }, From 8bde1b9c48499932a22aa71b281ab6656f8ba102 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 5 Apr 2024 13:10:02 +0100 Subject: [PATCH 5/5] Add changeset --- .changeset/green-waves-tie.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/green-waves-tie.md diff --git a/.changeset/green-waves-tie.md b/.changeset/green-waves-tie.md new file mode 100644 index 00000000..56c4bae8 --- /dev/null +++ b/.changeset/green-waves-tie.md @@ -0,0 +1,6 @@ +--- +"@gql.tada/cli-utils": patch +"@gql.tada/internal": patch +--- + +Add bundled licenses of internalized modules