@@ -9,7 +9,15 @@ import { isPackageExists } from 'local-pkg'
99import { collectionNames } from './collection-names'
1010import type { CustomCollection , ServerBundleOptions , RemoteCollection } from './types'
1111
12- export const isFullCollectionExists = isPackageExists ( '@iconify/json' )
12+ function getResolvePaths ( nuxt : Nuxt ) : string [ ] {
13+ return Array . from ( new Set (
14+ [ nuxt . options . rootDir , nuxt . options . workspaceDir ] . filter ( Boolean ) ,
15+ ) )
16+ }
17+
18+ export function hasFullCollection ( nuxt : Nuxt ) : boolean {
19+ return isPackageExists ( '@iconify/json' , { paths : getResolvePaths ( nuxt ) } )
20+ }
1321
1422export async function resolveCollection (
1523 nuxt : Nuxt ,
@@ -24,8 +32,8 @@ export async function resolveCollection(
2432 return collection
2533}
2634
27- export function getCollectionPath ( collection : string ) {
28- return isFullCollectionExists
35+ export function getCollectionPath ( collection : string , nuxt : Nuxt ) {
36+ return hasFullCollection ( nuxt )
2937 ? `@iconify/json/json/${ collection } .json`
3038 : `@iconify-json/${ collection } /icons.json`
3139}
@@ -117,16 +125,18 @@ async function parseCustomCollection(
117125 return result
118126}
119127
120- export async function discoverInstalledCollections ( ) : Promise < ServerBundleOptions [ 'collections' ] > {
121- const collections = isFullCollectionExists
128+ export async function discoverInstalledCollections ( nuxt : Nuxt ) : Promise < ServerBundleOptions [ 'collections' ] > {
129+ const paths = getResolvePaths ( nuxt )
130+ const fullCollectionInstalled = hasFullCollection ( nuxt )
131+ const collections = fullCollectionInstalled
122132 ? collectionNames
123- : collectionNames . filter ( collection => isPackageExists ( '@iconify-json/' + collection ) )
124- if ( isFullCollectionExists )
133+ : collectionNames . filter ( collection => isPackageExists ( '@iconify-json/' + collection , { paths } ) )
134+ if ( fullCollectionInstalled )
125135 logger . success ( `Nuxt Icon discovered local-installed ${ collections . length } collections (@iconify/json)` )
126136 else if ( collections . length )
127137 logger . success ( `Nuxt Icon discovered local-installed ${ collections . length } collections:` , collections . join ( ', ' ) )
128138
129- if ( isFullCollectionExists )
139+ if ( fullCollectionInstalled )
130140 logger . warn ( 'Currently all iconify collections are included in the bundle, which might be inefficient, consider explicit name the collections you use in the `icon.serverBundle.collections` option' )
131141
132142 return collections
0 commit comments