Skip to content

Commit

Permalink
fix: support direct file path in dirs options
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Dec 10, 2024
1 parent 6907b88 commit 1671bf1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ Unimport.vite({

### Directory Auto Import

```ts
Unimport.vite({
dirs: [
'./composables/*',
]
})
```

Scan for modules under `./composables` and auto-import the named exports.

#### Nested Directories

```ts
Unimport.vite({
dirs: [
Expand Down
5 changes: 5 additions & 0 deletions src/node/scan-dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export function normalizeScanDirs(dirs: (string | ScanDir)[], options?: ScanDirE
const glob = resolveGlobsExclude(isString ? dir : dir.glob, cwd)
const types = isString ? topLevelTypes : (dir.types ?? topLevelTypes)

// Ends with a extension, consider as a file
if (glob.match(/\.\w+$/))
return { glob, types }

// Otherwise, append the default file patterns `*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}`
const withFilePatterns = filePatterns.map(filePattern => ({ glob: joinGlobFilePattern(glob, filePattern), types }))
return [{ glob, types }, ...withFilePatterns]
}).flat()
Expand Down

0 comments on commit 1671bf1

Please sign in to comment.