mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
* build: enable `@typescript-eslint/no-import-type-side-effects` * build: disable `@typescript-eslint/consistent-type-imports` * chore: apply fixes for `no-import-type-side-effects` pnpm exec eslint "**/src/**/*.ts" "**/test/**/*.ts" --fix
25 lines
763 B
TypeScript
25 lines
763 B
TypeScript
import type { PackageFiles } from '@pnpm/store.cafs'
|
|
|
|
export function readdir (index: { files: PackageFiles }, dir: string): string[] {
|
|
const dirs = new Set<string>()
|
|
const prefix = dir ? `${dir}/` : ''
|
|
for (const filePath of index.files.keys()) {
|
|
if (filePath.startsWith(prefix)) {
|
|
const parts = filePath.substring(dir.length).split('/')
|
|
dirs.add(parts[0] || parts[1])
|
|
}
|
|
}
|
|
return Array.from(dirs)
|
|
}
|
|
|
|
export type DirEntityType = 'file' | 'directory'
|
|
|
|
export function dirEntityType (index: { files: PackageFiles }, p: string): DirEntityType | undefined {
|
|
if (index.files.has(p)) return 'file'
|
|
const prefix = `${p}/`
|
|
for (const k of index.files.keys()) {
|
|
if (k.startsWith(prefix)) return 'directory'
|
|
}
|
|
return undefined
|
|
}
|