( packageFolderOrPubspecPaths: string[], existsSync: (itemPath: string) => boolean = fs.existsSync, readFileSync: (itemPath: string) => string = (p) => fs.readFileSync(p, "utf8").toString(), )
| 250 | * of a Pub Workspace root and not the child packages. |
| 251 | */ |
| 252 | export function getPubWorkspaceOrPackageFolderInfo( |
| 253 | packageFolderOrPubspecPaths: string[], |
| 254 | existsSync: (itemPath: string) => boolean = fs.existsSync, |
| 255 | readFileSync: (itemPath: string) => string = (p) => fs.readFileSync(p, "utf8").toString(), |
| 256 | ): PubWorkspaceOrPackageFolderInfo[] { |
| 257 | const pubWorkspacePackageCounts = new Map<string, number>(); |
| 258 | |
| 259 | for (const packageFolderOrPubspecPath of packageFolderOrPubspecPaths) { |
| 260 | const packageFolderPath = path.basename(packageFolderOrPubspecPath) === "pubspec.yaml" |
| 261 | ? path.dirname(packageFolderOrPubspecPath) |
| 262 | : packageFolderOrPubspecPath; |
| 263 | const workspaceRootPath = getPubWorkspaceFolderOrPackageFolderPath(packageFolderOrPubspecPath, existsSync, readFileSync); |
| 264 | |
| 265 | let count = pubWorkspacePackageCounts.get(workspaceRootPath) ?? 0; |
| 266 | const isRoot = workspaceRootPath === packageFolderPath; |
| 267 | if (!isRoot) |
| 268 | count++; |
| 269 | |
| 270 | pubWorkspacePackageCounts.set(workspaceRootPath, count); |
| 271 | } |
| 272 | |
| 273 | return [...pubWorkspacePackageCounts.entries()] |
| 274 | .map((p) => p[1] ? { path: p[0], workspacePackageCount: p[1] } : { path: p[0] }) |
| 275 | .sort((a, b) => a.path.localeCompare(b.path)); |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Returns the uris of "pub roots" for a set of package folders/pubspecs, where "pub root" is |
no test coverage detected