Read workspace glob patterns from package.json + pnpm-workspace.yaml.
(projectRoot: string)
| 859 | |
| 860 | /** Read workspace glob patterns from package.json + pnpm-workspace.yaml. */ |
| 861 | function readWorkspaceGlobs(projectRoot: string): string[] { |
| 862 | const out: string[] = []; |
| 863 | |
| 864 | // package.json `workspaces` (npm / yarn / bun): array, or Yarn's |
| 865 | // `{ packages: [...], nohoist: [...] }` object form. |
| 866 | try { |
| 867 | const pkg = JSON.parse( |
| 868 | fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf-8') |
| 869 | ); |
| 870 | const ws = pkg?.workspaces; |
| 871 | if (Array.isArray(ws)) { |
| 872 | out.push(...ws.filter((w: unknown): w is string => typeof w === 'string')); |
| 873 | } else if (ws && Array.isArray(ws.packages)) { |
| 874 | out.push(...ws.packages.filter((w: unknown): w is string => typeof w === 'string')); |
| 875 | } |
| 876 | } catch { |
| 877 | /* no / invalid package.json — not a workspace root */ |
| 878 | } |
| 879 | |
| 880 | // pnpm-workspace.yaml `packages:` list. Parsed with a minimal line |
| 881 | // scanner so we don't pull in a YAML dependency. |
| 882 | try { |
| 883 | const yaml = fs.readFileSync(path.join(projectRoot, 'pnpm-workspace.yaml'), 'utf-8'); |
| 884 | out.push(...parsePnpmPackages(yaml)); |
| 885 | } catch { |
| 886 | /* no pnpm-workspace.yaml */ |
| 887 | } |
| 888 | |
| 889 | return out; |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * Minimal pnpm-workspace.yaml `packages:` extractor. Handles the only shape |
no test coverage detected