|
| 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 {IncomingMessage, ServerResponse} from 'http'; |
| 12 | +import type {CacheStore, MetroCache} from 'metro-cache'; |
| 13 | +import type {CustomResolver} from 'metro-resolver'; |
| 14 | +import type {JsTransformerConfig} from 'metro-transform-worker'; |
| 15 | +import type { |
| 16 | + DeltaResult, |
| 17 | + Module, |
| 18 | + ReadOnlyGraph, |
| 19 | + SerializerOptions, |
| 20 | + TransformResult, |
| 21 | +} from 'metro/DeltaBundler/types'; |
| 22 | +import type {Reporter} from 'metro/lib/reporting'; |
| 23 | +import type Server from 'metro/Server'; |
| 24 | + |
| 25 | +export interface ExtraTransformOptions { |
| 26 | + readonly preloadedModules: {[path: string]: true} | false; |
| 27 | + readonly ramGroups: string[]; |
| 28 | + readonly transform: Readonly<{ |
| 29 | + experimentalImportSupport: boolean; |
| 30 | + inlineRequires: {blockList: {[path: string]: true}} | boolean; |
| 31 | + nonInlinedRequires?: ReadonlyArray<string>; |
| 32 | + unstable_disableES6Transforms?: boolean; |
| 33 | + }>; |
| 34 | +} |
| 35 | + |
| 36 | +export interface GetTransformOptionsOpts { |
| 37 | + dev: boolean; |
| 38 | + hot: boolean; |
| 39 | + platform?: string; |
| 40 | +} |
| 41 | + |
| 42 | +export type GetTransformOptions = ( |
| 43 | + entryPoints: ReadonlyArray<string>, |
| 44 | + options: GetTransformOptionsOpts, |
| 45 | + getDependenciesOf: (filePath: string) => Promise<string[]>, |
| 46 | +) => Promise<Partial<ExtraTransformOptions>>; |
| 47 | + |
| 48 | +export type Middleware = ( |
| 49 | + incomingMessage: IncomingMessage, |
| 50 | + serverResponse: ServerResponse, |
| 51 | + error: (e?: Error) => unknown, |
| 52 | +) => unknown; |
| 53 | + |
| 54 | +export type PerfAnnotations = Partial<{ |
| 55 | + string: {[key: string]: string}; |
| 56 | + int: {[key: string]: number}; |
| 57 | + double: {[key: string]: number}; |
| 58 | + bool: {[key: string]: boolean}; |
| 59 | + string_array: {[key: string]: string[]}; |
| 60 | + int_array: {[key: string]: number[]}; |
| 61 | + double_array: {[key: string]: number[]}; |
| 62 | + bool_array: {[key: string]: boolean[]}; |
| 63 | +}>; |
| 64 | + |
| 65 | +export type PerfLoggerPointOptions = Readonly<{ |
| 66 | + /** |
| 67 | + * The time this event point occurred, if it differs from the time the point was logged. |
| 68 | + */ |
| 69 | + timestamp?: number; |
| 70 | +}>; |
| 71 | + |
| 72 | +export interface PerfLogger { |
| 73 | + point(name: string, opts?: PerfLoggerPointOptions): void; |
| 74 | + annotate(annotations: PerfAnnotations): void; |
| 75 | + subSpan(label: string): PerfLogger; |
| 76 | +} |
| 77 | + |
| 78 | +export interface RootPerfLogger extends PerfLogger { |
| 79 | + start(opts?: PerfLoggerPointOptions): void; |
| 80 | + end( |
| 81 | + status: 'SUCCESS' | 'FAIL' | 'CANCEL', |
| 82 | + opts?: PerfLoggerPointOptions, |
| 83 | + ): void; |
| 84 | +} |
| 85 | + |
| 86 | +export type PerfLoggerFactoryOptions = Readonly<{ |
| 87 | + key?: number; |
| 88 | +}>; |
| 89 | + |
| 90 | +export type PerfLoggerFactory = ( |
| 91 | + type: 'START_UP' | 'BUNDLING_REQUEST' | 'HMR', |
| 92 | + opts?: PerfLoggerFactoryOptions, |
| 93 | +) => RootPerfLogger; |
| 94 | + |
| 95 | +export interface ResolverConfigT { |
| 96 | + assetExts: ReadonlyArray<string>; |
| 97 | + assetResolutions: ReadonlyArray<string>; |
| 98 | + blacklistRE?: RegExp | RegExp[]; |
| 99 | + blockList: RegExp | RegExp[]; |
| 100 | + dependencyExtractor?: string; |
| 101 | + disableHierarchicalLookup: boolean; |
| 102 | + extraNodeModules: {[name: string]: string}; |
| 103 | + emptyModulePath: string; |
| 104 | + hasteImplModulePath?: string; |
| 105 | + nodeModulesPaths: ReadonlyArray<string>; |
| 106 | + platforms: ReadonlyArray<string>; |
| 107 | + resolveRequest?: CustomResolver; |
| 108 | + resolverMainFields: ReadonlyArray<string>; |
| 109 | + sourceExts: ReadonlyArray<string>; |
| 110 | + unstable_enableSymlinks: boolean; |
| 111 | + unstable_conditionNames: ReadonlyArray<string>; |
| 112 | + unstable_conditionsByPlatform: Readonly<{ |
| 113 | + [platform: string]: ReadonlyArray<string>; |
| 114 | + }>; |
| 115 | + unstable_enablePackageExports: boolean; |
| 116 | + useWatchman: boolean; |
| 117 | + requireCycleIgnorePatterns: ReadonlyArray<RegExp>; |
| 118 | +} |
| 119 | + |
| 120 | +export interface SerializerConfigT { |
| 121 | + createModuleIdFactory: () => (path: string) => number; |
| 122 | + customSerializer: |
| 123 | + | (( |
| 124 | + entryPoint: string, |
| 125 | + preModules: ReadonlyArray<Module>, |
| 126 | + graph: ReadOnlyGraph, |
| 127 | + options: SerializerOptions, |
| 128 | + ) => Promise<string | {code: string; map: string}>) |
| 129 | + | null; |
| 130 | + experimentalSerializerHook: ( |
| 131 | + graph: ReadOnlyGraph, |
| 132 | + delta: DeltaResult, |
| 133 | + ) => unknown; |
| 134 | + getModulesRunBeforeMainModule: (entryFilePath: string) => string[]; |
| 135 | + getPolyfills: (options: {platform: string | null}) => ReadonlyArray<string>; |
| 136 | + getRunModuleStatement: (moduleId: number | string) => string; |
| 137 | + polyfillModuleNames: ReadonlyArray<string>; |
| 138 | + processModuleFilter: (modules: Module) => boolean; |
| 139 | +} |
| 140 | + |
| 141 | +export interface TransformerConfigT extends JsTransformerConfig { |
| 142 | + getTransformOptions: GetTransformOptions; |
| 143 | + transformVariants: Readonly<{[name: string]: unknown}>; |
| 144 | + workerPath: string; |
| 145 | + publicPath: string; |
| 146 | +} |
| 147 | + |
| 148 | +export interface MetalConfigT { |
| 149 | + cacheStores: ReadonlyArray<CacheStore<TransformResult>>; |
| 150 | + cacheVersion: string; |
| 151 | + fileMapCacheDirectory?: string; |
| 152 | + /** Deprecated, alias of fileMapCacheDirectory */ |
| 153 | + hasteMapCacheDirectory?: string; |
| 154 | + maxWorkers: number; |
| 155 | + unstable_perfLoggerFactory?: PerfLoggerFactory | null; |
| 156 | + projectRoot: string; |
| 157 | + stickyWorkers: boolean; |
| 158 | + transformerPath: string; |
| 159 | + reporter: Reporter; |
| 160 | + resetCache: boolean; |
| 161 | + watchFolders: ReadonlyArray<string>; |
| 162 | +} |
| 163 | + |
| 164 | +export interface ServerConfigT { |
| 165 | + enhanceMiddleware: (middleware: Middleware, server: Server) => Middleware; |
| 166 | + experimentalImportBundleSupport: boolean; |
| 167 | + port: number; |
| 168 | + rewriteRequestUrl: (url: string) => string; |
| 169 | + runInspectorProxy: boolean; |
| 170 | + unstable_serverRoot: string | null; |
| 171 | + useGlobalHotkey: boolean; |
| 172 | + verifyConnections: boolean; |
| 173 | +} |
| 174 | + |
| 175 | +export interface SymbolicatorConfigT { |
| 176 | + customizeFrame: (frame: { |
| 177 | + readonly file?: string; |
| 178 | + readonly lineNumber?: number; |
| 179 | + readonly column?: number; |
| 180 | + readonly methodName?: string; |
| 181 | + }) => |
| 182 | + | {readonly collapse?: boolean} |
| 183 | + | undefined |
| 184 | + | Promise<{readonly collapse?: boolean}> |
| 185 | + | Promise<undefined>; |
| 186 | +} |
| 187 | + |
| 188 | +export interface WatcherConfigT { |
| 189 | + additionalExts: ReadonlyArray<string>; |
| 190 | + watchman: { |
| 191 | + deferStates: ReadonlyArray<string>; |
| 192 | + }; |
| 193 | + healthCheck: { |
| 194 | + enabled: boolean; |
| 195 | + interval: number; |
| 196 | + timeout: number; |
| 197 | + filePrefix: string; |
| 198 | + }; |
| 199 | +} |
| 200 | + |
| 201 | +export interface WatcherInputConfigT |
| 202 | + extends Partial<Omit<WatcherConfigT, 'healthCheck'>> { |
| 203 | + healthCheck?: Partial<WatcherConfigT['healthCheck']>; |
| 204 | +} |
| 205 | + |
| 206 | +export interface InputConfigT |
| 207 | + extends Partial<Omit<MetalConfigT, 'cacheStores'>> { |
| 208 | + readonly cacheStores?: |
| 209 | + | ReadonlyArray<CacheStore<TransformResult>> |
| 210 | + | ((metroCache: MetroCache) => ReadonlyArray<CacheStore<TransformResult>>); |
| 211 | + readonly resolver?: Partial<ResolverConfigT>; |
| 212 | + readonly server?: Partial<ServerConfigT>; |
| 213 | + readonly serializer?: Partial<SerializerConfigT>; |
| 214 | + readonly symbolicator?: Partial<SymbolicatorConfigT>; |
| 215 | + readonly transformer?: Partial<TransformerConfigT>; |
| 216 | + readonly watcher?: Partial<WatcherInputConfigT>; |
| 217 | +} |
| 218 | + |
| 219 | +export type MetroConfig = InputConfigT; |
| 220 | + |
| 221 | +export interface IntermediateConfigT extends MetalConfigT { |
| 222 | + resolver: ResolverConfigT; |
| 223 | + server: ServerConfigT; |
| 224 | + serializer: SerializerConfigT; |
| 225 | + symbolicator: SymbolicatorConfigT; |
| 226 | + transformer: TransformerConfigT; |
| 227 | + watcher: WatcherConfigT; |
| 228 | +} |
| 229 | + |
| 230 | +export interface ConfigT extends Readonly<MetalConfigT> { |
| 231 | + readonly resolver: Readonly<ResolverConfigT>; |
| 232 | + readonly server: Readonly<ServerConfigT>; |
| 233 | + readonly serializer: Readonly<SerializerConfigT>; |
| 234 | + readonly symbolicator: Readonly<SymbolicatorConfigT>; |
| 235 | + readonly transformer: Readonly<TransformerConfigT>; |
| 236 | + readonly watcher: Readonly<WatcherConfigT>; |
| 237 | +} |
| 238 | + |
| 239 | +export interface YargArguments { |
| 240 | + config?: string; |
| 241 | + cwd?: string; |
| 242 | + port?: string | number; |
| 243 | + host?: string; |
| 244 | + projectRoot?: string; |
| 245 | + watchFolders?: string[]; |
| 246 | + assetExts?: string[]; |
| 247 | + sourceExts?: string[]; |
| 248 | + platforms?: string[]; |
| 249 | + 'max-workers'?: string | number; |
| 250 | + maxWorkers?: string | number; |
| 251 | + transformer?: string; |
| 252 | + 'reset-cache'?: boolean; |
| 253 | + resetCache?: boolean; |
| 254 | + runInspectorProxy?: boolean; |
| 255 | + verbose?: boolean; |
| 256 | +} |
0 commit comments