Files
element-plus/internal/build-utils/src/pkg.ts
Monday1997 9062df2f31 fix(build): path compatible with Windows platform (#21423)
* fix(build-utils): fn excludeFiles has bug if path with 'test' in win32

* fix: update

* chore: rename slash to normalizePath

---------

Co-authored-by: btea <2356281422@qq.com>
Co-authored-by: qiang <qw13131wang@gmail.com>
2025-08-21 11:39:32 +08:00

40 lines
1.3 KiB
TypeScript

import findWorkspacePackages from '@pnpm/find-workspace-packages'
import { normalizePath, projRoot } from './paths'
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
): Record<'dependencies' | 'peerDependencies', string[]> => {
const manifest = getPackageManifest(pkgPath)
const { dependencies = {}, peerDependencies = {} } = manifest
return {
dependencies: Object.keys(dependencies),
peerDependencies: Object.keys(peerDependencies),
}
}
export const excludeFiles = (files: string[]) => {
const excludes = ['node_modules', 'test', 'mock', 'gulpfile', 'dist']
const projRootPath = normalizePath(projRoot)
return files.filter((file) => {
const position = file.startsWith(projRootPath) ? projRootPath.length : 0
return !excludes.some((exclude) => file.includes(exclude, position))
})
}