Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[ignore]
<PROJECT_ROOT>/packages/.*/build/.*
<PROJECT_ROOT>/\.hg/.*
<PROJECT_ROOT>/\.\(hg\|sl\|git\)/.*
# this transient dep bundles tests with their package, which flow attempts to parse
# and crashes out as the test includes purposely malformed json
<PROJECT_ROOT>\(/.*\)?/node_modules/resolve/test/.*
Expand Down
14 changes: 6 additions & 8 deletions packages/metro-babel-transformer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type BabelTransformOptions = NonNullable<
>;

export type CustomTransformOptions = {
[string]: unknown,
[key: string]: unknown,
__proto__: null,
...
};
Expand Down Expand Up @@ -80,7 +80,7 @@ export type BabelTransformerCacheKeyOptions = Readonly<{
}>;

export type BabelTransformer = Readonly<{
transform: BabelTransformerArgs => Readonly<{
transform: (transformerArgs: BabelTransformerArgs) => Readonly<{
ast: BabelNodeFile,
// Deprecated, will be removed in a future breaking release. Function maps
// will be generated by an input Babel plugin instead and written into
Expand All @@ -92,12 +92,10 @@ export type BabelTransformer = Readonly<{
getCacheKey?: (options?: BabelTransformerCacheKeyOptions) => string,
}>;

function transform({
filename,
options,
plugins,
src,
}: BabelTransformerArgs): ReturnType<BabelTransformer['transform']> {
function transform(
opts: BabelTransformerArgs,
): ReturnType<BabelTransformer['transform']> {
const {filename, options, plugins, src} = opts;
const OLD_BABEL_ENV = process.env.BABEL_ENV;
process.env.BABEL_ENV = options.dev
? 'development'
Expand Down
8 changes: 4 additions & 4 deletions packages/metro-babel-transformer/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @noformat
* @oncall react_native
* @generated SignedSource<<c71ff6c13c916919d1340d231518de8f>>
* @generated SignedSource<<2503f88efd80b39e4d860870017af66d>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro-babel-transformer/src/index.js
Expand All @@ -24,7 +24,7 @@ type BabelTransformOptions = NonNullable<
Parameters<typeof transformFromAstSync>[2]
>;
export type CustomTransformOptions = {
[$$Key$$: string]: unknown;
[key: string]: unknown;
};
export type TransformProfile = 'default' | 'hermes-stable' | 'hermes-canary';
type BabelTransformerOptions = Readonly<{
Expand Down Expand Up @@ -85,15 +85,15 @@ export type BabelTransformerCacheKeyOptions = Readonly<{
enableBabelRCLookup?: boolean;
}>;
export type BabelTransformer = Readonly<{
transform: ($$PARAM_0$$: BabelTransformerArgs) => Readonly<{
transform: (transformerArgs: BabelTransformerArgs) => Readonly<{
ast: BabelNodeFile;
functionMap?: BabelFileFunctionMapMetadata;
metadata?: MetroBabelFileMetadata;
}>;
getCacheKey?: (options?: BabelTransformerCacheKeyOptions) => string;
}>;
declare function transform(
$$PARAM_0$$: BabelTransformerArgs,
opts: BabelTransformerArgs,
): ReturnType<BabelTransformer['transform']>;
/**
* Generates a cache key component based on the user's Babel configuration files.
Expand Down
21 changes: 13 additions & 8 deletions packages/metro-config/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type ResolverConfigT = {
dependencyExtractor: ?string,
emptyModulePath: string,
enableGlobalPackages: boolean,
extraNodeModules: {[name: string]: string, ...},
extraNodeModules: {[packageName: string]: string, ...},
hasteImplModulePath: ?string,
nodeModulesPaths: ReadonlyArray<string>,
platforms: ReadonlyArray<string>,
Expand Down Expand Up @@ -139,7 +139,7 @@ type SerializerConfigT = {
delta: DeltaResult<>,
) => unknown,
getModulesRunBeforeMainModule: (entryFilePath: string) => Array<string>,
getPolyfills: ({platform: ?string, ...}) => ReadonlyArray<string>,
getPolyfills: (ctx: {platform: ?string, ...}) => ReadonlyArray<string>,
getRunModuleStatement: (
moduleId: number | string,
globalPrefix: string,
Expand Down Expand Up @@ -178,10 +178,13 @@ type CacheStoresConfigT = ReadonlyArray<CacheStore<TransformResult<>>>;

type ServerConfigT = {
/** @deprecated */
enhanceMiddleware: (Middleware, MetroServer) => Middleware | Server,
enhanceMiddleware: (
middleware: Middleware,
server: MetroServer,
) => Middleware | Server,
forwardClientLogs: boolean,
port: number,
rewriteRequestUrl: string => string,
rewriteRequestUrl: (url: string) => string,
unstable_serverRoot: ?string,
useGlobalHotkey: boolean,
verifyConnections: boolean,
Expand All @@ -196,16 +199,16 @@ type ServerConfigT = {
};

type SymbolicatorConfigT = {
customizeFrame: ({
customizeFrame: (frame: {
+file: ?string,
+lineNumber: ?number,
+column: ?number,
+methodName: ?string,
...
}) => ?{+collapse?: boolean} | Promise<?{+collapse?: boolean}>,
customizeStack: (
Array<IntermediateStackFrame>,
unknown,
symbolicatedStack: Array<IntermediateStackFrame>,
extraData: unknown,
) => Array<IntermediateStackFrame> | Promise<Array<IntermediateStackFrame>>,
};

Expand All @@ -230,7 +233,9 @@ type WatcherConfigT = {
export type InputConfigT = Partial<
Readonly<
MetalConfigT & {
cacheStores: CacheStoresConfigT | (MetroCache => CacheStoresConfigT),
cacheStores:
| CacheStoresConfigT
| ((metroCache: MetroCache) => CacheStoresConfigT),
resolver: Readonly<Partial<ResolverConfigT>>,
server: Readonly<Partial<ServerConfigT>>,
serializer: Readonly<Partial<SerializerConfigT>>,
Expand Down
20 changes: 10 additions & 10 deletions packages/metro-config/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @noformat
* @oncall react_native
* @generated SignedSource<<9c62bc2ca711f9693edc135a382a382a>>
* @generated SignedSource<<45e0111f05ce2350b8be53c72dd0c8c7>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro-config/src/types.js
Expand Down Expand Up @@ -97,7 +97,7 @@ type ResolverConfigT = {
dependencyExtractor: null | undefined | string;
emptyModulePath: string;
enableGlobalPackages: boolean;
extraNodeModules: {[name: string]: string};
extraNodeModules: {[packageName: string]: string};
hasteImplModulePath: null | undefined | string;
nodeModulesPaths: ReadonlyArray<string>;
platforms: ReadonlyArray<string>;
Expand Down Expand Up @@ -130,7 +130,7 @@ type SerializerConfigT = {
delta: DeltaResult,
) => unknown;
getModulesRunBeforeMainModule: (entryFilePath: string) => Array<string>;
getPolyfills: ($$PARAM_0$$: {
getPolyfills: (ctx: {
platform: null | undefined | string;
}) => ReadonlyArray<string>;
getRunModuleStatement: (
Expand Down Expand Up @@ -178,12 +178,12 @@ type CacheStoresConfigT = ReadonlyArray<CacheStore<TransformResult>>;
type ServerConfigT = {
/** @deprecated */
enhanceMiddleware: (
$$PARAM_0$$: Middleware,
$$PARAM_1$$: MetroServer,
middleware: Middleware,
server: MetroServer,
) => Middleware | Server;
forwardClientLogs: boolean;
port: number;
rewriteRequestUrl: ($$PARAM_0$$: string) => string;
rewriteRequestUrl: (url: string) => string;
unstable_serverRoot: null | undefined | string;
useGlobalHotkey: boolean;
verifyConnections: boolean;
Expand All @@ -197,7 +197,7 @@ type ServerConfigT = {
};
};
type SymbolicatorConfigT = {
customizeFrame: ($$PARAM_0$$: {
customizeFrame: (frame: {
readonly file: null | undefined | string;
readonly lineNumber: null | undefined | number;
readonly column: null | undefined | number;
Expand All @@ -206,8 +206,8 @@ type SymbolicatorConfigT = {
| (null | undefined | {readonly collapse?: boolean})
| Promise<null | undefined | {readonly collapse?: boolean}>;
customizeStack: (
$$PARAM_0$$: Array<IntermediateStackFrame>,
$$PARAM_1$$: unknown,
symbolicatedStack: Array<IntermediateStackFrame>,
extraData: unknown,
) => Array<IntermediateStackFrame> | Promise<Array<IntermediateStackFrame>>;
};
type WatcherConfigT = {
Expand All @@ -227,7 +227,7 @@ export type InputConfigT = Partial<
MetalConfigT & {
cacheStores:
| CacheStoresConfigT
| (($$PARAM_0$$: MetroCache) => CacheStoresConfigT);
| ((metroCache: MetroCache) => CacheStoresConfigT);
resolver: Readonly<Partial<ResolverConfigT>>;
server: Readonly<Partial<ServerConfigT>>;
serializer: Readonly<Partial<SerializerConfigT>>;
Expand Down
14 changes: 5 additions & 9 deletions packages/metro-file-map/src/cache/DiskCacheManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ export class DiskCacheManager implements CacheManager {
#tryWrite: ?() => Promise<void>;
#stopListening: ?() => void;

constructor(
{buildParameters}: CacheManagerFactoryOptions,
{autoSave = {}, cacheDirectory, cacheFilePrefix}: DiskCacheConfig,
) {
constructor(opts: CacheManagerFactoryOptions, config: DiskCacheConfig) {
const {buildParameters} = opts;
const {autoSave = {}, cacheDirectory, cacheFilePrefix} = config;
this.#cachePath = DiskCacheManager.getCacheFilePath(
buildParameters,
cacheFilePrefix,
Expand Down Expand Up @@ -103,12 +102,9 @@ export class DiskCacheManager implements CacheManager {

async write(
getSnapshot: () => CacheData,
{
changedSinceCacheRead,
eventSource,
onWriteError,
}: CacheManagerWriteOptions,
opts: CacheManagerWriteOptions,
): Promise<void> {
const {changedSinceCacheRead, eventSource, onWriteError} = opts;
// Initialise a writer function using a promise queue to ensure writes are
// sequenced.
const tryWrite = (this.#tryWrite = () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/metro-file-map/src/flow-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export type ChangedFileMetadata = Readonly<{
}>;

export type ChangeEvent = Readonly<{
logger: ?RootPerfLogger,
logger?: ?RootPerfLogger,
changes: ReadonlyFileSystemChanges<Readonly<ChangedFileMetadata>>,
rootDir: string,
}>;
Expand All @@ -110,7 +110,7 @@ export type ChangeEventMetadata = {
export type Console = typeof global.console;

export type CrawlerOptions = {
abortSignal: ?AbortSignal,
abortSignal?: ?AbortSignal,
computeSha1: boolean,
console: Console,
extensions: ReadonlyArray<string>,
Expand Down Expand Up @@ -328,8 +328,8 @@ export interface FileSystem {
mixedStartPath: string,
subpath: string,
opts: {
breakOnSegment: ?string,
invalidatedBy: ?Set<string>,
breakOnSegment?: ?string,
invalidatedBy?: ?Set<string>,
subpathType: 'f' | 'd',
},
): ?{
Expand Down
7 changes: 4 additions & 3 deletions packages/metro-file-map/src/plugins/HastePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ export default class HastePlugin
this.#failValidationOnConflicts = options.failValidationOnConflicts;
}

async initialize({
files,
}: FileMapPluginInitOptions<null, string | null>): Promise<void> {
async initialize(
opts: FileMapPluginInitOptions<null, string | null>,
): Promise<void> {
this.#perfLogger?.point('constructHasteMap_start');
const files = opts.files;
let hasteFiles = 0;
for (const {
baseName,
Expand Down
9 changes: 3 additions & 6 deletions packages/metro-file-map/types/cache/DiskCacheManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @noformat
* @oncall react_native
* @generated SignedSource<<9cdec2a3b7a46f0a893dd5dc392a5294>>
* @generated SignedSource<<1276c0a64e0ad55f32baa402baf919da>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro-file-map/src/cache/DiskCacheManager.js
Expand All @@ -30,10 +30,7 @@ type DiskCacheConfig = Readonly<{
cacheDirectory?: null | undefined | string;
}>;
export declare class DiskCacheManager implements CacheManager {
constructor(
$$PARAM_0$$: CacheManagerFactoryOptions,
$$PARAM_1$$: DiskCacheConfig,
);
constructor(opts: CacheManagerFactoryOptions, config: DiskCacheConfig);
static getCacheFilePath(
buildParameters: BuildParameters,
cacheFilePrefix?: null | undefined | string,
Expand All @@ -43,7 +40,7 @@ export declare class DiskCacheManager implements CacheManager {
read(): Promise<null | undefined | CacheData>;
write(
getSnapshot: () => CacheData,
$$PARAM_1$$: CacheManagerWriteOptions,
opts: CacheManagerWriteOptions,
): Promise<void>;
end(): Promise<void>;
}
10 changes: 5 additions & 5 deletions packages/metro-file-map/types/flow-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @noformat
* @oncall react_native
* @generated SignedSource<<b3646c81d37188726a1fc27777dcbede>>
* @generated SignedSource<<ffc6f9b096f7d4a23bbd86997a3044d6>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro-file-map/src/flow-types.js
Expand Down Expand Up @@ -80,7 +80,7 @@ export type ChangedFileMetadata = Readonly<{
modifiedTime?: null | undefined | number;
}>;
export type ChangeEvent = Readonly<{
logger: null | undefined | RootPerfLogger;
logger?: null | undefined | RootPerfLogger;
changes: ReadonlyFileSystemChanges<Readonly<ChangedFileMetadata>>;
rootDir: string;
}>;
Expand All @@ -91,7 +91,7 @@ export type ChangeEventMetadata = {
};
export type Console = typeof global.console;
export type CrawlerOptions = {
abortSignal: null | undefined | AbortSignal;
abortSignal?: null | undefined | AbortSignal;
computeSha1: boolean;
console: Console;
extensions: ReadonlyArray<string>;
Expand Down Expand Up @@ -289,8 +289,8 @@ export interface FileSystem {
mixedStartPath: string,
subpath: string,
opts: {
breakOnSegment: null | undefined | string;
invalidatedBy: null | undefined | Set<string>;
breakOnSegment?: null | undefined | string;
invalidatedBy?: null | undefined | Set<string>;
subpathType: 'f' | 'd';
},
): null | undefined | {absolutePath: string; containerRelativePath: string};
Expand Down
4 changes: 2 additions & 2 deletions packages/metro-file-map/types/plugins/HastePlugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @noformat
* @oncall react_native
* @generated SignedSource<<3d1462ab2325a09553e02b69b5de84eb>>
* @generated SignedSource<<d1c8a8bc5a39d65b817f19d70211260b>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro-file-map/src/plugins/HastePlugin.js
Expand Down Expand Up @@ -44,7 +44,7 @@ declare class HastePlugin
readonly name: 'haste';
constructor(options: HasteMapOptions);
initialize(
$$PARAM_0$$: FileMapPluginInitOptions<null, string | null>,
opts: FileMapPluginInitOptions<null, string | null>,
): Promise<void>;
getSerializableSnapshot(): null;
getModule(
Expand Down
4 changes: 2 additions & 2 deletions packages/metro-resolver/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export type ResolutionContext = Readonly<{
* @deprecated, prefer `fileSystemLookup`
*/
doesFileExist: DoesFileExist,
extraNodeModules: ?{[string]: string, ...},
extraNodeModules: ?{[packageName: string]: string, ...},

/** Is resolving for a development bundle. */
dev: boolean,
Expand Down Expand Up @@ -239,6 +239,6 @@ export type CustomResolver = (

export type CustomResolverOptions = {
__proto__: null,
+[string]: unknown,
+[key: string]: unknown,
...
};
Loading
Loading