Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -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/<target>/: 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/<target>/: 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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 30 additions & 1 deletion esbuild.mjs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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`)
}
Loading