diff options
author | Chris Meyers <chris.meyers.fsu@gmail.com> | 2014-10-02 22:48:52 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-10-04 06:25:59 +0400 |
commit | 7a1472fbdbe99956ad19f629e7eb1cc07ba026ef (patch) | |
tree | 2bec239eaf18a8dd10ef5141e997a1e8fea1bc48 /test/common-tap.js | |
parent | 80557fc773ee9c990bfeb7596830797143c34aee (diff) |
added npm cache cleanup script
Diffstat (limited to 'test/common-tap.js')
-rw-r--r-- | test/common-tap.js | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/test/common-tap.js b/test/common-tap.js index 745528944..2efca30c4 100644 --- a/test/common-tap.js +++ b/test/common-tap.js @@ -1,13 +1,13 @@ var spawn = require("child_process").spawn +var path = require("path") +var fs = require("fs") var port = exports.port = 1337 exports.registry = "http://localhost:" + port process.env.npm_config_loglevel = "error" -var npm_config_cache = __dirname + '/npm_cache' -exports.child_env = { - npm_config_cache: npm_config_cache, -} +var npm_config_cache = path.resolve(__dirname, "npm_cache") +exports.npm_config_cache = npm_config_cache var bin = exports.bin = require.resolve("../bin/npm-cli.js") var once = require("once") @@ -19,7 +19,7 @@ exports.npm = function (cmd, opts, cb) { opts.env = opts.env ? opts.env : process.env if (!opts.env.npm_config_cache) { - opts.env.npm_config_cache = __dirname + "/npm_cache" + opts.env.npm_config_cache = npm_config_cache } var stdout = "" @@ -42,3 +42,26 @@ exports.npm = function (cmd, opts, cb) { }) return child } + +// based on http://bit.ly/1tkI6DJ +function deleteNpmCacheRecursivelySync(cache) { + cache = cache ? cache : npm_config_cache + var files = [] + var res + if( fs.existsSync(cache) ) { + files = fs.readdirSync(cache) + files.forEach(function(file,index) { + var curPath = path.resolve(cache, file) + if(fs.lstatSync(curPath).isDirectory()) { // recurse + deleteNpmCacheRecursivelySync(curPath) + } else { // delete file + if (res = fs.unlinkSync(curPath)) + throw Error("Failed to delete file " + curPath + ", error " + res) + } + }) + if (res = fs.rmdirSync(cache)) + throw Error("Failed to delete directory " + cache + ", error " + res) + } + return 0 +} +exports.deleteNpmCacheRecursivelySync = deleteNpmCacheRecursivelySync
\ No newline at end of file |