/** * THIRD_PARTY_NOTICES.md carries what the LGPL and Apache-2.0 ask for: the * full license texts, every LGPL component with its version and source, and * the Apache-2.0 files of @waggle/core. Regenerate the file when this fails: * node scripts/generate-third-party-notices.mjs */ import fs from 'node:fs'; import path from 'node:path'; import { describe, expect, it } from 'vitest'; import { npmArtifacts, npmClosure, readLockfilePackages, uniqueVersions } from './license-inventory.mjs'; const ROOT = path.resolve(import.meta.dirname, '..'); const notices = fs.readFileSync(path.join(ROOT, 'THIRD_PARTY_NOTICES.md'), 'utf8'); const lgplSection = notices.slice(notices.indexOf('### LGPL-3.0'), notices.indexOf('### MPL-2.0')); const readText = (file: string) => fs.readFileSync(path.join(ROOT, file), 'utf8').replace(/\r\n?/g, '\n').trim(); describe('THIRD_PARTY_NOTICES.md', () => { it('carries the full LGPL-3.0 and GPL-3.0 texts', () => { const lgpl = readText('scripts/license-texts/LGPL-3.0.txt'); const gpl = readText('scripts/license-texts/GPL-3.0.txt'); expect(lgpl).toContain('GNU LESSER GENERAL PUBLIC LICENSE'); expect(gpl).toContain('How to Apply These Terms to Your New Programs'); expect(notices).toContain(lgpl); expect(notices).toContain(gpl); }); it('names every shipped LGPL package with its version, unmodified, and its source', () => { const packages = readLockfilePackages(); const lgplPackages = npmArtifacts().flatMap((artifact) => uniqueVersions(npmClosure(packages, artifact).packages.values())) .filter((pkg) => /LGPL/.test(pkg.license ?? '')); expect(lgplPackages.length).toBeGreaterThan(0); expect(lgplSection).toContain('Each ships unmodified, as a separate library'); for (const pkg of lgplPackages) { const row = lgplSection.split('\n').find((line) => line.startsWith(`| ${pkg.name} | ${pkg.version} |`)); expect(row, `${pkg.name}@${pkg.version} is missing from the LGPL section`).toBeDefined(); expect(row).toMatch(/https:\/\/(?:github\.com\/\S+\/releases\/tag\/v\S+|registry\.npmjs\.org\/\S+\.tgz)/); } }); it('lists the Apache-2.0 files of @waggle/core with the Apache-2.0 text', () => { const listed = [...readText('packages/core/LICENSE.md').matchAll(/^\| `(src\/[^`]+)` \|/gm)].map((match) => match[1]); expect(listed.length).toBeGreaterThan(0); for (const file of listed) expect(notices).toContain(`| \`packages/core/${file}\` |`); expect(notices).toContain(readText('packages/core/LICENSE-APACHE')); }); });