Skip to content

Commit

Permalink
feat: base on cwd if not appoint base.
Browse files Browse the repository at this point in the history
  • Loading branch information
s3xysteak committed Mar 16, 2024
1 parent 9c1eb76 commit 687b842
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/core/parser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import process from 'node:process'
import { dirname } from 'node:path'
import { promises as fs } from 'node:fs'
import { parse as swcParse } from '@swc/core'
Expand Down Expand Up @@ -61,7 +62,7 @@ export async function expCollector(path: string, base?: string): Promise<string[
.forEach(async path => await recursion(path, dirname(filePath)))
}

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

return result
}
12 changes: 8 additions & 4 deletions test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { describe, expect, it } from 'vitest'
import { expCollector, parser } from '@core/parser'

describe('parser', () => {
const base = fileURLToPath(new URL('./', import.meta.url))

it('parser', async () => {
const content = await fs.readFile(resolve(base, './parserLab/index.ts'), 'utf-8')
const content = await fs.readFile(
resolve(
fileURLToPath(new URL('./', import.meta.url)),
'./parserLab/index.ts',
),
'utf-8',
)
const res = await parser(content)

expect(res.exp).toEqual(['one', 'two', 'getThree', 'funcIndex', 'ClassIndex'])
Expand All @@ -18,7 +22,7 @@ describe('parser', () => {
it('expCollector', async () => {
const target = ['one', 'two', 'getThree', 'funcIndex', 'ClassIndex', 'func1', 'func2', 'func3', 'fRe'].sort()

const result = await expCollector('./parserLab', base).then(res => res.sort())
const result = await expCollector('./test/parserLab').then(res => res.sort())
expect(result).toEqual(target)
})
})

0 comments on commit 687b842

Please sign in to comment.