Improve version data logging

This commit is contained in:
Rico Sta. Cruz
2016-01-30 21:38:11 +08:00
parent b75d2b3663
commit b76dced367
3 changed files with 23 additions and 4 deletions

View File

@@ -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))

View File

@@ -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('')

View File

@@ -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
}
})