mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46769 (Further refactors to logging after D63255296.) Fully decouples `community-cli-plugin` from the unlisted optional dependency on `react-native-community/cli-tools'`. This is motivated by changes in https://github.com/facebook/react-native/pull/46627 which switch to using Metro's `TerminalReporter` API for emitting logs safely. - Swaps out logs in the dev server for the `unstable_server_log` Metro reporter event. - Swaps out `logger.debug()` calls for the `debug` package, currently used by Metro and `dev-middleware`. - Swaps out other logs in the `bundle` command for `console`. - (Also specify missing `semver` dep.) Changelog: [Internal] Reviewed By: hoxyq Differential Revision: D63328268 fbshipit-source-id: f552748ecc3456bd5fb8870c3a51d744a6bf3e70
45 lines
1013 B
JavaScript
45 lines
1013 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
* @oncall react_native
|
|
*/
|
|
|
|
import type TerminalReporter from 'metro/src/lib/TerminalReporter';
|
|
|
|
type LoggerFn = (...message: $ReadOnlyArray<string>) => void;
|
|
|
|
/**
|
|
* Create a dev-middleware logger object that will emit logs via Metro's
|
|
* terminal reporter.
|
|
*/
|
|
export default function createDevMiddlewareLogger(
|
|
reporter: TerminalReporter,
|
|
): $ReadOnly<{
|
|
info: LoggerFn,
|
|
error: LoggerFn,
|
|
warn: LoggerFn,
|
|
}> {
|
|
return {
|
|
info: makeLogger(reporter, 'info'),
|
|
warn: makeLogger(reporter, 'warn'),
|
|
error: makeLogger(reporter, 'error'),
|
|
};
|
|
}
|
|
|
|
function makeLogger(
|
|
reporter: TerminalReporter,
|
|
level: 'info' | 'warn' | 'error',
|
|
): LoggerFn {
|
|
return (...data: Array<mixed>) =>
|
|
reporter.update({
|
|
type: 'unstable_server_log',
|
|
level,
|
|
data,
|
|
});
|
|
}
|