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/lib/splitBundleOptions' { 100 import type { SplitBundleOptions } from 'metro/src/shared/types'; 101 102 function splitBundleOptions(options: BundleOptions): SplitBundleOptions; 103 104 export default splitBundleOptions; 105} 106 107declare module 'metro/src/DeltaBundler/Serializers/helpers/js' { 108 import type { JsOutput } from 'metro-transform-worker'; 109 import type { MixedOutput, Module } from 'metro'; 110 111 export function getJsOutput( 112 module: readonly { 113 output: readonly MixedOutput[]; 114 path?: string; 115 } 116 ): JsOutput; 117 118 export function isJsModule(module: Module<unknown>): boolean; 119} 120 121declare module 'metro/src/Assets' { 122 export type AssetInfo = { 123 files: string[]; 124 hash: string; 125 name: string; 126 scales: number[]; 127 type: string; 128 }; 129 130 export type AssetDataWithoutFiles = { 131 __packager_asset: boolean; 132 fileSystemLocation: string; 133 hash: string; 134 height: number | null; 135 httpServerLocation: string; 136 name: string; 137 scales: number[]; 138 type: string; 139 width: number | null; 140 }; 141 142 export type AssetDataFiltered = { 143 __packager_asset: boolean; 144 hash: string; 145 height: number | null; 146 httpServerLocation: string; 147 name: string; 148 scales: number[]; 149 type: string; 150 width: number | null; 151 }; 152 153 export type AssetData = AssetDataWithoutFiles & { files: string[] }; 154 155 export type AssetDataPlugin = (assetData: AssetData) => AssetData | Promise<AssetData>; 156 157 export async function getAsset( 158 relativePath: string, 159 projectRoot: string, 160 watchFolders: readonly string[], 161 platform: string | null | undefined, 162 assetExts: readonly string[] 163 ): Promise<Buffer>; 164 165 async function getAssetData( 166 assetPath: string, 167 localPath: string, 168 assetDataPlugins: readonly string[], 169 platform: string | null | undefined, 170 publicPath: string 171 ): Promise<AssetData>; 172} 173 174declare module 'metro' { 175 export * from 'metro/src/index.d'; 176 177 // Exports `Server` from 'metro' since TypeScript re-exporting doesn't work for default exports. 178 // https://github.com/facebook/metro/blob/40f9f068109f27ccd80f45f861501a8839f36d85/packages/metro/types/index.d.ts#L14 179 // https://github.com/facebook/metro/blob/40f9f068109f27ccd80f45f861501a8839f36d85/packages/metro/types/Server.d.ts#L89 180 export { default as Server } from 'metro/src/Server'; 181 182 // Exports `createConnectMiddleware` from 'metro' as a typo fix. 183 // https://github.com/facebook/metro/blob/40f9f068109f27ccd80f45f861501a8839f36d85/packages/metro/types/index.d.ts#L129 184 // https://github.com/facebook/metro/blob/40f9f068109f27ccd80f45f861501a8839f36d85/packages/metro/src/index.flow.js#L199 185 export { createConnectMiddleWare as createConnectMiddleware } from 'metro/src/index.d'; 186} 187 188declare module 'metro/src/DeltaBundler/Serializers/baseJSBundle' { 189 import { ReadOnlyGraph, MixedOutput, Module, Graph, SerializerOptions } from 'metro'; 190 191 type ModuleMap = readonly [number, string][]; 192 193 type Bundle = { 194 readonly modules: ModuleMap; 195 readonly post: string; 196 readonly pre: string; 197 }; 198 199 export default function baseJSBundle( 200 entryPoint: string, 201 preModules: readonly Module<MixedOutput>[], 202 graph: ReadOnlyGraph, 203 options: SerializerOptions 204 ): Bundle; 205} 206 207declare module 'metro/src/lib/bundleToString' { 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 type BundleMetadata = { 217 readonly pre: number; 218 readonly post: number; 219 readonly modules: readonly [number, number][]; 220 }; 221 222 export default function bundleToString(bundle: Bundle): { 223 readonly code: string; 224 readonly metadata: BundleMetadata; 225 }; 226} 227 228declare module 'metro/src/IncrementalBundler' { 229 import type OriginalIncrementalBundler from 'metro/src/IncrementalBundler.d'; 230 231 // Overrides the `IncrementalBundler.getDependencies` returned type for inconsistent 232 // ReadOnlyDependencies<void> <-> ReadOnlyDependencies<> type. 233 // https://github.com/facebook/metro/blob/40f9f068109f27ccd80f45f861501a8839f36d85/packages/metro/src/IncrementalBundler.js#L159 234 // https://github.com/facebook/metro/blob/40f9f068109f27ccd80f45f861501a8839f36d85/packages/metro/types/IncrementalBundler.d.ts#L66 235 export default class IncrementalBundler extends OriginalIncrementalBundler { 236 getDependencies( 237 entryFiles: readonly string[], 238 transformOptions: TransformInputOptions, 239 resolverOptions: ResolverInputOptions, 240 otherOptions?: OtherOptions 241 ): Promise<ReadOnlyDependencies>; 242 } 243} 244