pkg.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import findWorkspacePackages from '@pnpm/find-workspace-packages'
  2. import { projRoot } from './paths'
  3. import type { ProjectManifest } from '@pnpm/types'
  4. export const getWorkspacePackages = () => findWorkspacePackages(projRoot)
  5. export const getWorkspaceNames = async (dir = projRoot) => {
  6. const pkgs = await findWorkspacePackages(projRoot)
  7. return pkgs
  8. .filter(pkg => pkg.dir.startsWith(dir))
  9. .map(pkg => pkg.manifest.name)
  10. .filter((name): name is string => !!name)
  11. }
  12. export const getPackageManifest = (pkgPath: string) => {
  13. // eslint-disable-next-line @typescript-eslint/no-var-requires
  14. return require(pkgPath) as ProjectManifest
  15. }
  16. export const getPackageDependencies = (pkgPath: string): Record<'dependencies' | 'peerDependencies', string[]> => {
  17. const manifest = getPackageManifest(pkgPath)
  18. const { dependencies = {}, peerDependencies = {} } = manifest
  19. return {
  20. dependencies: Object.keys(dependencies),
  21. peerDependencies: Object.keys(peerDependencies),
  22. }
  23. }
  24. export const excludeFiles = (files: string[]) => {
  25. const excludes = ['node_modules', 'test', 'mock', 'gulpfile', 'dist']
  26. return files.filter(path => !excludes.some(exclude => path.includes(exclude)))
  27. }