metro 0.84.0 → 0.84.1
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 +15 -14
- package/src/Server.js +10 -6
- package/src/Server.js.flow +9 -10
- package/src/index.flow.js +24 -10
- package/src/index.flow.js.flow +25 -10
- package/src/lib/TerminalReporter.js +6 -7
- package/src/lib/TerminalReporter.js.flow +6 -15
- package/src/lib/bundleProgressUtils.js +19 -0
- package/src/lib/bundleProgressUtils.js.flow +35 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.84.
|
|
3
|
+
"version": "0.84.1",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -40,18 +40,18 @@
|
|
|
40
40
|
"jest-worker": "^29.7.0",
|
|
41
41
|
"jsc-safe-url": "^0.2.2",
|
|
42
42
|
"lodash.throttle": "^4.1.1",
|
|
43
|
-
"metro-babel-transformer": "0.84.
|
|
44
|
-
"metro-cache": "0.84.
|
|
45
|
-
"metro-cache-key": "0.84.
|
|
46
|
-
"metro-config": "0.84.
|
|
47
|
-
"metro-core": "0.84.
|
|
48
|
-
"metro-file-map": "0.84.
|
|
49
|
-
"metro-resolver": "0.84.
|
|
50
|
-
"metro-runtime": "0.84.
|
|
51
|
-
"metro-source-map": "0.84.
|
|
52
|
-
"metro-symbolicate": "0.84.
|
|
53
|
-
"metro-transform-plugins": "0.84.
|
|
54
|
-
"metro-transform-worker": "0.84.
|
|
43
|
+
"metro-babel-transformer": "0.84.1",
|
|
44
|
+
"metro-cache": "0.84.1",
|
|
45
|
+
"metro-cache-key": "0.84.1",
|
|
46
|
+
"metro-config": "0.84.1",
|
|
47
|
+
"metro-core": "0.84.1",
|
|
48
|
+
"metro-file-map": "0.84.1",
|
|
49
|
+
"metro-resolver": "0.84.1",
|
|
50
|
+
"metro-runtime": "0.84.1",
|
|
51
|
+
"metro-source-map": "0.84.1",
|
|
52
|
+
"metro-symbolicate": "0.84.1",
|
|
53
|
+
"metro-transform-plugins": "0.84.1",
|
|
54
|
+
"metro-transform-worker": "0.84.1",
|
|
55
55
|
"mime-types": "^3.0.1",
|
|
56
56
|
"nullthrows": "^1.1.1",
|
|
57
57
|
"serialize-error": "^2.1.0",
|
|
@@ -72,10 +72,11 @@
|
|
|
72
72
|
"dedent": "^0.7.0",
|
|
73
73
|
"jest-snapshot": "^29.7.0",
|
|
74
74
|
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
75
|
-
"metro-babel-register": "0.84.
|
|
75
|
+
"metro-babel-register": "0.84.1",
|
|
76
76
|
"metro-memory-fs": "*",
|
|
77
77
|
"mock-req": "^0.2.0",
|
|
78
78
|
"mock-res": "^0.6.0",
|
|
79
|
+
"selfsigned": "^5.5.0",
|
|
79
80
|
"stack-trace": "^0.0.10"
|
|
80
81
|
},
|
|
81
82
|
"license": "MIT",
|
package/src/Server.js
CHANGED
|
@@ -25,6 +25,7 @@ var _IncrementalBundler = _interopRequireDefault(
|
|
|
25
25
|
var _ResourceNotFoundError = _interopRequireDefault(
|
|
26
26
|
require("./IncrementalBundler/ResourceNotFoundError"),
|
|
27
27
|
);
|
|
28
|
+
var _bundleProgressUtils = require("./lib/bundleProgressUtils");
|
|
28
29
|
var _bundleToString = _interopRequireDefault(require("./lib/bundleToString"));
|
|
29
30
|
var _formatBundlingError = _interopRequireDefault(
|
|
30
31
|
require("./lib/formatBundlingError"),
|
|
@@ -679,14 +680,16 @@ class Server {
|
|
|
679
680
|
}
|
|
680
681
|
const mres = _MultipartResponse.default.wrapIfSupported(req, res);
|
|
681
682
|
let onProgress = null;
|
|
682
|
-
let
|
|
683
|
+
let lastRatio = -1;
|
|
683
684
|
if (this._config.reporter) {
|
|
684
685
|
onProgress = (transformedFileCount, totalFileCount) => {
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
|
|
686
|
+
const newRatio = (0,
|
|
687
|
+
_bundleProgressUtils.calculateBundleProgressRatio)(
|
|
688
|
+
transformedFileCount,
|
|
689
|
+
totalFileCount,
|
|
690
|
+
lastRatio,
|
|
688
691
|
);
|
|
689
|
-
if (
|
|
692
|
+
if (newRatio > lastRatio) {
|
|
690
693
|
if (mres instanceof _MultipartResponse.default) {
|
|
691
694
|
mres.writeChunk(
|
|
692
695
|
{
|
|
@@ -695,13 +698,14 @@ class Server {
|
|
|
695
698
|
JSON.stringify({
|
|
696
699
|
done: transformedFileCount,
|
|
697
700
|
total: totalFileCount,
|
|
701
|
+
percent: Math.floor(newRatio * 100),
|
|
698
702
|
}),
|
|
699
703
|
);
|
|
700
704
|
}
|
|
701
705
|
if (res.socket != null && res.socket.uncork != null) {
|
|
702
706
|
res.socket.uncork();
|
|
703
707
|
}
|
|
704
|
-
|
|
708
|
+
lastRatio = newRatio;
|
|
705
709
|
}
|
|
706
710
|
this._reporter.update({
|
|
707
711
|
buildID: getBuildID(buildNumber),
|
package/src/Server.js.flow
CHANGED
|
@@ -52,6 +52,7 @@ import getRamBundleInfo from './DeltaBundler/Serializers/getRamBundleInfo';
|
|
|
52
52
|
import {sourceMapStringNonBlocking} from './DeltaBundler/Serializers/sourceMapString';
|
|
53
53
|
import IncrementalBundler from './IncrementalBundler';
|
|
54
54
|
import ResourceNotFoundError from './IncrementalBundler/ResourceNotFoundError';
|
|
55
|
+
import {calculateBundleProgressRatio} from './lib/bundleProgressUtils';
|
|
55
56
|
import bundleToString from './lib/bundleToString';
|
|
56
57
|
import formatBundlingError from './lib/formatBundlingError';
|
|
57
58
|
import getGraphId from './lib/getGraphId';
|
|
@@ -857,25 +858,23 @@ export default class Server {
|
|
|
857
858
|
const mres = MultipartResponse.wrapIfSupported(req, res);
|
|
858
859
|
|
|
859
860
|
let onProgress = null;
|
|
860
|
-
let
|
|
861
|
+
let lastRatio = -1;
|
|
861
862
|
if (this._config.reporter) {
|
|
862
863
|
onProgress = (transformedFileCount: number, totalFileCount: number) => {
|
|
863
|
-
const
|
|
864
|
-
|
|
865
|
-
|
|
864
|
+
const newRatio = calculateBundleProgressRatio(
|
|
865
|
+
transformedFileCount,
|
|
866
|
+
totalFileCount,
|
|
867
|
+
lastRatio,
|
|
866
868
|
);
|
|
867
869
|
|
|
868
|
-
|
|
869
|
-
// UI updates slow enough for the client to actually handle them. For
|
|
870
|
-
// that, we check the percentage, and only send percentages that are
|
|
871
|
-
// actually different and that have increased from the last one we sent.
|
|
872
|
-
if (currentProgress > lastProgress || totalFileCount < 10) {
|
|
870
|
+
if (newRatio > lastRatio) {
|
|
873
871
|
if (mres instanceof MultipartResponse) {
|
|
874
872
|
mres.writeChunk(
|
|
875
873
|
{'Content-Type': 'application/json'},
|
|
876
874
|
JSON.stringify({
|
|
877
875
|
done: transformedFileCount,
|
|
878
876
|
total: totalFileCount,
|
|
877
|
+
percent: Math.floor(newRatio * 100),
|
|
879
878
|
}),
|
|
880
879
|
);
|
|
881
880
|
}
|
|
@@ -891,7 +890,7 @@ export default class Server {
|
|
|
891
890
|
res.socket.uncork();
|
|
892
891
|
}
|
|
893
892
|
|
|
894
|
-
|
|
893
|
+
lastRatio = newRatio;
|
|
895
894
|
}
|
|
896
895
|
|
|
897
896
|
this._reporter.update({
|
package/src/index.flow.js
CHANGED
|
@@ -204,7 +204,7 @@ const runServer = async (
|
|
|
204
204
|
_chalk.default.inverse.yellow.bold(" DEPRECATED "),
|
|
205
205
|
"The `secure`, `secureCert`, and `secureKey` options are now deprecated. " +
|
|
206
206
|
"Please use the `secureServerOptions` object instead to pass options to " +
|
|
207
|
-
"Metro's https development server.",
|
|
207
|
+
"Metro's https development server, or `config.server.tls` in Metro's configuration",
|
|
208
208
|
);
|
|
209
209
|
}
|
|
210
210
|
const connect = require("connect");
|
|
@@ -223,15 +223,29 @@ const runServer = async (
|
|
|
223
223
|
}
|
|
224
224
|
serverApp.use(middleware);
|
|
225
225
|
let httpServer;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
226
|
+
const { tls } = config.server;
|
|
227
|
+
if (
|
|
228
|
+
secure === true ||
|
|
229
|
+
secureServerOptions != null ||
|
|
230
|
+
typeof tls === "object"
|
|
231
|
+
) {
|
|
232
|
+
const options = {
|
|
233
|
+
key:
|
|
234
|
+
typeof tls === "object"
|
|
235
|
+
? tls.key
|
|
236
|
+
: typeof secureKey === "string"
|
|
237
|
+
? _fs.default.readFileSync(secureKey)
|
|
238
|
+
: undefined,
|
|
239
|
+
cert:
|
|
240
|
+
typeof tls === "object"
|
|
241
|
+
? tls.cert
|
|
242
|
+
: typeof secureCert === "string"
|
|
243
|
+
? _fs.default.readFileSync(secureCert)
|
|
244
|
+
: undefined,
|
|
245
|
+
ca: typeof tls === "object" ? tls.ca : undefined,
|
|
246
|
+
requestCert: typeof tls === "object" ? tls.requestCert : undefined,
|
|
247
|
+
...(secureServerOptions ?? {}),
|
|
248
|
+
};
|
|
235
249
|
httpServer = _https.default.createServer(options, serverApp);
|
|
236
250
|
} else {
|
|
237
251
|
httpServer = _http.default.createServer(serverApp);
|
package/src/index.flow.js.flow
CHANGED
|
@@ -280,7 +280,7 @@ export const runServer = async (
|
|
|
280
280
|
chalk.inverse.yellow.bold(' DEPRECATED '),
|
|
281
281
|
'The `secure`, `secureCert`, and `secureKey` options are now deprecated. ' +
|
|
282
282
|
'Please use the `secureServerOptions` object instead to pass options to ' +
|
|
283
|
-
"Metro's https development server.",
|
|
283
|
+
"Metro's https development server, or `config.server.tls` in Metro's configuration",
|
|
284
284
|
);
|
|
285
285
|
}
|
|
286
286
|
// Lazy require
|
|
@@ -307,15 +307,30 @@ export const runServer = async (
|
|
|
307
307
|
|
|
308
308
|
let httpServer;
|
|
309
309
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
310
|
+
const {tls} = config.server;
|
|
311
|
+
if (
|
|
312
|
+
secure === true ||
|
|
313
|
+
secureServerOptions != null ||
|
|
314
|
+
typeof tls === 'object'
|
|
315
|
+
) {
|
|
316
|
+
const options = {
|
|
317
|
+
key:
|
|
318
|
+
typeof tls === 'object'
|
|
319
|
+
? tls.key
|
|
320
|
+
: typeof secureKey === 'string'
|
|
321
|
+
? fs.readFileSync(secureKey)
|
|
322
|
+
: undefined,
|
|
323
|
+
cert:
|
|
324
|
+
typeof tls === 'object'
|
|
325
|
+
? tls.cert
|
|
326
|
+
: typeof secureCert === 'string'
|
|
327
|
+
? fs.readFileSync(secureCert)
|
|
328
|
+
: undefined,
|
|
329
|
+
ca: typeof tls === 'object' ? tls.ca : undefined,
|
|
330
|
+
requestCert: typeof tls === 'object' ? tls.requestCert : undefined,
|
|
331
|
+
...(secureServerOptions ?? {}),
|
|
332
|
+
};
|
|
333
|
+
|
|
319
334
|
// $FlowFixMe[incompatible-type] 'http' and 'https' Flow types do not match
|
|
320
335
|
httpServer = https.createServer(options, serverApp);
|
|
321
336
|
} else {
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true,
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _bundleProgressUtils = require("./bundleProgressUtils");
|
|
7
8
|
var _logToConsole = _interopRequireDefault(require("./logToConsole"));
|
|
8
9
|
var reporting = _interopRequireWildcard(require("./reporting"));
|
|
9
10
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
@@ -78,7 +79,7 @@ class TerminalReporter {
|
|
|
78
79
|
_chalk.default.bgWhite.white(
|
|
79
80
|
LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar),
|
|
80
81
|
) +
|
|
81
|
-
_chalk.default.bold(` ${(100 * ratio)
|
|
82
|
+
_chalk.default.bold(` ${Math.floor(100 * ratio)}% `) +
|
|
82
83
|
_chalk.default.dim(`(${transformedFileCount}/${totalFileCount})`)
|
|
83
84
|
: "";
|
|
84
85
|
return (
|
|
@@ -287,12 +288,10 @@ class TerminalReporter {
|
|
|
287
288
|
if (currentProgress == null) {
|
|
288
289
|
return;
|
|
289
290
|
}
|
|
290
|
-
const ratio =
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
),
|
|
295
|
-
0.999,
|
|
291
|
+
const ratio = (0, _bundleProgressUtils.calculateBundleProgressRatio)(
|
|
292
|
+
transformedFileCount,
|
|
293
|
+
totalFileCount,
|
|
294
|
+
currentProgress.ratio,
|
|
296
295
|
);
|
|
297
296
|
Object.assign(currentProgress, {
|
|
298
297
|
ratio,
|
|
@@ -13,6 +13,7 @@ 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
15
|
|
|
16
|
+
import {calculateBundleProgressRatio} from './bundleProgressUtils';
|
|
16
17
|
import logToConsole from './logToConsole';
|
|
17
18
|
import * as reporting from './reporting';
|
|
18
19
|
import chalk from 'chalk';
|
|
@@ -132,7 +133,7 @@ export default class TerminalReporter {
|
|
|
132
133
|
chalk.bgWhite.white(
|
|
133
134
|
LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar),
|
|
134
135
|
) +
|
|
135
|
-
chalk.bold(` ${(100 * ratio)
|
|
136
|
+
chalk.bold(` ${Math.floor(100 * ratio)}% `) +
|
|
136
137
|
chalk.dim(`(${transformedFileCount}/${totalFileCount})`)
|
|
137
138
|
: '';
|
|
138
139
|
|
|
@@ -352,14 +353,6 @@ export default class TerminalReporter {
|
|
|
352
353
|
});
|
|
353
354
|
}
|
|
354
355
|
|
|
355
|
-
/**
|
|
356
|
-
* Because we know the `totalFileCount` is going to progressively increase
|
|
357
|
-
* starting with 1:
|
|
358
|
-
* - We use Math.max(totalFileCount, 10) to prevent the ratio to raise too
|
|
359
|
-
* quickly when the total file count is low. (e.g 1/2 5/6)
|
|
360
|
-
* - We prevent the ratio from going backwards.
|
|
361
|
-
* - Instead, we use Math.pow(ratio, 2) to as a conservative measure of progress.
|
|
362
|
-
*/
|
|
363
356
|
_updateBundleProgress({
|
|
364
357
|
buildID,
|
|
365
358
|
transformedFileCount,
|
|
@@ -375,12 +368,10 @@ export default class TerminalReporter {
|
|
|
375
368
|
return;
|
|
376
369
|
}
|
|
377
370
|
|
|
378
|
-
const ratio =
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
),
|
|
383
|
-
0.999, // make sure not to go above 99.9% to not get rounded to 100%,
|
|
371
|
+
const ratio = calculateBundleProgressRatio(
|
|
372
|
+
transformedFileCount,
|
|
373
|
+
totalFileCount,
|
|
374
|
+
currentProgress.ratio,
|
|
384
375
|
);
|
|
385
376
|
|
|
386
377
|
// $FlowFixMe[unsafe-object-assign]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.calculateBundleProgressRatio = calculateBundleProgressRatio;
|
|
7
|
+
function calculateBundleProgressRatio(
|
|
8
|
+
transformedFileCount,
|
|
9
|
+
totalFileCount,
|
|
10
|
+
previousRatio,
|
|
11
|
+
) {
|
|
12
|
+
const baseRatio = Math.pow(
|
|
13
|
+
transformedFileCount / Math.max(totalFileCount, 10),
|
|
14
|
+
2,
|
|
15
|
+
);
|
|
16
|
+
const ratio =
|
|
17
|
+
previousRatio != null ? Math.max(baseRatio, previousRatio) : baseRatio;
|
|
18
|
+
return Math.min(ratio, 0.999);
|
|
19
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Calculates a conservative progress ratio for bundle building.
|
|
14
|
+
*
|
|
15
|
+
* Because we know the `totalFileCount` is going to progressively increase
|
|
16
|
+
* starting with 1:
|
|
17
|
+
* - We use Math.max(totalFileCount, 10) to prevent the ratio from raising too
|
|
18
|
+
* quickly when the total file count is low. (e.g 1/2 5/6)
|
|
19
|
+
* - We use Math.pow(ratio, 2) as a conservative measure of progress.
|
|
20
|
+
* - The ratio is capped at 0.999 to ensure we don't display 100% until done.
|
|
21
|
+
* - If previousRatio is provided, the ratio will not go backwards.
|
|
22
|
+
*/
|
|
23
|
+
export function calculateBundleProgressRatio(
|
|
24
|
+
transformedFileCount: number,
|
|
25
|
+
totalFileCount: number,
|
|
26
|
+
previousRatio?: number,
|
|
27
|
+
): number {
|
|
28
|
+
const baseRatio = Math.pow(
|
|
29
|
+
transformedFileCount / Math.max(totalFileCount, 10),
|
|
30
|
+
2,
|
|
31
|
+
);
|
|
32
|
+
const ratio =
|
|
33
|
+
previousRatio != null ? Math.max(baseRatio, previousRatio) : baseRatio;
|
|
34
|
+
return Math.min(ratio, 0.999);
|
|
35
|
+
}
|