modules/npm: Change SetEscapeHTML to false

Closes #8512
This commit is contained in:
Shohei Ueda 2021-05-09 07:20:28 +09:00 committed by GitHub
parent b660ea8d54
commit 504c78da4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 78 deletions

View file

@ -135,7 +135,11 @@ JS imported in module: |
b.WithSourceFile("package.json", `{
"name": "mypack",
"version": "1.2.3",
"scripts": {},
"scripts": {
"client": "wait-on http://localhost:1313 && open http://localhost:1313",
"start": "run-p client server",
"test": "echo 'hoge' > hoge"
},
"dependencies": {
"nonon": "error"
}
@ -144,7 +148,11 @@ JS imported in module: |
b.WithSourceFile("package.hugo.json", `{
"name": "mypack",
"version": "1.2.3",
"scripts": {},
"scripts": {
"client": "wait-on http://localhost:1313 && open http://localhost:1313",
"start": "run-p client server",
"test": "echo 'hoge' > hoge"
},
"dependencies": {
"foo": "1.2.3"
},
@ -185,9 +193,14 @@ JS imported in module: |
"tailwindcss": "1.8.0"
},
"name": "mypack",
"scripts": {},
"scripts": {
"client": "wait-on http://localhost:1313 && open http://localhost:1313",
"start": "run-p client server",
"test": "echo 'hoge' > hoge"
},
"version": "1.2.3"
}`
}
`
})
})
@ -198,7 +211,11 @@ JS imported in module: |
const origPackageJSON = `{
"name": "mypack",
"version": "1.2.3",
"scripts": {},
"scripts": {
"client": "wait-on http://localhost:1313 && open http://localhost:1313",
"start": "run-p client server",
"test": "echo 'hoge' > hoge"
},
"dependencies": {
"moo": "1.2.3"
}
@ -236,9 +253,14 @@ JS imported in module: |
"tailwindcss": "1.2.0"
},
"name": "mypack",
"scripts": {},
"scripts": {
"client": "wait-on http://localhost:1313 && open http://localhost:1313",
"start": "run-p client server",
"test": "echo 'hoge' > hoge"
},
"version": "1.2.3"
}`
}
`
})
// https://github.com/gohugoio/hugo/issues/7690
@ -278,7 +300,8 @@ JS imported in module: |
},
"name": "myhugosite",
"version": "0.1.0"
}`
}
`
})
})
}

View file

@ -14,9 +14,11 @@
package npm
import (
"bytes"
"encoding/json"
"fmt"
"io"
"strings"
"github.com/gohugoio/hugo/common/hugio"
@ -129,12 +131,15 @@ func Pack(fs afero.Fs, fis []hugofs.FileMetaInfo) error {
b.originalPackageJSON["comments"] = commentsm
// Write it out to the project package.json
packageJSONData, err := json.MarshalIndent(b.originalPackageJSON, "", " ")
if err != nil {
packageJSONData := new(bytes.Buffer)
encoder := json.NewEncoder(packageJSONData)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", strings.Repeat(" ", 2))
if err := encoder.Encode(b.originalPackageJSON); err != nil {
return errors.Wrap(err, "npm pack: failed to marshal JSON")
}
if err := afero.WriteFile(fs, packageJSONName, packageJSONData, 0666); err != nil {
if err := afero.WriteFile(fs, packageJSONName, packageJSONData.Bytes(), 0666); err != nil {
return errors.Wrap(err, "npm pack: failed to write package.json")
}