Regexes with super-linear backtracking (S8786 x16) are rewritten to stay linear on long runs; each new pattern gives the same results as the old one on 150k-450k fuzzed inputs (except where noted) and finishes adversarial 50k-character inputs in under 3 ms: - tag-generator QUALIFIER_SUFFIX_RE starts just before a `:`/space run (`(^|[^:\s])…` + "$1"), never inside one - timeline-parser matches `line.trimEnd()` with a greedy label, and renders with trimEnd(); cleanCpuName collapses whitespace before the patterns - editor-store endings, Google Play urlPattern (lookahead for `id=`), channel-phrase punctuation, SPDX OR/AND split, legal-docs slug and link stripping (link text/URL may not contain `[`), base64url padding, and a loop for trailing slashes in the worker router Others: - S2871: sorts take the shared code-unit comparator (same order as before; THIRD_PARTY_NOTICES is unchanged) - S4822: ErrorBoundary catches the logger import with .catch(), which a try/catch never could - S3516: migrateProfilesState returns a new object - S7773: Number.parseInt (x10) - S9379: Modal takes an initialFocusRef (Radix onOpenAutoFocus), so the shortcut search box gets focus without an autoFocus attribute - S2245: generateId drops the Math.random fallback; getRandomValues exists everywhere the app runs, and a non-random ID is worse than an error - S4036: NOSONAR on the dev script's `git` call (PATH lookup by design) - S6505/S8543: every workflow installs with `npm ci --ignore-scripts`, and CI runs `npm run cf:check` instead of `npx wrangler …` - S6358: Android sets allowBackup="false" — app data is no longer copied to Google Drive backups; Backup & Restore moves it to a new phone Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
260 lines
10 KiB
TypeScript
260 lines
10 KiB
TypeScript
/**
|
|
* 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");
|
|
// Split on the bare operator; each part is trimmed by the recursive call.
|
|
if (/\sOR\s/i.test(expr)) return expr.split(/\sOR\s/i).some(licenseAllowed);
|
|
if (/\sAND\s/i.test(expr)) return expr.split(/\sAND\s/i).every(licenseAllowed);
|
|
return ALLOWED.has(expr);
|
|
}
|
|
|
|
interface PackageJson {
|
|
name?: string;
|
|
version?: string;
|
|
license?: string;
|
|
homepage?: string;
|
|
repository?: string | { url?: string };
|
|
dependencies?: Record<string, string>;
|
|
devDependencies?: Record<string, string>;
|
|
}
|
|
|
|
function readJson<T>(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<PackageJson>(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<string>();
|
|
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(compareCodeUnits);
|
|
}
|
|
|
|
/**
|
|
* 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<string, { license: string; url: string }> = {
|
|
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<PackageJson>(resolve(ROOT, "package.json"));
|
|
const runtime = npmRows(Object.keys(pkg.dependencies ?? {}));
|
|
const dev = npmRows(Object.keys(pkg.devDependencies ?? {}));
|
|
return `<!-- Generated by scripts/third-party.ts (npm run generate:third-party). Edit the script, not this file; CI fails when it is stale. -->
|
|
|
|
# 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 | <https://www.cloudflare.com/terms/> |
|
|
| Cloudflare Turnstile | Bot check before entering | <https://www.cloudflare.com/turnstile-privacy-policy/> |
|
|
| Cloudflare Web Analytics | Cookieless, aggregate visit statistics | <https://www.cloudflare.com/privacypolicy/> |
|
|
|
|
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 — <https://www.anthropic.com>. 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<string, { dev?: boolean; devOptional?: boolean; license?: unknown }>;
|
|
}>(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);
|
|
}
|