MCPcopy Create free account
hub / github.com/nuxt/icon / loadClientBundleCollections

Method loadClientBundleCollections

src/context.ts:148–199  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

146 }
147
148 async loadClientBundleCollections(): Promise<ResolvedBundleIcons> {
149 const {
150 includeCustomCollections = this.options.provider !== 'server',
151 scan = false,
152 } = this.options.clientBundle || {}
153
154 // Filter out the `i-` prefix and deduplicate
155 const userIcons = new Set((this.options.clientBundle?.icons || []).map(i => i.replace(/^i[-:]/, '')))
156
157 let customCollections: IconifyJSON[] = []
158 if (this.options.customCollections?.length) {
159 customCollections = await this.loadCustomCollection()
160 }
161
162 if (scan && !this.scanner) {
163 // Merge (not overwrite) custom collection prefixes with user-provided
164 // additional collections, so custom icons stay detectable by the scanner
165 const additionalCollections = customCollections.map(c => c.prefix)
166 const scanOptions = scan === true
167 ? { additionalCollections }
168 : {
169 ...scan,
170 additionalCollections: [
171 ...additionalCollections,
172 ...scan.additionalCollections || [],
173 ],
174 }
175 this.scanner = new IconUsageScanner(scanOptions)
176 await this.scanner.scanFiles(
177 this.nuxt.options._layers.map(layer => layer.cwd),
178 this.scannedIcons,
179 )
180 }
181
182 const icons = new Set<string>([...userIcons, ...this.scannedIcons])
183
184 // Let other modules contribute icons to the client bundle (they may also
185 // remove icons, e.g. scanned false positives)
186 await this.nuxt.callHook('icon:clientBundleIcons', icons)
187
188 return resolveBundleIcons({
189 icons: [...userIcons].filter(i => icons.has(i)),
190 scannedIcons: [...this.scannedIcons].filter(i => icons.has(i)),
191 extraIcons: [...icons].filter(i => !userIcons.has(i) && !this.scannedIcons.has(i)),
192 customCollections,
193 includeCustomCollections,
194 // Resolve collections from the Nuxt root (and workspace root as a fallback)
195 // instead of `process.cwd()`, so collections installed in a subproject are
196 // found when the command is launched from a workspace root.
197 resolvePaths: getResolvePaths(this.nuxt),
198 })
199 }
200}

Callers 2

getContentsFunction · 0.80

Calls 4

loadCustomCollectionMethod · 0.95
resolveBundleIconsFunction · 0.90
getResolvePathsFunction · 0.90
scanFilesMethod · 0.80

Tested by

no test coverage detected