diff --git a/.vscodeignore b/.vscodeignore index 9b4b84c..a87d48e 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -1,11 +1,12 @@ -# The package carries package.json, README.md, LICENSE, the icon, the bundle in dist/ and, in a -# platform's package (task package:all), that platform's spin CLI and its VERSION under -# bin//: everything else is how it is built and tested. +# The package carries package.json, README.md, LICENSE, the icon, the bundle in dist/ with the +# licenses of what it bundled and, in a platform's package (task package:all), that platform's +# spin CLI and its VERSION under bin//: everything else is how it is built and tested. ** !package.json !README.md !LICENSE !images/icon.png !dist/extension.js +!dist/THIRD_PARTY_NOTICES !bin/*/spin !bin/*/VERSION diff --git a/LICENSE b/LICENSE index f824c58..79ce61e 100644 --- a/LICENSE +++ b/LICENSE @@ -176,7 +176,7 @@ END OF TERMS AND CONDITIONS - Copyright The spin Authors + Copyright The spin-stack Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/esbuild.mjs b/esbuild.mjs index a2c8d27..d0e4de9 100644 --- a/esbuild.mjs +++ b/esbuild.mjs @@ -1,10 +1,12 @@ // Bundles the extension into dist/extension.js, or with --tests the integration suite into // dist-test/, which VS Code loads in its extension host. vscode is VS Code's own, never bundled. +import { readdirSync, readFileSync, writeFileSync } from "node:fs" +import { join } from "node:path" import { build } from "esbuild" const tests = process.argv.includes("--tests") -await build({ +const result = await build({ entryPoints: tests ? ["test/integration/suite.ts"] : ["src/extension.ts"], outfile: tests ? "dist-test/suite.js" : "dist/extension.js", bundle: true, @@ -14,5 +16,32 @@ await build({ external: ["vscode"], sourcemap: true, minify: !tests, + metafile: !tests, logLevel: "warning", }) + +if (!tests) { + writeFileSync("dist/THIRD_PARTY_NOTICES", notices(Object.keys(result.metafile.inputs))) +} + +// The license of every package the bundle took code from, as its MIT, BSD or Apache terms demand +// of a copy: the metafile's inputs are exactly what esbuild put in extension.js, so a package +// only installed for building is never named and one that reaches the bundle always is. +function notices(inputs) { + const dirs = new Set() + for (const input of inputs) { + const m = input.match(/^(.*node_modules\/(?:@[^/]+\/)?[^/]+)\//) + if (m) dirs.add(m[1]) + } + const parts = [...dirs].sort().map((dir) => { + const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")) + const file = readdirSync(dir) + .sort() + .find((f) => /^(licen[cs]e|copying|notice)/i.test(f)) + if (!file) throw new Error(`${pkg.name}@${pkg.version} is bundled and ships no license file`) + return `${pkg.name}@${pkg.version} (${pkg.license})\n\n${readFileSync(join(dir, file), "utf8").trim()}\n` + }) + const head = "Third-party software in dist/extension.js and the license of each.\n" + if (parts.length === 0) return `${head}\nThe bundle includes no third-party package.\n` + return [head, ...parts].join(`\n${"-".repeat(80)}\n\n`) +}