Skip to content

Commit

Permalink
fix(scan-dirs): retain the original dirs glob scanning (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
noootwo authored Dec 10, 2024
1 parent 7bc76c5 commit e647dfa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/node/scan-dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ export function normalizeScanDirs(dirs: (string | ScanDir)[], options?: ScanDirE

return dirs.map((dir) => {
const isString = typeof dir === 'string'
const glob = resolveGlobsExclude(isString ? dir : dir.glob, cwd)
const types = isString ? topLevelTypes : (dir.types ?? topLevelTypes)

return filePatterns.map((filePattern) => {
const glob = joinGlobFilePattern(resolveGlobsExclude(isString ? dir : dir.glob, cwd), filePattern)
const types = isString ? topLevelTypes : (dir.types ?? topLevelTypes)
return { glob, types }
})
const withFilePatterns = filePatterns.map(filePattern => ({ glob: joinGlobFilePattern(glob, filePattern), types }))
return [{ glob, types }, ...withFilePatterns]
}).flat()
}

Expand Down
22 changes: 22 additions & 0 deletions test/scan-dirs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ describe('scan-dirs', () => {
expect(doubleAsteriskExports.some(i => i.name === 'CustomType3')).toEqual(true)
expect(doubleAsteriskExports.some(i => i.name === 'CustomType2')).toEqual(true)
})

it('scanDirs original dirs glob', async () => {
const dir = join(__dirname, '../playground/composables/nested/index.ts')
const exports = await scanDirExports([dir])
expect(exports.some(i => i.name === 'CustomType3')).toEqual(true)

const dirWithSingleAsterisk = join(__dirname, '../playground/composables/nested/*/index.ts')
const singleAsteriskExports = await scanDirExports([dirWithSingleAsterisk])
expect(singleAsteriskExports.some(i => i.name === 'CustomType2')).toEqual(true)
})
})

it('normalizeScanDirs', () => {
Expand All @@ -267,6 +277,10 @@ it('normalizeScanDirs', () => {
}))
.toMatchInlineSnapshot(`
[
{
"glob": "/playground/composables/nested",
"types": true,
},
{
"glob": "/playground/composables/nested/*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}",
"types": true,
Expand All @@ -279,6 +293,10 @@ it('normalizeScanDirs', () => {
}))
.toMatchInlineSnapshot(`
[
{
"glob": "/playground/composables/nested/*",
"types": false,
},
{
"glob": "/playground/composables/nested/*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}",
"types": false,
Expand All @@ -290,6 +308,10 @@ it('normalizeScanDirs', () => {
}))
.toMatchInlineSnapshot(`
[
{
"glob": "/playground/composables/nested/**",
"types": true,
},
{
"glob": "/playground/composables/nested/**/*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}",
"types": true,
Expand Down

0 comments on commit e647dfa

Please sign in to comment.