metro 0.84.1 → 0.84.2

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.
Files changed (93) hide show
  1. package/package.json +14 -14
  2. package/src/Assets.d.ts +90 -0
  3. package/src/Bundler/util.d.ts +34 -0
  4. package/src/Bundler.d.ts +45 -0
  5. package/src/DeltaBundler/DeltaCalculator.d.ts +78 -0
  6. package/src/DeltaBundler/Graph.d.ts +174 -0
  7. package/src/DeltaBundler/Serializers/baseJSBundle.d.ts +27 -0
  8. package/src/DeltaBundler/Serializers/getAllFiles.d.ts +29 -0
  9. package/src/DeltaBundler/Serializers/getAssets.d.ts +32 -0
  10. package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +33 -0
  11. package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +55 -0
  12. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.d.ts +19 -0
  13. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.d.ts +40 -0
  14. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.d.ts +24 -0
  15. package/src/DeltaBundler/Serializers/helpers/js.d.ts +37 -0
  16. package/src/DeltaBundler/Serializers/helpers/processModules.d.ts +32 -0
  17. package/src/DeltaBundler/Serializers/hmrJSBundle.d.ts +37 -0
  18. package/src/DeltaBundler/Serializers/sourceMapGenerator.d.ts +36 -0
  19. package/src/DeltaBundler/Serializers/sourceMapObject.d.ts +30 -0
  20. package/src/DeltaBundler/Serializers/sourceMapString.d.ts +29 -0
  21. package/src/DeltaBundler/Transformer.d.ts +45 -0
  22. package/src/DeltaBundler/Worker.d.ts +44 -0
  23. package/src/DeltaBundler/WorkerFarm.d.ts +77 -0
  24. package/src/DeltaBundler/buildSubgraph.d.ts +37 -0
  25. package/src/DeltaBundler/getTransformCacheKey.d.ts +25 -0
  26. package/src/DeltaBundler/mergeDeltas.d.ts +24 -0
  27. package/src/DeltaBundler/types.d.ts +170 -0
  28. package/src/DeltaBundler.d.ts +67 -0
  29. package/src/HmrServer.d.ts +86 -0
  30. package/src/IncrementalBundler/GraphNotFoundError.d.ts +24 -0
  31. package/src/IncrementalBundler/ResourceNotFoundError.d.ts +22 -0
  32. package/src/IncrementalBundler/RevisionNotFoundError.d.ts +24 -0
  33. package/src/IncrementalBundler.d.ts +103 -0
  34. package/src/ModuleGraph/worker/JsFileWrapping.d.ts +36 -0
  35. package/src/ModuleGraph/worker/collectDependencies.d.ts +138 -0
  36. package/src/ModuleGraph/worker/generateImportNames.d.ts +26 -0
  37. package/src/ModuleGraph/worker/importLocationsPlugin.d.ts +33 -0
  38. package/src/Server/MultipartResponse.d.ts +37 -0
  39. package/src/Server/symbolicate.d.ts +38 -0
  40. package/src/Server.d.ts +278 -0
  41. package/src/cli/parseKeyValueParamArray.d.ts +21 -0
  42. package/src/cli-utils.d.ts +26 -0
  43. package/src/commands/build.d.ts +23 -0
  44. package/src/commands/dependencies.d.ts +23 -0
  45. package/src/commands/serve.d.ts +23 -0
  46. package/src/index.d.ts +187 -0
  47. package/src/lib/BatchProcessor.d.ts +61 -0
  48. package/src/lib/CountingSet.d.ts +55 -0
  49. package/src/lib/JsonReporter.d.ts +44 -0
  50. package/src/lib/RamBundleParser.d.ts +36 -0
  51. package/src/lib/TerminalReporter.d.ts +125 -0
  52. package/src/lib/bundleProgressUtils.d.ts +33 -0
  53. package/src/lib/bundleToString.d.ts +26 -0
  54. package/src/lib/contextModule.d.ts +40 -0
  55. package/src/lib/contextModuleTemplates.d.ts +32 -0
  56. package/src/lib/countLines.d.ts +19 -0
  57. package/src/lib/createWebsocketServer.d.ts +50 -0
  58. package/src/lib/debounceAsyncQueue.d.ts +22 -0
  59. package/src/lib/formatBundlingError.d.ts +30 -0
  60. package/src/lib/getAppendScripts.d.ts +38 -0
  61. package/src/lib/getGraphId.d.ts +32 -0
  62. package/src/lib/getPreludeCode.d.ts +25 -0
  63. package/src/lib/getPrependedScripts.d.ts +31 -0
  64. package/src/lib/isResolvedDependency.d.ts +22 -0
  65. package/src/lib/logToConsole.d.ts +26 -0
  66. package/src/lib/parseBundleOptionsFromBundleRequestUrl.d.ts +24 -0
  67. package/src/lib/parseCustomResolverOptions.d.ts +23 -0
  68. package/src/lib/parseCustomTransformOptions.d.ts +23 -0
  69. package/src/lib/parseJsonBody.d.ts +34 -0
  70. package/src/lib/pathUtils.d.ts +21 -0
  71. package/src/lib/relativizeSourceMap.d.ts +24 -0
  72. package/src/lib/reporting.d.ts +135 -0
  73. package/src/lib/splitBundleOptions.d.ts +23 -0
  74. package/src/lib/transformHelpers.d.ts +42 -0
  75. package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +133 -0
  76. package/src/node-haste/DependencyGraph/createFileMap.d.ts +36 -0
  77. package/src/node-haste/DependencyGraph.d.ts +93 -0
  78. package/src/node-haste/Package.d.ts +28 -0
  79. package/src/node-haste/PackageCache.d.ts +41 -0
  80. package/src/node-haste/lib/AssetPaths.d.ts +36 -0
  81. package/src/node-haste/lib/parsePlatformFilePath.d.ts +32 -0
  82. package/src/shared/output/RamBundle/as-assets.d.ts +32 -0
  83. package/src/shared/output/RamBundle/as-indexed-file.d.ts +45 -0
  84. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.d.ts +30 -0
  85. package/src/shared/output/RamBundle/magic-number.d.ts +21 -0
  86. package/src/shared/output/RamBundle/util.d.ts +48 -0
  87. package/src/shared/output/RamBundle/write-sourcemap.d.ts +23 -0
  88. package/src/shared/output/RamBundle.d.ts +33 -0
  89. package/src/shared/output/bundle.d.ts +34 -0
  90. package/src/shared/output/meta.d.ts +22 -0
  91. package/src/shared/output/unbundle.d.ts +18 -0
  92. package/src/shared/output/writeFile.d.ts +23 -0
  93. package/src/shared/types.d.ts +152 -0
package/src/index.d.ts ADDED
@@ -0,0 +1,187 @@
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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<6246e792b8fc5f3e524f443a31921cfc>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/index.flow.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ import type {AssetData} from './Assets';
19
+ import type {ReadOnlyGraph} from './DeltaBundler';
20
+ import type {ServerOptions} from './Server';
21
+ import type {BuildOptions, OutputOptions, RequestOptions} from './shared/types';
22
+ import type {HandleFunction} from 'connect';
23
+ import type {Server as HttpServer} from 'http';
24
+ import type {
25
+ Server as HttpsServer,
26
+ ServerOptions as HttpsServerOptions,
27
+ } from 'https';
28
+ import type {TransformProfile} from 'metro-babel-transformer';
29
+ import type {
30
+ ConfigT,
31
+ InputConfigT,
32
+ MetroConfig,
33
+ Middleware,
34
+ } from 'metro-config';
35
+ import type {CustomResolverOptions} from 'metro-resolver';
36
+ import type {CustomTransformOptions} from 'metro-transform-worker';
37
+ import type {Server as WebSocketServer} from 'ws';
38
+ import type $$IMPORT_TYPEOF_1$$ from 'yargs';
39
+
40
+ import JsonReporter from './lib/JsonReporter';
41
+ import TerminalReporter from './lib/TerminalReporter';
42
+ import MetroServer from './Server';
43
+ import {loadConfig, mergeConfig, resolveConfig} from 'metro-config';
44
+ import {Terminal} from 'metro-core';
45
+
46
+ type Yargs = typeof $$IMPORT_TYPEOF_1$$;
47
+ type MetroMiddleWare = {
48
+ attachHmrServer: (httpServer: HttpServer | HttpsServer) => void;
49
+ end: () => Promise<void>;
50
+ metroServer: MetroServer;
51
+ middleware: Middleware;
52
+ };
53
+ export type RunMetroOptions = Omit<
54
+ ServerOptions,
55
+ keyof {waitForBundler?: boolean}
56
+ > & {waitForBundler?: boolean};
57
+ export type RunServerOptions = Readonly<{
58
+ hasReducedPerformance?: boolean;
59
+ host?: string;
60
+ onError?: ($$PARAM_0$$: Error & {code?: string}) => void;
61
+ onReady?: (server: HttpServer | HttpsServer) => void;
62
+ onClose?: () => void;
63
+ secureServerOptions?: HttpsServerOptions;
64
+ secure?: boolean;
65
+ secureCert?: string;
66
+ secureKey?: string;
67
+ unstable_extraMiddleware?: ReadonlyArray<HandleFunction>;
68
+ waitForBundler?: boolean;
69
+ watch?: boolean;
70
+ websocketEndpoints?: Readonly<{[path: string]: WebSocketServer}>;
71
+ }>;
72
+ export type RunServerResult = {httpServer: HttpServer | HttpsServer};
73
+ type BuildGraphOptions = {
74
+ entries: ReadonlyArray<string>;
75
+ customTransformOptions?: CustomTransformOptions;
76
+ dev?: boolean;
77
+ minify?: boolean;
78
+ onProgress?: (transformedFileCount: number, totalFileCount: number) => void;
79
+ platform?: string;
80
+ type?: 'module' | 'script';
81
+ };
82
+ export type RunBuildOptions = {
83
+ entry: string;
84
+ assets?: boolean;
85
+ dev?: boolean;
86
+ out?: string;
87
+ bundleOut?: string;
88
+ sourceMapOut?: string;
89
+ onBegin?: () => void;
90
+ onComplete?: () => void;
91
+ onProgress?: (transformedFileCount: number, totalFileCount: number) => void;
92
+ minify?: boolean;
93
+ output?: Readonly<{
94
+ build: (
95
+ $$PARAM_0$$: MetroServer,
96
+ $$PARAM_1$$: RequestOptions,
97
+ $$PARAM_2$$: void | BuildOptions,
98
+ ) => Promise<{
99
+ code: string;
100
+ map: string;
101
+ assets?: ReadonlyArray<AssetData>;
102
+ }>;
103
+ save: (
104
+ $$PARAM_0$$: {code: string; map: string},
105
+ $$PARAM_1$$: OutputOptions,
106
+ $$PARAM_2$$: (logMessage: string) => void,
107
+ ) => Promise<unknown>;
108
+ }>;
109
+ platform?: string;
110
+ sourceMap?: boolean;
111
+ sourceMapUrl?: string;
112
+ customResolverOptions?: CustomResolverOptions;
113
+ customTransformOptions?: CustomTransformOptions;
114
+ unstable_transformProfile?: TransformProfile;
115
+ };
116
+ export type RunBuildResult = {
117
+ code: string;
118
+ map: string;
119
+ assets?: ReadonlyArray<AssetData>;
120
+ };
121
+ type BuildCommandOptions = Readonly<{[$$Key$$: string]: unknown}> | null;
122
+ type ServeCommandOptions = Readonly<{[$$Key$$: string]: unknown}> | null;
123
+ type DependenciesCommandOptions = Readonly<{
124
+ [$$Key$$: string]: unknown;
125
+ }> | null;
126
+ export {Terminal, JsonReporter, TerminalReporter};
127
+ export type {AssetData} from './Assets';
128
+ export type {Reporter, ReportableEvent} from './lib/reporting';
129
+ export type {TerminalReportableEvent} from './lib/TerminalReporter';
130
+ export type {MetroConfig};
131
+ export declare function runMetro(
132
+ config: InputConfigT,
133
+ options?: RunMetroOptions,
134
+ ): Promise<MetroServer>;
135
+ export {loadConfig, mergeConfig, resolveConfig};
136
+ export declare const createConnectMiddleware: (
137
+ config: ConfigT,
138
+ options?: RunMetroOptions,
139
+ ) => Promise<MetroMiddleWare>;
140
+ export declare type createConnectMiddleware = typeof createConnectMiddleware;
141
+ export declare const runServer: (
142
+ config: ConfigT,
143
+ $$PARAM_1$$?: RunServerOptions,
144
+ ) => Promise<RunServerResult>;
145
+ export declare type runServer = typeof runServer;
146
+ export declare const runBuild: (
147
+ config: ConfigT,
148
+ $$PARAM_1$$: RunBuildOptions,
149
+ ) => Promise<RunBuildResult>;
150
+ export declare type runBuild = typeof runBuild;
151
+ export declare const buildGraph: (
152
+ config: InputConfigT,
153
+ $$PARAM_1$$: BuildGraphOptions,
154
+ ) => Promise<ReadOnlyGraph>;
155
+ export declare type buildGraph = typeof buildGraph;
156
+ type AttachMetroCLIOptions = {
157
+ build?: BuildCommandOptions;
158
+ serve?: ServeCommandOptions;
159
+ dependencies?: DependenciesCommandOptions;
160
+ };
161
+ export declare const attachMetroCli: (
162
+ yargs: Yargs,
163
+ options?: AttachMetroCLIOptions,
164
+ ) => Yargs;
165
+ export declare type attachMetroCli = typeof attachMetroCli;
166
+ /**
167
+ * Backwards-compatibility with CommonJS consumers using interopRequireDefault.
168
+ * Do not add to this list.
169
+ *
170
+ * @deprecated Default import from 'metro' is deprecated, use named exports.
171
+ */
172
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: {
173
+ attachMetroCli: typeof attachMetroCli;
174
+ runServer: typeof runServer;
175
+ Terminal: typeof Terminal;
176
+ JsonReporter: typeof JsonReporter;
177
+ TerminalReporter: typeof TerminalReporter;
178
+ loadConfig: typeof loadConfig;
179
+ mergeConfig: typeof mergeConfig;
180
+ resolveConfig: typeof resolveConfig;
181
+ createConnectMiddleware: typeof createConnectMiddleware;
182
+ runBuild: typeof runBuild;
183
+ buildGraph: typeof buildGraph;
184
+ };
185
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
186
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
187
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
@@ -0,0 +1,61 @@
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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<5872ab26db1c8f4499c971170c5012c4>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/BatchProcessor.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ import {setTimeout} from 'timers';
19
+
20
+ type ProcessBatch<TItem, TResult> = (
21
+ batch: Array<TItem>,
22
+ ) => Promise<Array<TResult>>;
23
+ type BatchProcessorOptions = {
24
+ maximumDelayMs: number;
25
+ maximumItems: number;
26
+ concurrency: number;
27
+ };
28
+ type QueueItem<TItem, TResult> = {
29
+ item: TItem;
30
+ reject: (error: unknown) => unknown;
31
+ resolve: (result: TResult) => unknown;
32
+ };
33
+ /**
34
+ * We batch items together trying to minimize their processing, for example as
35
+ * network queries. For that we wait a small moment before processing a batch.
36
+ * We limit also the number of items we try to process in a single batch so that
37
+ * if we have many items pending in a short amount of time, we can start
38
+ * processing right away.
39
+ */
40
+ declare class BatchProcessor<TItem, TResult> {
41
+ _currentProcessCount: number;
42
+ _options: BatchProcessorOptions;
43
+ _processBatch: ProcessBatch<TItem, TResult>;
44
+ _queue: Array<QueueItem<TItem, TResult>>;
45
+ _timeoutHandle: null | undefined | ReturnType<typeof setTimeout>;
46
+ constructor(
47
+ options: BatchProcessorOptions,
48
+ processBatch: ProcessBatch<TItem, TResult>,
49
+ );
50
+ _onBatchFinished(): void;
51
+ _onBatchResults(
52
+ jobs: Array<QueueItem<TItem, TResult>>,
53
+ results: Array<TResult>,
54
+ ): void;
55
+ _onBatchError(jobs: Array<QueueItem<TItem, TResult>>, error: unknown): void;
56
+ _processQueue(): void;
57
+ _processQueueOnceReady(): void;
58
+ queue(item: TItem): Promise<TResult>;
59
+ getQueueLength(): number;
60
+ }
61
+ export default BatchProcessor;
@@ -0,0 +1,55 @@
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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<0fccda5d7f0eb38539316fa1fedae97b>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/CountingSet.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ export interface ReadOnlyCountingSet<T> extends Iterable<T> {
19
+ has(item: T): boolean;
20
+ readonly size: number;
21
+ count(item: T): number;
22
+ forEach<ThisT>(
23
+ callbackFn: (
24
+ this: ThisT,
25
+ value: T,
26
+ key: T,
27
+ set: ReadOnlyCountingSet<T>,
28
+ ) => unknown,
29
+ thisArg: ThisT,
30
+ ): void;
31
+ }
32
+ /**
33
+ * A Set that only deletes a given item when the number of delete(item) calls
34
+ * matches the number of add(item) calls. Iteration and `size` are in terms of
35
+ * *unique* items.
36
+ */
37
+ declare class CountingSet<T> implements ReadOnlyCountingSet<T> {
38
+ constructor(items?: Iterable<T>);
39
+ has(item: T): boolean;
40
+ add(item: T): void;
41
+ delete(item: T): void;
42
+ keys(): Iterator<T>;
43
+ values(): Iterator<T>;
44
+ entries(): Iterator<[T, T]>;
45
+ [Symbol.iterator](): Iterator<T>;
46
+ get size(): number;
47
+ count(item: T): number;
48
+ clear(): void;
49
+ forEach<ThisT>(
50
+ callbackFn: (this: ThisT, value: T, key: T, set: CountingSet<T>) => unknown,
51
+ thisArg: ThisT,
52
+ ): void;
53
+ toJSON(): unknown;
54
+ }
55
+ export default CountingSet;
@@ -0,0 +1,44 @@
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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<e7173f8dc5e076fd37b9a1cecd581f58>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/JsonReporter.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ import type {Writable} from 'stream';
19
+
20
+ export type SerializedError = {
21
+ message: string;
22
+ stack: string;
23
+ errors?: ReadonlyArray<SerializedError>;
24
+ cause?: SerializedError;
25
+ };
26
+ export type SerializedEvent<
27
+ TEvent extends {readonly [$$Key$$: string]: unknown},
28
+ > = TEvent extends {error: Error}
29
+ ? Omit<Omit<TEvent, 'error'>, keyof {error: SerializedError}> & {
30
+ error: SerializedError;
31
+ }
32
+ : TEvent;
33
+ declare class JsonReporter<
34
+ TEvent extends {readonly [$$Key$$: string]: unknown},
35
+ > {
36
+ _stream: Writable;
37
+ constructor(stream: Writable);
38
+ /**
39
+ * There is a special case for errors because they have non-enumerable fields.
40
+ * (Perhaps we should switch in favor of plain object?)
41
+ */
42
+ update(event: TEvent): void;
43
+ }
44
+ export default JsonReporter;
@@ -0,0 +1,36 @@
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
+ * @noformat
8
+ * @generated SignedSource<<ebddbde1dcdecbbee129fd96caaf3bb0>>
9
+ *
10
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
11
+ * Original file: packages/metro/src/lib/RamBundleParser.js
12
+ * To regenerate, run:
13
+ * js1 build metro-ts-defs (internal) OR
14
+ * yarn run build-ts-defs (OSS)
15
+ */
16
+
17
+ /**
18
+ * Implementation of a RAM bundle parser in JS.
19
+ *
20
+ * It receives a Buffer as an input and implements two main methods, which are
21
+ * able to run in constant time no matter the size of the bundle:
22
+ *
23
+ * getStartupCode(): returns the runtime and the startup code of the bundle.
24
+ * getModule(): returns the code for the specified module.
25
+ */
26
+ declare class RamBundleParser {
27
+ _buffer: Buffer;
28
+ _numModules: number;
29
+ _startupCodeLength: number;
30
+ _startOffset: number;
31
+ constructor(buffer: Buffer);
32
+ _readPosition(pos: number): number;
33
+ getStartupCode(): string;
34
+ getModule(id: number): string;
35
+ }
36
+ export default RamBundleParser;
@@ -0,0 +1,125 @@
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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<8218e45d6b5186264c4bf9e54086708a>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/TerminalReporter.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ import type {BundleDetails, ReportableEvent} from './reporting';
19
+ import type {Terminal} from 'metro-core';
20
+ import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
21
+
22
+ type BundleProgress = {
23
+ bundleDetails: BundleDetails;
24
+ transformedFileCount: number;
25
+ totalFileCount: number;
26
+ ratio: number;
27
+ isPrefetch?: boolean;
28
+ };
29
+ export type TerminalReportableEvent =
30
+ | ReportableEvent
31
+ | {
32
+ buildID: string;
33
+ type: 'bundle_transform_progressed_throttled';
34
+ transformedFileCount: number;
35
+ totalFileCount: number;
36
+ }
37
+ | {
38
+ type: 'unstable_server_log';
39
+ level: 'info' | 'warn' | 'error';
40
+ data: string | Array<unknown>;
41
+ }
42
+ | {type: 'unstable_server_menu_updated'; message: string}
43
+ | {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
+ /**
51
+ * We try to print useful information to the terminal for interactive builds.
52
+ * This implements the `Reporter` interface from the './reporting' module.
53
+ */
54
+ 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
+ readonly terminal: Terminal;
72
+ 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
+ /**
120
+ * Single entry point for reporting events. That allows us to implement the
121
+ * corresponding JSON reporter easily and have a consistent reporting.
122
+ */
123
+ update(event: TerminalReportableEvent): void;
124
+ }
125
+ export default TerminalReporter;
@@ -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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<6f0cfa5c118fa3cbe65acee044b8c927>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/bundleProgressUtils.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ /**
19
+ * Calculates a conservative progress ratio for bundle building.
20
+ *
21
+ * Because we know the `totalFileCount` is going to progressively increase
22
+ * starting with 1:
23
+ * - We use Math.max(totalFileCount, 10) to prevent the ratio from raising too
24
+ * quickly when the total file count is low. (e.g 1/2 5/6)
25
+ * - We use Math.pow(ratio, 2) as a conservative measure of progress.
26
+ * - The ratio is capped at 0.999 to ensure we don't display 100% until done.
27
+ * - If previousRatio is provided, the ratio will not go backwards.
28
+ */
29
+ export declare function calculateBundleProgressRatio(
30
+ transformedFileCount: number,
31
+ totalFileCount: number,
32
+ previousRatio?: number,
33
+ ): number;
@@ -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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<89a26e72bdd126e3feb0abc9b3186d33>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/bundleToString.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ import type {Bundle, BundleMetadata} from 'metro-runtime/src/modules/types';
19
+ /**
20
+ * Serializes a bundle into a plain JS bundle.
21
+ */
22
+ declare function bundleToString(bundle: Bundle): {
23
+ readonly code: string;
24
+ readonly metadata: BundleMetadata;
25
+ };
26
+ export default bundleToString;
@@ -0,0 +1,40 @@
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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<461f7a7b3b3d99d1f1e7eeeeb5125686>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/contextModule.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ import type {
19
+ ContextMode,
20
+ RequireContextParams,
21
+ } from '../ModuleGraph/worker/collectDependencies';
22
+
23
+ export type RequireContext = Readonly<{
24
+ recursive: boolean;
25
+ filter: RegExp;
26
+ /** Mode for resolving dynamic dependencies. Defaults to `sync` */
27
+ mode: ContextMode;
28
+ /** Absolute path of the directory to search in */
29
+ from: string;
30
+ }>;
31
+ /** Given a fully qualified require context, return a virtual file path that ensures uniqueness between paths with different contexts. */
32
+ export declare function deriveAbsolutePathFromContext(
33
+ from: string,
34
+ context: RequireContextParams,
35
+ ): string;
36
+ /** Match a file against a require context. */
37
+ export declare function fileMatchesContext(
38
+ testPath: string,
39
+ context: RequireContext,
40
+ ): boolean;
@@ -0,0 +1,32 @@
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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<bcc2ba36a2edccb791b6d380f2c27ebe>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/contextModuleTemplates.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ import type {ContextMode} from '../ModuleGraph/worker/collectDependencies';
19
+ /**
20
+ * Generate a context module as a virtual file string.
21
+ *
22
+ * @prop {ContextMode} mode indicates how the modules should be loaded.
23
+ * @prop {string} modulePath virtual file path for the virtual module. Example: `require.context('./src')` -> `'/path/to/project/src'`.
24
+ * @prop {string[]} files list of absolute file paths that must be exported from the context module. Example: `['/path/to/project/src/index.js']`.
25
+ *
26
+ * @returns a string representing a context module (virtual file contents).
27
+ */
28
+ export declare function getContextModuleTemplate(
29
+ mode: ContextMode,
30
+ modulePath: string,
31
+ files: string[],
32
+ ): string;
@@ -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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<a9f443cc44465917ebb470200e0f80d2>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/countLines.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ declare function countLines(string: string): number;
19
+ export default countLines;