Skip to content

Commit 07732e7

Browse files
huntiefacebook-github-bot
authored andcommitted
Sync .d.ts files for remaining packages from DefinitelyTyped
Summary: Adds definitely typed definitions for the following packages: - `metro` - `metro-babel-transfomer` - `metro-config` - `metro-core` - `metro-file-map` - `metro-resolver` - `metro-source-map` - `metro-transform-worker` Thanks afoxman and tido64 for originally contributing these types in DefinitelyTyped! 🙌🏻 Changelog: **[Types]** Add bundled TypeScript definitions (partial) for all packages previously on DefinitelyTyped Reviewed By: motiz88 Differential Revision: D44509764 fbshipit-source-id: 6c0c7f4054a47c3cccdf2630b5f694211b150cd3
1 parent c022c36 commit 07732e7

File tree

39 files changed

+2562
-0
lines changed

39 files changed

+2562
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 {FBSourceFunctionMap} from 'metro-source-map';
12+
13+
export interface CustomTransformOptions {
14+
[key: string]: unknown;
15+
}
16+
17+
export type TransformProfile = 'default' | 'hermes-stable' | 'hermes-canary';
18+
19+
export interface BabelTransformerOptions {
20+
readonly customTransformOptions?: CustomTransformOptions;
21+
readonly dev: boolean;
22+
readonly enableBabelRCLookup?: boolean;
23+
readonly enableBabelRuntime: boolean | string;
24+
readonly extendsBabelConfigPath?: string;
25+
readonly experimentalImportSupport?: boolean;
26+
readonly hermesParser?: boolean;
27+
readonly hot: boolean;
28+
readonly inlineRequires: boolean;
29+
readonly nonInlinedRequires?: ReadonlyArray<string>;
30+
readonly minify: boolean;
31+
readonly unstable_disableES6Transforms?: boolean;
32+
readonly platform: string | null;
33+
readonly projectRoot: string;
34+
readonly publicPath: string;
35+
readonly unstable_transformProfile?: TransformProfile;
36+
readonly globalPrefix: string;
37+
}
38+
39+
export interface BabelTransformerArgs {
40+
readonly filename: string;
41+
readonly options: BabelTransformerOptions;
42+
readonly plugins?: unknown;
43+
readonly src: string;
44+
}
45+
46+
export interface BabelTransformer {
47+
transform: (args: BabelTransformerArgs) => {
48+
ast: unknown;
49+
functionMap: FBSourceFunctionMap | null;
50+
};
51+
getCacheKey?: () => string;
52+
}
53+
54+
export const transform: BabelTransformer['transform'];
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
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+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 {ConfigT} from '../configTypes';
12+
13+
export default interface getDefaultConfig {
14+
(rootPath: string | null): Promise<ConfigT>;
15+
getDefaultValues: (rootPath: string | null) => ConfigT;
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 getDefaultConfig from './defaults';
12+
import {loadConfig, mergeConfig, resolveConfig} from './loadConfig';
13+
14+
export * from './configTypes';
15+
export {loadConfig, mergeConfig, resolveConfig, getDefaultConfig};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 {ConfigT, InputConfigT, YargArguments} from './configTypes';
12+
13+
export interface CosmiConfigResult {
14+
filepath: string;
15+
isEmpty: boolean;
16+
config:
17+
| ((partialConfig: ConfigT) => Promise<ConfigT>)
18+
| ((partialConfig: ConfigT) => ConfigT)
19+
| InputConfigT;
20+
}
21+
22+
export function loadConfig(
23+
argv?: YargArguments,
24+
defaultConfigOverrides?: InputConfigT,
25+
): Promise<ConfigT>;
26+
27+
export function resolveConfig(
28+
filePath?: string,
29+
cwd?: string,
30+
): Promise<ConfigT>;
31+
32+
export function mergeConfig(
33+
defaultConfig: InputConfigT,
34+
...configs: InputConfigT[]
35+
): ConfigT;

0 commit comments

Comments
 (0)