mirror of
https://github.com/gohugoio/hugo.git
synced 2024-05-11 05:54:58 +00: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:
@@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -382,6 +383,11 @@ func (c *collector) applyMounts(moduleImport Import, mod *moduleAdapter) error {
|
||||
return err
|
||||
}
|
||||
|
||||
mounts, err = c.mountCommonJSConfig(mod, mounts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mod.mounts = mounts
|
||||
return nil
|
||||
}
|
||||
@@ -549,6 +555,43 @@ func (c *collector) loadModules() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Matches postcss.config.js etc.
|
||||
var commonJSConfigs = regexp.MustCompile(`(babel|postcss|tailwind)\.config\.js`)
|
||||
|
||||
func (c *collector) mountCommonJSConfig(owner *moduleAdapter, mounts []Mount) ([]Mount, error) {
|
||||
for _, m := range mounts {
|
||||
if strings.HasPrefix(m.Target, files.JsConfigFolderMountPrefix) {
|
||||
// This follows the convention of the other component types (assets, content, etc.),
|
||||
// if one or more is specificed by the user, we skip the defaults.
|
||||
// These mounts were added to Hugo in 0.75.
|
||||
return mounts, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Mount the common JS config files.
|
||||
fis, err := afero.ReadDir(c.fs, owner.Dir())
|
||||
if err != nil {
|
||||
return mounts, err
|
||||
}
|
||||
|
||||
for _, fi := range fis {
|
||||
n := fi.Name()
|
||||
|
||||
should := n == files.FilenamePackageHugoJSON || n == files.FilenamePackageJSON
|
||||
should = should || commonJSConfigs.MatchString(n)
|
||||
|
||||
if should {
|
||||
mounts = append(mounts, Mount{
|
||||
Source: n,
|
||||
Target: filepath.Join(files.ComponentFolderAssets, files.FolderJSConfig, n),
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return mounts, nil
|
||||
}
|
||||
|
||||
func (c *collector) normalizeMounts(owner *moduleAdapter, mounts []Mount) ([]Mount, error) {
|
||||
var out []Mount
|
||||
dir := owner.Dir()
|
||||
|
Reference in New Issue
Block a user