metro 0.84.3 → 0.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -18
- package/src/Assets.js +23 -14
- package/src/Assets.js.flow +51 -38
- package/src/Bundler.d.ts +1 -5
- package/src/DeltaBundler/DeltaCalculator.d.ts +1 -16
- package/src/DeltaBundler/DeltaCalculator.js.flow +1 -1
- package/src/DeltaBundler/Graph.d.ts +1 -102
- package/src/DeltaBundler/Graph.js.flow +7 -7
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +1 -1
- package/src/DeltaBundler/Serializers/getAssets.js.flow +1 -1
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +5 -5
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +9 -9
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +3 -3
- package/src/DeltaBundler/Transformer.d.ts +2 -10
- package/src/DeltaBundler/Worker.flow.js.flow +1 -1
- package/src/DeltaBundler/WorkerFarm.d.ts +2 -47
- package/src/DeltaBundler/getTransformCacheKey.js.flow +3 -3
- package/src/DeltaBundler/types.js.flow +10 -10
- package/src/DeltaBundler.d.ts +1 -5
- package/src/HmrServer.d.ts +2 -45
- package/src/HmrServer.js.flow +10 -10
- package/src/IncrementalBundler.d.ts +1 -9
- package/src/IncrementalBundler.js.flow +9 -6
- package/src/ModuleGraph/worker/collectDependencies.d.ts +1 -2
- package/src/ModuleGraph/worker/collectDependencies.js +52 -0
- package/src/ModuleGraph/worker/collectDependencies.js.flow +67 -0
- package/src/Server/symbolicate.js.flow +13 -13
- package/src/Server.d.ts +3 -176
- package/src/Server.js +42 -5
- package/src/Server.js.flow +70 -28
- package/src/index.flow.js +2 -2
- package/src/index.flow.js.flow +2 -2
- package/src/lib/BatchProcessor.d.ts +1 -21
- package/src/lib/CountingSet.js.flow +1 -1
- package/src/lib/JsonReporter.d.ts +1 -2
- package/src/lib/JsonReporter.js.flow +4 -2
- package/src/lib/RamBundleParser.d.ts +1 -6
- package/src/lib/TerminalReporter.d.ts +2 -78
- package/src/lib/TerminalReporter.js +39 -41
- package/src/lib/TerminalReporter.js.flow +52 -33
- package/src/lib/bundleToString.js.flow +2 -2
- package/src/lib/createWebsocketServer.js.flow +4 -4
- package/src/lib/formatBundlingError.js.flow +1 -1
- package/src/lib/getPreludeCode.js.flow +5 -5
- package/src/lib/logToConsole.js +8 -7
- package/src/lib/logToConsole.js.flow +7 -7
- package/src/lib/reporting.js +16 -7
- package/src/lib/reporting.js.flow +16 -5
- package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +1 -13
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +1 -1
- package/src/node-haste/DependencyGraph/createFileMap.js +0 -2
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +0 -2
- package/src/node-haste/DependencyGraph.d.ts +1 -30
- package/src/node-haste/DependencyGraph.js.flow +2 -2
- package/src/shared/output/RamBundle/util.js.flow +4 -2
- package/src/shared/types.js.flow +31 -31
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @noformat
|
|
8
8
|
* @oncall react_native
|
|
9
|
-
* @generated SignedSource<<
|
|
9
|
+
* @generated SignedSource<<14645ae49e4ed5ce74bdd181db9098d4>>
|
|
10
10
|
*
|
|
11
11
|
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
12
|
* Original file: packages/metro/src/lib/TerminalReporter.js
|
|
@@ -15,17 +15,9 @@
|
|
|
15
15
|
* yarn run build-ts-defs (OSS)
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import type {
|
|
18
|
+
import type {ReportableEvent} from './reporting';
|
|
19
19
|
import type {Terminal} from 'metro-core';
|
|
20
|
-
import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
|
|
21
20
|
|
|
22
|
-
type BundleProgress = {
|
|
23
|
-
bundleDetails: BundleDetails;
|
|
24
|
-
transformedFileCount: number;
|
|
25
|
-
totalFileCount: number;
|
|
26
|
-
ratio: number;
|
|
27
|
-
isPrefetch?: boolean;
|
|
28
|
-
};
|
|
29
21
|
export type TerminalReportableEvent =
|
|
30
22
|
| ReportableEvent
|
|
31
23
|
| {
|
|
@@ -41,81 +33,13 @@ export type TerminalReportableEvent =
|
|
|
41
33
|
}
|
|
42
34
|
| {type: 'unstable_server_menu_updated'; message: string}
|
|
43
35
|
| {type: 'unstable_server_menu_cleared'};
|
|
44
|
-
type BuildPhase = 'in_progress' | 'done' | 'failed';
|
|
45
|
-
interface SnippetError extends Error {
|
|
46
|
-
code?: string;
|
|
47
|
-
filename?: string;
|
|
48
|
-
snippet?: string;
|
|
49
|
-
}
|
|
50
36
|
/**
|
|
51
37
|
* We try to print useful information to the terminal for interactive builds.
|
|
52
38
|
* This implements the `Reporter` interface from the './reporting' module.
|
|
53
39
|
*/
|
|
54
40
|
declare class TerminalReporter {
|
|
55
|
-
/**
|
|
56
|
-
* The bundle builds for which we are actively maintaining the status on the
|
|
57
|
-
* terminal, ie. showing a progress bar. There can be several bundles being
|
|
58
|
-
* built at the same time.
|
|
59
|
-
*/
|
|
60
|
-
_activeBundles: Map<string, BundleProgress>;
|
|
61
|
-
_interactionStatus: null | undefined | string;
|
|
62
|
-
_scheduleUpdateBundleProgress: {
|
|
63
|
-
(data: {
|
|
64
|
-
buildID: string;
|
|
65
|
-
transformedFileCount: number;
|
|
66
|
-
totalFileCount: number;
|
|
67
|
-
}): void;
|
|
68
|
-
cancel(): void;
|
|
69
|
-
};
|
|
70
|
-
_prevHealthCheckResult: null | undefined | HealthCheckResult;
|
|
71
41
|
readonly terminal: Terminal;
|
|
72
42
|
constructor(terminal: Terminal);
|
|
73
|
-
/**
|
|
74
|
-
* Construct a message that represents the progress of a
|
|
75
|
-
* single bundle build, for example:
|
|
76
|
-
*
|
|
77
|
-
* BUNDLE path/to/bundle.js ▓▓▓▓▓░░░░░░░░░░░ 36.6% (4790/7922)
|
|
78
|
-
*/
|
|
79
|
-
_getBundleStatusMessage(
|
|
80
|
-
$$PARAM_0$$: BundleProgress,
|
|
81
|
-
phase: BuildPhase,
|
|
82
|
-
): string;
|
|
83
|
-
_logBundleBuildDone(buildID: string): void;
|
|
84
|
-
_logBundleBuildFailed(buildID: string): void;
|
|
85
|
-
_logInitializing(port: number, hasReducedPerformance: boolean): void;
|
|
86
|
-
_logInitializingFailed(port: number, error: SnippetError): void;
|
|
87
|
-
/**
|
|
88
|
-
* This function is only concerned with logging and should not do state
|
|
89
|
-
* or terminal status updates.
|
|
90
|
-
*/
|
|
91
|
-
_log(event: TerminalReportableEvent): void;
|
|
92
|
-
/**
|
|
93
|
-
* We do not want to log the whole stacktrace for bundling error, because
|
|
94
|
-
* these are operational errors, not programming errors, and the stacktrace
|
|
95
|
-
* is not actionable to end users.
|
|
96
|
-
*/
|
|
97
|
-
_logBundlingError(error: SnippetError): void;
|
|
98
|
-
_logWorkerChunk(origin: 'stdout' | 'stderr', chunk: string): void;
|
|
99
|
-
_updateBundleProgress($$PARAM_0$$: {
|
|
100
|
-
buildID: string;
|
|
101
|
-
transformedFileCount: number;
|
|
102
|
-
totalFileCount: number;
|
|
103
|
-
}): void;
|
|
104
|
-
/**
|
|
105
|
-
* This function is exclusively concerned with updating the internal state.
|
|
106
|
-
* No logging or status updates should be done at this point.
|
|
107
|
-
*/
|
|
108
|
-
_updateState(event: TerminalReportableEvent): void;
|
|
109
|
-
/**
|
|
110
|
-
* Return a status message that is always consistent with the current state
|
|
111
|
-
* of the application. Having this single function ensures we don't have
|
|
112
|
-
* different callsites overriding each other status messages.
|
|
113
|
-
*/
|
|
114
|
-
_getStatusMessage(): string;
|
|
115
|
-
_logHmrClientError(e: Error): void;
|
|
116
|
-
_logWarning(message: string): void;
|
|
117
|
-
_logWatcherHealthCheckResult(result: HealthCheckResult): void;
|
|
118
|
-
_logWatcherStatus(status: WatcherStatus): void;
|
|
119
43
|
/**
|
|
120
44
|
* Single entry point for reporting events. That allows us to implement the
|
|
121
45
|
* corresponding JSON reporter easily and have a consistent reporting.
|
|
@@ -7,10 +7,10 @@ exports.default = void 0;
|
|
|
7
7
|
var _bundleProgressUtils = require("./bundleProgressUtils");
|
|
8
8
|
var _logToConsole = _interopRequireDefault(require("./logToConsole"));
|
|
9
9
|
var reporting = _interopRequireWildcard(require("./reporting"));
|
|
10
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
10
|
var _lodash = _interopRequireDefault(require("lodash.throttle"));
|
|
12
11
|
var _metroCore = require("metro-core");
|
|
13
12
|
var _path = _interopRequireDefault(require("path"));
|
|
13
|
+
var _util = _interopRequireDefault(require("util"));
|
|
14
14
|
function _interopRequireWildcard(e, t) {
|
|
15
15
|
if ("function" == typeof WeakMap)
|
|
16
16
|
var r = new WeakMap(),
|
|
@@ -41,6 +41,7 @@ function _interopRequireWildcard(e, t) {
|
|
|
41
41
|
function _interopRequireDefault(e) {
|
|
42
42
|
return e && e.__esModule ? e : { default: e };
|
|
43
43
|
}
|
|
44
|
+
const style = (format, text) => _util.default.styleText(format, text);
|
|
44
45
|
const DARK_BLOCK_CHAR = "\u2593";
|
|
45
46
|
const LIGHT_BLOCK_CHAR = "\u2591";
|
|
46
47
|
const MAX_PROGRESS_BAR_CHAR_WIDTH = 16;
|
|
@@ -68,26 +69,24 @@ class TerminalReporter {
|
|
|
68
69
|
const localPath = _path.default.relative(".", entryFile);
|
|
69
70
|
const filledBar = Math.floor(ratio * MAX_PROGRESS_BAR_CHAR_WIDTH);
|
|
70
71
|
const bundleTypeColor =
|
|
71
|
-
phase === "done"
|
|
72
|
-
? _chalk.default.green
|
|
73
|
-
: phase === "failed"
|
|
74
|
-
? _chalk.default.red
|
|
75
|
-
: _chalk.default.yellow;
|
|
72
|
+
phase === "done" ? ["green"] : phase === "failed" ? ["red"] : ["yellow"];
|
|
76
73
|
const progress =
|
|
77
74
|
phase === "in_progress"
|
|
78
|
-
?
|
|
79
|
-
|
|
75
|
+
? style(["green", "bgGreen"], DARK_BLOCK_CHAR.repeat(filledBar)) +
|
|
76
|
+
style(
|
|
77
|
+
["bgWhite", "white"],
|
|
80
78
|
LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar),
|
|
81
79
|
) +
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
style(["bold"], ` ${Math.floor(100 * ratio)}% `) +
|
|
81
|
+
style(["dim"], `(${transformedFileCount}/${totalFileCount})`)
|
|
84
82
|
: "";
|
|
85
83
|
return (
|
|
86
|
-
|
|
84
|
+
style(
|
|
85
|
+
[...bundleTypeColor, "inverse", "bold"],
|
|
87
86
|
` ${isPrefetch === true ? "PREBUNDLE" : bundleType.toUpperCase()} `,
|
|
88
87
|
) +
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
style(["reset", "dim"], ` ${_path.default.dirname(localPath)}/`) +
|
|
89
|
+
style(["bold"], _path.default.basename(localPath)) +
|
|
91
90
|
" " +
|
|
92
91
|
progress
|
|
93
92
|
);
|
|
@@ -132,38 +131,36 @@ class TerminalReporter {
|
|
|
132
131
|
"",
|
|
133
132
|
"",
|
|
134
133
|
];
|
|
135
|
-
const color = hasReducedPerformance
|
|
136
|
-
|
|
137
|
-
: _chalk.default.blue;
|
|
138
|
-
this.terminal.log(color(logo.join("\n")));
|
|
134
|
+
const color = hasReducedPerformance ? ["red"] : ["blue"];
|
|
135
|
+
this.terminal.log(style(color, logo.join("\n")));
|
|
139
136
|
}
|
|
140
137
|
_logInitializingFailed(port, error) {
|
|
141
138
|
if (error.code === "EADDRINUSE") {
|
|
142
139
|
this.terminal.log(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
"
|
|
146
|
-
|
|
140
|
+
style(["bgRed", "bold"], " ERROR "),
|
|
141
|
+
style(
|
|
142
|
+
["red"],
|
|
143
|
+
`Metro can't listen on port ${style(["bold"], String(port))}`,
|
|
147
144
|
),
|
|
148
145
|
);
|
|
149
146
|
this.terminal.log(
|
|
150
147
|
"Most likely another process is already using this port",
|
|
151
148
|
);
|
|
152
149
|
this.terminal.log("Run the following command to find out which process:");
|
|
153
|
-
this.terminal.log("\n ",
|
|
150
|
+
this.terminal.log("\n ", style(["bold"], "lsof -i :" + port), "\n");
|
|
154
151
|
this.terminal.log("Then, you can either shut down the other process:");
|
|
155
|
-
this.terminal.log("\n ",
|
|
152
|
+
this.terminal.log("\n ", style(["bold"], "kill -9 <PID>"), "\n");
|
|
156
153
|
this.terminal.log("or run Metro on different port.");
|
|
157
154
|
} else {
|
|
158
155
|
this.terminal.log(
|
|
159
|
-
|
|
160
|
-
|
|
156
|
+
style(["bgRed", "bold"], " ERROR "),
|
|
157
|
+
style(["red"], error.message),
|
|
161
158
|
);
|
|
162
159
|
const errorAttributes = JSON.stringify(error);
|
|
163
160
|
if (errorAttributes !== "{}") {
|
|
164
|
-
this.terminal.log(
|
|
161
|
+
this.terminal.log(style(["red"], errorAttributes));
|
|
165
162
|
}
|
|
166
|
-
this.terminal.log(
|
|
163
|
+
this.terminal.log(style(["red"], String(error.stack)));
|
|
167
164
|
}
|
|
168
165
|
}
|
|
169
166
|
_log(event) {
|
|
@@ -214,22 +211,21 @@ class TerminalReporter {
|
|
|
214
211
|
logFn(this.terminal, String(format), ...args);
|
|
215
212
|
break;
|
|
216
213
|
case "dep_graph_loading":
|
|
217
|
-
const color = event.hasReducedPerformance
|
|
218
|
-
? _chalk.default.red
|
|
219
|
-
: _chalk.default.blue;
|
|
214
|
+
const color = event.hasReducedPerformance ? ["red"] : ["blue"];
|
|
220
215
|
const version = "v" + require("../../package.json").version;
|
|
221
216
|
this.terminal.log(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
"
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
"
|
|
228
|
-
|
|
217
|
+
style(
|
|
218
|
+
[...color, "bold"],
|
|
219
|
+
" ".repeat(19 - version.length / 2) +
|
|
220
|
+
" Welcome to Metro " +
|
|
221
|
+
style(["white"], version) +
|
|
222
|
+
"\n",
|
|
223
|
+
) + style(["dim"], " Fast - Scalable - Integrated\n\n"),
|
|
229
224
|
);
|
|
230
225
|
if (event.hasReducedPerformance) {
|
|
231
226
|
this.terminal.log(
|
|
232
|
-
|
|
227
|
+
style(
|
|
228
|
+
["red"],
|
|
233
229
|
"Metro is operating with reduced performance.\n" +
|
|
234
230
|
"Please fix the problem above and restart Metro.\n\n",
|
|
235
231
|
),
|
|
@@ -360,7 +356,7 @@ class TerminalReporter {
|
|
|
360
356
|
case "success":
|
|
361
357
|
if (this._prevHealthCheckResult) {
|
|
362
358
|
this.terminal.log(
|
|
363
|
-
|
|
359
|
+
style(["green"], `Watcher ${watcherName} is now healthy.`),
|
|
364
360
|
);
|
|
365
361
|
}
|
|
366
362
|
break;
|
|
@@ -399,14 +395,16 @@ class TerminalReporter {
|
|
|
399
395
|
break;
|
|
400
396
|
case "watchman_slow_command":
|
|
401
397
|
this.terminal.log(
|
|
402
|
-
|
|
398
|
+
style(
|
|
399
|
+
["dim"],
|
|
403
400
|
`Waiting for Watchman \`${status.command}\` (${Math.round(status.timeElapsed / 1000)}s)...`,
|
|
404
401
|
),
|
|
405
402
|
);
|
|
406
403
|
break;
|
|
407
404
|
case "watchman_slow_command_complete":
|
|
408
405
|
this.terminal.log(
|
|
409
|
-
|
|
406
|
+
style(
|
|
407
|
+
["green"],
|
|
410
408
|
`Watchman \`${status.command}\` finished after ${(status.timeElapsed / 1000).toFixed(1)}s.`,
|
|
411
409
|
),
|
|
412
410
|
);
|
|
@@ -12,15 +12,22 @@
|
|
|
12
12
|
import type {BundleDetails, ReportableEvent} from './reporting';
|
|
13
13
|
import type {Terminal} from 'metro-core';
|
|
14
14
|
import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
|
|
15
|
+
import type {BackgroundColors, ForegroundColors, Modifiers} from 'util';
|
|
15
16
|
|
|
16
17
|
import {calculateBundleProgressRatio} from './bundleProgressUtils';
|
|
17
18
|
import logToConsole from './logToConsole';
|
|
18
19
|
import * as reporting from './reporting';
|
|
19
|
-
import chalk from 'chalk';
|
|
20
20
|
// $FlowFixMe[untyped-import] lodash.throttle
|
|
21
21
|
import throttle from 'lodash.throttle';
|
|
22
22
|
import {AmbiguousModuleResolutionError} from 'metro-core';
|
|
23
23
|
import path from 'path';
|
|
24
|
+
import util from 'util';
|
|
25
|
+
|
|
26
|
+
type StyleFormat = ReadonlyArray<
|
|
27
|
+
ForegroundColors | BackgroundColors | Modifiers,
|
|
28
|
+
>;
|
|
29
|
+
const style = (format: StyleFormat, text: string): string =>
|
|
30
|
+
util.styleText(format, text);
|
|
24
31
|
|
|
25
32
|
type BundleProgress = {
|
|
26
33
|
bundleDetails: BundleDetails,
|
|
@@ -93,7 +100,7 @@ export default class TerminalReporter {
|
|
|
93
100
|
};
|
|
94
101
|
_prevHealthCheckResult: ?HealthCheckResult;
|
|
95
102
|
|
|
96
|
-
|
|
103
|
+
readonly terminal: Terminal;
|
|
97
104
|
|
|
98
105
|
constructor(terminal: Terminal) {
|
|
99
106
|
this._activeBundles = new Map();
|
|
@@ -121,28 +128,26 @@ export default class TerminalReporter {
|
|
|
121
128
|
): string {
|
|
122
129
|
const localPath = path.relative('.', entryFile);
|
|
123
130
|
const filledBar = Math.floor(ratio * MAX_PROGRESS_BAR_CHAR_WIDTH);
|
|
124
|
-
const bundleTypeColor =
|
|
125
|
-
phase === 'done'
|
|
126
|
-
? chalk.green
|
|
127
|
-
: phase === 'failed'
|
|
128
|
-
? chalk.red
|
|
129
|
-
: chalk.yellow;
|
|
131
|
+
const bundleTypeColor: StyleFormat =
|
|
132
|
+
phase === 'done' ? ['green'] : phase === 'failed' ? ['red'] : ['yellow'];
|
|
130
133
|
const progress =
|
|
131
134
|
phase === 'in_progress'
|
|
132
|
-
?
|
|
133
|
-
|
|
135
|
+
? style(['green', 'bgGreen'], DARK_BLOCK_CHAR.repeat(filledBar)) +
|
|
136
|
+
style(
|
|
137
|
+
['bgWhite', 'white'],
|
|
134
138
|
LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar),
|
|
135
139
|
) +
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
style(['bold'], ` ${Math.floor(100 * ratio)}% `) +
|
|
141
|
+
style(['dim'], `(${transformedFileCount}/${totalFileCount})`)
|
|
138
142
|
: '';
|
|
139
143
|
|
|
140
144
|
return (
|
|
141
|
-
|
|
145
|
+
style(
|
|
146
|
+
[...bundleTypeColor, 'inverse', 'bold'],
|
|
142
147
|
` ${isPrefetch === true ? 'PREBUNDLE' : bundleType.toUpperCase()} `,
|
|
143
148
|
) +
|
|
144
|
-
|
|
145
|
-
|
|
149
|
+
style(['reset', 'dim'], ` ${path.dirname(localPath)}/`) +
|
|
150
|
+
style(['bold'], path.basename(localPath)) +
|
|
146
151
|
' ' +
|
|
147
152
|
progress
|
|
148
153
|
);
|
|
@@ -191,31 +196,37 @@ export default class TerminalReporter {
|
|
|
191
196
|
'',
|
|
192
197
|
];
|
|
193
198
|
|
|
194
|
-
const color = hasReducedPerformance ?
|
|
195
|
-
this.terminal.log(color
|
|
199
|
+
const color: StyleFormat = hasReducedPerformance ? ['red'] : ['blue'];
|
|
200
|
+
this.terminal.log(style(color, logo.join('\n')));
|
|
196
201
|
}
|
|
197
202
|
|
|
198
203
|
_logInitializingFailed(port: number, error: SnippetError): void {
|
|
199
204
|
if (error.code === 'EADDRINUSE') {
|
|
200
205
|
this.terminal.log(
|
|
201
|
-
|
|
202
|
-
|
|
206
|
+
style(['bgRed', 'bold'], ' ERROR '),
|
|
207
|
+
style(
|
|
208
|
+
['red'],
|
|
209
|
+
`Metro can't listen on port ${style(['bold'], String(port))}`,
|
|
210
|
+
),
|
|
203
211
|
);
|
|
204
212
|
this.terminal.log(
|
|
205
213
|
'Most likely another process is already using this port',
|
|
206
214
|
);
|
|
207
215
|
this.terminal.log('Run the following command to find out which process:');
|
|
208
|
-
this.terminal.log('\n ',
|
|
216
|
+
this.terminal.log('\n ', style(['bold'], 'lsof -i :' + port), '\n');
|
|
209
217
|
this.terminal.log('Then, you can either shut down the other process:');
|
|
210
|
-
this.terminal.log('\n ',
|
|
218
|
+
this.terminal.log('\n ', style(['bold'], 'kill -9 <PID>'), '\n');
|
|
211
219
|
this.terminal.log('or run Metro on different port.');
|
|
212
220
|
} else {
|
|
213
|
-
this.terminal.log(
|
|
221
|
+
this.terminal.log(
|
|
222
|
+
style(['bgRed', 'bold'], ' ERROR '),
|
|
223
|
+
style(['red'], error.message),
|
|
224
|
+
);
|
|
214
225
|
const errorAttributes = JSON.stringify(error);
|
|
215
226
|
if (errorAttributes !== '{}') {
|
|
216
|
-
this.terminal.log(
|
|
227
|
+
this.terminal.log(style(['red'], errorAttributes));
|
|
217
228
|
}
|
|
218
|
-
this.terminal.log(
|
|
229
|
+
this.terminal.log(style(['red'], String(error.stack)));
|
|
219
230
|
}
|
|
220
231
|
}
|
|
221
232
|
|
|
@@ -271,20 +282,26 @@ export default class TerminalReporter {
|
|
|
271
282
|
logFn(this.terminal, String(format), ...args);
|
|
272
283
|
break;
|
|
273
284
|
case 'dep_graph_loading':
|
|
274
|
-
const color = event.hasReducedPerformance
|
|
285
|
+
const color: StyleFormat = event.hasReducedPerformance
|
|
286
|
+
? ['red']
|
|
287
|
+
: ['blue'];
|
|
275
288
|
// eslint-disable-next-line import/no-commonjs
|
|
276
289
|
// $FlowFixMe[untyped-import] package.json
|
|
277
290
|
const version = 'v' + require('../../package.json').version;
|
|
278
291
|
this.terminal.log(
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
'
|
|
282
|
-
|
|
292
|
+
style(
|
|
293
|
+
[...color, 'bold'],
|
|
294
|
+
' '.repeat(19 - version.length / 2) +
|
|
295
|
+
' Welcome to Metro ' +
|
|
296
|
+
style(['white'], version) +
|
|
297
|
+
'\n',
|
|
298
|
+
) + style(['dim'], ' Fast - Scalable - Integrated\n\n'),
|
|
283
299
|
);
|
|
284
300
|
|
|
285
301
|
if (event.hasReducedPerformance) {
|
|
286
302
|
this.terminal.log(
|
|
287
|
-
|
|
303
|
+
style(
|
|
304
|
+
['red'],
|
|
288
305
|
'Metro is operating with reduced performance.\n' +
|
|
289
306
|
'Please fix the problem above and restart Metro.\n\n',
|
|
290
307
|
),
|
|
@@ -459,7 +476,7 @@ export default class TerminalReporter {
|
|
|
459
476
|
// Only report success after a prior failure.
|
|
460
477
|
if (this._prevHealthCheckResult) {
|
|
461
478
|
this.terminal.log(
|
|
462
|
-
|
|
479
|
+
style(['green'], `Watcher ${watcherName} is now healthy.`),
|
|
463
480
|
);
|
|
464
481
|
}
|
|
465
482
|
break;
|
|
@@ -499,7 +516,8 @@ export default class TerminalReporter {
|
|
|
499
516
|
break;
|
|
500
517
|
case 'watchman_slow_command':
|
|
501
518
|
this.terminal.log(
|
|
502
|
-
|
|
519
|
+
style(
|
|
520
|
+
['dim'],
|
|
503
521
|
`Waiting for Watchman \`${status.command}\` (${Math.round(
|
|
504
522
|
status.timeElapsed / 1000,
|
|
505
523
|
)}s)...`,
|
|
@@ -508,7 +526,8 @@ export default class TerminalReporter {
|
|
|
508
526
|
break;
|
|
509
527
|
case 'watchman_slow_command_complete':
|
|
510
528
|
this.terminal.log(
|
|
511
|
-
|
|
529
|
+
style(
|
|
530
|
+
['green'],
|
|
512
531
|
`Watchman \`${status.command}\` finished after ${(
|
|
513
532
|
status.timeElapsed / 1000
|
|
514
533
|
).toFixed(1)}s.`,
|
|
@@ -15,8 +15,8 @@ import type {Bundle, BundleMetadata} from 'metro-runtime/src/modules/types';
|
|
|
15
15
|
* Serializes a bundle into a plain JS bundle.
|
|
16
16
|
*/
|
|
17
17
|
export default function bundleToString(bundle: Bundle): {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
readonly code: string,
|
|
19
|
+
readonly metadata: BundleMetadata,
|
|
20
20
|
} {
|
|
21
21
|
let code = bundle.pre.length > 0 ? bundle.pre + '\n' : '';
|
|
22
22
|
const modules = [];
|
|
@@ -13,13 +13,13 @@ import {clearInterval, setInterval} from 'timers';
|
|
|
13
13
|
import ws from 'ws';
|
|
14
14
|
|
|
15
15
|
type WebsocketServiceInterface<T> = interface {
|
|
16
|
-
|
|
16
|
+
readonly onClientConnect: (
|
|
17
17
|
url: string,
|
|
18
18
|
sendFn: (data: string) => void,
|
|
19
19
|
) => Promise<?T>,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
readonly onClientDisconnect?: (client: T) => unknown,
|
|
21
|
+
readonly onClientError?: (client: T, e: Error) => unknown,
|
|
22
|
+
readonly onClientMessage?: (
|
|
23
23
|
client: T,
|
|
24
24
|
message: string | Buffer | ArrayBuffer | Array<Buffer>,
|
|
25
25
|
sendFn: (data: string) => void,
|
|
@@ -16,11 +16,11 @@ export default function getPreludeCode({
|
|
|
16
16
|
requireCycleIgnorePatterns,
|
|
17
17
|
unstable_forceFullRefreshPatterns,
|
|
18
18
|
}: {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
readonly extraVars?: {[string]: unknown, ...},
|
|
20
|
+
readonly isDev: boolean,
|
|
21
|
+
readonly globalPrefix: string,
|
|
22
|
+
readonly requireCycleIgnorePatterns: ReadonlyArray<RegExp>,
|
|
23
|
+
readonly unstable_forceFullRefreshPatterns: ReadonlyArray<RegExp>,
|
|
24
24
|
}): string {
|
|
25
25
|
const vars = [
|
|
26
26
|
// Ensure these variable names match the ones referenced in metro-runtime
|
package/src/lib/logToConsole.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true,
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
8
7
|
var _util = _interopRequireDefault(require("util"));
|
|
9
8
|
function _interopRequireDefault(e) {
|
|
10
9
|
return e && e.__esModule ? e : { default: e };
|
|
@@ -15,10 +14,10 @@ var _default = (terminal, level, ...data) => {
|
|
|
15
14
|
const logFunction = console[level] && level !== "trace" ? level : "log";
|
|
16
15
|
const color =
|
|
17
16
|
level === "error"
|
|
18
|
-
?
|
|
17
|
+
? ["inverse", "red"]
|
|
19
18
|
: level === "warn"
|
|
20
|
-
?
|
|
21
|
-
:
|
|
19
|
+
? ["inverse", "yellow"]
|
|
20
|
+
: ["inverse", "white"];
|
|
22
21
|
if (level === "group") {
|
|
23
22
|
groupStack.push(level);
|
|
24
23
|
} else if (level === "groupCollapsed") {
|
|
@@ -27,7 +26,7 @@ var _default = (terminal, level, ...data) => {
|
|
|
27
26
|
collapsedGuardTimer = setTimeout(() => {
|
|
28
27
|
if (groupStack.includes("groupCollapsed")) {
|
|
29
28
|
terminal.log(
|
|
30
|
-
|
|
29
|
+
_util.default.styleText(["inverse", "yellow", "bold"], " WARN "),
|
|
31
30
|
"Expected `console.groupEnd` to be called after `console.groupCollapsed`.",
|
|
32
31
|
);
|
|
33
32
|
groupStack.length = 0;
|
|
@@ -47,8 +46,10 @@ var _default = (terminal, level, ...data) => {
|
|
|
47
46
|
data[data.length - 1] = lastItem.trimEnd();
|
|
48
47
|
}
|
|
49
48
|
terminal.log(
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
_util.default.styleText(
|
|
50
|
+
[...color, "bold"],
|
|
51
|
+
` ${logFunction.toUpperCase()} `,
|
|
52
|
+
) + "".padEnd(groupStack.length * 2, " "),
|
|
52
53
|
_util.default.format(...data),
|
|
53
54
|
);
|
|
54
55
|
}
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
/* eslint-disable no-console */
|
|
12
12
|
|
|
13
13
|
import type {Terminal} from 'metro-core';
|
|
14
|
+
import type {BackgroundColors, ForegroundColors, Modifiers} from 'util';
|
|
14
15
|
|
|
15
|
-
import chalk from 'chalk';
|
|
16
16
|
import util from 'util';
|
|
17
17
|
|
|
18
18
|
const groupStack = [];
|
|
@@ -21,12 +21,12 @@ let collapsedGuardTimer;
|
|
|
21
21
|
export default (terminal: Terminal, level: string, ...data: Array<unknown>) => {
|
|
22
22
|
// $FlowFixMe[invalid-computed-prop]
|
|
23
23
|
const logFunction = console[level] && level !== 'trace' ? level : 'log';
|
|
24
|
-
const color =
|
|
24
|
+
const color: ReadonlyArray<ForegroundColors | BackgroundColors | Modifiers> =
|
|
25
25
|
level === 'error'
|
|
26
|
-
?
|
|
26
|
+
? ['inverse', 'red']
|
|
27
27
|
: level === 'warn'
|
|
28
|
-
?
|
|
29
|
-
:
|
|
28
|
+
? ['inverse', 'yellow']
|
|
29
|
+
: ['inverse', 'white'];
|
|
30
30
|
|
|
31
31
|
if (level === 'group') {
|
|
32
32
|
groupStack.push(level);
|
|
@@ -37,7 +37,7 @@ export default (terminal: Terminal, level: string, ...data: Array<unknown>) => {
|
|
|
37
37
|
collapsedGuardTimer = setTimeout(() => {
|
|
38
38
|
if (groupStack.includes('groupCollapsed')) {
|
|
39
39
|
terminal.log(
|
|
40
|
-
|
|
40
|
+
util.styleText(['inverse', 'yellow', 'bold'], ' WARN '),
|
|
41
41
|
'Expected `console.groupEnd` to be called after `console.groupCollapsed`.',
|
|
42
42
|
);
|
|
43
43
|
groupStack.length = 0;
|
|
@@ -60,7 +60,7 @@ export default (terminal: Terminal, level: string, ...data: Array<unknown>) => {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
terminal.log(
|
|
63
|
-
color
|
|
63
|
+
util.styleText([...color, 'bold'], ` ${logFunction.toUpperCase()} `) +
|
|
64
64
|
''.padEnd(groupStack.length * 2, ' '),
|
|
65
65
|
// `util.format` actually accepts any arguments.
|
|
66
66
|
// If the first argument is a string, it tries to format it.
|
package/src/lib/reporting.js
CHANGED
|
@@ -7,30 +7,39 @@ exports.logError = logError;
|
|
|
7
7
|
exports.logInfo = logInfo;
|
|
8
8
|
exports.logWarning = logWarning;
|
|
9
9
|
exports.nullReporter = void 0;
|
|
10
|
-
var
|
|
10
|
+
var _tty = _interopRequireDefault(require("tty"));
|
|
11
11
|
var _util = _interopRequireDefault(require("util"));
|
|
12
12
|
function _interopRequireDefault(e) {
|
|
13
13
|
return e && e.__esModule ? e : { default: e };
|
|
14
14
|
}
|
|
15
|
+
const supportsColor = () =>
|
|
16
|
+
process.stdout instanceof _tty.default.WriteStream &&
|
|
17
|
+
process.stdout.hasColors();
|
|
15
18
|
function logWarning(terminal, format, ...args) {
|
|
16
19
|
const str = _util.default.format(format, ...args);
|
|
17
|
-
terminal.log(
|
|
20
|
+
terminal.log(
|
|
21
|
+
"%s %s",
|
|
22
|
+
_util.default.styleText(["yellow", "inverse", "bold"], " WARN "),
|
|
23
|
+
str,
|
|
24
|
+
);
|
|
18
25
|
}
|
|
19
26
|
function logError(terminal, format, ...args) {
|
|
20
27
|
terminal.log(
|
|
21
28
|
"%s %s",
|
|
22
|
-
|
|
29
|
+
_util.default.styleText(["red", "inverse", "bold"], " ERROR "),
|
|
23
30
|
_util.default.format(
|
|
24
|
-
|
|
25
|
-
? format
|
|
26
|
-
: _util.default.stripVTControlCharacters(format),
|
|
31
|
+
supportsColor() ? format : _util.default.stripVTControlCharacters(format),
|
|
27
32
|
...args,
|
|
28
33
|
),
|
|
29
34
|
);
|
|
30
35
|
}
|
|
31
36
|
function logInfo(terminal, format, ...args) {
|
|
32
37
|
const str = _util.default.format(format, ...args);
|
|
33
|
-
terminal.log(
|
|
38
|
+
terminal.log(
|
|
39
|
+
"%s %s",
|
|
40
|
+
_util.default.styleText(["cyan", "inverse", "bold"], " INFO "),
|
|
41
|
+
str,
|
|
42
|
+
);
|
|
34
43
|
}
|
|
35
44
|
const nullReporter = (exports.nullReporter = {
|
|
36
45
|
update() {},
|