MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / readWorkspaceGlobs

Function readWorkspaceGlobs

src/resolution/workspace-packages.ts:233–262  ·  view source on GitHub ↗

Read workspace glob patterns from package.json + pnpm-workspace.yaml.

(projectRoot: string)

Source from the content-addressed store, hash-verified

231
232/** Read workspace glob patterns from package.json + pnpm-workspace.yaml. */
233function readWorkspaceGlobs(projectRoot: string): string[] {
234 const out: string[] = [];
235
236 // package.json `workspaces` (npm / yarn / bun): array, or Yarn's
237 // `{ packages: [...], nohoist: [...] }` object form.
238 try {
239 const pkg = JSON.parse(
240 fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf-8')
241 );
242 const ws = pkg?.workspaces;
243 if (Array.isArray(ws)) {
244 out.push(...ws.filter((w: unknown): w is string => typeof w === 'string'));
245 } else if (ws && Array.isArray(ws.packages)) {
246 out.push(...ws.packages.filter((w: unknown): w is string => typeof w === 'string'));
247 }
248 } catch {
249 /* no / invalid package.json — not a workspace root */
250 }
251
252 // pnpm-workspace.yaml `packages:` list. Parsed with a minimal line
253 // scanner so we don't pull in a YAML dependency.
254 try {
255 const yaml = fs.readFileSync(path.join(projectRoot, 'pnpm-workspace.yaml'), 'utf-8');
256 out.push(...parsePnpmPackages(yaml));
257 } catch {
258 /* no pnpm-workspace.yaml */
259 }
260
261 return out;
262}
263
264/**
265 * Minimal pnpm-workspace.yaml `packages:` extractor. Handles the only shape

Callers 1

loadWorkspacePackagesFunction · 0.85

Calls 2

parsePnpmPackagesFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected