-
-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from rstacruz/improved-logging
Improved logging
- Loading branch information
Showing
12 changed files
with
203 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = require('rc')('npm', { | ||
pnpm_concurrency: 16, | ||
pnpm_store_path: 'node_modules/.store' | ||
module.exports = require('rc')('pnpm', { | ||
concurrency: 16, | ||
store_path: 'node_modules/.store', | ||
logger: 'pretty' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,7 @@ | ||
var chalk = require('chalk') | ||
var config = require('./config') | ||
var supportsColor = require('supports-color') | ||
|
||
var observatory = require('observatory') | ||
observatory.settings({ prefix: ' ', width: 74 }) | ||
|
||
module.exports = function logger () { | ||
return function (pkg) { | ||
var pkgData // package.json | ||
var res // resolution | ||
var t | ||
|
||
if (pkg.name) { | ||
t = observatory.add(pkg.name + ' ' + | ||
chalk.gray(pkg.rawSpec || '')) | ||
} else { | ||
t = observatory.add('' + | ||
chalk.gray(pkg.rawSpec || '')) | ||
} | ||
|
||
// resolve() is the first thing it does. | ||
t.status(chalk.yellow('finding ·')) | ||
return status | ||
|
||
// log('resolved', pkgData) | ||
// log('downloading') | ||
// log('downloading', { done: 1, total: 200 }) | ||
// log('depnedencies') | ||
// log('error', err) | ||
function status (status, args) { | ||
if (status === 'resolved') { | ||
res = args | ||
} else if (status === 'download-queued') { | ||
if (res.version) { | ||
t.status(chalk.gray('wait ' + res.version + ' ·')) | ||
} else { | ||
t.status(chalk.gray('wait ·')) | ||
} | ||
} else if (status === 'downloading') { | ||
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 { | ||
t.details('') | ||
} | ||
} else if (status === 'done') { | ||
if (pkgData) { | ||
t.status(chalk.green('' + pkgData.version + ' ✓')) | ||
.details('') | ||
} else { | ||
t.status(chalk.green('OK ✓')) | ||
.details('') | ||
} | ||
} else if (status === 'package.json') { | ||
pkgData = args | ||
} else if (status === 'dependencies') { | ||
t.status(chalk.gray('' + pkgData.version + ' ·')) | ||
.details('') | ||
} else if (status === 'error') { | ||
t.status(chalk.red('ERROR ✗')) | ||
.details('') | ||
} else if (status === 'stdout') { | ||
observatory.add(chalk.blue(args.name) + ' ' + chalk.gray(args.line)) | ||
} else if (status === 'stderr') { | ||
observatory.add(chalk.blue(args.name) + '! ' + chalk.gray(args.line)) | ||
} else { | ||
t.status(status) | ||
.details('') | ||
} | ||
} | ||
} | ||
} | ||
module.exports = | ||
(config.logger === 'pretty' && supportsColor) | ||
? require('./logger/pretty') | ||
: require('./logger/simple') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
var chalk = require('chalk') | ||
|
||
var observatory = require('observatory') | ||
observatory.settings({ prefix: ' ', width: 74 }) | ||
|
||
module.exports = function logger () { | ||
return function (pkg) { | ||
var pkgData // package.json | ||
var res // resolution | ||
var t | ||
|
||
if (pkg.name) { | ||
t = observatory.add(pkg.name + ' ' + | ||
chalk.gray(pkg.rawSpec || '')) | ||
} else { | ||
t = observatory.add('' + | ||
chalk.gray(pkg.rawSpec || '')) | ||
} | ||
|
||
// the first thing it (probably) does is wait in queue to query the npm registry | ||
t.status(chalk.gray('·')) | ||
return status | ||
|
||
// log('resolved', pkgData) | ||
// log('downloading') | ||
// log('downloading', { done: 1, total: 200 }) | ||
// log('depnedencies') | ||
// log('error', err) | ||
function status (status, args) { | ||
if (status === 'resolving') { | ||
t.status(chalk.yellow('finding ·')) | ||
} else if (status === 'resolved') { | ||
res = args | ||
} else if (status === 'download-queued') { | ||
if (res.version) { | ||
t.status(chalk.gray('queued ' + res.version + ' ↓')) | ||
} else { | ||
t.status(chalk.gray('queued ↓')) | ||
} | ||
} else if (status === 'downloading') { | ||
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 { | ||
t.details('') | ||
} | ||
} else if (status === 'done') { | ||
if (pkgData) { | ||
t.status(chalk.green('' + pkgData.version + ' ✓')) | ||
.details('') | ||
} else { | ||
t.status(chalk.green('OK ✓')) | ||
.details('') | ||
} | ||
} else if (status === 'package.json') { | ||
pkgData = args | ||
} else if (status === 'dependencies') { | ||
t.status(chalk.gray('' + pkgData.version + ' ·')) | ||
.details('') | ||
} else if (status === 'error') { | ||
t.status(chalk.red('ERROR ✗')) | ||
.details('') | ||
} else if (status === 'stdout') { | ||
observatory.add(chalk.blue(args.name) + ' ' + chalk.gray(args.line)) | ||
} else if (status === 'stderr') { | ||
observatory.add(chalk.blue(args.name) + '! ' + chalk.gray(args.line)) | ||
} else { | ||
t.status(status) | ||
.details('') | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
var chalk = require('chalk') | ||
|
||
var UPDATERS = [ | ||
'resolving', 'resolved', 'download-start', 'dependencies' | ||
] | ||
|
||
var BAR_LENGTH = 20 | ||
|
||
var s = { | ||
gray: chalk.gray, | ||
green: chalk.green, | ||
bold: chalk.bold | ||
} | ||
|
||
/* | ||
* Simple percent logger | ||
*/ | ||
|
||
module.exports = function logger () { | ||
var out = process.stdout | ||
var progress = { done: 0, total: 0 } | ||
var lastStatus | ||
var done = {} | ||
|
||
process.on('exit', _ => { | ||
out.write(reset()) | ||
}) | ||
|
||
return function (pkg) { | ||
var name = pkg.name | ||
? (pkg.name + ' ' + pkg.rawSpec) | ||
: pkg.rawSpec | ||
|
||
update() | ||
progress.total += UPDATERS.length + 20 | ||
var left = UPDATERS.length + 20 | ||
var pkgData | ||
|
||
return function (status, args) { | ||
if (status === 'done') progress.done += left | ||
|
||
if (~UPDATERS.indexOf(status)) { | ||
progress.done += 1 | ||
left -= 1 | ||
} | ||
|
||
if (status === 'package.json') { | ||
pkgData = args | ||
} | ||
|
||
lastStatus = name | ||
|
||
if (status === 'done') { | ||
if (pkgData && pkgData.version) { | ||
update(pkgData.name + ' ' + s.gray(pkgData.version)) | ||
} else { | ||
update(pkgData && pkgData.name || name) | ||
} | ||
} else { | ||
update() | ||
} | ||
} | ||
|
||
function update (line) { | ||
if (line && !done[line]) { | ||
done[line] = true | ||
out.write(reset() + line + '\n') | ||
} | ||
|
||
var percent = progress.done / progress.total | ||
if (progress.total > 0 && out.isTTY) { | ||
var bar = Math.round(percent * BAR_LENGTH) | ||
out.write( | ||
reset() + | ||
s.bold(Math.round(percent * 100) + '%') + ' ' + | ||
s.green(Array(bar).join('=') + '>') + | ||
Array(BAR_LENGTH - bar).join(' ') + ' ' + | ||
s.gray(lastStatus.substr(0, 40))) + ' ' | ||
} | ||
} | ||
} | ||
|
||
function reset () { | ||
return out.isTTY | ||
? '\r' + Array(out.columns).join(' ') + '\r' | ||
: '' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.