( sitePackagesDir: string )
| 118 | * @returns Map of normalized package name to distribution info |
| 119 | */ |
| 120 | export async function scanDistributions( |
| 121 | sitePackagesDir: string |
| 122 | ): Promise<DistributionIndex> { |
| 123 | const mod = await importWasmModule(); |
| 124 | const index: DistributionIndex = new Map(); |
| 125 | |
| 126 | // List all .dist-info directories |
| 127 | let entries: string[]; |
| 128 | try { |
| 129 | entries = await readdir(sitePackagesDir); |
| 130 | } catch { |
| 131 | return index; |
| 132 | } |
| 133 | |
| 134 | const distInfoDirs = entries.filter(e => e.endsWith('.dist-info')); |
| 135 | |
| 136 | for (const dirName of distInfoDirs) { |
| 137 | const distInfoPath = join(sitePackagesDir, dirName); |
| 138 | |
| 139 | // METADATA is required |
| 140 | const metadataContent = await readDistInfoFile(distInfoPath, 'METADATA'); |
| 141 | if (!metadataContent) { |
| 142 | console.debug(`Missing METADATA in ${dirName}`); |
| 143 | continue; |
| 144 | } |
| 145 | |
| 146 | // Parse METADATA via WASM |
| 147 | let metadata; |
| 148 | try { |
| 149 | metadata = mod.parseDistMetadata( |
| 150 | new TextEncoder().encode(metadataContent) |
| 151 | ); |
| 152 | } catch (e) { |
| 153 | console.debug(`Failed to parse METADATA for ${dirName}: ${e}`); |
| 154 | continue; |
| 155 | } |
| 156 | |
| 157 | // Normalize the package name |
| 158 | const normalizedName = mod.normalizePackageName(metadata.name); |
| 159 | |
| 160 | // Parse RECORD (optional) -- analogous to Distribution.files |
| 161 | let files: PackagePath[] = []; |
| 162 | const recordContent = await readDistInfoFile(distInfoPath, 'RECORD'); |
| 163 | if (recordContent) { |
| 164 | try { |
| 165 | files = mod.parseRecord(recordContent); |
| 166 | } catch (e) { |
| 167 | console.warn(`Failed to parse RECORD for ${dirName}: ${e}`); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | // Parse direct_url.json (optional) -- analogous to Distribution.origin |
| 172 | let origin: DirectUrlInfo | undefined; |
| 173 | const directUrlContent = await readDistInfoFile( |
| 174 | distInfoPath, |
| 175 | 'direct_url.json' |
| 176 | ); |
| 177 | if (directUrlContent) { |
no test coverage detected