Permalink
Browse files

blah. not working. just a savepoint. Need to rewrite the top half of …

…uninstall.js, everything through secondPart needs to be retooled so that the eventual 'to be removed' list includes the recursively included children. Totally wasn't written with that in mind. *rage*. But it's 18:00, and I'm not gonna get it done tonight.
  • Loading branch information...
1 parent 16a0180 commit 64dfad33b86c5cac2a4097fc4eeec0c87469b97f @isaacs isaacs committed Oct 20, 2010
Showing with 80 additions and 29 deletions.
  1. +65 −24 lib/uninstall.js
  2. +15 −5 scripts/install.sh
View
@@ -22,23 +22,24 @@ var rm = require("./utils/rm-rf")
, asyncMap = require("./utils/async-map")
, loadPackageDefaults = require("./utils/load-package-defaults")
-function uninstall (args, cb) {
+function uninstall (args, cb_) {
// for each arg:
// unpack if no version found
unpackArgs(args, function (er, args) {
- if (er) return cb(er)
- if (!args || !args.length) return cb()
+ if (er) return cb_(er)
+ if (!args || !args.length) return cb_()
var rb = npm.ROLLBACK
npm.ROLLBACK = true
- chain
- ( [firstPart, args]
- , [secondPart, args]
- , function (er) {
- npm.ROLLBACK = rb
- cb(er)
- }
- )
+ function cb (er) {
+ npm.ROLLBACK = rb
+ cb_(er)
+ }
+ firstPart(args, function (er, done) {
+ if (er) return cb(er)
+ if (done) return cb()
+ secondPart(args, cb)
+ })
})
}
function unpackArgs (rawArgs, cb) {
@@ -47,8 +48,16 @@ function unpackArgs (rawArgs, cb) {
var args = []
, argData = []
rawArgs.filter(function (a) { return a }).forEach(function (arg) {
- arg = Array.isArray(arg) ? arg : arg.split("@")
- var ver = arg[1] || ""
+ while (arg._id) arg = arg._id
+ log.warn(arg, "remove arg")
+ arg = Array.isArray(arg) ? arg
+ : typeof arg === "string" ? arg.split("@")
+ : arg
+ if (!arg) return
+ if (!Array.isArray(arg)) {
+ return args.push([arg.name,arg.version])
+ }
+ var ver = arg.slice(1).join("@")
, pkg = arg[0] || ""
arg = arg.join("@")
if (!installed.hasOwnProperty(pkg)) return log(arg, "not installed")
@@ -57,7 +66,9 @@ function unpackArgs (rawArgs, cb) {
if (semver.satisfies(v, ver)) args.push([pkg, v])
})
})
+ log.warn(args, "first unpack, about to read them")
asyncMap(args, function (arg, cb) {
+ log.warn(arg, "reading")
var jsonFile = path.join(npm.dir,arg[0],arg[1],"package","package.json")
readJson( jsonFile
, arg[1]
@@ -67,6 +78,7 @@ function unpackArgs (rawArgs, cb) {
if (er) return cb(er)
data.version = arg[1]
data._id = data.name+"@"+data.version
+ log.warn(data._id, "pushing data into list")
argData.push(data)
argData[data._id] = data
// todo: remove this kludge. 0.1.28
@@ -76,23 +88,34 @@ function unpackArgs (rawArgs, cb) {
}
)
}, function (er) {
+ log.warn(Object.keys(argData), "argData keys")
return cb(er, argData)
})
})
}
function firstPart (args, cb) {
+ log.warn(args, "uninstall firstPart args")
asyncMap(args, function (arg, cb) {
+ log.warn([arg._id, arg], "firstPart asyncMap")
var pkgdir = path.join(npm.dir, arg.name, arg.version)
- log.silly(Object.keys(args), "uninstall firstPart args")
- chain
- ( [lifecycle, arg, "preuninstall"]
- , [lifecycle, arg, "uninstall"]
- , [checkActive, arg]
- , [checkDependents, arg, args]
- , [log, "safe to uninstall: "+arg._id, "uninstall"]
- , cb
- )
- }, log.er(cb, "Failed safety check"))
+ if (!arg._id) {
+ log.error(arg, "Invalid remove thing")
+ }
+ checkActive(arg, function (er) {
+ if (er) return cb(er)
+ checkDependents(arg, args, function (er, deps) {
+ if (er) return cb(er)
+ chain
+ ( [lifecycle, arg, "preuninstall"]
+ , [lifecycle, arg, "uninstall"]
+ , [log, "safe to uninstall: "+arg._id, "uninstall"]
+ , function (er, deps) { cb(er, deps) }
+ )
+ })
+ })
+ }, function (er, deps) {
+ if (er) return log.er(cb, "Failed safety check")(er)
+ })
}
// if this package is active, and auto-deactivate isn't true, then fail
function checkActive (pkg, cb) {
@@ -117,18 +140,36 @@ function checkDependents (pkg, others, cb) {
var depDir = path.join(npm.dir, pkg.name, pkg.version, "dependents")
fs.readdir(depDir, function (er, deps) {
if (er) return cb() // no dependents
+ var safe = true
+ , conflicts = []
for (var i = 0, l = deps.length; i < l; i ++) {
var dep = deps[i]
// if this dependent is on the list, then it's ok,
// because it'll be removed, too.
- if (!others[dep]) return cb(new Error(
+ if (!others[dep]) conflicts.push(dep)
+ }
+ if (conflicts.length) {
+ log.warn(others, "others")
+ if (npm.config.get("recursive")) {
+ return uninstall(others.concat(deps), function (er) {
+ return cb(er, true)
+ })
+ }
+ return cb(new Error(
pkg.name+"@"+pkg.version+" depended upon by "+deps.join(",")+".\n"
+"Cannot remove"))
}
cb()
})
}
+
+
+
+
+
+
+
function secondPart (args, cb) {
asyncMap(args, function (arg, cb) {
var name = arg.name
View
@@ -1,10 +1,20 @@
#!/bin/sh
r=${RANDOM-$(date +%s)}
+TMP=$(mktemp -dt npm.XXXXXX)
+if [ "$TMP" == "" ]; then
+ TMP=$PWD/npm-$r
+ mkdir -- "$TMP" || (echo "failed to mkdir $TMP" >&2 ; exit 1)
+fi
+BACK="$PWD"
tar=${TAR-$(if which gtar 1>/dev/null 2>/dev/null; then echo "gtar" ; else echo "tar" ; fi)}
-mkdir npm-$r \
- && cd npm-$r \
- && curl -L http://github.com/isaacs/npm/tarball/master | $tar xzf - --strip-components=1 \
+egrep=$(if which gegrep 1>/dev/null 2>/dev/null; then echo "gegrep" ; else echo "egrep" ; fi)
+cd -- "$TMP" \
+ && curl -L $(
+ curl http://registry.npmjs.org/npm/latest \
+ | $egrep -o 'tarball":"[^"]+' \
+ | $egrep -o 'http://.*'
+ ) | $tar xzf - --strip-components=1 \
&& make uninstall install \
- && cd .. \
- && rm -rf npm-$r \
+ && cd -- "$BACK" \
+ && rm -rf -- "$TMP" \
&& echo "It worked"

0 comments on commit 64dfad3

Please sign in to comment.