diff options
author | Martin Cooper <mfncooper@gmail.com> | 2012-02-19 07:38:24 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-02-24 01:16:29 +0400 |
commit | 754744bd6e339fdf98da3126ae191fe87b94dcd3 (patch) | |
tree | 82a1e1ad00426e8315f7e36529bb00fb720c85ae | |
parent | b6c8d31799cf6197f7fac007a474ff02b0efc809 (diff) |
Fix #1753 Make a copy of the cached objects we'll modify.
-rw-r--r-- | lib/utils/read-installed.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/utils/read-installed.js b/lib/utils/read-installed.js index 6c0ece25b..60cbea15c 100644 --- a/lib/utils/read-installed.js +++ b/lib/utils/read-installed.js @@ -125,7 +125,8 @@ function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, cb) { }) readJson(path.resolve(folder, "package.json"), function (er, data) { - obj = data + obj = copy(data) + if (!parent) { obj = obj || true er = null @@ -269,6 +270,15 @@ function findUnmet (obj) { return obj } +function copy (obj) { + if (!obj || typeof obj !== 'object') return obj + if (Array.isArray(obj)) return obj.map(copy) + + var o = {} + for (var i in obj) o[i] = copy(obj[i]) + return o +} + if (module === require.main) { var util = require("util") console.error("testing") |