metro 0.84.1 → 0.84.3

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 (112) hide show
  1. package/package.json +15 -15
  2. package/src/Assets.d.ts +90 -0
  3. package/src/Bundler/util.d.ts +34 -0
  4. package/src/Bundler/util.js.flow +3 -3
  5. package/src/Bundler.d.ts +45 -0
  6. package/src/DeltaBundler/DeltaCalculator.d.ts +68 -0
  7. package/src/DeltaBundler/DeltaCalculator.js +55 -46
  8. package/src/DeltaBundler/DeltaCalculator.js.flow +72 -61
  9. package/src/DeltaBundler/Graph.d.ts +174 -0
  10. package/src/DeltaBundler/Serializers/baseJSBundle.d.ts +27 -0
  11. package/src/DeltaBundler/Serializers/getAllFiles.d.ts +29 -0
  12. package/src/DeltaBundler/Serializers/getAssets.d.ts +32 -0
  13. package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +33 -0
  14. package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +55 -0
  15. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.d.ts +19 -0
  16. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.d.ts +40 -0
  17. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.d.ts +24 -0
  18. package/src/DeltaBundler/Serializers/helpers/js.d.ts +37 -0
  19. package/src/DeltaBundler/Serializers/helpers/processModules.d.ts +32 -0
  20. package/src/DeltaBundler/Serializers/hmrJSBundle.d.ts +37 -0
  21. package/src/DeltaBundler/Serializers/sourceMapGenerator.d.ts +36 -0
  22. package/src/DeltaBundler/Serializers/sourceMapObject.d.ts +30 -0
  23. package/src/DeltaBundler/Serializers/sourceMapString.d.ts +29 -0
  24. package/src/DeltaBundler/Transformer.d.ts +45 -0
  25. package/src/DeltaBundler/Worker.d.ts +44 -0
  26. package/src/DeltaBundler/WorkerFarm.d.ts +77 -0
  27. package/src/DeltaBundler/buildSubgraph.d.ts +37 -0
  28. package/src/DeltaBundler/getTransformCacheKey.d.ts +25 -0
  29. package/src/DeltaBundler/getTransformCacheKey.js +3 -1
  30. package/src/DeltaBundler/getTransformCacheKey.js.flow +7 -2
  31. package/src/DeltaBundler/mergeDeltas.d.ts +24 -0
  32. package/src/DeltaBundler/types.d.ts +170 -0
  33. package/src/DeltaBundler.d.ts +67 -0
  34. package/src/HmrServer.d.ts +98 -0
  35. package/src/HmrServer.js +7 -0
  36. package/src/HmrServer.js.flow +15 -5
  37. package/src/IncrementalBundler/GraphNotFoundError.d.ts +24 -0
  38. package/src/IncrementalBundler/ResourceNotFoundError.d.ts +22 -0
  39. package/src/IncrementalBundler/RevisionNotFoundError.d.ts +24 -0
  40. package/src/IncrementalBundler.d.ts +103 -0
  41. package/src/ModuleGraph/worker/JsFileWrapping.d.ts +36 -0
  42. package/src/ModuleGraph/worker/collectDependencies.d.ts +138 -0
  43. package/src/ModuleGraph/worker/generateImportNames.d.ts +26 -0
  44. package/src/ModuleGraph/worker/importLocationsPlugin.d.ts +33 -0
  45. package/src/Server/MultipartResponse.d.ts +37 -0
  46. package/src/Server/symbolicate.d.ts +38 -0
  47. package/src/Server.d.ts +278 -0
  48. package/src/cli/parseKeyValueParamArray.d.ts +21 -0
  49. package/src/cli-utils.d.ts +26 -0
  50. package/src/commands/build.d.ts +23 -0
  51. package/src/commands/dependencies.d.ts +23 -0
  52. package/src/commands/serve.d.ts +23 -0
  53. package/src/index.d.ts +206 -0
  54. package/src/index.flow.js.flow +21 -2
  55. package/src/lib/BatchProcessor.d.ts +61 -0
  56. package/src/lib/CountingSet.d.ts +55 -0
  57. package/src/lib/JsonReporter.d.ts +44 -0
  58. package/src/lib/JsonReporter.js.flow +2 -2
  59. package/src/lib/RamBundleParser.d.ts +36 -0
  60. package/src/lib/TerminalReporter.d.ts +125 -0
  61. package/src/lib/bundleProgressUtils.d.ts +33 -0
  62. package/src/lib/bundleToString.d.ts +26 -0
  63. package/src/lib/contextModule.d.ts +40 -0
  64. package/src/lib/contextModuleTemplates.d.ts +32 -0
  65. package/src/lib/countLines.d.ts +19 -0
  66. package/src/lib/createWebsocketServer.d.ts +50 -0
  67. package/src/lib/debounceAsyncQueue.d.ts +22 -0
  68. package/src/lib/formatBundlingError.d.ts +30 -0
  69. package/src/lib/getAppendScripts.d.ts +38 -0
  70. package/src/lib/getAppendScripts.js.flow +2 -2
  71. package/src/lib/getGraphId.d.ts +32 -0
  72. package/src/lib/getPreludeCode.d.ts +25 -0
  73. package/src/lib/getPrependedScripts.d.ts +31 -0
  74. package/src/lib/isResolvedDependency.d.ts +22 -0
  75. package/src/lib/logToConsole.d.ts +26 -0
  76. package/src/lib/parseBundleOptionsFromBundleRequestUrl.d.ts +24 -0
  77. package/src/lib/parseCustomResolverOptions.d.ts +23 -0
  78. package/src/lib/parseCustomTransformOptions.d.ts +23 -0
  79. package/src/lib/parseJsonBody.d.ts +34 -0
  80. package/src/lib/pathUtils.d.ts +21 -0
  81. package/src/lib/relativizeSourceMap.d.ts +24 -0
  82. package/src/lib/reporting.d.ts +135 -0
  83. package/src/lib/splitBundleOptions.d.ts +23 -0
  84. package/src/lib/transformHelpers.d.ts +42 -0
  85. package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +120 -0
  86. package/src/node-haste/DependencyGraph/ModuleResolution.js +4 -22
  87. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +10 -59
  88. package/src/node-haste/DependencyGraph/createFileMap.d.ts +36 -0
  89. package/src/node-haste/DependencyGraph/createFileMap.js +1 -1
  90. package/src/node-haste/DependencyGraph/createFileMap.js.flow +4 -2
  91. package/src/node-haste/DependencyGraph.d.ts +90 -0
  92. package/src/node-haste/DependencyGraph.js +22 -11
  93. package/src/node-haste/DependencyGraph.js.flow +24 -13
  94. package/src/node-haste/PackageCache.d.ts +37 -0
  95. package/src/node-haste/PackageCache.js +65 -54
  96. package/src/node-haste/PackageCache.js.flow +103 -79
  97. package/src/node-haste/lib/AssetPaths.d.ts +36 -0
  98. package/src/node-haste/lib/parsePlatformFilePath.d.ts +32 -0
  99. package/src/shared/output/RamBundle/as-assets.d.ts +32 -0
  100. package/src/shared/output/RamBundle/as-indexed-file.d.ts +45 -0
  101. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.d.ts +30 -0
  102. package/src/shared/output/RamBundle/magic-number.d.ts +21 -0
  103. package/src/shared/output/RamBundle/util.d.ts +48 -0
  104. package/src/shared/output/RamBundle/write-sourcemap.d.ts +23 -0
  105. package/src/shared/output/RamBundle.d.ts +33 -0
  106. package/src/shared/output/bundle.d.ts +34 -0
  107. package/src/shared/output/meta.d.ts +22 -0
  108. package/src/shared/output/unbundle.d.ts +18 -0
  109. package/src/shared/output/writeFile.d.ts +23 -0
  110. package/src/shared/types.d.ts +152 -0
  111. package/src/node-haste/Package.js +0 -28
  112. package/src/node-haste/Package.js.flow +0 -39
@@ -0,0 +1,31 @@
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<<a85e80b79c0295e96824c17436edfcca>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/getPrependedScripts.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 Bundler from '../Bundler';
19
+ import type {Module, default as DeltaBundler} from '../DeltaBundler';
20
+ import type {TransformInputOptions} from '../DeltaBundler/types';
21
+ import type {ResolverInputOptions} from '../shared/types';
22
+ import type {ConfigT} from 'metro-config';
23
+
24
+ declare function getPrependedScripts(
25
+ config: ConfigT,
26
+ options: Omit<TransformInputOptions, 'type'>,
27
+ resolverOptions: ResolverInputOptions,
28
+ bundler: Bundler,
29
+ deltaBundler: DeltaBundler,
30
+ ): Promise<ReadonlyArray<Module>>;
31
+ export default getPrependedScripts;
@@ -0,0 +1,22 @@
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<<f1d42fcf747b4fa7641e50b8d4ddc424>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/isResolvedDependency.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 {Dependency, ResolvedDependency} from '../DeltaBundler/types';
19
+
20
+ export declare function isResolvedDependency(
21
+ dep: Dependency,
22
+ ): dep is ResolvedDependency;
@@ -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
+ * @generated SignedSource<<95cf7d414507e2035210d06882d858b3>>
9
+ *
10
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
11
+ * Original file: packages/metro/src/lib/logToConsole.js
12
+ * To regenerate, run:
13
+ * js1 build metro-ts-defs (internal) OR
14
+ * yarn run build-ts-defs (OSS)
15
+ */
16
+
17
+ import type {Terminal} from 'metro-core';
18
+
19
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: (
20
+ terminal: Terminal,
21
+ level: string,
22
+ ...data: Array<unknown>
23
+ ) => void;
24
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
25
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
26
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
@@ -0,0 +1,24 @@
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<<972fc847af4a55ba0e4863c90532e99c>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/parseBundleOptionsFromBundleRequestUrl.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 {BundleOptions} from '../shared/types';
19
+
20
+ declare function parseBundleOptionsFromBundleRequestUrl(
21
+ rawNonJscSafeUrlEncodedUrl: string,
22
+ platforms: Set<string>,
23
+ ): Omit<BundleOptions, keyof {bundleType: string}> & {bundleType: string};
24
+ export default parseBundleOptionsFromBundleRequestUrl;
@@ -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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<e0f212b1e687fef985215d8c152e7c04>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/parseCustomResolverOptions.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 {CustomResolverOptions} from 'metro-resolver';
19
+
20
+ declare function parseCustomResolverOptions(
21
+ searchParams: URLSearchParams,
22
+ ): CustomResolverOptions;
23
+ export default parseCustomResolverOptions;
@@ -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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<086e5d861160a99775fa58beba59492a>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/parseCustomTransformOptions.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 {CustomTransformOptions} from 'metro-transform-worker';
19
+
20
+ declare function parseCustomTransformOptions(
21
+ searchParams: URLSearchParams,
22
+ ): CustomTransformOptions;
23
+ export default parseCustomTransformOptions;
@@ -0,0 +1,34 @@
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<<cd5e7346556814416374b8c8e79a8674>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/parseJsonBody.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 {IncomingMessage} from 'http';
19
+
20
+ export type JsonData =
21
+ | {[$$Key$$: string]: JsonData}
22
+ | Array<JsonData>
23
+ | string
24
+ | number
25
+ | boolean
26
+ | null;
27
+ /**
28
+ * Attempt to parse a request body as JSON.
29
+ */
30
+ declare function parseJsonBody(
31
+ req: IncomingMessage,
32
+ options?: {strict?: boolean},
33
+ ): Promise<JsonData>;
34
+ export default parseJsonBody;
@@ -0,0 +1,21 @@
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<<61d935169a7ad0d7f2d7b4c6e4eb0a96>>
9
+ *
10
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
11
+ * Original file: packages/metro/src/lib/pathUtils.js
12
+ * To regenerate, run:
13
+ * js1 build metro-ts-defs (internal) OR
14
+ * yarn run build-ts-defs (OSS)
15
+ */
16
+
17
+ export declare const normalizePathSeparatorsToPosix: (
18
+ $$PARAM_0$$: string,
19
+ ) => string;
20
+ export declare type normalizePathSeparatorsToPosix =
21
+ typeof normalizePathSeparatorsToPosix;
@@ -0,0 +1,24 @@
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<<5282fe2c42baa79f957ef2a40bec560b>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/relativizeSourceMap.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 {MixedSourceMap} from 'metro-source-map';
19
+
20
+ declare function relativizeSourceMapInline(
21
+ sourceMap: MixedSourceMap,
22
+ sourcesRoot: string,
23
+ ): void;
24
+ export default relativizeSourceMapInline;
@@ -0,0 +1,135 @@
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<<1ff95f1ad6bb911f3d2c2bc41d59bc1a>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/reporting.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 {Terminal} from 'metro-core';
19
+ import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
20
+ import type {CustomResolverOptions} from 'metro-resolver';
21
+ import type {CustomTransformOptions} from 'metro-transform-worker';
22
+
23
+ export type BundleDetails = {
24
+ bundleType: string;
25
+ customResolverOptions: CustomResolverOptions;
26
+ customTransformOptions: CustomTransformOptions;
27
+ dev: boolean;
28
+ entryFile: string;
29
+ minify: boolean;
30
+ platform: null | undefined | string;
31
+ };
32
+ /**
33
+ * A tagged union of all the actions that may happen and we may want to
34
+ * report to the tool user.
35
+ */
36
+ export type ReportableEvent =
37
+ | {port: number; hasReducedPerformance: boolean; type: 'initialize_started'}
38
+ | {type: 'initialize_failed'; port: number; error: Error}
39
+ | {type: 'initialize_done'; port: number}
40
+ | {buildID: string; type: 'bundle_build_done'}
41
+ | {buildID: string; type: 'bundle_build_failed'}
42
+ | {type: 'bundle_save_log'; message: string}
43
+ | {
44
+ buildID: string;
45
+ bundleDetails: BundleDetails;
46
+ isPrefetch?: boolean;
47
+ type: 'bundle_build_started';
48
+ }
49
+ | {error: Error; type: 'bundling_error'}
50
+ | {type: 'dep_graph_loading'; hasReducedPerformance: boolean}
51
+ | {type: 'dep_graph_loaded'}
52
+ | {
53
+ buildID: string;
54
+ type: 'bundle_transform_progressed';
55
+ transformedFileCount: number;
56
+ totalFileCount: number;
57
+ }
58
+ | {type: 'cache_read_error'; error: Error}
59
+ | {type: 'cache_write_error'; error: Error}
60
+ | {type: 'transform_cache_reset'}
61
+ | {type: 'worker_stdout_chunk'; chunk: string}
62
+ | {type: 'worker_stderr_chunk'; chunk: string}
63
+ | {type: 'hmr_client_error'; error: Error}
64
+ | {
65
+ type: 'client_log';
66
+ level:
67
+ | 'trace'
68
+ | 'info'
69
+ | 'warn'
70
+ | 'log'
71
+ | 'group'
72
+ | 'groupCollapsed'
73
+ | 'groupEnd'
74
+ | 'debug';
75
+ data: Array<unknown>;
76
+ }
77
+ | {type: 'resolver_warning'; message: string}
78
+ | {type: 'server_listening'; port: number; address: string; family: string}
79
+ | {type: 'transformer_load_started'}
80
+ | {type: 'transformer_load_done'}
81
+ | {type: 'transformer_load_failed'; error: Error}
82
+ | {type: 'watcher_health_check_result'; result: HealthCheckResult}
83
+ | {type: 'watcher_status'; status: WatcherStatus};
84
+ /**
85
+ * Code across the application takes a reporter as an option and calls the
86
+ * update whenever one of the ReportableEvent happens. Code does not directly
87
+ * write to the standard output, because a build would be:
88
+ *
89
+ * 1. ad-hoc, embedded into another tool, in which case we do not want to
90
+ * pollute that tool's own output. The tool is free to present the
91
+ * warnings/progress we generate any way they want, by specifing a custom
92
+ * reporter.
93
+ * 2. run as a background process from another tool, in which case we want
94
+ * to expose updates in a way that is easily machine-readable, for example
95
+ * a JSON-stream. We don't want to pollute it with textual messages.
96
+ *
97
+ * We centralize terminal reporting into a single place because we want the
98
+ * output to be robust and consistent. The most common reporter is
99
+ * TerminalReporter, that should be the only place in the application should
100
+ * access the `terminal` module (nor the `console`).
101
+ */
102
+ export type Reporter = {update(event: ReportableEvent): void};
103
+ /**
104
+ * A standard way to log a warning to the terminal. This should not be called
105
+ * from some arbitrary Metro logic, only from the reporters. Instead of
106
+ * calling this, add a new type of ReportableEvent instead, and implement a
107
+ * proper handler in the reporter(s).
108
+ */
109
+ export declare function logWarning(
110
+ terminal: Terminal,
111
+ format: string,
112
+ ...args: Array<unknown>
113
+ ): void;
114
+ /**
115
+ * Similar to `logWarning`, but for messages that require the user to act.
116
+ */
117
+ export declare function logError(
118
+ terminal: Terminal,
119
+ format: string,
120
+ ...args: Array<unknown>
121
+ ): void;
122
+ /**
123
+ * Similar to `logWarning`, but for informational messages.
124
+ */
125
+ export declare function logInfo(
126
+ terminal: Terminal,
127
+ format: string,
128
+ ...args: Array<unknown>
129
+ ): void;
130
+ /**
131
+ * A reporter that does nothing. Errors and warnings will be swallowed, that
132
+ * is generally not what you want.
133
+ */
134
+ export declare const nullReporter: {update(): void};
135
+ export declare type nullReporter = typeof nullReporter;
@@ -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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<cf1e935fe7a5b1c8573b53b1c1921e70>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/splitBundleOptions.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 {BundleOptions, SplitBundleOptions} from '../shared/types';
19
+ /**
20
+ * Splits a BundleOptions object into smaller, more manageable parts.
21
+ */
22
+ declare function splitBundleOptions(options: BundleOptions): SplitBundleOptions;
23
+ export default splitBundleOptions;
@@ -0,0 +1,42 @@
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<<dfdfdf9ddb80994cc031e3767a87b56f>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/lib/transformHelpers.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 Bundler from '../Bundler';
19
+ import type {TransformFn, default as DeltaBundler} from '../DeltaBundler';
20
+ import type {
21
+ BundlerResolution,
22
+ TransformInputOptions,
23
+ TransformResultDependency,
24
+ } from '../DeltaBundler/types';
25
+ import type {ResolverInputOptions} from '../shared/types';
26
+ import type {ConfigT} from 'metro-config';
27
+
28
+ export declare function getTransformFn(
29
+ entryFiles: ReadonlyArray<string>,
30
+ bundler: Bundler,
31
+ deltaBundler: DeltaBundler,
32
+ config: ConfigT,
33
+ options: TransformInputOptions,
34
+ resolverOptions: ResolverInputOptions,
35
+ ): Promise<TransformFn>;
36
+ export declare function getResolveDependencyFn(
37
+ bundler: Bundler,
38
+ platform: null | undefined | string,
39
+ resolverOptions: ResolverInputOptions,
40
+ ): Promise<
41
+ (from: string, dependency: TransformResultDependency) => BundlerResolution
42
+ >;
@@ -0,0 +1,120 @@
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<<0024fd05b95efe19a24f9acc84ff474b>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/node-haste/DependencyGraph/ModuleResolution.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
+ BundlerResolution,
20
+ TransformResultDependency,
21
+ } from '../../DeltaBundler/types';
22
+ import type {Reporter} from '../../lib/reporting';
23
+ import type {ResolverInputOptions} from '../../shared/types';
24
+ import type {
25
+ CustomResolver,
26
+ DoesFileExist,
27
+ FileCandidates,
28
+ FileSystemLookup,
29
+ Resolution,
30
+ ResolveAsset,
31
+ } from 'metro-resolver';
32
+ import type {PackageForModule, PackageJson} from 'metro-resolver/private/types';
33
+
34
+ export type DirExistsFn = (filePath: string) => boolean;
35
+ type Options = Readonly<{
36
+ assetExts: ReadonlySet<string>;
37
+ dirExists: DirExistsFn;
38
+ disableHierarchicalLookup: boolean;
39
+ doesFileExist: DoesFileExist;
40
+ emptyModulePath: string;
41
+ extraNodeModules: null | undefined | object;
42
+ fileSystemLookup: FileSystemLookup;
43
+ getHasteModulePath: (
44
+ name: string,
45
+ platform: null | undefined | string,
46
+ ) => null | undefined | string;
47
+ getHastePackagePath: (
48
+ name: string,
49
+ platform: null | undefined | string,
50
+ ) => null | undefined | string;
51
+ mainFields: ReadonlyArray<string>;
52
+ getPackage: (packageJsonPath: string) => null | undefined | PackageJson;
53
+ getPackageForModule: (
54
+ absolutePath: string,
55
+ ) => null | undefined | PackageForModule;
56
+ nodeModulesPaths: ReadonlyArray<string>;
57
+ preferNativePlatform: boolean;
58
+ projectRoot: string;
59
+ reporter: Reporter;
60
+ resolveAsset: ResolveAsset;
61
+ resolveRequest: null | undefined | CustomResolver;
62
+ sourceExts: ReadonlyArray<string>;
63
+ unstable_conditionNames: ReadonlyArray<string>;
64
+ unstable_conditionsByPlatform: Readonly<{
65
+ [platform: string]: ReadonlyArray<string>;
66
+ }>;
67
+ unstable_enablePackageExports: boolean;
68
+ unstable_incrementalResolution: boolean;
69
+ }>;
70
+ export declare class ModuleResolver {
71
+ _options: Options;
72
+ _projectRootFakeModulePath: string;
73
+ _cachedEmptyModule: null | undefined | BundlerResolution;
74
+ constructor(options: Options);
75
+ _getEmptyModule(): BundlerResolution;
76
+ resolveDependency(
77
+ originModulePath: string,
78
+ dependency: TransformResultDependency,
79
+ allowHaste: boolean,
80
+ platform: string | null,
81
+ resolverOptions: ResolverInputOptions,
82
+ ): BundlerResolution;
83
+ /**
84
+ * TODO: Return Resolution instead of coercing to BundlerResolution here
85
+ */
86
+ _getFileResolvedModule(resolution: Resolution): BundlerResolution;
87
+ _logWarning: (message: string) => void;
88
+ _removeRoot(candidates: FileCandidates): FileCandidates;
89
+ }
90
+ export declare class UnableToResolveError extends Error {
91
+ /**
92
+ * File path of the module that tried to require a module, ex. `/js/foo.js`.
93
+ */
94
+ originModulePath: string;
95
+ /**
96
+ * The name of the module that was required, no necessarily a path,
97
+ * ex. `./bar`, or `invariant`.
98
+ */
99
+ targetModuleName: string;
100
+ /**
101
+ * Original error that causes this error
102
+ */
103
+ cause: null | undefined | Error;
104
+ /**
105
+ * Fixed type field in common with other Metro build errors.
106
+ */
107
+ readonly type: 'UnableToResolveError';
108
+ constructor(
109
+ originModulePath: string,
110
+ targetModuleName: string,
111
+ message: string,
112
+ options?: Readonly<{
113
+ dependency?: null | undefined | TransformResultDependency;
114
+ cause?: Error;
115
+ }>,
116
+ );
117
+ buildCodeFrameMessage(
118
+ dependency: null | undefined | TransformResultDependency,
119
+ ): null | undefined | string;
120
+ }
@@ -86,6 +86,8 @@ class ModuleResolver {
86
86
  doesFileExist,
87
87
  extraNodeModules,
88
88
  fileSystemLookup,
89
+ getPackage,
90
+ getPackageForModule,
89
91
  mainFields,
90
92
  nodeModulesPaths,
91
93
  preferNativePlatform,
@@ -109,9 +111,8 @@ class ModuleResolver {
109
111
  doesFileExist,
110
112
  extraNodeModules,
111
113
  fileSystemLookup,
112
- getPackage: this._getPackage,
113
- getPackageForModule: (absoluteModulePath) =>
114
- this._getPackageForModule(absoluteModulePath),
114
+ getPackage,
115
+ getPackageForModule,
115
116
  isESMImport: dependency.data.isESMImport,
116
117
  mainFields,
117
118
  nodeModulesPaths,
@@ -191,25 +192,6 @@ class ModuleResolver {
191
192
  throw error;
192
193
  }
193
194
  }
194
- _getPackage = (packageJsonPath) => {
195
- try {
196
- return this._options.packageCache.getPackage(packageJsonPath).read();
197
- } catch (e) {}
198
- return null;
199
- };
200
- _getPackageForModule = (absolutePath) => {
201
- let result;
202
- try {
203
- result = this._options.packageCache.getPackageOf(absolutePath);
204
- } catch (e) {}
205
- return result != null
206
- ? {
207
- packageJson: result.pkg.read(),
208
- packageRelativePath: result.packageRelativePath,
209
- rootPath: _path.default.dirname(result.pkg.path),
210
- }
211
- : null;
212
- };
213
195
  _getFileResolvedModule(resolution) {
214
196
  switch (resolution.type) {
215
197
  case "sourceFile":