Skip to content

Commit

Permalink
expose TerminalReporter for Reporter implementations (facebook#1009)
Browse files Browse the repository at this point in the history
Summary:
We are experimenting with creating our own `Reporter` that can intercept `console.log` messages and turn those into a filterable stream that gets subscribed via a WebSocket. IE

```ts
// this is ok I guess:
import { TerminalReporter } from 'metro/src/lib/TerminalReporter';
// this is preferred, "official" export, hence this PR
import { TerminalReporter } from 'metro';

export default class Reporter extends TerminalReporter {
  update(event) {
    switch (event.type) {
      case 'client_log':
        // send
        break;
      default:
        TerminalReporter.prototype.update(event);
    }
  }
}
```

To make this easy, I just want to expose `TerminalReporter` from the module, rather than reach into the file.

Pull Request resolved: facebook#1009

Test Plan: Not much needed here, AFAICT.

Reviewed By: motiz88

Differential Revision: D46842101

Pulled By: robhogan

fbshipit-source-id: 94f302a07992bd8cb007b2f107284e59a2be47c9
  • Loading branch information
colinta authored and facebook-github-bot committed Jun 19, 2023
1 parent 4b22efb commit 417e6f2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/metro/src/index.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const makeServeCommand = require('./commands/serve');
const MetroHmrServer = require('./HmrServer');
const IncrementalBundler = require('./IncrementalBundler');
const createWebsocketServer = require('./lib/createWebsocketServer');
const TerminalReporter = require('./lib/TerminalReporter');
const MetroServer = require('./Server');
const outputBundle = require('./shared/output/bundle');
const chalk = require('chalk');
Expand Down Expand Up @@ -140,6 +141,7 @@ type BuildCommandOptions = {} | null;
type ServeCommandOptions = {} | null;

exports.Terminal = Terminal;
exports.TerminalReporter = TerminalReporter;

export type {MetroConfig};

Expand Down
2 changes: 1 addition & 1 deletion packages/metro/src/lib/TerminalReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ class TerminalReporter {

/**
* Single entry point for reporting events. That allows us to implement the
* corresponding JSON reporter easily and have a consistent repor∏ting.
* corresponding JSON reporter easily and have a consistent reporting.
*/
update(event: TerminalReportableEvent): void {
if (event.type === 'bundle_transform_progressed') {
Expand Down
1 change: 1 addition & 0 deletions packages/metro/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {OutputOptions, RequestOptions} from './shared/types';

export {loadConfig, mergeConfig, resolveConfig} from 'metro-config';
export {Terminal} from 'metro-core';
export {TerminalReporter} from './lib/TerminalReporter';

export {HttpServer, HttpsServer};

Expand Down

0 comments on commit 417e6f2

Please sign in to comment.