mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
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
This commit is contained in:
@@ -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...)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user