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:
Bjørn Erik Pedersen 2020-09-09 22:31:43 +02:00
parent 9df60b62f9
commit 85ba9bfffb
16 changed files with 721 additions and 46 deletions

View file

@ -56,7 +56,9 @@ func ApplyProjectConfigDefaults(cfg config.Provider, mod Module) error {
// the basic level.
componentsConfigured := make(map[string]bool)
for _, mnt := range moda.mounts {
componentsConfigured[mnt.Component()] = true
if !strings.HasPrefix(mnt.Target, files.JsConfigFolderMountPrefix) {
componentsConfigured[mnt.Component()] = true
}
}
type dirKeyComponent struct {
@ -318,12 +320,21 @@ type Mount struct {
Target string // relative target path, e.g. "assets/bootstrap/scss"
Lang string // any language code associated with this mount.
}
func (m Mount) Component() string {
return strings.Split(m.Target, fileSeparator)[0]
}
func (m Mount) ComponentAndName() (string, string) {
k := strings.Index(m.Target, fileSeparator)
if k == -1 {
return m.Target, ""
}
return m.Target[:k], m.Target[k+1:]
}
func getStaticDirs(cfg config.Provider) []string {
var staticDirs []string
for i := -1; i <= 10; i++ {