(cwd: string)
| 383 | } |
| 384 | |
| 385 | function detectWorkspace(cwd: string): WorkspaceInfo { |
| 386 | const packageJsonPath = path.join(cwd, 'package.json') |
| 387 | |
| 388 | // Check pnpm workspaces (pnpm-workspace.yaml) |
| 389 | const pnpmWorkspacePath = path.join(cwd, 'pnpm-workspace.yaml') |
| 390 | if (fs.existsSync(pnpmWorkspacePath)) { |
| 391 | const packages = parsePnpmWorkspace(pnpmWorkspacePath) |
| 392 | if (packages.length > 0) { |
| 393 | return { isMonorepo: true, type: 'pnpm', packages } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | // Check npm/yarn workspaces (package.json workspaces field) |
| 398 | if (fs.existsSync(packageJsonPath)) { |
| 399 | const packages = parsePackageJsonWorkspaces(packageJsonPath) |
| 400 | if (packages.length > 0) { |
| 401 | return { isMonorepo: true, type: 'npm', packages } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | // Check Lerna (lerna.json) |
| 406 | const lernaPath = path.join(cwd, 'lerna.json') |
| 407 | if (fs.existsSync(lernaPath)) { |
| 408 | const packages = parseLernaConfig(lernaPath) |
| 409 | if (packages.length > 0) { |
| 410 | return { isMonorepo: true, type: 'lerna', packages } |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | // Check Nx (nx.json) |
| 415 | const nxPath = path.join(cwd, 'nx.json') |
| 416 | if (fs.existsSync(nxPath)) { |
| 417 | const packages = parseNxWorkspace(cwd, packageJsonPath) |
| 418 | if (packages.length > 0) { |
| 419 | return { isMonorepo: true, type: 'nx', packages } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | return { isMonorepo: false, type: null, packages: [] } |
| 424 | } |
| 425 | |
| 426 | function parsePnpmWorkspace(filePath: string): string[] { |
| 427 | try { |
no test coverage detected