Skip to content

Commit 1345dc9

Browse files
fix: include Nuxt layers in icon scanner context. (#505)
Co-authored-by: Anthony Fu (via agent) <[email protected]>
1 parent c56ee64 commit 1345dc9

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<Icon name="uil:0-plus" />
3+
</template>

playgrounds/dummy/nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default defineNuxtConfig({})

playgrounds/nuxt/nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Module from '../../src/module'
33
export default defineNuxtConfig({
44
extends: [
55
'./base',
6+
'../dummy',
67
],
78

89
modules: [

src/context.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ export class NuxtIconModuleContext {
173173
],
174174
}
175175
this.scanner = new IconUsageScanner(scanOptions)
176-
await this.scanner.scanFiles(this.nuxt.options.rootDir, this.scannedIcons)
176+
await this.scanner.scanFiles(
177+
this.nuxt.options._layers.map(layer => layer.cwd),
178+
this.scannedIcons,
179+
)
177180
}
178181

179182
const icons = new Set<string>([...userIcons, ...this.scannedIcons])

src/core/scan.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,26 @@ export class IconUsageScanner {
4646
}
4747

4848
async scanFiles(
49-
cwd: string,
49+
cwd: string | string[],
5050
set: Set<string> = new Set(),
5151
) {
52-
const files = await glob(
53-
this.globInclude,
54-
{
55-
ignore: this.globExclude,
56-
cwd,
57-
absolute: true,
58-
expandDirectories: false,
59-
},
52+
const dirs = Array.isArray(cwd) ? cwd : [cwd]
53+
const files = new Set(
54+
(await Promise.all(
55+
dirs.map(dir => glob(
56+
this.globInclude,
57+
{
58+
ignore: this.globExclude,
59+
cwd: dir,
60+
absolute: true,
61+
expandDirectories: false,
62+
},
63+
)),
64+
)).flat(),
6065
)
6166

6267
await Promise.all(
63-
files.map(async (file) => {
68+
[...files].map(async (file) => {
6469
const code = await fs.readFile(file, 'utf-8').catch(() => '')
6570
this.extractFromCode(code, set)
6671
}),

0 commit comments

Comments
 (0)