From b76dced367da4f8d312bf277380a7208927fdccc Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Sat, 30 Jan 2016 21:38:11 +0800 Subject: [PATCH] Improve version data logging --- lib/install.js | 13 ++++++++++++- lib/logger.js | 13 ++++++++++--- lib/resolve/npm.js | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/install.js b/lib/install.js index bc678f917e..cd6589315c 100644 --- a/lib/install.js +++ b/lib/install.js @@ -89,12 +89,21 @@ module.exports = function install (ctx, pkgSpec, modules, options) { return resolve(pkg.spec) .then(saveResolution) - .then(_ => log('resolved', pkg.fullname)) + .then(_ => log('resolved', pkg)) .then(_ => make(join(modules, pkg.spec.name), false, _ => Promise.resolve() .then(_ => buildToStoreCached(ctx, paths, pkg, log)) .then(_ => mkdirp(paths.modules)) .then(_ => symlinkToModules(paths.target, paths.modules)))) + + // package.json data isn't logged if it was already installed before, + // so do it again to be sure. it's not always available though + .then(_ => { + try { + return log('package.json', requireJson(join(paths.target, 'package.json'))) + } catch (e) { } }) + + // done .then(_ => log('done')) .catch(err => { log('error', err) @@ -104,6 +113,7 @@ module.exports = function install (ctx, pkgSpec, modules, options) { // set metadata as fetched from resolve() function saveResolution (res) { pkg.fullname = res.fullname + pkg.version = res.version pkg.dist = res.dist paths.target = join(ctx.store, res.fullname) } @@ -160,6 +170,7 @@ function buildInStore (ctx, paths, pkg, log) { return Promise.resolve() .then(_ => { fulldata = requireJson(abspath(join(paths.tmp, 'package.json'))) }) + .then(_ => log('package.json', fulldata)) // link node_modules/.bin .then(_ => linkBins(paths.modules, paths.tmp, paths.target)) diff --git a/lib/logger.js b/lib/logger.js index c7c08079a4..00891329f1 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -5,7 +5,8 @@ observatory.settings({ prefix: ' ', width: 74 }) module.exports = function logger () { return function (pkg) { - var pkgData + var pkgData // package.json + var res // resolution var t = observatory.add(pkg.name + ' ' + chalk.gray(pkg.rawSpec || '')) @@ -19,9 +20,13 @@ module.exports = function logger () { // log('error', err) function status (status, args) { if (status === 'resolved') { - pkgData = args + res = args } else if (status === 'downloading') { - t.status(chalk.yellow('downloading ' + pkgData.version + ' ·')) + if (res.version) { + t.status(chalk.yellow('downloading ' + res.version + ' ·')) + } else { + t.status(chalk.yellow('downloading ·')) + } if (args && args.total && args.done < args.total) { t.details('' + Math.round(args.done / args.total * 100) + '%') } else { @@ -35,6 +40,8 @@ module.exports = function logger () { t.status(chalk.green('OK ✓')) .details('') } + } else if (status === 'package.json') { + pkgData = args } else if (status === 'dependencies') { t.status(chalk.gray('' + pkgData.version + ' ·')) .details('') diff --git a/lib/resolve/npm.js b/lib/resolve/npm.js index a4bb875bea..0f89cf2eaa 100644 --- a/lib/resolve/npm.js +++ b/lib/resolve/npm.js @@ -27,6 +27,7 @@ module.exports = function resolveNpm (pkg) { .then(res => { return { fullname: '' + res.name.replace('/', '!') + '@' + res.version, + version: res.version, // used for displaying dist: res.dist } })