Skip to content

Commit

Permalink
feat: Remove duplicates. Performance improved by Set
Browse files Browse the repository at this point in the history
  • Loading branch information
s3xysteak committed May 12, 2024
1 parent 17b4d9f commit d35c101
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ import { p } from '@s3xysteak/utils'
import { findPath, getPkg } from './utils'

export async function expCollector(path: string, base?: string): Promise<string[]> {
const result: string[] = []
const result = new Set<string>()

const recursion = async (path: string, base?: string) => {
const filePath = await findPath(path, base)
const content = await fs.readFile(filePath, 'utf-8')

const { exp, refer } = await parser(content)
result.push(...exp)

exp.forEach((val) => { result.add(val) })

await p(refer, { concurrency: Number.POSITIVE_INFINITY })
.forEach(async path => await recursion(path, dirname(filePath)))
}

await recursion(path, base ?? process.cwd())

return result
return Array.from(result)
}

export interface ParseValue {
Expand Down

0 comments on commit d35c101

Please sign in to comment.