From c838b07df117cb3fa8e2f3781c5860c9d093bc04 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Mon, 16 Nov 2026 15:53:39 -0300 Subject: [PATCH] license: ship the bundle's third-party notices in the VSIX esbuild writes dist/THIRD_PARTY_NOTICES from its metafile: the license text of every npm package whose code reached dist/extension.js, as their terms demand of a copy. Today the bundle takes none, so the file says so; a package that starts reaching the bundle is named without anyone remembering to, and one with no license file fails the build. LICENSE's appendix names the copyright holder as the spin-stack Authors, the same line every spin-stack repository carries. Co-Authored-By: Claude Opus 5.5 --- .vscodeignore | 7 ++++--- LICENSE | 2 +- esbuild.mjs | 31 ++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) 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`) +}