chore(package): automatically sort dependencies

This commit is contained in:
Pooya Parsa 2018-09-21 01:04:08 +04:30
parent 2f781eadbb
commit a7be6349f5
4 changed files with 23 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import EventEmitter from 'events'
import { sync as spawnSync } from 'cross-spawn'
import consola from 'consola'
import { readFileSync, existsSync, readJSONSync, writeFileSync, copySync, removeSync } from 'fs-extra'
import _ from 'lodash'
import { builtinsMap } from './builtins'
const DEFAULTS = {
@ -10,6 +11,8 @@ const DEFAULTS = {
buildSuffix: process.env.BUILD_SUFFIX
}
const sortObjectKeys = obj => _(obj).toPairs().sortBy(0).fromPairs().value()
export default class Package extends EventEmitter {
constructor(options) {
super()
@ -119,6 +122,16 @@ export default class Package extends EventEmitter {
}
}
sortDependencies() {
if (this.packageObj.dependencies) {
this.packageObj.dependencies = sortObjectKeys(this.packageObj.dependencies)
}
if (this.packageObj.devDependencies) {
this.packageObj.devDependencies = sortObjectKeys(this.packageObj.devDependencies)
}
}
updateDependencies({ dist, sources = [], extras = [], exclude = [] }) {
const dependencies = {}
const requireRegex = /require\('([-@/\w]+)'\)/g

4
package.js Normal file
View File

@ -0,0 +1,4 @@
export default (pkg) => {
pkg.sortDependencies()
pkg.writePackage()
}

View File

@ -26,6 +26,9 @@ export default (pkg, { load }) => {
'bin'
])
// Sort dependencies
pkg.sortDependencies()
// Update package.json
pkg.writePackage()

View File

@ -41,6 +41,9 @@ export default (pkg, { load }) => {
]
})
// Sort dependencies
pkg.sortDependencies()
// Update package.json
pkg.writePackage()