|
1 | 1 | #!/usr/bin/env node |
2 | | -import { execSync } from "node:child_process"; |
3 | | -import { readFileSync } from "node:fs"; |
4 | | -import { join } from "node:path"; |
5 | | - |
6 | | -type Package = { |
7 | | - name: string; |
8 | | - versions: string[]; |
9 | | - paths: string[]; |
10 | | - license: string; |
11 | | - homepage: string; |
12 | | -}; |
13 | | - |
14 | | -type PackageJson = { |
15 | | - dependencies?: Record<string, string>; |
16 | | -}; |
17 | | - |
18 | | -// Packages whose direct dependencies we want to include in NOTICE.md |
19 | | -const PUBLISHED_PACKAGES = [ |
20 | | - "packages/appkit", |
21 | | - "packages/appkit-ui", |
22 | | - "packages/shared", |
23 | | -]; |
24 | | - |
25 | | -function getDirectDependencies(): Set<string> { |
26 | | - const directDeps = new Set<string>(); |
27 | | - |
28 | | - for (const pkgPath of PUBLISHED_PACKAGES) { |
29 | | - const pkgJsonPath = join(process.cwd(), pkgPath, "package.json"); |
30 | | - try { |
31 | | - const content = readFileSync(pkgJsonPath, "utf8"); |
32 | | - const pkgJson: PackageJson = JSON.parse(content); |
33 | | - |
34 | | - if (pkgJson.dependencies) { |
35 | | - for (const depName of Object.keys(pkgJson.dependencies)) { |
36 | | - if (!pkgJson.dependencies[depName].startsWith("workspace:")) { |
37 | | - directDeps.add(depName); |
38 | | - } |
39 | | - } |
40 | | - } |
41 | | - } catch (err) { |
42 | | - console.error(`Warning: Could not read ${pkgJsonPath}:`, err); |
43 | | - } |
44 | | - } |
45 | | - |
46 | | - return directDeps; |
47 | | -} |
| 2 | +import { type Package, getDirectDependencyLicenses } from "./license-utils"; |
48 | 3 |
|
49 | 4 | try { |
50 | | - const output = execSync("pnpm licenses list --json --production", { |
51 | | - encoding: "utf8", |
52 | | - }); |
53 | | - const licenses: Record<string, Package[]> = JSON.parse(output); |
54 | | - const directDeps = getDirectDependencies(); |
55 | | - |
56 | | - const dependencies: Package[] = []; |
57 | | - |
58 | | - for (const [licenseName, packages] of Object.entries(licenses)) { |
59 | | - for (const pkg of packages) { |
60 | | - // Only include direct dependencies |
61 | | - if (directDeps.has(pkg.name)) { |
62 | | - dependencies.push({ ...pkg, license: licenseName }); |
63 | | - } |
64 | | - } |
65 | | - } |
66 | | - |
67 | | - main(dependencies); |
| 5 | + const packages = getDirectDependencyLicenses(); |
| 6 | + main(packages); |
68 | 7 | } catch (err) { |
69 | 8 | console.error("❌ Error running license check:", err); |
70 | 9 | process.exit(1); |
@@ -96,7 +35,7 @@ This Software contains code from the following open source projects: |
96 | 35 | } |
97 | 36 | notice += `| [${dep.name}](https://www.npmjs.com/package/${ |
98 | 37 | dep.name |
99 | | - }) | ${dep.versions.join(", ")} | ${dep.license} | ${dep.homepage} |\n`; |
| 38 | + }) | ${dep.versions.join(", ")} | ${dep.license} | ${dep.homepage ?? ""} |\n`; |
100 | 39 | } |
101 | 40 | // eslint-disable-next-line no-console |
102 | 41 | console.log(notice); |
|
0 commit comments