metro 0.83.3 → 0.83.5
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 +28 -24
- package/src/Assets.d.ts +83 -0
- package/src/Assets.js +42 -29
- package/src/Assets.js.flow +26 -15
- package/src/Bundler/util.d.ts +27 -0
- package/src/Bundler/util.js +25 -21
- package/src/Bundler/util.js.flow +2 -2
- package/src/Bundler.d.ts +14 -15
- package/src/Bundler.js.flow +1 -1
- package/src/DeltaBundler/DeltaCalculator.d.ts +71 -0
- package/src/DeltaBundler/DeltaCalculator.js +4 -4
- package/src/DeltaBundler/DeltaCalculator.js.flow +8 -8
- package/src/DeltaBundler/Graph.d.ts +135 -8
- package/src/DeltaBundler/Graph.js +16 -16
- package/src/DeltaBundler/Graph.js.flow +30 -30
- package/src/DeltaBundler/Serializers/baseJSBundle.d.ts +20 -0
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -1
- package/src/DeltaBundler/Serializers/getAllFiles.d.ts +22 -0
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getAssets.d.ts +25 -0
- package/src/DeltaBundler/Serializers/getAssets.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +36 -6
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +8 -8
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.d.ts +12 -0
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.d.ts +33 -0
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.d.ts +17 -0
- package/src/DeltaBundler/Serializers/helpers/js.d.ts +30 -0
- package/src/DeltaBundler/Serializers/helpers/js.js +25 -21
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +6 -6
- package/src/DeltaBundler/Serializers/helpers/processModules.d.ts +25 -0
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -3
- package/src/DeltaBundler/Serializers/hmrJSBundle.d.ts +30 -0
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +25 -21
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +5 -5
- package/src/DeltaBundler/Serializers/sourceMapGenerator.d.ts +29 -0
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -6
- package/src/DeltaBundler/Serializers/sourceMapObject.d.ts +23 -0
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +2 -2
- package/src/DeltaBundler/Serializers/sourceMapString.d.ts +22 -0
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -2
- package/src/DeltaBundler/Transformer.d.ts +38 -0
- package/src/DeltaBundler/Transformer.js.flow +3 -3
- package/src/DeltaBundler/Worker.d.ts +19 -27
- package/src/DeltaBundler/Worker.flow.js.flow +1 -1
- package/src/DeltaBundler/WorkerFarm.d.ts +70 -0
- package/src/DeltaBundler/WorkerFarm.js +1 -1
- package/src/DeltaBundler/WorkerFarm.js.flow +26 -13
- package/src/DeltaBundler/buildSubgraph.d.ts +30 -0
- package/src/DeltaBundler/buildSubgraph.js +4 -4
- package/src/DeltaBundler/buildSubgraph.js.flow +8 -8
- package/src/DeltaBundler/getTransformCacheKey.d.ts +18 -0
- package/src/DeltaBundler/mergeDeltas.d.ts +17 -0
- package/src/DeltaBundler/types.d.ts +97 -100
- package/src/DeltaBundler/types.js.flow +36 -34
- package/src/DeltaBundler.d.ts +14 -12
- package/src/DeltaBundler.js.flow +2 -2
- package/src/HmrServer.d.ts +79 -0
- package/src/HmrServer.js +34 -29
- package/src/HmrServer.js.flow +17 -12
- package/src/IncrementalBundler/GraphNotFoundError.d.ts +17 -0
- package/src/IncrementalBundler/ResourceNotFoundError.d.ts +15 -0
- package/src/IncrementalBundler/RevisionNotFoundError.d.ts +17 -0
- package/src/IncrementalBundler.d.ts +43 -45
- package/src/IncrementalBundler.js +29 -21
- package/src/IncrementalBundler.js.flow +13 -9
- package/src/ModuleGraph/worker/JsFileWrapping.d.ts +29 -0
- package/src/ModuleGraph/worker/JsFileWrapping.js +25 -21
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +10 -5
- package/src/ModuleGraph/worker/collectDependencies.d.ts +118 -14
- package/src/ModuleGraph/worker/collectDependencies.js +25 -21
- package/src/ModuleGraph/worker/collectDependencies.js.flow +27 -21
- package/src/ModuleGraph/worker/generateImportNames.d.ts +19 -0
- package/src/ModuleGraph/worker/generateImportNames.js.flow +4 -2
- package/src/ModuleGraph/worker/importLocationsPlugin.d.ts +26 -0
- package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +7 -3
- package/src/Server/MultipartResponse.d.ts +5 -6
- package/src/Server/MultipartResponse.js.flow +1 -1
- package/src/Server/symbolicate.js.flow +4 -4
- package/src/Server.d.ts +220 -67
- package/src/Server.js +149 -45
- package/src/Server.js.flow +167 -57
- package/src/cli/parseKeyValueParamArray.d.ts +14 -0
- package/src/cli/parseKeyValueParamArray.js.flow +1 -1
- package/src/cli-utils.d.ts +19 -0
- package/src/cli-utils.js.flow +2 -2
- package/src/commands/build.d.ts +16 -0
- package/src/commands/build.js.flow +11 -10
- package/src/commands/dependencies.d.ts +16 -0
- package/src/commands/dependencies.js.flow +8 -4
- package/src/commands/serve.d.ts +16 -0
- package/src/commands/serve.js +2 -0
- package/src/commands/serve.js.flow +14 -9
- package/src/index.d.ts +97 -110
- package/src/index.flow.js +53 -35
- package/src/index.flow.js.flow +49 -29
- package/src/integration_tests/basic_bundle/AssetRegistry.js.flow +1 -1
- package/src/integration_tests/basic_bundle/ErrorBundle.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import-with-escapes.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require-with-embedded-comment.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-specifier-with-escapes.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-require.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/index.js +25 -21
- package/src/integration_tests/basic_bundle/import-export/index.js.flow +3 -3
- package/src/integration_tests/basic_bundle/import-export/utils.js.flow +2 -2
- package/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js.flow +1 -1
- package/src/integration_tests/basic_bundle/optional-dependencies/index.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/conflict.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/empty.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/matching.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js.flow +2 -2
- package/src/integration_tests/basic_bundle/require-context/utils.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js.flow +1 -1
- package/src/integration_tests/execBundle.js.flow +1 -1
- package/src/lib/BatchProcessor.d.ts +54 -0
- package/src/lib/BatchProcessor.js +5 -2
- package/src/lib/BatchProcessor.js.flow +10 -7
- package/src/lib/CountingSet.d.ts +10 -10
- package/src/lib/CountingSet.js.flow +4 -4
- package/src/lib/JsonReporter.d.ts +37 -0
- package/src/lib/JsonReporter.js +5 -3
- package/src/lib/JsonReporter.js.flow +19 -17
- package/src/lib/RamBundleParser.d.ts +29 -0
- package/src/lib/RamBundleParser.js.flow +1 -1
- package/src/lib/TerminalReporter.d.ts +97 -6
- package/src/lib/TerminalReporter.js +37 -34
- package/src/lib/TerminalReporter.js.flow +21 -30
- package/src/lib/bundleProgressUtils.d.ts +26 -0
- package/src/lib/bundleProgressUtils.js +19 -0
- package/src/lib/bundleProgressUtils.js.flow +35 -0
- package/src/lib/bundleToString.d.ts +19 -0
- package/src/lib/contextModule.d.ts +20 -9
- package/src/lib/contextModule.js.flow +1 -1
- package/src/lib/contextModuleTemplates.d.ts +25 -0
- package/src/lib/contextModuleTemplates.js +25 -21
- package/src/lib/countLines.d.ts +12 -0
- package/src/lib/countLines.js +4 -3
- package/src/lib/countLines.js.flow +3 -4
- package/src/lib/createWebsocketServer.d.ts +43 -0
- package/src/lib/createWebsocketServer.js +9 -2
- package/src/lib/createWebsocketServer.js.flow +16 -9
- package/src/lib/debounceAsyncQueue.d.ts +15 -0
- package/src/lib/debounceAsyncQueue.js.flow +1 -1
- package/src/lib/formatBundlingError.d.ts +23 -0
- package/src/lib/formatBundlingError.js.flow +1 -1
- package/src/lib/getAppendScripts.d.ts +31 -0
- package/src/lib/getAppendScripts.js.flow +4 -4
- package/src/lib/getGraphId.d.ts +15 -1
- package/src/lib/getGraphId.js.flow +1 -1
- package/src/lib/getPreludeCode.d.ts +18 -0
- package/src/lib/getPreludeCode.js +4 -0
- package/src/lib/getPreludeCode.js.flow +10 -3
- package/src/lib/getPrependedScripts.d.ts +24 -0
- package/src/lib/getPrependedScripts.js +36 -22
- package/src/lib/getPrependedScripts.js.flow +10 -3
- package/src/lib/isResolvedDependency.d.ts +15 -0
- package/src/lib/logToConsole.d.ts +19 -0
- package/src/lib/logToConsole.js.flow +2 -2
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.d.ts +17 -0
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +25 -21
- package/src/lib/parseCustomResolverOptions.d.ts +16 -0
- package/src/lib/parseCustomResolverOptions.js.flow +2 -2
- package/src/lib/parseCustomTransformOptions.d.ts +16 -0
- package/src/lib/parseCustomTransformOptions.js.flow +1 -1
- package/src/lib/parseJsonBody.d.ts +27 -0
- package/src/lib/parseJsonBody.js.flow +11 -1
- package/src/lib/pathUtils.d.ts +14 -0
- package/src/lib/pathUtils.js +25 -21
- package/src/lib/pathUtils.js.flow +1 -1
- package/src/lib/relativizeSourceMap.d.ts +17 -0
- package/src/lib/reporting.d.ts +65 -81
- package/src/lib/reporting.js.flow +4 -4
- package/src/lib/splitBundleOptions.d.ts +16 -0
- package/src/lib/transformHelpers.d.ts +35 -0
- package/src/lib/transformHelpers.js +11 -9
- package/src/lib/transformHelpers.js.flow +17 -15
- package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +126 -0
- package/src/node-haste/DependencyGraph/ModuleResolution.js +48 -42
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +35 -32
- package/src/node-haste/DependencyGraph/createFileMap.d.ts +29 -0
- package/src/node-haste/DependencyGraph/createFileMap.js +56 -38
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +44 -18
- package/src/node-haste/DependencyGraph.d.ts +57 -33
- package/src/node-haste/DependencyGraph.js +40 -31
- package/src/node-haste/DependencyGraph.js.flow +35 -37
- package/src/node-haste/Package.d.ts +21 -0
- package/src/node-haste/PackageCache.d.ts +34 -0
- package/src/node-haste/lib/AssetPaths.d.ts +29 -0
- package/src/node-haste/lib/AssetPaths.js +2 -2
- package/src/node-haste/lib/AssetPaths.js.flow +4 -4
- package/src/node-haste/lib/parsePlatformFilePath.d.ts +25 -0
- package/src/node-haste/lib/parsePlatformFilePath.js +6 -6
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +4 -4
- package/src/shared/output/RamBundle/as-assets.d.ts +25 -0
- package/src/shared/output/RamBundle/as-assets.js.flow +6 -6
- package/src/shared/output/RamBundle/as-indexed-file.d.ts +38 -0
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +5 -5
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.d.ts +23 -0
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +5 -5
- package/src/shared/output/RamBundle/magic-number.d.ts +14 -0
- package/src/shared/output/RamBundle/util.d.ts +41 -0
- package/src/shared/output/RamBundle/util.js.flow +5 -5
- package/src/shared/output/RamBundle/write-sourcemap.d.ts +16 -0
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -1
- package/src/shared/output/RamBundle.d.ts +26 -0
- package/src/shared/output/RamBundle.js.flow +1 -1
- package/src/shared/output/bundle.d.ts +9 -17
- package/src/shared/output/bundle.flow.js.flow +3 -3
- package/src/shared/output/meta.d.ts +15 -0
- package/src/shared/output/meta.js +2 -2
- package/src/shared/output/meta.js.flow +1 -1
- package/src/shared/output/unbundle.d.ts +11 -0
- package/src/shared/output/writeFile.d.ts +16 -0
- package/src/shared/output/writeFile.js +8 -3
- package/src/shared/output/writeFile.js.flow +8 -2
- package/src/shared/types.d.ts +81 -66
- package/src/shared/types.js.flow +20 -5
- package/src/Asset.d.ts +0 -25
- package/src/ModuleGraph/test-helpers.js +0 -75
package/src/lib/CountingSet.d.ts
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
export interface ReadOnlyCountingSet<T> extends Iterable<T> {
|
|
12
12
|
has(item: T): boolean;
|
|
13
|
-
[Symbol.iterator](): Iterator<T>;
|
|
14
13
|
readonly size: number;
|
|
15
14
|
count(item: T): number;
|
|
16
15
|
forEach<ThisT>(
|
|
@@ -23,26 +22,27 @@ export interface ReadOnlyCountingSet<T> extends Iterable<T> {
|
|
|
23
22
|
thisArg: ThisT,
|
|
24
23
|
): void;
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
/**
|
|
26
|
+
* A Set that only deletes a given item when the number of delete(item) calls
|
|
27
|
+
* matches the number of add(item) calls. Iteration and `size` are in terms of
|
|
28
|
+
* *unique* items.
|
|
29
|
+
*/
|
|
30
|
+
declare class CountingSet<T> implements ReadOnlyCountingSet<T> {
|
|
28
31
|
constructor(items?: Iterable<T>);
|
|
29
|
-
get size(): number;
|
|
30
32
|
has(item: T): boolean;
|
|
31
33
|
add(item: T): void;
|
|
32
34
|
delete(item: T): void;
|
|
33
35
|
keys(): Iterator<T>;
|
|
34
36
|
values(): Iterator<T>;
|
|
37
|
+
entries(): Iterator<[T, T]>;
|
|
35
38
|
[Symbol.iterator](): Iterator<T>;
|
|
39
|
+
get size(): number;
|
|
36
40
|
count(item: T): number;
|
|
37
41
|
clear(): void;
|
|
38
42
|
forEach<ThisT>(
|
|
39
|
-
callbackFn: (
|
|
40
|
-
this: ThisT,
|
|
41
|
-
value: T,
|
|
42
|
-
key: T,
|
|
43
|
-
set: ReadOnlyCountingSet<T>,
|
|
44
|
-
) => unknown,
|
|
43
|
+
callbackFn: (this: ThisT, value: T, key: T, set: CountingSet<T>) => unknown,
|
|
45
44
|
thisArg: ThisT,
|
|
46
45
|
): void;
|
|
47
46
|
toJSON(): unknown;
|
|
48
47
|
}
|
|
48
|
+
export default CountingSet;
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
export interface ReadOnlyCountingSet<T> extends Iterable<T> {
|
|
13
13
|
has(item: T): boolean;
|
|
14
|
-
@@iterator(): Iterator<T>;
|
|
15
14
|
+size: number;
|
|
16
15
|
count(item: T): number;
|
|
17
16
|
forEach<ThisT>(
|
|
@@ -20,7 +19,7 @@ export interface ReadOnlyCountingSet<T> extends Iterable<T> {
|
|
|
20
19
|
value: T,
|
|
21
20
|
key: T,
|
|
22
21
|
set: ReadOnlyCountingSet<T>,
|
|
23
|
-
) =>
|
|
22
|
+
) => unknown,
|
|
24
23
|
|
|
25
24
|
// NOTE: Should be optional, but Flow seems happy to infer undefined here
|
|
26
25
|
// which is what we want.
|
|
@@ -88,6 +87,7 @@ export default class CountingSet<T> implements ReadOnlyCountingSet<T> {
|
|
|
88
87
|
|
|
89
88
|
/*::
|
|
90
89
|
// For Flow's benefit
|
|
90
|
+
// $FlowFixMe[duplicate-class-member]
|
|
91
91
|
@@iterator(): Iterator<T> {
|
|
92
92
|
return this.values();
|
|
93
93
|
}
|
|
@@ -108,7 +108,7 @@ export default class CountingSet<T> implements ReadOnlyCountingSet<T> {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
forEach<ThisT>(
|
|
111
|
-
callbackFn: (this: ThisT, value: T, key: T, set: CountingSet<T>) =>
|
|
111
|
+
callbackFn: (this: ThisT, value: T, key: T, set: CountingSet<T>) => unknown,
|
|
112
112
|
thisArg: ThisT,
|
|
113
113
|
): void {
|
|
114
114
|
for (const item of this) {
|
|
@@ -121,7 +121,7 @@ export default class CountingSet<T> implements ReadOnlyCountingSet<T> {
|
|
|
121
121
|
// extend to custom collection classes. Instead let's assume values are
|
|
122
122
|
// sortable ( = strings) and make this look like an array with some stable
|
|
123
123
|
// order.
|
|
124
|
-
toJSON():
|
|
124
|
+
toJSON(): unknown {
|
|
125
125
|
return [...this].sort();
|
|
126
126
|
}
|
|
127
127
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
* @format
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {Writable} from 'stream';
|
|
12
|
+
|
|
13
|
+
export type SerializedError = {
|
|
14
|
+
message: string;
|
|
15
|
+
stack: string;
|
|
16
|
+
errors?: ReadonlyArray<SerializedError>;
|
|
17
|
+
cause?: SerializedError;
|
|
18
|
+
};
|
|
19
|
+
export type SerializedEvent<
|
|
20
|
+
TEvent extends {readonly [$$Key$$: string]: unknown},
|
|
21
|
+
> = TEvent extends {error: Error}
|
|
22
|
+
? Omit<Omit<TEvent, 'error'>, keyof {error: SerializedError}> & {
|
|
23
|
+
error: SerializedError;
|
|
24
|
+
}
|
|
25
|
+
: TEvent;
|
|
26
|
+
declare class JsonReporter<
|
|
27
|
+
TEvent extends {readonly [$$Key$$: string]: unknown},
|
|
28
|
+
> {
|
|
29
|
+
_stream: Writable;
|
|
30
|
+
constructor(stream: Writable);
|
|
31
|
+
/**
|
|
32
|
+
* There is a special case for errors because they have non-enumerable fields.
|
|
33
|
+
* (Perhaps we should switch in favor of plain object?)
|
|
34
|
+
*/
|
|
35
|
+
update(event: TEvent): void;
|
|
36
|
+
}
|
|
37
|
+
export default JsonReporter;
|
package/src/lib/JsonReporter.js
CHANGED
|
@@ -9,15 +9,17 @@ class JsonReporter {
|
|
|
9
9
|
this._stream = stream;
|
|
10
10
|
}
|
|
11
11
|
update(event) {
|
|
12
|
+
let eventToWrite = event;
|
|
12
13
|
if (event.error instanceof Error) {
|
|
13
14
|
const { message, stack } = event.error;
|
|
14
|
-
|
|
15
|
+
eventToWrite = {
|
|
16
|
+
...eventToWrite,
|
|
15
17
|
error: serializeError(event.error),
|
|
16
18
|
message,
|
|
17
19
|
stack,
|
|
18
|
-
}
|
|
20
|
+
};
|
|
19
21
|
}
|
|
20
|
-
this._stream.write(JSON.stringify(
|
|
22
|
+
this._stream.write(JSON.stringify(eventToWrite) + "\n");
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
exports.default = JsonReporter;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @flow
|
|
7
|
+
* @flow strict-local
|
|
8
8
|
* @format
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
@@ -14,23 +14,24 @@ import type {Writable} from 'stream';
|
|
|
14
14
|
export type SerializedError = {
|
|
15
15
|
message: string,
|
|
16
16
|
stack: string,
|
|
17
|
-
errors?:
|
|
17
|
+
errors?: ReadonlyArray<SerializedError>,
|
|
18
18
|
cause?: SerializedError,
|
|
19
19
|
...
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
export type SerializedEvent<TEvent: {[string]:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
export type SerializedEvent<TEvent: {+[string]: unknown, ...}> =
|
|
23
|
+
TEvent extends {
|
|
24
|
+
error: Error,
|
|
25
|
+
...
|
|
26
|
+
}
|
|
27
|
+
? {
|
|
28
|
+
...Omit<TEvent, 'error'>,
|
|
29
|
+
error: SerializedError,
|
|
30
|
+
...
|
|
31
|
+
}
|
|
32
|
+
: TEvent;
|
|
32
33
|
|
|
33
|
-
export default class JsonReporter<TEvent: {[string]:
|
|
34
|
+
export default class JsonReporter<TEvent: {+[string]: unknown, ...}> {
|
|
34
35
|
_stream: Writable;
|
|
35
36
|
|
|
36
37
|
constructor(stream: Writable) {
|
|
@@ -42,19 +43,20 @@ export default class JsonReporter<TEvent: {[string]: any, ...}> {
|
|
|
42
43
|
* (Perhaps we should switch in favor of plain object?)
|
|
43
44
|
*/
|
|
44
45
|
update(event: TEvent): void {
|
|
46
|
+
let eventToWrite = event;
|
|
45
47
|
if (event.error instanceof Error) {
|
|
46
48
|
const {message, stack} = event.error;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
eventToWrite = {
|
|
50
|
+
...eventToWrite,
|
|
49
51
|
error: serializeError(event.error),
|
|
50
52
|
// TODO: Preexisting issue - this writes message, stack, etc. as
|
|
51
53
|
// top-level siblings of event.error (which was serialized to {}), whereas it was presumably
|
|
52
54
|
// intended to nest them _under_ error. Fix this in a breaking change.
|
|
53
55
|
message,
|
|
54
56
|
stack,
|
|
55
|
-
}
|
|
57
|
+
};
|
|
56
58
|
}
|
|
57
|
-
this._stream.write(JSON.stringify(
|
|
59
|
+
this._stream.write(JSON.stringify(eventToWrite) + '\n');
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
* @format
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Implementation of a RAM bundle parser in JS.
|
|
12
|
+
*
|
|
13
|
+
* It receives a Buffer as an input and implements two main methods, which are
|
|
14
|
+
* able to run in constant time no matter the size of the bundle:
|
|
15
|
+
*
|
|
16
|
+
* getStartupCode(): returns the runtime and the startup code of the bundle.
|
|
17
|
+
* getModule(): returns the code for the specified module.
|
|
18
|
+
*/
|
|
19
|
+
declare class RamBundleParser {
|
|
20
|
+
_buffer: Buffer;
|
|
21
|
+
_numModules: number;
|
|
22
|
+
_startupCodeLength: number;
|
|
23
|
+
_startOffset: number;
|
|
24
|
+
constructor(buffer: Buffer);
|
|
25
|
+
_readPosition(pos: number): number;
|
|
26
|
+
getStartupCode(): string;
|
|
27
|
+
getModule(id: number): string;
|
|
28
|
+
}
|
|
29
|
+
export default RamBundleParser;
|
|
@@ -8,9 +8,17 @@
|
|
|
8
8
|
* @oncall react_native
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import {ReportableEvent} from './reporting';
|
|
12
|
-
import {Terminal} from 'metro-core';
|
|
11
|
+
import type {BundleDetails, ReportableEvent} from './reporting';
|
|
12
|
+
import type {Terminal} from 'metro-core';
|
|
13
|
+
import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
|
|
13
14
|
|
|
15
|
+
type BundleProgress = {
|
|
16
|
+
bundleDetails: BundleDetails;
|
|
17
|
+
transformedFileCount: number;
|
|
18
|
+
totalFileCount: number;
|
|
19
|
+
ratio: number;
|
|
20
|
+
isPrefetch?: boolean;
|
|
21
|
+
};
|
|
14
22
|
export type TerminalReportableEvent =
|
|
15
23
|
| ReportableEvent
|
|
16
24
|
| {
|
|
@@ -18,10 +26,93 @@ export type TerminalReportableEvent =
|
|
|
18
26
|
type: 'bundle_transform_progressed_throttled';
|
|
19
27
|
transformedFileCount: number;
|
|
20
28
|
totalFileCount: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
type: 'unstable_server_log';
|
|
32
|
+
level: 'info' | 'warn' | 'error';
|
|
33
|
+
data: string | Array<unknown>;
|
|
34
|
+
}
|
|
35
|
+
| {type: 'unstable_server_menu_updated'; message: string}
|
|
36
|
+
| {type: 'unstable_server_menu_cleared'};
|
|
37
|
+
type BuildPhase = 'in_progress' | 'done' | 'failed';
|
|
38
|
+
interface SnippetError extends Error {
|
|
39
|
+
code?: string;
|
|
40
|
+
filename?: string;
|
|
41
|
+
snippet?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* We try to print useful information to the terminal for interactive builds.
|
|
45
|
+
* This implements the `Reporter` interface from the './reporting' module.
|
|
46
|
+
*/
|
|
47
|
+
declare class TerminalReporter {
|
|
48
|
+
/**
|
|
49
|
+
* The bundle builds for which we are actively maintaining the status on the
|
|
50
|
+
* terminal, ie. showing a progress bar. There can be several bundles being
|
|
51
|
+
* built at the same time.
|
|
52
|
+
*/
|
|
53
|
+
_activeBundles: Map<string, BundleProgress>;
|
|
54
|
+
_interactionStatus: null | undefined | string;
|
|
55
|
+
_scheduleUpdateBundleProgress: {
|
|
56
|
+
(data: {
|
|
57
|
+
buildID: string;
|
|
58
|
+
transformedFileCount: number;
|
|
59
|
+
totalFileCount: number;
|
|
60
|
+
}): void;
|
|
61
|
+
cancel(): void;
|
|
62
|
+
};
|
|
63
|
+
_prevHealthCheckResult: null | undefined | HealthCheckResult;
|
|
25
64
|
readonly terminal: Terminal;
|
|
65
|
+
constructor(terminal: Terminal);
|
|
66
|
+
/**
|
|
67
|
+
* Construct a message that represents the progress of a
|
|
68
|
+
* single bundle build, for example:
|
|
69
|
+
*
|
|
70
|
+
* BUNDLE path/to/bundle.js ▓▓▓▓▓░░░░░░░░░░░ 36.6% (4790/7922)
|
|
71
|
+
*/
|
|
72
|
+
_getBundleStatusMessage(
|
|
73
|
+
$$PARAM_0$$: BundleProgress,
|
|
74
|
+
phase: BuildPhase,
|
|
75
|
+
): string;
|
|
76
|
+
_logBundleBuildDone(buildID: string): void;
|
|
77
|
+
_logBundleBuildFailed(buildID: string): void;
|
|
78
|
+
_logInitializing(port: number, hasReducedPerformance: boolean): void;
|
|
79
|
+
_logInitializingFailed(port: number, error: SnippetError): void;
|
|
80
|
+
/**
|
|
81
|
+
* This function is only concerned with logging and should not do state
|
|
82
|
+
* or terminal status updates.
|
|
83
|
+
*/
|
|
84
|
+
_log(event: TerminalReportableEvent): void;
|
|
85
|
+
/**
|
|
86
|
+
* We do not want to log the whole stacktrace for bundling error, because
|
|
87
|
+
* these are operational errors, not programming errors, and the stacktrace
|
|
88
|
+
* is not actionable to end users.
|
|
89
|
+
*/
|
|
90
|
+
_logBundlingError(error: SnippetError): void;
|
|
91
|
+
_logWorkerChunk(origin: 'stdout' | 'stderr', chunk: string): void;
|
|
92
|
+
_updateBundleProgress($$PARAM_0$$: {
|
|
93
|
+
buildID: string;
|
|
94
|
+
transformedFileCount: number;
|
|
95
|
+
totalFileCount: number;
|
|
96
|
+
}): void;
|
|
97
|
+
/**
|
|
98
|
+
* This function is exclusively concerned with updating the internal state.
|
|
99
|
+
* No logging or status updates should be done at this point.
|
|
100
|
+
*/
|
|
101
|
+
_updateState(event: TerminalReportableEvent): void;
|
|
102
|
+
/**
|
|
103
|
+
* Return a status message that is always consistent with the current state
|
|
104
|
+
* of the application. Having this single function ensures we don't have
|
|
105
|
+
* different callsites overriding each other status messages.
|
|
106
|
+
*/
|
|
107
|
+
_getStatusMessage(): string;
|
|
108
|
+
_logHmrClientError(e: Error): void;
|
|
109
|
+
_logWarning(message: string): void;
|
|
110
|
+
_logWatcherHealthCheckResult(result: HealthCheckResult): void;
|
|
111
|
+
_logWatcherStatus(status: WatcherStatus): void;
|
|
112
|
+
/**
|
|
113
|
+
* Single entry point for reporting events. That allows us to implement the
|
|
114
|
+
* corresponding JSON reporter easily and have a consistent reporting.
|
|
115
|
+
*/
|
|
26
116
|
update(event: TerminalReportableEvent): void;
|
|
27
117
|
}
|
|
118
|
+
export default TerminalReporter;
|
|
@@ -4,34 +4,39 @@ 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"));
|
|
10
11
|
var _lodash = _interopRequireDefault(require("lodash.throttle"));
|
|
11
12
|
var _metroCore = require("metro-core");
|
|
12
13
|
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
function
|
|
14
|
-
if ("function"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var n = { __proto__: null },
|
|
28
|
-
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
29
|
-
for (var u in e)
|
|
30
|
-
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
31
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
32
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
14
|
+
function _interopRequireWildcard(e, t) {
|
|
15
|
+
if ("function" == typeof WeakMap)
|
|
16
|
+
var r = new WeakMap(),
|
|
17
|
+
n = new WeakMap();
|
|
18
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
19
|
+
if (!t && e && e.__esModule) return e;
|
|
20
|
+
var o,
|
|
21
|
+
i,
|
|
22
|
+
f = { __proto__: null, default: e };
|
|
23
|
+
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
24
|
+
return f;
|
|
25
|
+
if ((o = t ? n : r)) {
|
|
26
|
+
if (o.has(e)) return o.get(e);
|
|
27
|
+
o.set(e, f);
|
|
33
28
|
}
|
|
34
|
-
|
|
29
|
+
for (const t in e)
|
|
30
|
+
"default" !== t &&
|
|
31
|
+
{}.hasOwnProperty.call(e, t) &&
|
|
32
|
+
((i =
|
|
33
|
+
(o = Object.defineProperty) &&
|
|
34
|
+
Object.getOwnPropertyDescriptor(e, t)) &&
|
|
35
|
+
(i.get || i.set)
|
|
36
|
+
? o(f, t, i)
|
|
37
|
+
: (f[t] = e[t]));
|
|
38
|
+
return f;
|
|
39
|
+
})(e, t);
|
|
35
40
|
}
|
|
36
41
|
function _interopRequireDefault(e) {
|
|
37
42
|
return e && e.__esModule ? e : { default: e };
|
|
@@ -60,9 +65,6 @@ class TerminalReporter {
|
|
|
60
65
|
},
|
|
61
66
|
phase,
|
|
62
67
|
) {
|
|
63
|
-
if (isPrefetch) {
|
|
64
|
-
bundleType = "PREBUNDLE";
|
|
65
|
-
}
|
|
66
68
|
const localPath = _path.default.relative(".", entryFile);
|
|
67
69
|
const filledBar = Math.floor(ratio * MAX_PROGRESS_BAR_CHAR_WIDTH);
|
|
68
70
|
const bundleTypeColor =
|
|
@@ -77,11 +79,13 @@ class TerminalReporter {
|
|
|
77
79
|
_chalk.default.bgWhite.white(
|
|
78
80
|
LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar),
|
|
79
81
|
) +
|
|
80
|
-
_chalk.default.bold(` ${(100 * ratio)
|
|
82
|
+
_chalk.default.bold(` ${Math.floor(100 * ratio)}% `) +
|
|
81
83
|
_chalk.default.dim(`(${transformedFileCount}/${totalFileCount})`)
|
|
82
84
|
: "";
|
|
83
85
|
return (
|
|
84
|
-
bundleTypeColor.inverse.bold(
|
|
86
|
+
bundleTypeColor.inverse.bold(
|
|
87
|
+
` ${isPrefetch === true ? "PREBUNDLE" : bundleType.toUpperCase()} `,
|
|
88
|
+
) +
|
|
85
89
|
_chalk.default.reset.dim(` ${_path.default.dirname(localPath)}/`) +
|
|
86
90
|
_chalk.default.bold(_path.default.basename(localPath)) +
|
|
87
91
|
" " +
|
|
@@ -261,8 +265,9 @@ class TerminalReporter {
|
|
|
261
265
|
message = error.stack;
|
|
262
266
|
}
|
|
263
267
|
}
|
|
264
|
-
|
|
265
|
-
|
|
268
|
+
const filename = error.filename;
|
|
269
|
+
if (filename?.length && !message.includes(filename)) {
|
|
270
|
+
message += ` [${filename}]`;
|
|
266
271
|
}
|
|
267
272
|
if (error.snippet != null) {
|
|
268
273
|
message += "\n" + error.snippet;
|
|
@@ -283,12 +288,10 @@ class TerminalReporter {
|
|
|
283
288
|
if (currentProgress == null) {
|
|
284
289
|
return;
|
|
285
290
|
}
|
|
286
|
-
const ratio =
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
),
|
|
291
|
-
0.999,
|
|
291
|
+
const ratio = (0, _bundleProgressUtils.calculateBundleProgressRatio)(
|
|
292
|
+
transformedFileCount,
|
|
293
|
+
totalFileCount,
|
|
294
|
+
currentProgress.ratio,
|
|
292
295
|
);
|
|
293
296
|
Object.assign(currentProgress, {
|
|
294
297
|
ratio,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @flow
|
|
7
|
+
* @flow strict-local
|
|
8
8
|
* @format
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
@@ -13,9 +13,11 @@ 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';
|
|
20
|
+
// $FlowFixMe[untyped-import] lodash.throttle
|
|
19
21
|
import throttle from 'lodash.throttle';
|
|
20
22
|
import {AmbiguousModuleResolutionError} from 'metro-core';
|
|
21
23
|
import path from 'path';
|
|
@@ -41,7 +43,7 @@ export type TerminalReportableEvent =
|
|
|
41
43
|
| {
|
|
42
44
|
type: 'unstable_server_log',
|
|
43
45
|
level: 'info' | 'warn' | 'error',
|
|
44
|
-
data: string | Array<
|
|
46
|
+
data: string | Array<unknown>,
|
|
45
47
|
...
|
|
46
48
|
}
|
|
47
49
|
| {
|
|
@@ -56,11 +58,11 @@ export type TerminalReportableEvent =
|
|
|
56
58
|
|
|
57
59
|
type BuildPhase = 'in_progress' | 'done' | 'failed';
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
interface SnippetError extends Error {
|
|
62
|
+
code?: string;
|
|
63
|
+
filename?: string;
|
|
64
|
+
snippet?: string;
|
|
65
|
+
}
|
|
64
66
|
|
|
65
67
|
const DARK_BLOCK_CHAR = '\u2593';
|
|
66
68
|
const LIGHT_BLOCK_CHAR = '\u2591';
|
|
@@ -117,10 +119,6 @@ export default class TerminalReporter {
|
|
|
117
119
|
}: BundleProgress,
|
|
118
120
|
phase: BuildPhase,
|
|
119
121
|
): string {
|
|
120
|
-
if (isPrefetch) {
|
|
121
|
-
bundleType = 'PREBUNDLE';
|
|
122
|
-
}
|
|
123
|
-
|
|
124
122
|
const localPath = path.relative('.', entryFile);
|
|
125
123
|
const filledBar = Math.floor(ratio * MAX_PROGRESS_BAR_CHAR_WIDTH);
|
|
126
124
|
const bundleTypeColor =
|
|
@@ -135,12 +133,14 @@ export default class TerminalReporter {
|
|
|
135
133
|
chalk.bgWhite.white(
|
|
136
134
|
LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar),
|
|
137
135
|
) +
|
|
138
|
-
chalk.bold(` ${(100 * ratio)
|
|
136
|
+
chalk.bold(` ${Math.floor(100 * ratio)}% `) +
|
|
139
137
|
chalk.dim(`(${transformedFileCount}/${totalFileCount})`)
|
|
140
138
|
: '';
|
|
141
139
|
|
|
142
140
|
return (
|
|
143
|
-
bundleTypeColor.inverse.bold(
|
|
141
|
+
bundleTypeColor.inverse.bold(
|
|
142
|
+
` ${isPrefetch === true ? 'PREBUNDLE' : bundleType.toUpperCase()} `,
|
|
143
|
+
) +
|
|
144
144
|
chalk.reset.dim(` ${path.dirname(localPath)}/`) +
|
|
145
145
|
chalk.bold(path.basename(localPath)) +
|
|
146
146
|
' ' +
|
|
@@ -273,6 +273,7 @@ export default class TerminalReporter {
|
|
|
273
273
|
case 'dep_graph_loading':
|
|
274
274
|
const color = event.hasReducedPerformance ? chalk.red : chalk.blue;
|
|
275
275
|
// eslint-disable-next-line import/no-commonjs
|
|
276
|
+
// $FlowFixMe[untyped-import] package.json
|
|
276
277
|
const version = 'v' + require('../../package.json').version;
|
|
277
278
|
this.terminal.log(
|
|
278
279
|
color.bold(
|
|
@@ -331,9 +332,9 @@ export default class TerminalReporter {
|
|
|
331
332
|
}
|
|
332
333
|
}
|
|
333
334
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
message += ` [${
|
|
335
|
+
const filename = error.filename;
|
|
336
|
+
if (filename?.length && !message.includes(filename)) {
|
|
337
|
+
message += ` [${filename}]`;
|
|
337
338
|
}
|
|
338
339
|
|
|
339
340
|
if (error.snippet != null) {
|
|
@@ -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,26 @@
|
|
|
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
|
+
* @format
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Calculates a conservative progress ratio for bundle building.
|
|
13
|
+
*
|
|
14
|
+
* Because we know the `totalFileCount` is going to progressively increase
|
|
15
|
+
* starting with 1:
|
|
16
|
+
* - We use Math.max(totalFileCount, 10) to prevent the ratio from raising too
|
|
17
|
+
* quickly when the total file count is low. (e.g 1/2 5/6)
|
|
18
|
+
* - We use Math.pow(ratio, 2) as a conservative measure of progress.
|
|
19
|
+
* - The ratio is capped at 0.999 to ensure we don't display 100% until done.
|
|
20
|
+
* - If previousRatio is provided, the ratio will not go backwards.
|
|
21
|
+
*/
|
|
22
|
+
export declare function calculateBundleProgressRatio(
|
|
23
|
+
transformedFileCount: number,
|
|
24
|
+
totalFileCount: number,
|
|
25
|
+
previousRatio?: number,
|
|
26
|
+
): number;
|
|
@@ -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
|
+
}
|