packager: add utilities to log errors internally

Reviewed By: davidaurelio

Differential Revision: D4468471

fbshipit-source-id: 10deb5014d06e4d3bb9d3122eef362c09f74d044
This commit is contained in:
Jean Lauliac 2017-01-27 11:05:00 -08:00 коммит произвёл Facebook Github Bot
Родитель 9dee696ed8
Коммит abf75fa23c
2 изменённых файлов: 50 добавлений и 0 удалений

41
packager/react-packager/src/lib/__mocks__/BatchProcessor.js поставляемый Normal file
Просмотреть файл

@ -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); 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 * A reporter that does nothing. Errors and warnings will be swallowed, that
* is generally not what you want. * is generally not what you want.
@ -92,5 +100,6 @@ const nullReporter = {update() {}};
module.exports = { module.exports = {
logWarning, logWarning,
logError,
nullReporter, nullReporter,
}; };