()
| 128 | } |
| 129 | |
| 130 | async function main() { |
| 131 | const args = process.argv.slice(2); |
| 132 | const outputIdx = args.indexOf("--output"); |
| 133 | const outputFile = outputIdx !== -1 && args[outputIdx + 1] |
| 134 | ? args[outputIdx + 1] |
| 135 | : OUTPUT_DEFAULT; |
| 136 | |
| 137 | const lockfilePath = path.join(process.cwd(), "yarn.lock"); |
| 138 | if (!fs.existsSync(lockfilePath)) { |
| 139 | console.error("yarn.lock not found in current directory. Run `yarn install` first."); |
| 140 | process.exit(1); |
| 141 | } |
| 142 | |
| 143 | console.log("1. Parsing yarn.lock..."); |
| 144 | const resolutions = parseYarnLock(lockfilePath); |
| 145 | console.log(` Found ${resolutions.length} external package entries`); |
| 146 | |
| 147 | // Deduplicate by name+version |
| 148 | const uniquePackages = new Map(); |
| 149 | for (const resolution of resolutions) { |
| 150 | const parsed = parseResolution(resolution); |
| 151 | if (!parsed) continue; |
| 152 | const key = `${parsed.name}@${parsed.version}`; |
| 153 | if (!uniquePackages.has(key)) { |
| 154 | uniquePackages.set(key, parsed); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | const packages = Array.from(uniquePackages.values()); |
| 159 | console.log(` ${packages.length} unique packages after deduplication`); |
| 160 | |
| 161 | console.log("\n2. Fetching license information from npm registry..."); |
| 162 | const results = await processInBatches(packages, CONCURRENCY, (pkg) => |
| 163 | fetchLicense(pkg.name, pkg.version) |
| 164 | ); |
| 165 | |
| 166 | // Apply license overrides from npmLicenseMap.json |
| 167 | const licenseMap = loadLicenseMap(); |
| 168 | const overrideCount = applyLicenseMap(results, licenseMap); |
| 169 | if (overrideCount > 0) { |
| 170 | console.log(`\n Applied ${overrideCount} license override(s) from npmLicenseMap.json`); |
| 171 | } |
| 172 | |
| 173 | // Sort by package name for stable output |
| 174 | results.sort((a, b) => a.name.localeCompare(b.name) || a.version.localeCompare(b.version)); |
| 175 | |
| 176 | const output = { |
| 177 | generatedAt: new Date().toISOString(), |
| 178 | totalPackages: results.length, |
| 179 | packages: results, |
| 180 | }; |
| 181 | |
| 182 | const outputPath = path.join(process.cwd(), outputFile); |
| 183 | fs.writeFileSync(outputPath, JSON.stringify(output, null, 2) + "\n"); |
| 184 | console.log(`\n3. Results written to ${outputFile}`); |
| 185 | |
| 186 | // Print summary |
| 187 | const licenseCounts = {}; |
no test coverage detected