Skip to content

Commit 1a83944

Browse files
pksunkarahaoqunjiang
authored andcommitted
fix(cli): make sortObject consistent even when keyOrder is given (vuejs#2326)
1 parent d350be2 commit 1a83944

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

packages/@vue/cli/lib/Generator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ module.exports = class Generator {
179179
'name',
180180
'version',
181181
'private',
182+
'description',
183+
'author',
182184
'scripts',
183185
'dependencies',
184186
'devDependencies',
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
module.exports = function sortObject (obj, keyOrder) {
22
if (!obj) return
33
const res = {}
4-
const keys = Object.keys(obj)
5-
const getOrder = key => {
6-
const i = keyOrder.indexOf(key)
7-
return i === -1 ? Infinity : i
8-
}
4+
95
if (keyOrder) {
10-
keys.sort((a, b) => {
11-
return getOrder(a) - getOrder(b)
6+
keyOrder.forEach(key => {
7+
res[key] = obj[key]
8+
delete obj[key]
129
})
13-
} else {
14-
keys.sort()
1510
}
11+
12+
const keys = Object.keys(obj)
13+
14+
keys.sort()
1615
keys.forEach(key => {
1716
res[key] = obj[key]
1817
})
18+
1919
return res
2020
}

0 commit comments

Comments
 (0)