Skip to content

Commit

Permalink
feat: sort pre/post scripts with colon together
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji committed Jan 11, 2025
1 parent 0bf1155 commit f139830
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,24 @@ const sortScripts = onObject((scripts, packageJson) => {
keys.sort()
}

const order = keys.flatMap((key) =>
prefixable.has(key) ? [`pre${key}`, key, `post${key}`] : [key],
)
const scriptsKeyMap = new Map()

keys
.flatMap((key) =>
prefixable.has(key) ? [`pre${key}`, key, `post${key}`] : [key],
)
.forEach((key) => {
const [prefix] = key.split(':')
const keySet = scriptsKeyMap.has(prefix)
? scriptsKeyMap.get(prefix)
: new Set()
scriptsKeyMap.set(prefix, keySet.add(key))
})

const order = [...scriptsKeyMap.values()].flat().reduce((keys, keySet) => {
keys.push(...keySet)
return keys
}, [])

return sortObjectKeys(scripts, order)
})
Expand Down

0 comments on commit f139830

Please sign in to comment.