Skip to content

Commit

Permalink
fix: children dir Repetitive display
Browse files Browse the repository at this point in the history
  • Loading branch information
amihhs committed Aug 17, 2023
1 parent 30a4ebc commit 5dfea8e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ add vite-plugin-dirs/client to compilerOptions.types of your tsconfig:
```json
{
"compilerOptions": {
"types": ["vite-plugin-dirs/client"]
"types": [
"vite-plugin-dirs/client"
]
}
}

Expand Down
15 changes: 0 additions & 15 deletions playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@
</head>
<body>
<pre id="app"></pre>
<pre id="inline"></pre>
<pre id="alias"></pre>
<script type="module" src="/src/main.ts"></script>

<script type="module">
const rawModules = import.meta.globEager('./*.json', { as: 'raw' })
const globraw = {}
Object.keys(rawModules).forEach((key) => {
globraw[key] = JSON.parse(rawModules[key])
})
document.getElementById('inline').textContent = JSON.stringify(globraw, null, 2)

const aliased = import.meta.glob('~/fixtures/*.*', { eager: true })
document.getElementById('alias').textContent = JSON.stringify(aliased, null, 2)
</script>

</body>
</html>
2 changes: 1 addition & 1 deletion playground/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import './style.css'

const app = document.getElementById('app')!

const settled = import.meta.dirs('/src', { exhaustive: true })
const settled = import.meta.dirs('/src', { exhaustive: false })

app.textContent = JSON.stringify(settled, null, 2)
4 changes: 1 addition & 3 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export async function parsedImportDirs(
const end = ast.range![1]
const resolvedDirs = await Promise.all(dirs.map(d => toAbsolutePath(d, root, dir ?? root, resolveId)))
const maps = await generateDirsMaps(resolvedDirs)
// console.log('map', JSON.stringify(map))
return {
firstArgType: type,
start,
Expand Down Expand Up @@ -147,15 +146,14 @@ function analyzeSecondArgument(arg2: Node | undefined, err: (msg: string) => Err

async function generateDirsMaps(dirs: string[]): Promise<DirMap[]> {
const dirsDetail: DirMap[] = []

for (const dir of dirs) {
const files = readdirSync(dir)
const fileDetails: DirMap[] = []
for (const i of files) {
const stat = lstatSync(join(dir, i))
if (stat.isDirectory()) {
const children = await generateDirsMaps([join(dir, i)])
fileDetails.push({ name: basename(i), type: 'dir', children })
fileDetails.push({ name: basename(i), type: 'dir', children: children[0].children })
}
else {
fileDetails.push({ name: basename(i), type: 'file' })
Expand Down

0 comments on commit 5dfea8e

Please sign in to comment.