gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.73k stars 7.53k forks source link

hugo mod npm pack formats/reorder package.json #7711

Closed davidsneighbour closed 4 years ago

davidsneighbour commented 4 years ago

What version of Hugo are you using (hugo version)?

Hugo Static Site Generator v0.75.1-A4A7BAB7/extended linux/amd64 BuildDate: 2020-09-15T06:57:20Z

Running hugo mod npm pack breaks regular special characters and encodes them in package.json.

Original:

{
  "author": "Patrick Kollitsch <patrick@domainname>",
  "scripts": {
    "algolia": "hugo --quiet && atomic-algolia && rm -rf public"
  },
  "browserslist": [
    "> 1%",
    "last 2 version"
  ]
}

After running hugo mod npm pack

{
 "author": "Patrick Kollitsch \u003cpatrick@domainname\u003e",
 "browserslist": [
  "\u003e 1%",
  "last 2 version"
 ],
 "scripts": {
  "algolia": "hugo --quiet \u0026\u0026 atomic-algolia \u0026\u0026 rm -rf public"
 }
}

(not sure if I understand the use of the command right)

davidsneighbour commented 4 years ago

The repo is here if it needs testing: https://github.com/davidsneighbour/samui-samui.de

bep commented 4 years ago

Are you saying that the above doesn't work?

davidsneighbour commented 4 years ago

Sorry, I just assumed that the encoding like \u003c would throw errors when I run npm install or one of the npm scripts. I recreated the issue just now and it appears that the encoding does not turn up on every call of hugo mod npm pack. I ran it twice this time to see the encoded characters.

Also I checked npm install and npm run algolia and it appears that those encodings can be read by npm - both commands run without complaining. So this is probably something that can be closed.

It's just not very readable for humans.

davidsneighbour commented 4 years ago

Running npm install after hugo mod npm pack changes the encoding back to readable characters.

davidsneighbour commented 4 years ago

Also, the sorting of package.json ends up alphabetically. If it's possible then the comment array should just be added to the end instead of resorting the whole file? I know that's hair splitting, but a package.json that has the name, version and other main information in the beginning is better readable, don't you think?

bep commented 4 years ago

This is Go's JSON encoder; I will have a look at this, but I'm not ... implementing a JSON encoder. I have a very unsentimental relationship with how my package.json is ordered.

bep commented 4 years ago

Also, you need to consider package.hugo.json as the new origina -- the file you edit ... There are some missing pieces in all of this, but I had to start somewhere.

davidsneighbour commented 4 years ago

closing this in favour of being less pedantic about the order in package.json.

davidsneighbour commented 3 years ago

There is a npm package called fixpack that solves this issue for everyone with OCD :)

https://www.npmjs.com/package/fixpack

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.