1declare module 'metro/src/shared/output/bundle' { 2 export function build( 3 arg0: Server, 4 arg1: RequestOptions 5 ): Promise<{ 6 code: string; 7 map: string; 8 }>; 9 export function save( 10 arg0: { 11 code: string; 12 map: string; 13 }, 14 arg1: OutputOptions, 15 arg2: (...args: string[]) => void 16 ): Promise<unknown>; 17} 18 19declare module 'metro/src/HmrServer' { 20 export class MetroHmrServer { 21 constructor(...args: any[]); 22 } 23 24 module.exports = MetroHmrServer; 25} 26 27declare module 'metro/src/ModuleGraph/worker/collectDependencies' { 28 export type AllowOptionalDependenciesWithOptions = { 29 exclude: string[]; 30 }; 31 32 export type DynamicRequiresBehavior = 'throwAtRuntime' | 'reject'; 33 34 export type AllowOptionalDependencies = boolean | AllowOptionalDependenciesWithOptions; 35} 36 37declare module 'metro/src/DeltaBundler/types.flow' { 38 export type AllowOptionalDependenciesWithOptions = { 39 exclude: string[]; 40 }; 41 42 export type AllowOptionalDependencies = boolean | AllowOptionalDependenciesWithOptions; 43} 44declare module 'metro/src/DeltaBundler' { 45 export type AsyncDependencyType = 'async' | 'prefetch'; 46 export type TransformResultDependency = { 47 /** 48 * The literal name provided to a require or import call. For example 'foo' in 49 * case of `require('foo')`. 50 */ 51 name: string; 52 53 /** 54 * Extra data returned by the dependency extractor. 55 */ 56 data: { 57 /** 58 * A locally unique key for this dependency within the current module. 59 */ 60 key: string; 61 /** 62 * If not null, this dependency is due to a dynamic `import()` or `__prefetchImport()` call. 63 */ 64 asyncType: AsyncDependencyType | null; 65 /** 66 * The condition for splitting on this dependency edge. 67 */ 68 splitCondition?: { 69 mobileConfigName: string; 70 }; 71 /** 72 * The dependency is enclosed in a try/catch block. 73 */ 74 isOptional?: boolean; 75 76 locs: $ReadOnlyArray<BabelSourceLocation>; 77 78 /** Context for requiring a collection of modules. */ 79 contextParams?: RequireContextParams; 80 }; 81 }; 82} 83 84declare module 'metro/src/lib/countLines' { 85 const countLines = (string: string) => number; 86 87 module.exports = countLines; 88 export default countLines; 89} 90 91declare module 'metro/src/lib/createWebsocketServer' { 92 export function createWebsocketServer<TClient extends object>({ 93 websocketServer, 94 }: HMROptions<TClient>): typeof import('ws').Server; 95 96 module.exports = createWebsocketServer; 97} 98 99declare module 'metro/src/DeltaBundler/Serializers/getAssets' { 100 import { ConfigT } from 'metro-config'; 101 102 function getMetroAssets( 103 dependencies: ReadOnlyDependencies, 104 options: { 105 processModuleFilter: ConfigT['serializer']['processModuleFilter']; 106 assetPlugins: ConfigT['transformer']['assetPlugins']; 107 platform: string; 108 projectRoot: string; 109 publicPath: string; 110 } 111 ); 112 113 export default getMetroAssets; 114} 115 116declare module 'metro/src/lib/splitBundleOptions' { 117 import type { SplitBundleOptions } from 'metro/src/shared/types'; 118 119 function splitBundleOptions(options: BundleOptions): SplitBundleOptions; 120 121 export default splitBundleOptions; 122} 123 124declare module 'metro/src/DeltaBundler/Serializers/helpers/js' { 125 import type { JsOutput } from 'metro-transform-worker'; 126 import type { MixedOutput, Module } from 'metro'; 127 128 export function getJsOutput( 129 module: readonly { 130 output: readonly MixedOutput[]; 131 path?: string; 132 } 133 ): JsOutput; 134 135 export function isJsModule(module: Module<unknown>): boolean; 136} 137 138declare module 'metro/src/Assets' { 139 export type AssetInfo = { 140 files: string[]; 141 hash: string; 142 name: string; 143 scales: number[]; 144 type: string; 145 }; 146 147 export type AssetDataWithoutFiles = { 148 __packager_asset: boolean; 149 fileSystemLocation: string; 150 hash: string; 151 height: number | null; 152 httpServerLocation: string; 153 name: string; 154 scales: number[]; 155 type: string; 156 width: number | null; 157 }; 158 159 export type AssetDataFiltered = { 160 __packager_asset: boolean; 161 hash: string; 162 height: number | null; 163 httpServerLocation: string; 164 name: string; 165 scales: number[]; 166 type: string; 167 width: number | null; 168 }; 169 170 export type AssetData = AssetDataWithoutFiles & { files: string[] }; 171 172 export type AssetDataPlugin = (assetData: AssetData) => AssetData | Promise<AssetData>; 173 174 export async function getAsset( 175 relativePath: string, 176 projectRoot: string, 177 watchFolders: readonly string[], 178 platform: string | null | undefined, 179 assetExts: readonly string[] 180 ): Promise<Buffer>; 181 182 async function getAssetData( 183 assetPath: string, 184 localPath: string, 185 assetDataPlugins: readonly string[], 186 platform: string | null | undefined, 187 publicPath: string 188 ): Promise<AssetData>; 189} 190 191declare module 'metro' { 192 export * from 'metro/src/index.d'; 193 194 // Exports `Server` from 'metro' since TypeScript re-exporting doesn't work for default exports. 195 // https://github.com/facebook/metro/blob/40f9f068109f27ccd80f45f861501a8839f36d85/packages/metro/types/index.d.ts#L14 196 // https://github.com/facebook/metro/blob/40f9f068109f27ccd80f45f861501a8839f36d85/packages/metro/types/Server.d.ts#L89 197 export { default as Server } from 'metro/src/Server'; 198 199 // Exports `createConnectMiddleware` from 'metro' as a typo fix. 200 // https://github.com/facebook/metro/blob/40f9f068109f27ccd80f45f861501a8839f36d85/packages/metro/types/index.d.ts#L129 201 // https://github.com/facebook/metro/blob/40f9f068109f27ccd80f45f861501a8839f36d85/packages/metro/src/index.flow.js#L199 202 export { createConnectMiddleWare as createConnectMiddleware } from 'metro/src/index.d'; 203} 204 205declare module 'metro/src/DeltaBundler/Serializers/baseJSBundle' { 206 import { ReadOnlyGraph, MixedOutput, Module, Graph, SerializerOptions } from 'metro'; 207 208 type ModuleMap = readonly [number, string][]; 209 210 type Bundle = { 211 readonly modules: ModuleMap; 212 readonly post: string; 213 readonly pre: string; 214 }; 215 216 export default function baseJSBundle( 217 entryPoint: string, 218 preModules: readonly Module<MixedOutput>[], 219 graph: ReadOnlyGraph, 220 options: SerializerOptions 221 ): Bundle; 222} 223 224declare module 'metro/src/lib/bundleToString' { 225 type ModuleMap = readonly [number, string][]; 226 227 type Bundle = { 228 readonly modules: ModuleMap; 229 readonly post: string; 230 readonly pre: string; 231 }; 232 233 type BundleMetadata = { 234 readonly pre: number; 235 readonly post: number; 236 readonly modules: readonly [number, number][]; 237 }; 238 239 export default function bundleToString(bundle: Bundle): { 240 readonly code: string; 241 readonly metadata: BundleMetadata; 242 }; 243} 244 245declare module 'metro/src/IncrementalBundler' { 246 import type OriginalIncrementalBundler from 'metro/src/IncrementalBundler.d'; 247 248 // Overrides the `IncrementalBundler.getDependencies` returned type for inconsistent 249 // ReadOnlyDependencies<void> <-> ReadOnlyDependencies<> type. 250 // https://github.com/facebook/metro/blob/40f9f068109f27ccd80f45f861501a8839f36d85/packages/metro/src/IncrementalBundler.js#L159 251 // https://github.com/facebook/metro/blob/40f9f068109f27ccd80f45f861501a8839f36d85/packages/metro/types/IncrementalBundler.d.ts#L66 252 export default class IncrementalBundler extends OriginalIncrementalBundler { 253 getDependencies( 254 entryFiles: readonly string[], 255 transformOptions: TransformInputOptions, 256 resolverOptions: ResolverInputOptions, 257 otherOptions?: OtherOptions 258 ): Promise<ReadOnlyDependencies>; 259 } 260} 261