Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Fix #1302 Clear out the json cache on unbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Aug 24, 2011
1 parent b5b4b86 commit 3be288b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/unbuild.js
Expand Up @@ -23,6 +23,7 @@ function unbuild_ (folder, cb) {
readJson(path.resolve(folder, "package.json"), function (er, pkg) { readJson(path.resolve(folder, "package.json"), function (er, pkg) {
// if no json, then just trash it, but no scripts or whatever. // if no json, then just trash it, but no scripts or whatever.
if (er) return rm(folder, cb) if (er) return rm(folder, cb)
readJson.clearCache(folder)
chain chain
( [ [lifecycle, pkg, "preuninstall", folder] ( [ [lifecycle, pkg, "preuninstall", folder]
, [lifecycle, pkg, "uninstall", folder] , [lifecycle, pkg, "uninstall", folder]
Expand Down
18 changes: 18 additions & 0 deletions lib/utils/read-json.js
Expand Up @@ -3,6 +3,7 @@ module.exports = readJson
readJson.processJson = processJson readJson.processJson = processJson
readJson.unParsePeople = unParsePeople readJson.unParsePeople = unParsePeople
readJson.parsePeople = parsePeople readJson.parsePeople = parsePeople
readJson.clearCache = clearCache


var fs = require("graceful-fs") var fs = require("graceful-fs")
, semver = require("semver") , semver = require("semver")
Expand Down Expand Up @@ -110,6 +111,7 @@ function processJson (opts, cb) {
} }
} }
} }

function processJsonString (opts, cb) { return function (er, jsonString) { function processJsonString (opts, cb) { return function (er, jsonString) {
jsonString += "" jsonString += ""
if (er) return cb(er, jsonString) if (er) return cb(er, jsonString)
Expand All @@ -132,6 +134,7 @@ function processJsonString (opts, cb) { return function (er, jsonString) {
return processObject(opts, cb)(er, json) return processObject(opts, cb)(er, json)
}} }}



function jsonParseFail (ex, file, cb) { function jsonParseFail (ex, file, cb) {
var e = new Error( var e = new Error(
"Failed to parse json\n"+ex.message) "Failed to parse json\n"+ex.message)
Expand Down Expand Up @@ -309,6 +312,7 @@ function processObject (opts, cb) { return function (er, json) {
if (cb) cb(null,json) if (cb) cb(null,json)
return json return json
}} }}

function depObjectify (deps) { function depObjectify (deps) {
if (!Array.isArray(deps)) return deps if (!Array.isArray(deps)) return deps
var o = {} var o = {}
Expand All @@ -318,6 +322,7 @@ function depObjectify (deps) {
}) })
return o return o
} }

function testEngine (json) { function testEngine (json) {
// if engines is empty, then assume that node is allowed. // if engines is empty, then assume that node is allowed.
log.silly(json, "testEngine") log.silly(json, "testEngine")
Expand Down Expand Up @@ -368,6 +373,7 @@ function testEngine (json) {
} }


function unParsePeople (json) { return parsePeople(json, true) } function unParsePeople (json) { return parsePeople(json, true) }

function parsePeople (json, un) { function parsePeople (json, un) {
var fn = un ? unParsePerson : parsePerson var fn = un ? unParsePerson : parsePerson
if (json.author) json.author = fn(json.author) if (json.author) json.author = fn(json.author)
Expand All @@ -376,6 +382,7 @@ function parsePeople (json, un) {
}) })
return json return json
} }

function unParsePerson (person) { function unParsePerson (person) {
if (typeof person === "string") return person if (typeof person === "string") return person
var name = person.name || "" var name = person.name || ""
Expand All @@ -385,6 +392,7 @@ function unParsePerson (person) {
, email = e ? (" <"+e+">") : "" , email = e ? (" <"+e+">") : ""
return name+email+url return name+email+url
} }

function parsePerson (person) { function parsePerson (person) {
if (typeof person !== "string") return person if (typeof person !== "string") return person
var name = person.match(/^([^\(<]+)/) var name = person.match(/^([^\(<]+)/)
Expand All @@ -396,3 +404,13 @@ function parsePerson (person) {
if (url) obj.url = url[1] if (url) obj.url = url[1]
return obj return obj
} }

function clearCache (prefix) {
if (!prefix) {
cache = {}
return
}
Object.keys(cache).forEach(function (c) {
if (c.indexOf(prefix) === 0) delete cache[c]
})
}

0 comments on commit 3be288b

Please sign in to comment.