All files / scripts/monorepo packages.ts

0% Statements 0/28
100% Branches 1/1
100% Functions 1/1
0% Lines 0/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41                                                                                 
import type { MonorepoInfo } from './detect'
import fs from 'node:fs'
import path from 'node:path'
import { glob as globby } from 'tinyglobby'
import { normalizePath } from '../utils/path'
 
export interface PackageInfo {
  path: string
  name: string
  version?: string
  private: boolean
  manifest: Record<string, any>
}
 
export async function findPackages(monorepo: MonorepoInfo): Promise<PackageInfo[]> {
  const patterns = monorepo.packages.map(p =>
    normalizePath(path.join(monorepo.root, p, 'package.json')),
  )
 
  const results = await globby(patterns, {
    absolute: true,
    cwd: monorepo.root,
    expandDirectories: false,
    ignore: ['**/node_modules/**'],
  })
 
  return Promise.all(
    results.map(async (pkgPath) => {
      const content = fs.readFileSync(pkgPath, 'utf8')
      const manifest = JSON.parse(content)
      return {
        path: path.dirname(pkgPath),
        name: manifest.name,
        version: manifest.version,
        private: !!manifest.private,
        manifest,
      }
    }),
  )
}