@@ -27,9 +27,13 @@ function installCollection(dir: string, prefix: string, icon: string) {
2727 } ) )
2828}
2929
30- function createContext ( rootDir : string , workspaceDir : string , icons : string [ ] , hookIcons : string [ ] = [ ] ) {
30+ function createContext ( rootDir : string , workspaceDir : string , icons : string [ ] , hookIcons : string [ ] = [ ] , layerDirs : string [ ] = [ ] ) {
3131 const nuxt = {
32- options : { rootDir, workspaceDir } ,
32+ options : {
33+ rootDir,
34+ workspaceDir,
35+ _layers : [ { cwd : rootDir , config : { rootDir } } , ...layerDirs . map ( dir => ( { cwd : dir , config : { rootDir : dir } } ) ) ] ,
36+ } ,
3337 // Mimic a module contributing icons through the `icon:clientBundleIcons` hook
3438 callHook : async ( _name : string , set : Set < string > ) => {
3539 for ( const icon of hookIcons )
@@ -48,11 +52,13 @@ let root: string
4852const appDir = ( ) => join ( root , 'app' )
4953const wsDir = ( ) => join ( root , 'ws' )
5054const emptyDir = ( ) => join ( root , 'empty' )
55+ const layerDir = ( ) => join ( root , 'layer' )
5156
5257beforeAll ( ( ) => {
5358 root = mkdtempSync ( join ( tmpdir ( ) , 'nuxt-icon-client-bundle-' ) )
5459 installCollection ( appDir ( ) , 'nuxt-icon-test' , 'foo' )
5560 installCollection ( wsDir ( ) , 'nuxt-icon-test-ws' , 'bar' )
61+ installCollection ( layerDir ( ) , 'nuxt-icon-test-layer' , 'baz' )
5662 mkdirSync ( emptyDir ( ) , { recursive : true } )
5763} )
5864
@@ -80,6 +86,16 @@ it('falls back to workspaceDir when the collection is not under rootDir', async
8086 expect ( result . collections . find ( c => c . prefix === 'nuxt-icon-test-ws' ) ?. icons . bar ) . toBeTruthy ( )
8187} )
8288
89+ it ( 'resolves a collection installed by a layer rather than the app' , async ( ) => {
90+ // The layer owns the dependency, so it resolves from neither `rootDir` nor `workspaceDir`.
91+ const context = createContext ( emptyDir ( ) , emptyDir ( ) , [ 'nuxt-icon-test-layer:baz' ] , [ ] , [ layerDir ( ) ] )
92+ const result = await context . loadClientBundleCollections ( )
93+
94+ expect ( result . failed ) . toEqual ( [ ] )
95+ expect ( result . count ) . toBe ( 1 )
96+ expect ( result . collections . find ( c => c . prefix === 'nuxt-icon-test-layer' ) ?. icons . baz ) . toBeTruthy ( )
97+ } )
98+
8399it ( 'does not hard-fail when a hook-contributed icon cannot be resolved' , async ( ) => {
84100 // A module adds an icon from a collection that is not installed. It must be
85101 // best-effort: omitted from the bundle (so it falls back to runtime loading)
0 commit comments