import findWorkspacePackages from '@pnpm/find-workspace-packages' import { buildConfig } from '../build-info' import { EP_PREFIX } from './constants' import { projRoot } from './paths' import type { Module } from '../build-info' import type { ProjectManifest } from '@pnpm/types' export const getWorkspacePackages = () => findWorkspacePackages(projRoot) export const getWorkspaceNames = async (dir = projRoot) => { const pkgs = await findWorkspacePackages(projRoot) return pkgs .filter((pkg) => pkg.dir.startsWith(dir)) .map((pkg) => pkg.manifest.name) .filter((name): name is string => !!name) } export const getPackageManifest = (pkgPath: string) => { // eslint-disable-next-line @typescript-eslint/no-var-requires return require(pkgPath) as ProjectManifest } export const getPackageDependencies = (pkgPath: string): string[] => { const manifest = getPackageManifest(pkgPath) const { dependencies } = manifest return Object.keys(dependencies ?? {}) } export const pathRewriter = (module: Module) => { const config = buildConfig[module] return (id: string) => { id = id.replaceAll(`${EP_PREFIX}/theme-chalk`, 'element-plus/theme-chalk') id = id.replaceAll(`${EP_PREFIX}/`, `${config.bundle.path}/`) return id } } export const excludeFiles = (files: string[]) => { const excludes = ['node_modules', 'test', 'mock', 'gulpfile', 'dist'] return files.filter( (path) => !excludes.some((exclude) => path.includes(exclude)) ) }