Skip to content

Commit

Permalink
Flow types: strengthen change event guarantee, fix missing type coverage
Browse files Browse the repository at this point in the history
Summary:
`metadata` on file change events out of metro-file-map is typed as optional and nullable, but in fact is always set within metro-file-map, and DeltaCalculator would throw if it wasn’t - Flow didn’t pick that up only because a $FlowFixMe hid the problem.

This is a Flow-only change to reflect that and improve coverage.

Changelog: Internal

Reviewed By: huntie

Differential Revision: D67259536
  • Loading branch information
robhogan authored and facebook-github-bot committed Dec 16, 2024
1 parent 91e5dfc commit 250e344
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/metro-file-map/src/flow-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export type DuplicatesIndex = Map<string, Map<string, DuplicatesSet>>;

export type EventsQueue = Array<{
filePath: Path,
metadata?: ?ChangeEventMetadata,
metadata: ChangeEventMetadata,
type: string,
}>;

Expand Down
17 changes: 3 additions & 14 deletions packages/metro/src/DeltaBundler/DeltaCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import type {DeltaResult, Options} from './types.flow';
import type {RootPerfLogger} from 'metro-config';
import type {ChangeEventMetadata} from 'metro-file-map';
import type {ChangeEvent} from 'metro-file-map';

import {Graph} from './Graph';
import path from 'path';
Expand Down Expand Up @@ -173,9 +173,7 @@ class DeltaCalculator<T> extends EventEmitter {
return this._graph;
}

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
_handleMultipleFileChanges = changeEvent => {
_handleMultipleFileChanges = (changeEvent: ChangeEvent) => {
changeEvent.eventsQueue.forEach(eventInfo => {
this._handleFileChange(eventInfo, changeEvent.logger);
});
Expand All @@ -187,16 +185,7 @@ class DeltaCalculator<T> extends EventEmitter {
* when the delta needs to be calculated.
*/
_handleFileChange = (
{
type,
filePath,
metadata,
}: {
type: string,
filePath: string,
metadata: ChangeEventMetadata,
...
},
{type, filePath, metadata}: ChangeEvent['eventsQueue'][number],
logger: ?RootPerfLogger,
): mixed => {
debug('Handling %s: %s (type: %s)', type, filePath, metadata.type);
Expand Down

0 comments on commit 250e344

Please sign in to comment.