Skip to content

Commit 1f3e259

Browse files
robhoganmeta-codesync[bot]
authored andcommitted
metro-file-map: Make plugin.bulkUpdate synchronous
Summary: There's no need for this to be async and making it synchronous simplifies some upcoming work Changelog: Internal Reviewed By: vzaidman Differential Revision: D92007667 fbshipit-source-id: 7e4f764d5750de45041b189e5518e5c081ee8cf4
1 parent 6181565 commit 1f3e259

11 files changed

Lines changed: 22 additions & 29 deletions

File tree

packages/metro-file-map/src/cache/__tests__/DiskCacheManager-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('cacheManager', () => {
105105
let pluginCacheKey = 'foo';
106106
const plugin: FileMapPlugin<> = {
107107
name: 'foo',
108-
async bulkUpdate() {},
108+
bulkUpdate() {},
109109
async initialize() {},
110110
assertValid() {},
111111
getSerializableSnapshot() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export interface FileMapPlugin<
213213
initOptions: FileMapPluginInitOptions<SerializableState, PerFileData>,
214214
): Promise<void>;
215215
assertValid(): void;
216-
bulkUpdate(delta: FileMapDelta<?PerFileData>): Promise<void>;
216+
bulkUpdate(delta: FileMapDelta<?PerFileData>): void;
217217
getSerializableSnapshot(): SerializableState;
218218
onRemovedFile(relativeFilePath: string, pluginData: ?PerFileData): void;
219219
onNewOrModifiedFile(relativeFilePath: string, pluginData: ?PerFileData): void;

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -667,21 +667,16 @@ export default class FileMap extends EventEmitter {
667667
this.#startupPerfLogger?.point('applyFileDelta_add_end');
668668

669669
this.#startupPerfLogger?.point('applyFileDelta_updatePlugins_start');
670-
671-
await Promise.all([
672-
plugins.map(({plugin, dataIdx}) => {
673-
const mapFn: (
674-
[CanonicalPath, FileMetadata],
675-
) => [CanonicalPath, unknown] =
676-
dataIdx != null
677-
? ([relativePath, fileData]) => [relativePath, fileData[dataIdx]]
678-
: ([relativePath, fileData]) => [relativePath, null];
679-
return plugin.bulkUpdate({
680-
addedOrModified: mapIterator(changedFiles.entries(), mapFn),
681-
removed: mapIterator(removed.values(), mapFn),
682-
});
683-
}),
684-
]);
670+
plugins.forEach(({plugin, dataIdx}) => {
671+
const mapFn: ([CanonicalPath, FileMetadata]) => [CanonicalPath, unknown] =
672+
dataIdx != null
673+
? ([relativePath, fileData]) => [relativePath, fileData[dataIdx]]
674+
: ([relativePath, fileData]) => [relativePath, null];
675+
plugin.bulkUpdate({
676+
addedOrModified: mapIterator(changedFiles.entries(), mapFn),
677+
removed: mapIterator(removed.values(), mapFn),
678+
});
679+
});
685680
this.#startupPerfLogger?.point('applyFileDelta_updatePlugins_end');
686681
this.#startupPerfLogger?.point('applyFileDelta_end');
687682
}

packages/metro-file-map/src/plugins/DependencyPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default class DependencyPlugin
6464
return null;
6565
}
6666

67-
async bulkUpdate(delta: FileMapDelta<?ReadonlyArray<string>>): Promise<void> {
67+
bulkUpdate(delta: FileMapDelta<?ReadonlyArray<string>>): void {
6868
// No-op: Worker already populated plugin data
6969
// Plugin data is write-only from worker
7070
}

packages/metro-file-map/src/plugins/HastePlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export default class HastePlugin
237237
);
238238
}
239239

240-
async bulkUpdate(delta: FileMapDelta<?string>): Promise<void> {
240+
bulkUpdate(delta: FileMapDelta<?string>): void {
241241
// Process removals first so that moves aren't treated as duplicates.
242242
for (const [normalPath, maybeHasteId] of delta.removed) {
243243
this.onRemovedFile(normalPath, maybeHasteId);

packages/metro-file-map/src/plugins/MockPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default class MockPlugin
7979
this.#raw = pluginState;
8080
} else {
8181
// Otherwise, traverse all files to rebuild
82-
await this.bulkUpdate({
82+
this.bulkUpdate({
8383
addedOrModified: [
8484
...files.fileIterator({
8585
includeNodeModules: false,
@@ -102,7 +102,7 @@ export default class MockPlugin
102102
);
103103
}
104104

105-
async bulkUpdate(delta: FileMapDelta<>): Promise<void> {
105+
bulkUpdate(delta: FileMapDelta<>): void {
106106
// Process removals first so that moves aren't treated as duplicates.
107107
for (const [relativeFilePath] of delta.removed) {
108108
this.onRemovedFile(relativeFilePath);

packages/metro-file-map/src/plugins/haste/__tests__/HastePlugin-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ describe.each([['win32'], ['posix']])('HastePlugin on %s', platform => {
141141
expect(hasteMap.getModule('Bar')).not.toBeNull();
142142
});
143143

144-
test('fixes duplicates, adds and removes modules', async () => {
144+
test('fixes duplicates, adds and removes modules', () => {
145145
expect(() => hasteMap.getModule('Duplicate')).toThrow(
146146
DuplicateHasteCandidatesError,
147147
);
148-
await hasteMap.bulkUpdate({
148+
hasteMap.bulkUpdate({
149149
removed: [
150150
[p('project/Duplicate.js'), 'Duplicate'],
151151
[p('project/Foo.js'), 'NameForFoo'],

packages/metro-file-map/types/flow-types.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ export interface FileMapPlugin<
176176
initOptions: FileMapPluginInitOptions<SerializableState, PerFileData>,
177177
): Promise<void>;
178178
assertValid(): void;
179-
bulkUpdate(
180-
delta: FileMapDelta<null | undefined | PerFileData>,
181-
): Promise<void>;
179+
bulkUpdate(delta: FileMapDelta<null | undefined | PerFileData>): void;
182180
getSerializableSnapshot(): SerializableState;
183181
onRemovedFile(
184182
relativeFilePath: string,

packages/metro-file-map/types/plugins/DependencyPlugin.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ declare class DependencyPlugin
3434
getSerializableSnapshot(): null;
3535
bulkUpdate(
3636
delta: FileMapDelta<null | undefined | ReadonlyArray<string>>,
37-
): Promise<void>;
37+
): void;
3838
onNewOrModifiedFile(
3939
relativeFilePath: string,
4040
pluginData: null | undefined | ReadonlyArray<string>,

packages/metro-file-map/types/plugins/HastePlugin.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ declare class HastePlugin
5252
platform: null | undefined | string,
5353
_supportsNativePlatform?: null | undefined | boolean,
5454
): null | undefined | Path;
55-
bulkUpdate(delta: FileMapDelta<null | undefined | string>): Promise<void>;
55+
bulkUpdate(delta: FileMapDelta<null | undefined | string>): void;
5656
onNewOrModifiedFile(
5757
relativeFilePath: string,
5858
id: null | undefined | string,

0 commit comments

Comments
 (0)