/** * Third-party licensing, generated and enforced. * * npm run generate:third-party rewrite THIRD_PARTY_NOTICES.md * npm run check:licenses fail if it is stale, or if anything shipped * to users carries a license not on the list * * THIRD_PARTY_NOTICES.md used to be hand-maintained and had drifted three * majors behind (React 18, Vite 7, Tailwind 3 …). It is now built from * package.json, the installed packages and Cargo.toml/Cargo.lock, so CI * catches the drift instead of a reader. The full license texts of every * package bundled into the web app are emitted separately by Vite * (`build.license`) to /licenses/third-party.md. */ import { readFileSync, writeFileSync } from "fs"; import { resolve } from "path"; import { compareCodeUnits } from "../../src/utils/sort.ts"; const ROOT = resolve(import.meta.dirname, "../.."); const NOTICES = resolve(ROOT, "THIRD_PARTY_NOTICES.md"); /** Licenses acceptable for code that ships inside the app. */ const ALLOWED = new Set([ "MIT", "ISC", "Apache-2.0", "BSD-2-Clause", "BSD-3-Clause", "0BSD", "CC0-1.0", "Unlicense", "BlueOak-1.0.0", "OFL-1.1", "Zlib", "MPL-2.0", ]); /** SPDX expression → allowed? `OR` needs one side, `AND` needs both. */ export function licenseAllowed(expression: string): boolean { const expr = expression.trim().replace(/^\((.*)\)$/, "$1"); if (/\sOR\s/i.test(expr)) return expr.split(/\s+OR\s+/i).some(licenseAllowed); if (/\sAND\s/i.test(expr)) return expr.split(/\s+AND\s+/i).every(licenseAllowed); return ALLOWED.has(expr); } interface PackageJson { name?: string; version?: string; license?: string; homepage?: string; repository?: string | { url?: string }; dependencies?: Record; devDependencies?: Record; } function readJson(path: string): T { return JSON.parse(readFileSync(path, "utf8")) as T; } function projectUrl(pkg: PackageJson): string { const repo = typeof pkg.repository === "string" ? pkg.repository : pkg.repository?.url; const fromRepo = repo ?.replace(/^git\+/, "") .replace(/^git:\/\//, "https://") .replace(/^github:/, "https://github.com/") .replace(/\.git$/, ""); if (fromRepo && /^https?:\/\//.test(fromRepo)) return fromRepo; if (fromRepo && /^[\w.-]+\/[\w.-]+$/.test(fromRepo)) return `https://github.com/${fromRepo}`; return pkg.homepage ?? ""; } interface Row { name: string; version: string; license: string; url: string; } function npmRows(keys: string[]): Row[] { return keys .map((key) => { const pkg = readJson(resolve(ROOT, "node_modules", key, "package.json")); return { // An npm alias installs under its key: `"typescript": // "npm:@typescript/typescript6@…"` puts @typescript/typescript6 in // node_modules/typescript. Name the package that is really there. name: pkg.name ?? key, version: pkg.version ?? "?", license: pkg.license ?? "UNKNOWN", url: projectUrl(pkg), }; }) .sort((a, b) => compareCodeUnits(a.name, b.name)); } /** * Crates `src-tauri/Cargo.toml` depends on directly — the `[dependencies]`, * `[build-dependencies]` and `[target.….dependencies]` tables. Dev-only * dependencies don't ship and are left out. */ export function directCrates(toml: string): string[] { const names = new Set(); let inDependencies = false; for (const raw of toml.replace(/\r\n/g, "\n").split("\n")) { const line = raw.trim(); if (line.startsWith("[")) { inDependencies = /^\[(?:target\..+\.)?(?:build-)?dependencies\]$/.test(line); continue; } const name = inDependencies ? /^([A-Za-z0-9_-]+)\s*=/.exec(line)?.[1] : undefined; if (name) names.add(name); } return [...names].sort(); } /** * License and project page of the direct crates that aren't Tauri's own. * Cargo.lock carries no license, so a new dependency fails the generator * until it is added here; `cargo deny` vets the transitive tree. */ const OTHER_CRATES: Record = { serde: { license: "MIT OR Apache-2.0", url: "https://github.com/serde-rs/serde" }, }; function crateInfo(name: string): { license: string; url: string } { if (name.startsWith("tauri-plugin")) { return { license: "Apache-2.0 OR MIT", url: "https://github.com/tauri-apps/plugins-workspace" }; } if (name.startsWith("tauri")) { return { license: "Apache-2.0 OR MIT", url: "https://github.com/tauri-apps/tauri" }; } const info = OTHER_CRATES[name]; if (!info) { throw new Error( `src-tauri depends on "${name}": add its license and project page to OTHER_CRATES in scripts/lib/third-party.ts`, ); } return info; } function crateRows(): Row[] { const toml = readFileSync(resolve(ROOT, "src-tauri/Cargo.toml"), "utf8"); const lock = readFileSync(resolve(ROOT, "src-tauri/Cargo.lock"), "utf8").replace(/\r\n/g, "\n"); return directCrates(toml).map((name) => { const version = new RegExp(`\\[\\[package\\]\\]\\nname = "${name}"\\nversion = "([^"]+)"`).exec(lock)?.[1] ?? "?"; return { name, version, ...crateInfo(name) }; }); } function table(rows: Row[], heading: string): string { const lines = rows.map( (r) => `| \`${r.name}\` | ${r.version} | ${r.license} | ${r.url ? `<${r.url}>` : "—"} |`, ); return [ `| ${heading} | Version | License | Project |`, "| --- | --- | --- | --- |", ...lines, ].join("\n"); } export function renderNotices(): string { const pkg = readJson(resolve(ROOT, "package.json")); const runtime = npmRows(Object.keys(pkg.dependencies ?? {})); const dev = npmRows(Object.keys(pkg.devDependencies ?? {})); return ` # Third-Party Notices YTDescGen is built on the open-source software and services below. Each component keeps its own license; the linked project pages carry the full terms. The **complete license text of every package bundled into the web app** — including transitive dependencies such as \`scheduler\` or \`@babel/runtime\` — is published with each release at [\`/licenses/third-party.md\`](https://ytgenerator.stream/licenses/third-party.md), generated by Vite from the exact build. ## Runtime dependencies Bundled into the web app and the desktop / Android apps. ${table(runtime, "Package")} ## Build and development tools Used to build, test and check YTDescGen. Not shipped to users. ${table(dev, "Package")} ## Desktop and Android shell (Rust crates) Direct dependencies of \`src-tauri/\`. Transitive crates are checked in CI by \`cargo deny\` (see \`src-tauri/deny.toml\`); \`cargo tree\` lists them all. ${table(crateRows(), "Crate")} ## Fonts and icons - **Icons:** [Lucide](https://lucide.dev/) (\`lucide-react\`, ISC). Brand marks, where shown, come from [Simple Icons](https://simpleicons.org/) (CC0-1.0); the trademarks belong to their owners. - **Fonts:** [Inter](https://rsms.me/inter/) and [JetBrains Mono](https://www.jetbrains.com/lp/mono/), bundled with the app from the \`@fontsource-variable\` packages above (SIL Open Font License 1.1, \`OFL-1.1\`). ## Services (web app only) The web app at ytgenerator.stream is delivered by Cloudflare. These are services, not bundled code; the [Privacy Policy](PRIVACY.md) explains what each processes. | Service | Purpose | Terms | | --- | --- | --- | | Cloudflare Workers | Hosting and delivery | | | Cloudflare Turnstile | Bot check before entering | | | Cloudflare Web Analytics | Cookieless, aggregate visit statistics | | The desktop and Android apps use none of them. ## AI-assisted development As described in the [Disclaimer](DISCLAIMER.md), YTDescGen is developed with **Anthropic's Claude Code** (Claude Opus models). The model contributes source code, translations, documentation and CI configuration; every change is reviewed by the maintainer (\`@poli0981\`) before it is merged. Claude is a product of Anthropic, PBC — . The Apache-2.0 license in [\`LICENSE\`](LICENSE) is granted by the project author, not by Anthropic. ## Questions and omissions Licensing and attribution questions: **copyright@poli0981.dev**. If you believe something is missing here, open an issue or pull request per [\`CONTRIBUTING.md\`](CONTRIBUTING.md). `; } /** Production packages (bundled into the app) whose license is not allowed. */ export function disallowedProductionLicenses(): string[] { const lock = readJson<{ packages: Record; }>(resolve(ROOT, "package-lock.json")); const bad: string[] = []; for (const [path, entry] of Object.entries(lock.packages)) { if (path === "" || entry.dev || entry.devOptional) continue; const license = typeof entry.license === "string" ? entry.license : "UNKNOWN"; if (!licenseAllowed(license)) bad.push(`${path.replace(/^.*node_modules\//, "")} (${license})`); } return bad; } export function main(): void { const write = process.argv.includes("--write"); const expected = renderNotices(); if (write) { writeFileSync(NOTICES, expected); console.log("THIRD_PARTY_NOTICES.md regenerated."); return; } let failed = false; const bad = disallowedProductionLicenses(); if (bad.length > 0) { failed = true; console.error(`✗ Bundled packages with licenses outside the allowlist:\n ${bad.join("\n ")}`); } else { console.log("✓ Every bundled package has an allowed license."); } const current = readFileSync(NOTICES, "utf8").replace(/\r\n/g, "\n"); if (current !== expected) { failed = true; console.error("✗ THIRD_PARTY_NOTICES.md is stale — run `npm run generate:third-party`."); } else { console.log("✓ THIRD_PARTY_NOTICES.md matches package.json, the lockfile and Cargo.toml."); } if (failed) process.exit(1); }