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", `{ b.WithSourceFile("package.json", `{
"name": "mypack", "name": "mypack",
"version": "1.2.3", "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": { "dependencies": {
"nonon": "error" "nonon": "error"
} }
@ -144,7 +148,11 @@ JS imported in module: |
b.WithSourceFile("package.hugo.json", `{ b.WithSourceFile("package.hugo.json", `{
"name": "mypack", "name": "mypack",
"version": "1.2.3", "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": { "dependencies": {
"foo": "1.2.3" "foo": "1.2.3"
}, },
@ -160,34 +168,39 @@ JS imported in module: |
b.AssertFileContentFn("package.json", func(s string) bool { b.AssertFileContentFn("package.json", func(s string) bool {
return s == `{ return s == `{
"comments": { "comments": {
"dependencies": {
"foo": "project",
"react-dom": "github.com/gohugoio/hugoTestModule2"
},
"devDependencies": {
"@babel/cli": "github.com/gohugoio/hugoTestModule2",
"@babel/core": "github.com/gohugoio/hugoTestModule2",
"@babel/preset-env": "github.com/gohugoio/hugoTestModule2",
"postcss-cli": "project",
"tailwindcss": "project"
}
},
"dependencies": { "dependencies": {
"foo": "project", "foo": "1.2.3",
"react-dom": "github.com/gohugoio/hugoTestModule2" "react-dom": "^16.13.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "github.com/gohugoio/hugoTestModule2", "@babel/cli": "7.8.4",
"@babel/core": "github.com/gohugoio/hugoTestModule2", "@babel/core": "7.9.0",
"@babel/preset-env": "github.com/gohugoio/hugoTestModule2", "@babel/preset-env": "7.9.5",
"postcss-cli": "project", "postcss-cli": "7.8.0",
"tailwindcss": "project" "tailwindcss": "1.8.0"
} },
}, "name": "mypack",
"dependencies": { "scripts": {
"foo": "1.2.3", "client": "wait-on http://localhost:1313 && open http://localhost:1313",
"react-dom": "^16.13.1" "start": "run-p client server",
}, "test": "echo 'hoge' > hoge"
"devDependencies": { },
"@babel/cli": "7.8.4", "version": "1.2.3"
"@babel/core": "7.9.0", }
"@babel/preset-env": "7.9.5", `
"postcss-cli": "7.8.0",
"tailwindcss": "1.8.0"
},
"name": "mypack",
"scripts": {},
"version": "1.2.3"
}`
}) })
}) })
@ -198,7 +211,11 @@ JS imported in module: |
const origPackageJSON = `{ const origPackageJSON = `{
"name": "mypack", "name": "mypack",
"version": "1.2.3", "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": { "dependencies": {
"moo": "1.2.3" "moo": "1.2.3"
} }
@ -211,34 +228,39 @@ JS imported in module: |
b.AssertFileContentFn("package.json", func(s string) bool { b.AssertFileContentFn("package.json", func(s string) bool {
return s == `{ return s == `{
"comments": { "comments": {
"dependencies": {
"moo": "project",
"react-dom": "github.com/gohugoio/hugoTestModule2"
},
"devDependencies": {
"@babel/cli": "github.com/gohugoio/hugoTestModule2",
"@babel/core": "github.com/gohugoio/hugoTestModule2",
"@babel/preset-env": "github.com/gohugoio/hugoTestModule2",
"postcss-cli": "github.com/gohugoio/hugoTestModule2",
"tailwindcss": "github.com/gohugoio/hugoTestModule2"
}
},
"dependencies": { "dependencies": {
"moo": "project", "moo": "1.2.3",
"react-dom": "github.com/gohugoio/hugoTestModule2" "react-dom": "^16.13.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "github.com/gohugoio/hugoTestModule2", "@babel/cli": "7.8.4",
"@babel/core": "github.com/gohugoio/hugoTestModule2", "@babel/core": "7.9.0",
"@babel/preset-env": "github.com/gohugoio/hugoTestModule2", "@babel/preset-env": "7.9.5",
"postcss-cli": "github.com/gohugoio/hugoTestModule2", "postcss-cli": "7.1.0",
"tailwindcss": "github.com/gohugoio/hugoTestModule2" "tailwindcss": "1.2.0"
} },
}, "name": "mypack",
"dependencies": { "scripts": {
"moo": "1.2.3", "client": "wait-on http://localhost:1313 && open http://localhost:1313",
"react-dom": "^16.13.1" "start": "run-p client server",
}, "test": "echo 'hoge' > hoge"
"devDependencies": { },
"@babel/cli": "7.8.4", "version": "1.2.3"
"@babel/core": "7.9.0", }
"@babel/preset-env": "7.9.5", `
"postcss-cli": "7.1.0",
"tailwindcss": "1.2.0"
},
"name": "mypack",
"scripts": {},
"version": "1.2.3"
}`
}) })
// https://github.com/gohugoio/hugo/issues/7690 // https://github.com/gohugoio/hugo/issues/7690
@ -254,31 +276,32 @@ JS imported in module: |
b.AssertFileContentFn("package.json", func(s string) bool { b.AssertFileContentFn("package.json", func(s string) bool {
return s == `{ return s == `{
"comments": { "comments": {
"dependencies": {
"react-dom": "github.com/gohugoio/hugoTestModule2"
},
"devDependencies": {
"@babel/cli": "github.com/gohugoio/hugoTestModule2",
"@babel/core": "github.com/gohugoio/hugoTestModule2",
"@babel/preset-env": "github.com/gohugoio/hugoTestModule2",
"postcss-cli": "github.com/gohugoio/hugoTestModule2",
"tailwindcss": "github.com/gohugoio/hugoTestModule2"
}
},
"dependencies": { "dependencies": {
"react-dom": "github.com/gohugoio/hugoTestModule2" "react-dom": "^16.13.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "github.com/gohugoio/hugoTestModule2", "@babel/cli": "7.8.4",
"@babel/core": "github.com/gohugoio/hugoTestModule2", "@babel/core": "7.9.0",
"@babel/preset-env": "github.com/gohugoio/hugoTestModule2", "@babel/preset-env": "7.9.5",
"postcss-cli": "github.com/gohugoio/hugoTestModule2", "postcss-cli": "7.1.0",
"tailwindcss": "github.com/gohugoio/hugoTestModule2" "tailwindcss": "1.2.0"
} },
}, "name": "myhugosite",
"dependencies": { "version": "0.1.0"
"react-dom": "^16.13.1" }
}, `
"devDependencies": {
"@babel/cli": "7.8.4",
"@babel/core": "7.9.0",
"@babel/preset-env": "7.9.5",
"postcss-cli": "7.1.0",
"tailwindcss": "1.2.0"
},
"name": "myhugosite",
"version": "0.1.0"
}`
}) })
}) })
} }

View file

@ -14,9 +14,11 @@
package npm package npm
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"strings"
"github.com/gohugoio/hugo/common/hugio" "github.com/gohugoio/hugo/common/hugio"
@ -129,12 +131,15 @@ func Pack(fs afero.Fs, fis []hugofs.FileMetaInfo) error {
b.originalPackageJSON["comments"] = commentsm b.originalPackageJSON["comments"] = commentsm
// Write it out to the project package.json // Write it out to the project package.json
packageJSONData, err := json.MarshalIndent(b.originalPackageJSON, "", " ") packageJSONData := new(bytes.Buffer)
if err != nil { 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") 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") return errors.Wrap(err, "npm pack: failed to write package.json")
} }