diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-09-09 22:31:43 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-09-13 20:55:29 +0200 |
commit | 85ba9bfffba9bfd0b095cb766f72700d4c211e31 (patch) | |
tree | 43b66efaafe4cb804234ca7273873ab949305799 /hugolib/filesystems/basefs.go | |
parent | 9df60b62f9c4e36a269f0c6e9a69bee9dc691031 (diff) |
Add "hugo mod npm pack"
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into:
```
assets/_jsconfig
´``
These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename.
But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific.
This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above.
Fixes #7644
Fixes #7656
Fixes #7675
Diffstat (limited to 'hugolib/filesystems/basefs.go')
-rw-r--r-- | hugolib/filesystems/basefs.go | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index 57a95a037..76d49055c 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -49,6 +49,9 @@ type BaseFs struct { // SourceFilesystems contains the different source file systems. *SourceFilesystems + // The project source. + SourceFs afero.Fs + // The filesystem used to publish the rendered site. // This usually maps to /my-project/public. PublishFs afero.Fs @@ -100,6 +103,23 @@ func (b *BaseFs) RelContentDir(filename string) string { return filename } +// ResolveJSConfigFile resolves the JS-related config file to a absolute +// filename. One example of such would be postcss.config.js. +func (fs *BaseFs) ResolveJSConfigFile(name string) string { + // First look in assets/_jsconfig + fi, err := fs.Assets.Fs.Stat(filepath.Join(files.FolderJSConfig, name)) + if err == nil { + return fi.(hugofs.FileMetaInfo).Meta().Filename() + } + // Fall back to the work dir. + fi, err = fs.Work.Stat(name) + if err == nil { + return fi.(hugofs.FileMetaInfo).Meta().Filename() + } + + return "" +} + // SourceFilesystems contains the different source file systems. These can be // composite file systems (theme and project etc.), and they have all root // set to the source type the provides: data, i18n, static, layouts. @@ -346,8 +366,10 @@ func NewBase(p *paths.Paths, logger *loggers.Logger, options ...func(*BaseFs) er } publishFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Destination, p.AbsPublishDir)) + sourceFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Source, p.WorkingDir)) b := &BaseFs{ + SourceFs: sourceFs, PublishFs: publishFs, } @@ -696,11 +718,16 @@ type filesystemsCollector struct { func (c *filesystemsCollector) addDirs(rfs *hugofs.RootMappingFs) { for _, componentFolder := range files.ComponentFolders { - dirs, err := rfs.Dirs(componentFolder) + c.addDir(rfs, componentFolder) + } - if err == nil { - c.overlayDirs[componentFolder] = append(c.overlayDirs[componentFolder], dirs...) - } +} + +func (c *filesystemsCollector) addDir(rfs *hugofs.RootMappingFs, componentFolder string) { + dirs, err := rfs.Dirs(componentFolder) + + if err == nil { + c.overlayDirs[componentFolder] = append(c.overlayDirs[componentFolder], dirs...) } } |