Permalink
Browse files

Sort dependencies when --save'ing.

Uses sorted-object package to abstract away code shared by shrinkwrap and
install.
  • Loading branch information...
1 parent 70fd532 commit 6fd6ff7e536ea6acd33037b1878d4eca1f931985 @domenic domenic committed with robertkowalski Dec 27, 2013
View
@@ -74,6 +74,7 @@ var npm = require("./npm.js")
, archy = require("archy")
, isGitUrl = require("./utils/is-git-url.js")
, npmInstallChecks = require("npm-install-checks")
+ , sortedObject = require("sorted-object")
function install (args, cb_) {
var hasArguments = !!args.length
@@ -378,7 +379,7 @@ function save (where, installed, tree, pretty, hasArguments, cb) {
var bundle = data.bundleDependencies || data.bundledDependencies
delete data.bundledDependencies
if (!Array.isArray(bundle)) bundle = []
- data.bundleDependencies = bundle
+ data.bundleDependencies = bundle.sort()
}
log.verbose('saving', things)
@@ -391,6 +392,8 @@ function save (where, installed, tree, pretty, hasArguments, cb) {
}
})
+ data[deps] = sortedObject(data[deps])
+
data = JSON.stringify(data, null, 2) + "\n"
fs.writeFile(saveTarget, data, function (er) {
cb(er, installed, tree, pretty)
View
@@ -8,6 +8,7 @@ var npm = require("./npm.js")
, fs = require("fs")
, path = require("path")
, readJson = require("read-package-json")
+ , sortedObject = require("sorted-object")
shrinkwrap.usage = "npm shrinkwrap"
@@ -58,7 +59,7 @@ function shrinkwrap_ (pkginfo, silent, dev, cb) {
function save (pkginfo, silent, cb) {
// copy the keys over in a well defined order
// because javascript objects serialize arbitrarily
- pkginfo.dependencies = copyOrder(pkginfo.dependencies)
+ pkginfo.dependencies = sortedObject(pkginfo.dependencies)
try {
var swdata = JSON.stringify(pkginfo, null, 2) + "\n"
} catch (er) {
@@ -75,12 +76,3 @@ function save (pkginfo, silent, cb) {
cb(null, pkginfo)
})
}
-
-function copyOrder(obj) {
- var result = {}
- var keys = Object.keys(obj).sort()
- keys.forEach(function (key) {
- result[key] = obj[key]
- })
- return result
-}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -81,7 +81,8 @@
"ansistyles": "~0.1.3",
"path-is-inside": "~1.0.0",
"columnify": "0.1.2",
- "npm-install-checks": "~1.0.0"
+ "npm-install-checks": "~1.0.0",
+ "sorted-object": "~1.0.0"
},
"bundleDependencies": [
"semver",
@@ -133,7 +134,8 @@
"ansistyles",
"path-is-inside",
"columnify",
- "npm-install-checks"
+ "npm-install-checks",
+ "sorted-object"
],
"devDependencies": {
"ronn": "~0.3.6",

1 comment on commit 6fd6ff7

💯 Was doing this manually all this time :)

Please sign in to comment.