MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / getPubWorkspaceOrPackageFolderInfo

Function getPubWorkspaceOrPackageFolderInfo

src/shared/vscode/pub.ts:252–276  ·  view source on GitHub ↗
(
	packageFolderOrPubspecPaths: string[],
	existsSync: (itemPath: string) => boolean = fs.existsSync,
	readFileSync: (itemPath: string) => string = (p) => fs.readFileSync(p, "utf8").toString(),
)

Source from the content-addressed store, hash-verified

250 * of a Pub Workspace root and not the child packages.
251 */
252export 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

Callers 2

packages.test.tsFile · 0.90
getFolderToRunCommandInFunction · 0.90

Calls 4

setMethod · 0.80
toStringMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected