Skip to content

Commit f3643cc

Browse files
SamChou19815meta-codesync[bot]
authored andcommitted
Adopt modern variance syntax in metro
Summary: ___ Differential Revision: D107108598 fbshipit-source-id: 63a226e5d9e99a6e260cedd41484a5e5131608dc
1 parent e1f4d61 commit f3643cc

66 files changed

Lines changed: 471 additions & 430 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/metro-cache/src/Cache.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import {Logger} from 'metro-core';
2121
* All get/set operations are logged via Metro's logger.
2222
*/
2323
export default class Cache<T> {
24-
+#stores: ReadonlyArray<CacheStore<T>>;
25-
+#hits: WeakMap<Buffer, CacheStore<T>> = new WeakMap();
24+
readonly #stores: ReadonlyArray<CacheStore<T>>;
25+
readonly #hits: WeakMap<Buffer, CacheStore<T>> = new WeakMap();
2626

2727
constructor(stores: ReadonlyArray<CacheStore<T>>) {
2828
this.#stores = stores;

‎packages/metro-cache/src/index.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ export {
3030
};
3131

3232
export interface MetroCache {
33-
+AutoCleanFileStore: typeof AutoCleanFileStore;
34-
+Cache: typeof Cache;
35-
+FileStore: typeof FileStore;
36-
+HttpGetStore: typeof HttpGetStore;
37-
+HttpStore: typeof HttpStore;
38-
+stableHash: typeof stableHash;
33+
readonly AutoCleanFileStore: typeof AutoCleanFileStore;
34+
readonly Cache: typeof Cache;
35+
readonly FileStore: typeof FileStore;
36+
readonly HttpGetStore: typeof HttpGetStore;
37+
readonly HttpStore: typeof HttpStore;
38+
readonly stableHash: typeof stableHash;
3939
}
4040

4141
/**

‎packages/metro-cache/src/stores/AutoCleanFileStore.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ type CleanOptions = Readonly<{
3030
* custom Metro cache that uses watches, hooks get/set, and/or implements LRU.
3131
*/
3232
export default class AutoCleanFileStore<T> extends FileStore<T> {
33-
+#intervalMs: number;
34-
+#cleanupThresholdMs: number;
35-
+#root: string;
33+
readonly #intervalMs: number;
34+
readonly #cleanupThresholdMs: number;
35+
readonly #root: string;
3636

3737
constructor(opts: CleanOptions) {
3838
super({root: opts.root});

‎packages/metro-cache/src/stores/FileStore.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type Options = Readonly<{
2020
}>;
2121

2222
export default class FileStore<T> {
23-
+#root: string;
23+
readonly #root: string;
2424

2525
constructor(options: Options) {
2626
this.#root = options.root;

‎packages/metro-config/src/types.js‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ type TransformerConfigT = {
153153
...JsTransformerConfig,
154154
getTransformOptions: GetTransformOptions,
155155
// TODO(moti): Remove this Meta-internal option from Metro's public config
156-
transformVariants: {+[name: string]: Partial<ExtraTransformOptions>},
156+
transformVariants: {readonly [name: string]: Partial<ExtraTransformOptions>},
157157
publicPath: string,
158158
unstable_workerThreads: boolean,
159159
};
@@ -197,12 +197,14 @@ type ServerConfigT = {
197197

198198
type SymbolicatorConfigT = {
199199
customizeFrame: ({
200-
+file: ?string,
201-
+lineNumber: ?number,
202-
+column: ?number,
203-
+methodName: ?string,
200+
readonly file: ?string,
201+
readonly lineNumber: ?number,
202+
readonly column: ?number,
203+
readonly methodName: ?string,
204204
...
205-
}) => ?{+collapse?: boolean} | Promise<?{+collapse?: boolean}>,
205+
}) =>
206+
| ?{readonly collapse?: boolean}
207+
| Promise<?{readonly collapse?: boolean}>,
206208
customizeStack: (
207209
Array<IntermediateStackFrame>,
208210
unknown,

‎packages/metro-core/src/errors/PackageResolutionError.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export default class PackageResolutionError extends Error {
1919
targetModuleName: string;
2020

2121
constructor(opts: {
22-
+originModulePath: string,
23-
+packageError: InvalidPackageError,
24-
+targetModuleName: string,
22+
readonly originModulePath: string,
23+
readonly packageError: InvalidPackageError,
24+
readonly targetModuleName: string,
2525
}) {
2626
const perr = opts.packageError;
2727
super(

‎packages/metro-file-map/src/Watcher.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ export type HealthCheckResult =
7171
export class Watcher extends EventEmitter {
7272
#activeWatcher: ?string;
7373
#backends: ReadonlyArray<WatcherBackend> = [];
74-
+#instanceId: number;
74+
readonly #instanceId: number;
7575
#nextHealthCheckId: number = 0;
76-
+#options: WatcherOptions;
77-
+#pendingHealthChecks: Map</* basename */ string, /* resolve */ () => void> =
78-
new Map();
76+
readonly #options: WatcherOptions;
77+
readonly #pendingHealthChecks: Map<
78+
/* basename */ string,
79+
/* resolve */ () => void,
80+
> = new Map();
7981

8082
constructor(options: WatcherOptions) {
8183
super();

‎packages/metro-file-map/src/cache/DiskCacheManager.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ const DEFAULT_DIRECTORY = tmpdir();
4242
const DEFAULT_AUTO_SAVE_DEBOUNCE_MS = 5000;
4343

4444
export class DiskCacheManager implements CacheManager {
45-
+#autoSaveOpts: ?AutoSaveOptions;
46-
+#cachePath: string;
45+
readonly #autoSaveOpts: ?AutoSaveOptions;
46+
readonly #cachePath: string;
4747
#debounceTimeout: ?Timeout = null;
4848
#writePromise: Promise<void> = Promise.resolve();
4949
#hasUnwrittenChanges: boolean = false;

‎packages/metro-file-map/src/flow-types.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ export type FileMapPluginInitOptions<
181181
): Iterable<{
182182
baseName: string,
183183
canonicalPath: string,
184-
+pluginData: ?PerFileData,
184+
readonly pluginData: ?PerFileData,
185185
}>,
186186
lookup(
187187
mixedPath: string,
188188
):
189189
| {exists: false}
190-
| {exists: true, type: 'f', +pluginData: PerFileData}
190+
| {exists: true, type: 'f', readonly pluginData: PerFileData}
191191
| {exists: true, type: 'd'},
192192
}>,
193193
pluginState: ?SerializableState,
@@ -215,7 +215,7 @@ export interface FileMapPlugin<
215215
in SerializableState extends void | V8Serializable = void | V8Serializable,
216216
in PerFileData extends void | V8Serializable = void | V8Serializable,
217217
> {
218-
+name: string;
218+
readonly name: string;
219219
initialize(
220220
initOptions: FileMapPluginInitOptions<SerializableState, PerFileData>,
221221
): Promise<void>;
@@ -460,12 +460,12 @@ export interface FileSystemListener {
460460
}
461461

462462
export interface ReadonlyFileSystemChanges<out T = FileMetadata> {
463-
+addedDirectories: Iterable<CanonicalPath>;
464-
+removedDirectories: Iterable<CanonicalPath>;
463+
readonly addedDirectories: Iterable<CanonicalPath>;
464+
readonly removedDirectories: Iterable<CanonicalPath>;
465465

466-
+addedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
467-
+modifiedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
468-
+removedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
466+
readonly addedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
467+
readonly modifiedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
468+
readonly removedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
469469
}
470470

471471
export interface MutableFileSystem extends FileSystem {

‎packages/metro-file-map/src/index.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,18 @@ const WATCHMAN_REQUIRED_CAPABILITIES = [
248248
*/
249249
export default class FileMap extends EventEmitter {
250250
#buildPromise: ?Promise<BuildResult>;
251-
+#cacheManager: CacheManager;
251+
readonly #cacheManager: CacheManager;
252252
#canUseWatchmanPromise: Promise<boolean>;
253253
#changeID: number;
254254
#changeInterval: ?IntervalID;
255-
+#console: Console;
256-
+#crawlerAbortController: AbortController;
257-
+#fileProcessor: FileProcessor;
255+
readonly #console: Console;
256+
readonly #crawlerAbortController: AbortController;
257+
readonly #fileProcessor: FileProcessor;
258258
#healthCheckInterval: ?IntervalID;
259-
+#options: InternalOptions;
260-
+#pathUtils: RootPathUtils;
261-
+#plugins: ReadonlyArray<IndexedPlugin>;
262-
+#startupPerfLogger: ?PerfLogger;
259+
readonly #options: InternalOptions;
260+
readonly #pathUtils: RootPathUtils;
261+
readonly #plugins: ReadonlyArray<IndexedPlugin>;
262+
readonly #startupPerfLogger: ?PerfLogger;
263263
#watcher: ?Watcher;
264264

265265
static create(options: InputOptions): FileMap {

0 commit comments

Comments
 (0)