Files
client/scripts/vendor-chat-notices.mjs
T
omar f618d8bce9
ci / linux-arm64-cross (push) Successful in 3m22s
ci / linux-x64 (push) Successful in 3m32s
chat: add safe hybrid Markdown editing with strict CSP
2026-11-02 11:32:31 +03:00

26 lines
2.3 KiB
JavaScript

// Collect redistribution notices from the exact package-lock used for vendored chat assets.
// Usage: node scripts/vendor-chat-notices.mjs <external npm workspace>
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const workspace = path.resolve(process.argv[2]);
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const lock = JSON.parse(fs.readFileSync(path.join(workspace, 'package-lock.json'), 'utf8'));
const output = ['Chat renderer dependency notices', 'The npm workspace inventory below conservatively includes build/type-only dependencies as well as runtime bundled dependencies; devDependencies (build tools such as esbuild) are not redistributed and are excluded.', 'DOMPurify is redistributed under its Apache-2.0 option. No official TeamSpeak bundle is redistributed.'];
const inventory = [];
for (const [location, entry] of Object.entries(lock.packages)) {
if (!location || entry.dev) continue;
const dir = path.join(workspace, location);
const metadata = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
const names = fs.readdirSync(dir).filter((name) => /^(licen[cs]e|copying|notice)([.-].*)?$/i.test(name) && fs.statSync(path.join(dir, name)).isFile());
if (!names.length && ['fastdom', 'strictdom'].includes(metadata.name)) names.push('README.md');
if (!names.length) throw new Error(`Missing redistribution notice: ${location}`);
inventory.push({ name: metadata.name, version: entry.version, license: metadata.license ?? (metadata.name === 'khroma' ? 'MIT (license file)' : null), resolved: entry.resolved, integrity: entry.integrity, location });
output.push(`\n===== ${metadata.name}@${entry.version} (${metadata.license ?? 'see license text'}) =====`);
for (const name of names) output.push(`\n--- ${name} ---\n${fs.readFileSync(path.join(dir, name), 'utf8')}`);
}
const dir = path.join(root, 'app/renderer/vendor');
fs.writeFileSync(path.join(dir, 'THIRD_PARTY_NOTICES.txt'), output.join('\n') + '\n');
fs.writeFileSync(path.join(dir, 'DEPENDENCIES.json'), JSON.stringify({ provenance: 'external npm workspace lock; conservative inventory, not an exact bundle module map', packages: inventory }, null, 2) + '\n');
console.log(`Wrote notices and provenance for ${inventory.length} packages`);