Read workspace glob patterns from package.json + pnpm-workspace.yaml.
(projectRoot: string)
| 87 | |
| 88 | /** Read workspace glob patterns from package.json + pnpm-workspace.yaml. */ |
| 89 | function readWorkspaceGlobs(projectRoot: string): string[] { |
| 90 | const out: string[] = []; |
| 91 | |
| 92 | // package.json `workspaces` (npm / yarn / bun): array, or Yarn's |
| 93 | // `{ packages: [...], nohoist: [...] }` object form. |
| 94 | try { |
| 95 | const pkg = JSON.parse( |
| 96 | fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf-8') |
| 97 | ); |
| 98 | const ws = pkg?.workspaces; |
| 99 | if (Array.isArray(ws)) { |
| 100 | out.push(...ws.filter((w: unknown): w is string => typeof w === 'string')); |
| 101 | } else if (ws && Array.isArray(ws.packages)) { |
| 102 | out.push(...ws.packages.filter((w: unknown): w is string => typeof w === 'string')); |
| 103 | } |
| 104 | } catch { |
| 105 | /* no / invalid package.json — not a workspace root */ |
| 106 | } |
| 107 | |
| 108 | // pnpm-workspace.yaml `packages:` list. Parsed with a minimal line |
| 109 | // scanner so we don't pull in a YAML dependency. |
| 110 | try { |
| 111 | const yaml = fs.readFileSync(path.join(projectRoot, 'pnpm-workspace.yaml'), 'utf-8'); |
| 112 | out.push(...parsePnpmPackages(yaml)); |
| 113 | } catch { |
| 114 | /* no pnpm-workspace.yaml */ |
| 115 | } |
| 116 | |
| 117 | return out; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Minimal pnpm-workspace.yaml `packages:` extractor. Handles the only shape |
no test coverage detected