metro 0.83.4 → 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 +17 -15
- package/src/Assets.d.ts +83 -0
- package/src/Assets.js +2 -9
- package/src/Bundler/util.d.ts +27 -0
- package/src/Bundler/util.js +2 -9
- package/src/Bundler.d.ts +38 -0
- package/src/Bundler.js +1 -5
- package/src/DeltaBundler/DeltaCalculator.d.ts +71 -0
- package/src/DeltaBundler/DeltaCalculator.js +1 -5
- package/src/DeltaBundler/Graph.d.ts +167 -0
- package/src/DeltaBundler/Graph.js +1 -5
- package/src/DeltaBundler/Serializers/baseJSBundle.d.ts +20 -0
- package/src/DeltaBundler/Serializers/baseJSBundle.js +1 -5
- package/src/DeltaBundler/Serializers/getAllFiles.d.ts +22 -0
- package/src/DeltaBundler/Serializers/getAssets.d.ts +25 -0
- package/src/DeltaBundler/Serializers/getAssets.js +1 -5
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +26 -0
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +48 -0
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js +1 -5
- 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 +2 -9
- package/src/DeltaBundler/Serializers/helpers/processModules.d.ts +25 -0
- package/src/DeltaBundler/Serializers/hmrJSBundle.d.ts +30 -0
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +2 -9
- package/src/DeltaBundler/Serializers/sourceMapGenerator.d.ts +29 -0
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js +1 -5
- package/src/DeltaBundler/Serializers/sourceMapObject.d.ts +23 -0
- package/src/DeltaBundler/Serializers/sourceMapString.d.ts +22 -0
- package/src/DeltaBundler/Transformer.d.ts +38 -0
- package/src/DeltaBundler/Transformer.js +1 -5
- package/src/DeltaBundler/Worker.d.ts +37 -0
- package/src/DeltaBundler/Worker.flow.js +1 -5
- package/src/DeltaBundler/WorkerFarm.d.ts +70 -0
- package/src/DeltaBundler/buildSubgraph.d.ts +30 -0
- package/src/DeltaBundler/buildSubgraph.js +1 -5
- package/src/DeltaBundler/getTransformCacheKey.d.ts +18 -0
- package/src/DeltaBundler/getTransformCacheKey.js +1 -5
- package/src/DeltaBundler/mergeDeltas.d.ts +17 -0
- package/src/DeltaBundler/types.d.ts +163 -0
- package/src/DeltaBundler/types.js +1 -5
- package/src/DeltaBundler.d.ts +60 -0
- package/src/DeltaBundler.js +1 -5
- package/src/HmrServer.d.ts +79 -0
- package/src/HmrServer.js +2 -9
- 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 +96 -0
- package/src/IncrementalBundler.js +2 -9
- package/src/ModuleGraph/worker/JsFileWrapping.d.ts +29 -0
- package/src/ModuleGraph/worker/JsFileWrapping.js +2 -9
- package/src/ModuleGraph/worker/collectDependencies.d.ts +131 -0
- package/src/ModuleGraph/worker/collectDependencies.js +2 -9
- package/src/ModuleGraph/worker/generateImportNames.d.ts +19 -0
- package/src/ModuleGraph/worker/generateImportNames.js +1 -5
- package/src/ModuleGraph/worker/importLocationsPlugin.d.ts +26 -0
- package/src/Server/MultipartResponse.d.ts +30 -0
- package/src/Server/MultipartResponse.js +1 -5
- package/src/Server/symbolicate.d.ts +31 -0
- package/src/Server.d.ts +271 -0
- package/src/Server.js +47 -15
- package/src/Server.js.flow +57 -10
- package/src/cli/parseKeyValueParamArray.d.ts +14 -0
- package/src/cli-utils.d.ts +19 -0
- package/src/cli-utils.js +1 -5
- package/src/commands/build.d.ts +16 -0
- package/src/commands/build.js +1 -5
- package/src/commands/dependencies.d.ts +16 -0
- package/src/commands/dependencies.js +1 -5
- package/src/commands/serve.d.ts +16 -0
- package/src/index.d.ts +180 -0
- package/src/index.flow.js +26 -19
- package/src/index.flow.js.flow +25 -10
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js +1 -5
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js +1 -5
- package/src/integration_tests/basic_bundle/import-export/index.js +2 -9
- package/src/integration_tests/execBundle.js +1 -5
- package/src/lib/BatchProcessor.d.ts +54 -0
- package/src/lib/BatchProcessor.js +1 -5
- package/src/lib/CountingSet.d.ts +48 -0
- package/src/lib/JsonReporter.d.ts +37 -0
- package/src/lib/RamBundleParser.d.ts +29 -0
- package/src/lib/RamBundleParser.js +1 -5
- package/src/lib/TerminalReporter.d.ts +118 -0
- package/src/lib/TerminalReporter.js +8 -16
- package/src/lib/TerminalReporter.js.flow +6 -15
- 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 +33 -0
- package/src/lib/contextModule.js +1 -5
- package/src/lib/contextModuleTemplates.d.ts +25 -0
- package/src/lib/contextModuleTemplates.js +1 -4
- package/src/lib/countLines.d.ts +12 -0
- package/src/lib/createWebsocketServer.d.ts +43 -0
- package/src/lib/createWebsocketServer.js +1 -5
- package/src/lib/debounceAsyncQueue.d.ts +15 -0
- package/src/lib/formatBundlingError.d.ts +23 -0
- package/src/lib/formatBundlingError.js +1 -5
- package/src/lib/getAppendScripts.d.ts +31 -0
- package/src/lib/getAppendScripts.js +1 -5
- package/src/lib/getGraphId.d.ts +25 -0
- package/src/lib/getGraphId.js +1 -5
- package/src/lib/getPreludeCode.d.ts +18 -0
- package/src/lib/getPrependedScripts.d.ts +24 -0
- package/src/lib/getPrependedScripts.js +2 -9
- package/src/lib/isResolvedDependency.d.ts +15 -0
- package/src/lib/logToConsole.d.ts +19 -0
- package/src/lib/logToConsole.js +1 -5
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.d.ts +17 -0
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +2 -9
- package/src/lib/parseCustomResolverOptions.d.ts +16 -0
- package/src/lib/parseCustomTransformOptions.d.ts +16 -0
- package/src/lib/parseJsonBody.d.ts +27 -0
- package/src/lib/pathUtils.d.ts +14 -0
- package/src/lib/pathUtils.js +1 -4
- package/src/lib/relativizeSourceMap.d.ts +17 -0
- package/src/lib/relativizeSourceMap.js +1 -5
- package/src/lib/reporting.d.ts +128 -0
- package/src/lib/reporting.js +1 -5
- package/src/lib/splitBundleOptions.d.ts +16 -0
- package/src/lib/transformHelpers.d.ts +35 -0
- package/src/lib/transformHelpers.js +1 -5
- package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +126 -0
- package/src/node-haste/DependencyGraph/ModuleResolution.js +2 -9
- package/src/node-haste/DependencyGraph/createFileMap.d.ts +29 -0
- package/src/node-haste/DependencyGraph/createFileMap.js +2 -9
- package/src/node-haste/DependencyGraph.d.ts +86 -0
- package/src/node-haste/DependencyGraph.js +1 -5
- package/src/node-haste/Package.d.ts +21 -0
- package/src/node-haste/Package.js +1 -5
- package/src/node-haste/PackageCache.d.ts +34 -0
- package/src/node-haste/PackageCache.js +1 -5
- package/src/node-haste/lib/AssetPaths.d.ts +29 -0
- package/src/node-haste/lib/AssetPaths.js +1 -5
- package/src/node-haste/lib/parsePlatformFilePath.d.ts +25 -0
- package/src/node-haste/lib/parsePlatformFilePath.js +1 -5
- package/src/shared/output/RamBundle/as-assets.d.ts +25 -0
- package/src/shared/output/RamBundle/as-assets.js +1 -5
- package/src/shared/output/RamBundle/as-indexed-file.d.ts +38 -0
- package/src/shared/output/RamBundle/as-indexed-file.js +1 -5
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.d.ts +23 -0
- 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 +1 -5
- package/src/shared/output/RamBundle/write-sourcemap.d.ts +16 -0
- package/src/shared/output/RamBundle/write-sourcemap.js +1 -5
- package/src/shared/output/RamBundle.d.ts +26 -0
- package/src/shared/output/RamBundle.js +1 -5
- package/src/shared/output/bundle.d.ts +27 -0
- package/src/shared/output/bundle.flow.js +1 -5
- package/src/shared/output/meta.d.ts +15 -0
- package/src/shared/output/meta.js +1 -5
- package/src/shared/output/unbundle.d.ts +11 -0
- package/src/shared/output/writeFile.d.ts +16 -0
- package/src/shared/output/writeFile.js +1 -5
- package/src/shared/types.d.ts +145 -0
|
@@ -7,11 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
8
8
|
var _timers = require("timers");
|
|
9
9
|
function _interopRequireDefault(e) {
|
|
10
|
-
return e && e.__esModule
|
|
11
|
-
? e
|
|
12
|
-
: {
|
|
13
|
-
default: e,
|
|
14
|
-
};
|
|
10
|
+
return e && e.__esModule ? e : { default: e };
|
|
15
11
|
}
|
|
16
12
|
class BatchProcessor {
|
|
17
13
|
constructor(options, processBatch) {
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
export interface ReadOnlyCountingSet<T> extends Iterable<T> {
|
|
12
|
+
has(item: T): boolean;
|
|
13
|
+
readonly size: number;
|
|
14
|
+
count(item: T): number;
|
|
15
|
+
forEach<ThisT>(
|
|
16
|
+
callbackFn: (
|
|
17
|
+
this: ThisT,
|
|
18
|
+
value: T,
|
|
19
|
+
key: T,
|
|
20
|
+
set: ReadOnlyCountingSet<T>,
|
|
21
|
+
) => unknown,
|
|
22
|
+
thisArg: ThisT,
|
|
23
|
+
): void;
|
|
24
|
+
}
|
|
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> {
|
|
31
|
+
constructor(items?: Iterable<T>);
|
|
32
|
+
has(item: T): boolean;
|
|
33
|
+
add(item: T): void;
|
|
34
|
+
delete(item: T): void;
|
|
35
|
+
keys(): Iterator<T>;
|
|
36
|
+
values(): Iterator<T>;
|
|
37
|
+
entries(): Iterator<[T, T]>;
|
|
38
|
+
[Symbol.iterator](): Iterator<T>;
|
|
39
|
+
get size(): number;
|
|
40
|
+
count(item: T): number;
|
|
41
|
+
clear(): void;
|
|
42
|
+
forEach<ThisT>(
|
|
43
|
+
callbackFn: (this: ThisT, value: T, key: T, set: CountingSet<T>) => unknown,
|
|
44
|
+
thisArg: ThisT,
|
|
45
|
+
): void;
|
|
46
|
+
toJSON(): unknown;
|
|
47
|
+
}
|
|
48
|
+
export default CountingSet;
|
|
@@ -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;
|
|
@@ -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,11 +8,7 @@ var _magicNumber = _interopRequireDefault(
|
|
|
8
8
|
require("../shared/output/RamBundle/magic-number"),
|
|
9
9
|
);
|
|
10
10
|
function _interopRequireDefault(e) {
|
|
11
|
-
return e && e.__esModule
|
|
12
|
-
? e
|
|
13
|
-
: {
|
|
14
|
-
default: e,
|
|
15
|
-
};
|
|
11
|
+
return e && e.__esModule ? e : { default: e };
|
|
16
12
|
}
|
|
17
13
|
const SIZEOF_UINT32 = 4;
|
|
18
14
|
const HEADER_SIZE = 3;
|
|
@@ -0,0 +1,118 @@
|
|
|
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 {BundleDetails, ReportableEvent} from './reporting';
|
|
12
|
+
import type {Terminal} from 'metro-core';
|
|
13
|
+
import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
|
|
14
|
+
|
|
15
|
+
type BundleProgress = {
|
|
16
|
+
bundleDetails: BundleDetails;
|
|
17
|
+
transformedFileCount: number;
|
|
18
|
+
totalFileCount: number;
|
|
19
|
+
ratio: number;
|
|
20
|
+
isPrefetch?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export type TerminalReportableEvent =
|
|
23
|
+
| ReportableEvent
|
|
24
|
+
| {
|
|
25
|
+
buildID: string;
|
|
26
|
+
type: 'bundle_transform_progressed_throttled';
|
|
27
|
+
transformedFileCount: number;
|
|
28
|
+
totalFileCount: number;
|
|
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;
|
|
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
|
+
*/
|
|
116
|
+
update(event: TerminalReportableEvent): void;
|
|
117
|
+
}
|
|
118
|
+
export default TerminalReporter;
|
|
@@ -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"));
|
|
@@ -18,10 +19,7 @@ function _interopRequireWildcard(e, t) {
|
|
|
18
19
|
if (!t && e && e.__esModule) return e;
|
|
19
20
|
var o,
|
|
20
21
|
i,
|
|
21
|
-
f = {
|
|
22
|
-
__proto__: null,
|
|
23
|
-
default: e,
|
|
24
|
-
};
|
|
22
|
+
f = { __proto__: null, default: e };
|
|
25
23
|
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
26
24
|
return f;
|
|
27
25
|
if ((o = t ? n : r)) {
|
|
@@ -41,11 +39,7 @@ function _interopRequireWildcard(e, t) {
|
|
|
41
39
|
})(e, t);
|
|
42
40
|
}
|
|
43
41
|
function _interopRequireDefault(e) {
|
|
44
|
-
return e && e.__esModule
|
|
45
|
-
? e
|
|
46
|
-
: {
|
|
47
|
-
default: e,
|
|
48
|
-
};
|
|
42
|
+
return e && e.__esModule ? e : { default: e };
|
|
49
43
|
}
|
|
50
44
|
const DARK_BLOCK_CHAR = "\u2593";
|
|
51
45
|
const LIGHT_BLOCK_CHAR = "\u2591";
|
|
@@ -85,7 +79,7 @@ class TerminalReporter {
|
|
|
85
79
|
_chalk.default.bgWhite.white(
|
|
86
80
|
LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar),
|
|
87
81
|
) +
|
|
88
|
-
_chalk.default.bold(` ${(100 * ratio)
|
|
82
|
+
_chalk.default.bold(` ${Math.floor(100 * ratio)}% `) +
|
|
89
83
|
_chalk.default.dim(`(${transformedFileCount}/${totalFileCount})`)
|
|
90
84
|
: "";
|
|
91
85
|
return (
|
|
@@ -294,12 +288,10 @@ class TerminalReporter {
|
|
|
294
288
|
if (currentProgress == null) {
|
|
295
289
|
return;
|
|
296
290
|
}
|
|
297
|
-
const ratio =
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
),
|
|
302
|
-
0.999,
|
|
291
|
+
const ratio = (0, _bundleProgressUtils.calculateBundleProgressRatio)(
|
|
292
|
+
transformedFileCount,
|
|
293
|
+
totalFileCount,
|
|
294
|
+
currentProgress.ratio,
|
|
303
295
|
);
|
|
304
296
|
Object.assign(currentProgress, {
|
|
305
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,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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 {Bundle, BundleMetadata} from 'metro-runtime/src/modules/types';
|
|
12
|
+
/**
|
|
13
|
+
* Serializes a bundle into a plain JS bundle.
|
|
14
|
+
*/
|
|
15
|
+
declare function bundleToString(bundle: Bundle): {
|
|
16
|
+
readonly code: string;
|
|
17
|
+
readonly metadata: BundleMetadata;
|
|
18
|
+
};
|
|
19
|
+
export default bundleToString;
|
|
@@ -0,0 +1,33 @@
|
|
|
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 {
|
|
12
|
+
ContextMode,
|
|
13
|
+
RequireContextParams,
|
|
14
|
+
} from '../ModuleGraph/worker/collectDependencies';
|
|
15
|
+
|
|
16
|
+
export type RequireContext = Readonly<{
|
|
17
|
+
recursive: boolean;
|
|
18
|
+
filter: RegExp;
|
|
19
|
+
/** Mode for resolving dynamic dependencies. Defaults to `sync` */
|
|
20
|
+
mode: ContextMode;
|
|
21
|
+
/** Absolute path of the directory to search in */
|
|
22
|
+
from: string;
|
|
23
|
+
}>;
|
|
24
|
+
/** Given a fully qualified require context, return a virtual file path that ensures uniqueness between paths with different contexts. */
|
|
25
|
+
export declare function deriveAbsolutePathFromContext(
|
|
26
|
+
from: string,
|
|
27
|
+
context: RequireContextParams,
|
|
28
|
+
): string;
|
|
29
|
+
/** Match a file against a require context. */
|
|
30
|
+
export declare function fileMatchesContext(
|
|
31
|
+
testPath: string,
|
|
32
|
+
context: RequireContext,
|
|
33
|
+
): boolean;
|
package/src/lib/contextModule.js
CHANGED
|
@@ -9,11 +9,7 @@ var _crypto = _interopRequireDefault(require("crypto"));
|
|
|
9
9
|
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
10
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
11
|
function _interopRequireDefault(e) {
|
|
12
|
-
return e && e.__esModule
|
|
13
|
-
? e
|
|
14
|
-
: {
|
|
15
|
-
default: e,
|
|
16
|
-
};
|
|
12
|
+
return e && e.__esModule ? e : { default: e };
|
|
17
13
|
}
|
|
18
14
|
function toHash(value) {
|
|
19
15
|
return _crypto.default.createHash("sha1").update(value).digest("hex");
|
|
@@ -0,0 +1,25 @@
|
|
|
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 {ContextMode} from '../ModuleGraph/worker/collectDependencies';
|
|
12
|
+
/**
|
|
13
|
+
* Generate a context module as a virtual file string.
|
|
14
|
+
*
|
|
15
|
+
* @prop {ContextMode} mode indicates how the modules should be loaded.
|
|
16
|
+
* @prop {string} modulePath virtual file path for the virtual module. Example: `require.context('./src')` -> `'/path/to/project/src'`.
|
|
17
|
+
* @prop {string[]} files list of absolute file paths that must be exported from the context module. Example: `['/path/to/project/src/index.js']`.
|
|
18
|
+
*
|
|
19
|
+
* @returns a string representing a context module (virtual file contents).
|
|
20
|
+
*/
|
|
21
|
+
export declare function getContextModuleTemplate(
|
|
22
|
+
mode: ContextMode,
|
|
23
|
+
modulePath: string,
|
|
24
|
+
files: string[],
|
|
25
|
+
): string;
|
|
@@ -14,10 +14,7 @@ function _interopRequireWildcard(e, t) {
|
|
|
14
14
|
if (!t && e && e.__esModule) return e;
|
|
15
15
|
var o,
|
|
16
16
|
i,
|
|
17
|
-
f = {
|
|
18
|
-
__proto__: null,
|
|
19
|
-
default: e,
|
|
20
|
-
};
|
|
17
|
+
f = { __proto__: null, default: e };
|
|
21
18
|
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
22
19
|
return f;
|
|
23
20
|
if ((o = t ? n : r)) {
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
declare function countLines(string: string): number;
|
|
12
|
+
export default countLines;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 ws from 'ws';
|
|
12
|
+
|
|
13
|
+
type WebsocketServiceInterface<T> = {
|
|
14
|
+
readonly onClientConnect: (
|
|
15
|
+
url: string,
|
|
16
|
+
sendFn: (data: string) => void,
|
|
17
|
+
) => Promise<null | undefined | T>;
|
|
18
|
+
readonly onClientDisconnect?: (client: T) => unknown;
|
|
19
|
+
readonly onClientError?: (client: T, e: Error) => unknown;
|
|
20
|
+
readonly onClientMessage?: (
|
|
21
|
+
client: T,
|
|
22
|
+
message: string | Buffer | ArrayBuffer | Array<Buffer>,
|
|
23
|
+
sendFn: (data: string) => void,
|
|
24
|
+
) => unknown;
|
|
25
|
+
};
|
|
26
|
+
type HMROptions<TClient> = {
|
|
27
|
+
websocketServer: WebsocketServiceInterface<TClient>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Returns a WebSocketServer to be attached to an existing HTTP instance. It forwards
|
|
31
|
+
* the received events on the given "websocketServer" parameter. It must be an
|
|
32
|
+
* object with the following fields:
|
|
33
|
+
*
|
|
34
|
+
* - onClientConnect
|
|
35
|
+
* - onClientError
|
|
36
|
+
* - onClientMessage
|
|
37
|
+
* - onClientDisconnect
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
declare function createWebsocketServer<TClient>(
|
|
41
|
+
$$PARAM_0$$: HMROptions<TClient>,
|
|
42
|
+
): ws.Server;
|
|
43
|
+
export default createWebsocketServer;
|
|
@@ -7,11 +7,7 @@ exports.default = createWebsocketServer;
|
|
|
7
7
|
var _timers = require("timers");
|
|
8
8
|
var _ws = _interopRequireDefault(require("ws"));
|
|
9
9
|
function _interopRequireDefault(e) {
|
|
10
|
-
return e && e.__esModule
|
|
11
|
-
? e
|
|
12
|
-
: {
|
|
13
|
-
default: e,
|
|
14
|
-
};
|
|
10
|
+
return e && e.__esModule ? e : { default: e };
|
|
15
11
|
}
|
|
16
12
|
const KEEP_ALIVE_INTERVAL_MS = 20000;
|
|
17
13
|
function createWebsocketServer({ websocketServer }) {
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
declare function debounceAsyncQueue<T>(
|
|
12
|
+
fn: () => Promise<T>,
|
|
13
|
+
delay: number,
|
|
14
|
+
): () => Promise<T>;
|
|
15
|
+
export default debounceAsyncQueue;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
import type {FormattedError} from 'metro-runtime/src/modules/types';
|
|
11
|
+
|
|
12
|
+
export type CustomError = Error & {
|
|
13
|
+
readonly type?: string;
|
|
14
|
+
filename?: string;
|
|
15
|
+
lineNumber?: number;
|
|
16
|
+
errors?: Array<{
|
|
17
|
+
description: string;
|
|
18
|
+
filename: string;
|
|
19
|
+
lineNumber: number;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
declare function formatBundlingError(error: CustomError): FormattedError;
|
|
23
|
+
export default formatBundlingError;
|