aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/npm
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2020-09-14 17:09:34 +0200
committerBjørn Erik Pedersen <[email protected]>2020-09-15 01:04:31 +0200
commit214afe4c1bb9c37bc6159e659d66ba9a268a2849 (patch)
tree86545eb1b2a4f09f7e2dfc850fe6f4251a569a32 /modules/npm
parentcd830bb0275fc39240861627ef26e146985b5c86 (diff)
downloadhugo-214afe4c1bb9c37bc6159e659d66ba9a268a2849.tar.gz
hugo-214afe4c1bb9c37bc6159e659d66ba9a268a2849.zip
modules/npm: Preserve the original package.json if it exists
Fixes #7690
Diffstat (limited to 'modules/npm')
-rw-r--r--modules/npm/package_builder.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/modules/npm/package_builder.go b/modules/npm/package_builder.go
index 23aac7246..c0a5b0dad 100644
--- a/modules/npm/package_builder.go
+++ b/modules/npm/package_builder.go
@@ -18,6 +18,8 @@ import (
"fmt"
"io"
+ "github.com/gohugoio/hugo/common/hugio"
+
"github.com/gohugoio/hugo/hugofs/files"
"github.com/pkg/errors"
@@ -51,7 +53,12 @@ func Pack(fs afero.Fs, fis []hugofs.FileMetaInfo) error {
if err != nil {
// Have a package.json?
fi, err = fs.Stat(packageJSONName)
- if err != nil {
+ if err == nil {
+ // Preserve the original in package.hugo.json.
+ if err = hugio.CopyFile(fs, packageJSONName, files.FilenamePackageHugoJSON); err != nil {
+ return errors.Wrap(err, "npm pack: failed to copy package file")
+ }
+ } else {
// Create one.
name := "project"
// Use the Hugo site's folder name as the default name.