mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
chore(package): automatically sort dependencies
This commit is contained in:
parent
2f781eadbb
commit
a7be6349f5
@ -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
4
package.js
Normal file
@ -0,0 +1,4 @@
|
||||
export default (pkg) => {
|
||||
pkg.sortDependencies()
|
||||
pkg.writePackage()
|
||||
}
|
@ -26,6 +26,9 @@ export default (pkg, { load }) => {
|
||||
'bin'
|
||||
])
|
||||
|
||||
// Sort dependencies
|
||||
pkg.sortDependencies()
|
||||
|
||||
// Update package.json
|
||||
pkg.writePackage()
|
||||
|
||||
|
@ -41,6 +41,9 @@ export default (pkg, { load }) => {
|
||||
]
|
||||
})
|
||||
|
||||
// Sort dependencies
|
||||
pkg.sortDependencies()
|
||||
|
||||
// Update package.json
|
||||
pkg.writePackage()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user