diff options
author | isaacs <i@izs.me> | 2010-04-25 03:42:22 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-04-25 03:42:22 +0400 |
commit | f45ac528f395357902cec08254279355674013fc (patch) | |
tree | b2bb7b162a6e1d7e74693988c51aa96131124ce9 /lib | |
parent | 31a7579d1f3b5e43e66c644c529e091dfff06f74 (diff) |
Refactor the commands onto npm.commands
Diffstat (limited to 'lib')
-rw-r--r-- | lib/activate.js | 2 | ||||
-rw-r--r-- | lib/build.js | 2 | ||||
-rw-r--r-- | lib/install.js | 42 | ||||
-rw-r--r-- | lib/link.js | 4 | ||||
-rw-r--r-- | lib/utils/chain.js | 2 |
5 files changed, 24 insertions, 28 deletions
diff --git a/lib/activate.js b/lib/activate.js index 7e1e08dc1..f97182482 100644 --- a/lib/activate.js +++ b/lib/activate.js @@ -33,7 +33,7 @@ function activate (pkg, version, cb) { // TODO: If "to" already exists, then do deactivate step implicitly chain( - function (cb) { npm.deactivate(pkg, function () { cb() }) }, + function (cb) { npm.commands.deactivate(pkg, function () { cb() }) }, function (cb) { fs.lstat(to, function (er, stat) { if (!er) return fs.readlink(to, function (active) { diff --git a/lib/build.js b/lib/build.js index 7332db9e7..9e410c1d0 100644 --- a/lib/build.js +++ b/lib/build.js @@ -96,7 +96,7 @@ function autoActivate (pkg, cb) { return cb(); } log(pkg.name+" "+pkg.version, "activate"); - npm.activate(pkg.name, pkg.version, cb); + npm.commands.activate(pkg.name, pkg.version, cb); }); } diff --git a/lib/install.js b/lib/install.js index a865d7667..067e721d2 100644 --- a/lib/install.js +++ b/lib/install.js @@ -38,29 +38,24 @@ function install (tarball, cb) { pkg = {}; // at this point, presumably the filesystem knows how to open it. - chain( - [fs, "stat", tarball], - [mkdir, unpackTargetDir], - [unpackTar, tarball, unpackTargetDir], - - // read the json and then save it - function (cb) { - readJson(path.join(unpackTargetDir, "package.json"), function (er, data) { - if (er) return cb(er, data); - // save this just for this install - npm.set(data._id, data); - pkg._data = data; - cb(null, data); - }); - }, - - // move to ROOT/.npm/{name}/{version}/package - [moveIntoPlace, unpackTargetDir, pkg], - - [npm, "build", pkg], - - cb - ); + chain( [fs, "stat", tarball] + , [mkdir, unpackTargetDir] + , [unpackTar, tarball, unpackTargetDir] + // read the json and then save it + , function (cb) { + readJson(path.join(unpackTargetDir, "package.json"), function (er, data) { + if (er) return cb(er, data); + // save this just for this install + npm.set(data._id, data); + pkg._data = data; + cb(null, data); + }); + } + // move to ROOT/.npm/{name}/{version}/package + , [moveIntoPlace, unpackTargetDir, pkg] + , [npm.commands, "build", pkg] + , cb + ) } // move to ROOT/.npm/{name}/{version}/package @@ -72,6 +67,7 @@ function moveIntoPlace (dir, pkg, cb) { var target = path.join(npm.dir, pkg.name, pkg.version); log("to: "+pkg.name+"-"+pkg.version+" from: "+dir, "moveIntoPlace"); + log(cb, "moveIntoPlace cb") chain( function (cb) { path.exists(target, function (e) { diff --git a/lib/link.js b/lib/link.js index adc9d3a43..a08561999 100644 --- a/lib/link.js +++ b/lib/link.js @@ -23,7 +23,7 @@ function link (folder, cb) { function (cb) { fs.stat(folder, function (er, stats) { if (er) return cb(er); if (!stats.isDirectory()) { - return cb(new Error("npm.link requires a directory")); + return cb(new Error("npm link requires a directory")); } log(folder+" is a directory", "link"); cb(); @@ -36,7 +36,7 @@ function link (folder, cb) { cb(); })}, [link_, folder, pkg], - [npm, "build", pkg], + [npm.commands, "build", pkg], cb ); } diff --git a/lib/utils/chain.js b/lib/utils/chain.js index f3c718d9f..cc10ee2a8 100644 --- a/lib/utils/chain.js +++ b/lib/utils/chain.js @@ -40,7 +40,7 @@ function chain () /* step, step, ..., cb */ { step.push(callback); } else fn = step; if (typeof fn !== "function") throw new Error( - "Non-function in chain()"); + "Non-function in chain() "+typeof(fn)); try { if (Array.isArray(step)) fn.apply(obj, step); |