MCPcopy
hub / github.com/vercel/next.js / detectWorkspace

Function detectWorkspace

packages/next-codemod/lib/agents-md.ts:385–424  ·  view source on GitHub ↗
(cwd: string)

Source from the content-addressed store, hash-verified

383}
384
385function 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
426function parsePnpmWorkspace(filePath: string): string[] {
427 try {

Callers 1

getNextjsVersionFunction · 0.85

Calls 5

parsePnpmWorkspaceFunction · 0.85
parseLernaConfigFunction · 0.85
parseNxWorkspaceFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected