diff options
author | isaacs <i@izs.me> | 2011-03-31 23:13:37 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-03-31 23:13:37 +0400 |
commit | 685f773421663e80eef5632756a0a29267ebbd88 (patch) | |
tree | 1ffed593aea57479e69bca89c7d16b3b79676e65 /lib | |
parent | 9e052c8cdf6b1497f503e7125174abaac9b72e9e (diff) |
bindist: Use install instead of unpack/build
The issue is that some packages use dependencies in their build process,
especially coffeescript projects that compile with "cake".
Doing it this way adds a little bit of overhead, but has a much higher
success rate.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/install.js | 59 | ||||
-rw-r--r-- | lib/publish.js | 65 |
2 files changed, 64 insertions, 60 deletions
diff --git a/lib/install.js b/lib/install.js index 6475fbfa8..d51f67098 100644 --- a/lib/install.js +++ b/lib/install.js @@ -137,47 +137,52 @@ var npm = require("../npm") , relativize = require("./utils/relativize") , output , url = require("url") + , mkdir = require("./utils/mkdir-p") function install (args, cb) { var where = npm.prefix if (npm.config.get("global")) where = path.resolve(where, "lib") - // internal api: install(what, where, cb) + // internal api: install(where, what, cb) if (arguments.length === 3) { where = args args = [cb] cb = arguments[2] - log([args, where], "install(where, what)") + log([where, args], "install(where, what)") } - // install dependencies locally by default, - // or install current folder globally - if (!args.length) { - if (npm.config.get("global")) args = ["."] - else return readJson(path.resolve("package.json"), function (er, data) { - if (er) return log.er(cb, "Couldn't read dependencies.")(er) - var deps = Object.keys(data.dependencies || {}) - if (!deps.length) return log("Nothing to do", "install", cb) + mkdir(where, function (er) { + if (er) return cb(er) + // install dependencies locally by default, + // or install current folder globally + if (!args.length) { + if (npm.config.get("global")) args = ["."] + else return readJson( path.resolve("package.json") + , function (er, data) { + if (er) return log.er(cb, "Couldn't read dependencies.")(er) + var deps = Object.keys(data.dependencies || {}) + if (!deps.length) return log("Nothing to do", "install", cb) + var previously = {} + previously[data.name] = data.version + installMany(deps.map(function (dep) { + var target = data.dependencies[dep] + if (!url.parse(target).protocol) { + target = dep + "@" + target + } + return target + }), where, previously, false, cb) + }) + } + + // initial "previously" is the name:version of the root, if it's got + // a pacakge.json file. + readJson(path.resolve(where, "package.json"), function (er, data) { + if (er) data = null var previously = {} - previously[data.name] = data.version - installMany(deps.map(function (dep) { - var target = data.dependencies[dep] - if (!url.parse(target).protocol) { - target = dep + "@" + target - } - return target - }), where, previously, false, cb) + if (data) previously[data.name] = data.version + installMany(args, where, previously, true, cb) }) - } - - // initial "previously" is the name:version of the root, if it's got - // a pacakge.json file. - readJson(path.resolve(where, "package.json"), function (er, data) { - if (er) data = null - var previously = {} - if (data) previously[data.name] = data.version - installMany(args, where, previously, true, cb) }) } diff --git a/lib/publish.js b/lib/publish.js index 86aebd0a9..a773f0d6e 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -54,46 +54,45 @@ function preBuild (data, bd, cb) { // pack to cache/package-<bd>.tgz var cf = path.resolve(npm.cache, data.name, data.version) var pb = path.resolve(cf, "build") + , buildTarget = path.resolve(pb, "node_modules", data.name) , tb = path.resolve(cf, "package-"+bd+".tgz") + , sourceBall = path.resolve(cf, "package.tgz") log.verbose("about to cache unpack") - npm.commands.cache.unpack(data.name, data.version, pb, function (er) { - log.verbose("back from cache unpack") - if (er) return cb(er) - npm.commands.build([pb], function (er) { - log.info(data._id, "prebuild done") - // build failure just means that we can't prebuild - if (er) { - log.warn(er.message, "prebuild failed "+bd) - return cb() + log.warn(sourceBall, "the tarball") + npm.commands.install(pb, sourceBall, function (er) { + log.info(data._id, "prebuild done") + // build failure just means that we can't prebuild + if (er) { + log.warn(er.message, "prebuild failed "+bd) + return cb() + } + // now strip the preinstall/install scripts + // they've already been run. + var pbj = path.resolve(buildTarget, "package.json") + readJson(pbj, function (er, pbo) { + if (er) return cb(er) + if (pbo.scripts) { + delete pbo.scripts.preinstall + delete pbo.scripts.install + delete pbo.scripts.postinstall } - // now strip the preinstall/install scripts - // they've already been run. - var pbj = path.resolve(pb, "package.json") - readJson(pbj, function (er, pbo) { + pbo.prebuilt = bd + pbo.files = pbo.files || [] + pbo.files.push("build") + fs.writeFile(pbj, JSON.stringify(pbo, null, 2), function (er) { if (er) return cb(er) - if (pbo.scripts) { - delete pbo.scripts.preinstall - delete pbo.scripts.install - delete pbo.scripts.postinstall - } - pbo.prebuilt = bd - pbo.files = pbo.files || [] - pbo.files.push("build") - fs.writeFile(pbj, JSON.stringify(pbo, null, 2), function (er) { + tar.pack(tb, buildTarget, pbo, true, function (er) { if (er) return cb(er) - tar.pack(tb, pb, pbo, false, function (er) { + // try to validate the shasum, too + sha.get(tb, function (er, shasum) { if (er) return cb(er) - // try to validate the shasum, too - sha.get(tb, function (er, shasum) { - if (er) return cb(er) - // binary distribution requires shasum checking. - if (!shasum) return cb() - data.dist.bin = data.dist.bin || {} - data.dist.bin[bd] = data.dist.bin[bd] || {} - data.dist.bin[bd].shasum = shasum - return cb(null, tb) - }) + // binary distribution requires shasum checking. + if (!shasum) return cb() + data.dist.bin = data.dist.bin || {} + data.dist.bin[bd] = data.dist.bin[bd] || {} + data.dist.bin[bd].shasum = shasum + return cb(null, tb) }) }) }) |