From a7be6349f5def6d97c4231bbecc8df3af18f41a8 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 21 Sep 2018 01:04:08 +0430 Subject: [PATCH] chore(package): automatically sort dependencies --- build/package.js | 13 +++++++++++++ package.js | 4 ++++ packages/nuxt-legacy/package.js | 3 +++ packages/nuxt-start/package.js | 3 +++ 4 files changed, 23 insertions(+) create mode 100644 package.js diff --git a/build/package.js b/build/package.js index 3d2bb810e5..21b0cd0a09 100644 --- a/build/package.js +++ b/build/package.js @@ -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 diff --git a/package.js b/package.js new file mode 100644 index 0000000000..6bbff4dd74 --- /dev/null +++ b/package.js @@ -0,0 +1,4 @@ +export default (pkg) => { + pkg.sortDependencies() + pkg.writePackage() +} diff --git a/packages/nuxt-legacy/package.js b/packages/nuxt-legacy/package.js index fc73a1641a..5598f552b8 100644 --- a/packages/nuxt-legacy/package.js +++ b/packages/nuxt-legacy/package.js @@ -26,6 +26,9 @@ export default (pkg, { load }) => { 'bin' ]) + // Sort dependencies + pkg.sortDependencies() + // Update package.json pkg.writePackage() diff --git a/packages/nuxt-start/package.js b/packages/nuxt-start/package.js index f5384b0045..92dc4a029d 100644 --- a/packages/nuxt-start/package.js +++ b/packages/nuxt-start/package.js @@ -41,6 +41,9 @@ export default (pkg, { load }) => { ] }) + // Sort dependencies + pkg.sortDependencies() + // Update package.json pkg.writePackage()