mirror of https://github.com/status-im/metro.git
packager: add utilities to log errors internally
Reviewed By: davidaurelio Differential Revision: D4468471 fbshipit-source-id: 10deb5014d06e4d3bb9d3122eef362c09f74d044
This commit is contained in:
parent
94f1c6b34a
commit
00940db5d5
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {EventEmitter} = require('events');
|
||||
|
||||
class BatchProcessorMock {
|
||||
|
||||
constructor(_, processBatch) {
|
||||
this._processBatch = processBatch;
|
||||
this._queue = [];
|
||||
BatchProcessorMock.mocks.emit('new', this);
|
||||
}
|
||||
|
||||
queue(item, callback) {
|
||||
this._queue.push([item, callback]);
|
||||
}
|
||||
|
||||
flush(callback) {
|
||||
const {_queue} = this;
|
||||
this._queue = [];
|
||||
process.nextTick(() => {
|
||||
this._processBatch(_queue.map(pair => pair[0]), (error, res) => {
|
||||
_queue.forEach((pair, i) => pair[1](error, res && res[i]));
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BatchProcessorMock.mocks = new EventEmitter();
|
||||
|
||||
module.exports = BatchProcessorMock;
|
|
@ -84,6 +84,14 @@ function logWarning(terminal: Terminal, format: string, ...args: Array<mixed>):
|
|||
terminal.log('%s: %s', chalk.yellow('warning'), str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to `logWarning`, but for messages that require the user to act.
|
||||
*/
|
||||
function logError(terminal: Terminal, format: string, ...args: Array<mixed>): void {
|
||||
const str = util.format(format, ...args);
|
||||
terminal.log('%s: %s', chalk.red('error'), str);
|
||||
}
|
||||
|
||||
/**
|
||||
* A reporter that does nothing. Errors and warnings will be swallowed, that
|
||||
* is generally not what you want.
|
||||
|
@ -92,5 +100,6 @@ const nullReporter = {update() {}};
|
|||
|
||||
module.exports = {
|
||||
logWarning,
|
||||
logError,
|
||||
nullReporter,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue