@@ -18,6 +18,7 @@ package filesystems
1818import (
1919 "fmt"
2020 "io"
21+ "io/fs"
2122 "os"
2223 "path/filepath"
2324 "strings"
@@ -235,9 +236,6 @@ type SourceFilesystems struct {
235236 Archetypes * SourceFilesystem
236237 Assets * SourceFilesystem
237238
238- // Note that this can not be mounted. It's currently fixed at the project root.
239- Vendor * SourceFilesystem
240-
241239 AssetsWithDuplicatesPreserved * SourceFilesystem
242240
243241 RootFss []* hugofs.RootMappingFs
@@ -246,6 +244,10 @@ type SourceFilesystems struct {
246244 // with any sub module's resource fs layered below.
247245 ResourcesCache afero.Fs // TODO1 remove this.
248246
247+ // A writable filesystem on top of the project's vendor directory
248+ // with any sub module's vendor fs layered.
249+ VendorFs afero.Fs
250+
249251 // The work folder (may be a composite of project and theme components).
250252 Work afero.Fs
251253
@@ -572,13 +574,13 @@ func (b *sourceFilesystemsBuilder) Build() (*SourceFilesystems, error) {
572574 b .result .Layouts = createView (files .ComponentFolderLayouts , b .theBigFs .overlayMounts )
573575 b .result .Assets = createView (files .ComponentFolderAssets , b .theBigFs .overlayMounts )
574576 b .result .ResourcesCache = b .theBigFs .overlayResources
577+ b .result .VendorFs = b .theBigFs .overlayVendor
575578 b .result .RootFss = b .theBigFs .rootFss
576579
577580 // data and i18n needs a different merge strategy.
578581 overlayMountsPreserveDupes := b .theBigFs .overlayMounts .WithDirsMerger (hugofs .AppendDirsMerger )
579582 b .result .Data = createView (files .ComponentFolderData , overlayMountsPreserveDupes )
580583 b .result .I18n = createView (files .ComponentFolderI18n , overlayMountsPreserveDupes )
581- b .result .Vendor = createView (files .FolderVendor , overlayMountsPreserveDupes )
582584 b .result .AssetsWithDuplicatesPreserved = createView (files .ComponentFolderAssets , overlayMountsPreserveDupes )
583585
584586 contentFs := hugofs .NewComponentFs (
@@ -632,6 +634,9 @@ func (b *sourceFilesystemsBuilder) createMainOverlayFs(p *paths.Paths) (*filesys
632634 overlayMountsStatic : overlayfs .New (overlayfs.Options {DirsMerger : hugofs .LanguageDirsMerger }),
633635 overlayFull : overlayfs .New (overlayfs.Options {}),
634636 overlayResources : overlayfs .New (overlayfs.Options {FirstWritable : true }),
637+ overlayVendor : overlayfs .New (overlayfs.Options {FirstWritable : true , DirsMerger : hugofs .DirsMergerPreserveDuplicateFunc (func (fi fs.DirEntry ) bool {
638+ return fi .Name () == "resources.json"
639+ })}),
635640 }
636641
637642 mods := p .AllModules ()
@@ -682,6 +687,7 @@ func (b *sourceFilesystemsBuilder) createOverlayFs(
682687 collector .overlayMountsFull = appendNopIfEmpty (collector .overlayMountsFull )
683688 collector .overlayFull = appendNopIfEmpty (collector .overlayFull )
684689 collector .overlayResources = appendNopIfEmpty (collector .overlayResources )
690+ collector .overlayVendor = appendNopIfEmpty (collector .overlayVendor )
685691
686692 return nil
687693 }
@@ -700,7 +706,16 @@ func (b *sourceFilesystemsBuilder) createOverlayFs(
700706 return md .dir , hpaths .AbsPathify (md .dir , path )
701707 }
702708
709+ modBase := collector .sourceProject
710+ if ! md .isMainProject {
711+ modBase = collector .sourceModules
712+ }
713+
703714 for i , mount := range md .Mounts () {
715+ if mount .Target == files .FolderVendor {
716+ collector .overlayVendor = collector .overlayVendor .Append (hugofs .NewBasePathFs (modBase , mount .Source ))
717+ continue
718+ }
704719 // Add more weight to early mounts.
705720 // When two mounts contain the same filename,
706721 // the first entry wins.
@@ -748,11 +763,6 @@ func (b *sourceFilesystemsBuilder) createOverlayFs(
748763 }
749764 }
750765
751- modBase := collector .sourceProject
752- if ! md .isMainProject {
753- modBase = collector .sourceModules
754- }
755-
756766 sourceStatic := modBase
757767
758768 rmfs , err := hugofs .NewRootMappingFs (modBase , fromTo ... )
@@ -835,7 +845,8 @@ type filesystemsCollector struct {
835845 overlayMountsStatic * overlayfs.OverlayFs
836846 overlayMountsFull * overlayfs.OverlayFs
837847 overlayFull * overlayfs.OverlayFs
838- overlayResources * overlayfs.OverlayFs
848+ overlayResources * overlayfs.OverlayFs // TODO1 remove
849+ overlayVendor * overlayfs.OverlayFs
839850
840851 rootFss []* hugofs.RootMappingFs
841852
0 commit comments