Closed fisker closed 4 years ago
Sorry, I missed the union line. So you are prepending them to defaulSortOrder too... Which I did happened be the behavior you want. We can rewrite like this now
-const _sortOrder = _.clone(sortPackageJSON.sortOrder)
-
-const sortPkgJSON = (jsonObj, pkgSortOrder) => {
-
- _.remove(sortPackageJSON.sortOrder)
-
- _.each(_.union(pkgSortOrder, _sortOrder), (v) => sortPackageJSON.sortOrder.push(v))
-
- return sortPackageJSON(jsonObj)
-}
+const sortPkgJSON = (jsonObj, pkgSortOrder) => sortPackageJSON(jsonObj, {sortOrder: pkgSortOrder})
@fisker nice, in hindsight I should have opened an issue with sort-package-json
when I had to hack around it. thanks!
Update: see comment bellow
I commited a new change to
sort-package-json
recently, with the new behavior,options.sortOrder
will prepend to defaultSortOrder instead of override. And I'm planning makesort-package-json
exportedsortOrder
a copy ofdefaultSortOrder
(or maybe remove it), since setsortPackageJson.sortOrder
directly has no effect.But I checked this repo
https://github.com/Bkucera/eslint-plugin-json-format/blob/feb247427f79674b0dcb720e00f724a0d3266670/lib/utils.js#L91-L98
We are overriding
sortPackageJson.sortOrder
by remove them and push new keys, can you explain why we need this?