Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix #1302 Clear out the json cache on unbuild

  • Loading branch information...
commit 3be288b4ce7d1d95e2a844f983bb2e0d599a2a90 1 parent b5b4b86
@isaacs isaacs authored
Showing with 19 additions and 0 deletions.
  1. +1 −0  lib/unbuild.js
  2. +18 −0 lib/utils/read-json.js
View
1  lib/unbuild.js
@@ -23,6 +23,7 @@ function unbuild_ (folder, cb) {
readJson(path.resolve(folder, "package.json"), function (er, pkg) {
// if no json, then just trash it, but no scripts or whatever.
if (er) return rm(folder, cb)
+ readJson.clearCache(folder)
chain
( [ [lifecycle, pkg, "preuninstall", folder]
, [lifecycle, pkg, "uninstall", folder]
View
18 lib/utils/read-json.js
@@ -3,6 +3,7 @@ module.exports = readJson
readJson.processJson = processJson
readJson.unParsePeople = unParsePeople
readJson.parsePeople = parsePeople
+readJson.clearCache = clearCache
var fs = require("graceful-fs")
, semver = require("semver")
@@ -110,6 +111,7 @@ function processJson (opts, cb) {
}
}
}
+
function processJsonString (opts, cb) { return function (er, jsonString) {
jsonString += ""
if (er) return cb(er, jsonString)
@@ -132,6 +134,7 @@ function processJsonString (opts, cb) { return function (er, jsonString) {
return processObject(opts, cb)(er, json)
}}
+
function jsonParseFail (ex, file, cb) {
var e = new Error(
"Failed to parse json\n"+ex.message)
@@ -309,6 +312,7 @@ function processObject (opts, cb) { return function (er, json) {
if (cb) cb(null,json)
return json
}}
+
function depObjectify (deps) {
if (!Array.isArray(deps)) return deps
var o = {}
@@ -318,6 +322,7 @@ function depObjectify (deps) {
})
return o
}
+
function testEngine (json) {
// if engines is empty, then assume that node is allowed.
log.silly(json, "testEngine")
@@ -368,6 +373,7 @@ function testEngine (json) {
}
function unParsePeople (json) { return parsePeople(json, true) }
+
function parsePeople (json, un) {
var fn = un ? unParsePerson : parsePerson
if (json.author) json.author = fn(json.author)
@@ -376,6 +382,7 @@ function parsePeople (json, un) {
})
return json
}
+
function unParsePerson (person) {
if (typeof person === "string") return person
var name = person.name || ""
@@ -385,6 +392,7 @@ function unParsePerson (person) {
, email = e ? (" <"+e+">") : ""
return name+email+url
}
+
function parsePerson (person) {
if (typeof person !== "string") return person
var name = person.match(/^([^\(<]+)/)
@@ -396,3 +404,13 @@ function parsePerson (person) {
if (url) obj.url = url[1]
return obj
}
+
+function clearCache (prefix) {
+ if (!prefix) {
+ cache = {}
+ return
+ }
+ Object.keys(cache).forEach(function (c) {
+ if (c.indexOf(prefix) === 0) delete cache[c]
+ })
+}
Please sign in to comment.
Something went wrong with that request. Please try again.