Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-09-09 23:31:43 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-09-13 21:55:29 +0300
commit85ba9bfffba9bfd0b095cb766f72700d4c211e31 (patch)
tree43b66efaafe4cb804234ca7273873ab949305799 /resources
parent9df60b62f9c4e36a269f0c6e9a69bee9dc691031 (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 'resources')
-rw-r--r--resources/resource_transformers/babel/babel.go25
-rw-r--r--resources/resource_transformers/postcss/postcss.go19
2 files changed, 18 insertions, 26 deletions
diff --git a/resources/resource_transformers/babel/babel.go b/resources/resource_transformers/babel/babel.go
index c5ab48dd8..4255210c3 100644
--- a/resources/resource_transformers/babel/babel.go
+++ b/resources/resource_transformers/babel/babel.go
@@ -14,6 +14,7 @@
package babel
import (
+ "bytes"
"io"
"os/exec"
"path/filepath"
@@ -27,7 +28,6 @@ import (
"github.com/mitchellh/mapstructure"
"github.com/gohugoio/hugo/common/herrors"
- "github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/resources/resource"
"github.com/pkg/errors"
@@ -120,6 +120,9 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
var configFile string
logger := t.rs.Logger
+ var errBuf bytes.Buffer
+ infoW := loggers.LoggerToWriterWithPrefix(logger.INFO, "babel")
+
if t.options.Config != "" {
configFile = t.options.Config
} else {
@@ -130,16 +133,10 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
// We need an abolute filename to the config file.
if !filepath.IsAbs(configFile) {
- // We resolve this against the virtual Work filesystem, to allow
- // this config file to live in one of the themes if needed.
- fi, err := t.rs.BaseFs.Work.Stat(configFile)
- if err != nil {
- if t.options.Config != "" {
- // Only fail if the user specificed config file is not found.
- return errors.Wrapf(err, "babel config %q not found:", configFile)
- }
- } else {
- configFile = fi.(hugofs.FileMetaInfo).Meta().Filename()
+ configFile = t.rs.BaseFs.ResolveJSConfigFile(configFile)
+ if configFile == "" && t.options.Config != "" {
+ // Only fail if the user specificed config file is not found.
+ return errors.Errorf("babel config %q not found:", configFile)
}
}
@@ -158,8 +155,8 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
cmd := exec.Command(binary, cmdArgs...)
cmd.Stdout = ctx.To
- cmd.Stderr = loggers.LoggerToWriterWithPrefix(logger.INFO, "babel")
- cmd.Env = hugo.GetExecEnviron(t.rs.Cfg)
+ cmd.Stderr = io.MultiWriter(infoW, &errBuf)
+ cmd.Env = hugo.GetExecEnviron(t.rs.WorkingDir, t.rs.Cfg, t.rs.BaseFs.Assets.Fs)
stdin, err := cmd.StdinPipe()
if err != nil {
@@ -173,7 +170,7 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
err = cmd.Run()
if err != nil {
- return err
+ return errors.Wrap(err, errBuf.String())
}
return nil
diff --git a/resources/resource_transformers/postcss/postcss.go b/resources/resource_transformers/postcss/postcss.go
index 258185a40..41472fe98 100644
--- a/resources/resource_transformers/postcss/postcss.go
+++ b/resources/resource_transformers/postcss/postcss.go
@@ -170,17 +170,11 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC
// We need an abolute filename to the config file.
if !filepath.IsAbs(configFile) {
- // We resolve this against the virtual Work filesystem, to allow
- // this config file to live in one of the themes if needed.
- fi, err := t.rs.BaseFs.Work.Stat(configFile)
- if err != nil {
- if t.options.Config != "" {
- // Only fail if the user specificed config file is not found.
- return errors.Wrapf(err, "postcss config %q not found:", configFile)
- }
- configFile = ""
- } else {
- configFile = fi.(hugofs.FileMetaInfo).Meta().Filename()
+ configFile = t.rs.BaseFs.ResolveJSConfigFile(configFile)
+ if configFile == "" && t.options.Config != "" {
+ // Only fail if the user specificed config file is not found.
+ return errors.Errorf("postcss config %q not found:", configFile)
+
}
}
@@ -202,7 +196,8 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC
cmd.Stdout = ctx.To
cmd.Stderr = io.MultiWriter(infoW, &errBuf)
- cmd.Env = hugo.GetExecEnviron(t.rs.Cfg)
+
+ cmd.Env = hugo.GetExecEnviron(t.rs.WorkingDir, t.rs.Cfg, t.rs.BaseFs.Assets.Fs)
stdin, err := cmd.StdinPipe()
if err != nil {