Skip to content

Commit e890c99

Browse files
skinssharkfacebook-github-bot
authored andcommitted
Back out "Process files before adding them to FileSystem"
Summary: Back out "[metro] Process files before adding them to `FileSystem`" Reviewed By: yungsters Differential Revision: D42909065 fbshipit-source-id: e4bfd6c7fc599b0fdfc1d95831f4cc20edcf8d94
1 parent 1a81060 commit e890c99

File tree

4 files changed

+125
-86
lines changed

4 files changed

+125
-86
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
Glob,
1515
MutableFileSystem,
1616
Path,
17+
VisitMetadata,
1718
} from './flow-types';
1819

1920
import H from './constants';
@@ -50,6 +51,33 @@ export default class HasteFS implements MutableFileSystem {
5051
this.#files.set(this._normalizePath(filePath), metadata);
5152
}
5253

54+
setVisitMetadata(
55+
filePath: Path,
56+
visitResult: $ReadOnly<VisitMetadata>,
57+
): void {
58+
const metadata = this._getFileData(filePath);
59+
if (!metadata) {
60+
throw new Error('Visited file not found in file map: ' + filePath);
61+
}
62+
metadata[H.VISITED] = 1;
63+
64+
if (visitResult.hasteId != null) {
65+
metadata[H.ID] = visitResult.hasteId;
66+
}
67+
68+
if ('sha1' in visitResult) {
69+
metadata[H.SHA1] = visitResult.sha1;
70+
}
71+
72+
if (visitResult.dependencies != null) {
73+
metadata[H.DEPENDENCIES] = visitResult.dependencies;
74+
}
75+
76+
if (visitResult.symlinkTarget != null) {
77+
metadata[H.SYMLINK] = visitResult.symlinkTarget;
78+
}
79+
}
80+
5381
getSerializableSnapshot(): FileData {
5482
return new Map(
5583
Array.from(this.#files.entries(), ([k, v]: [Path, FileMetaData]) => [
@@ -69,6 +97,16 @@ export default class HasteFS implements MutableFileSystem {
6997
return (fileMetadata && fileMetadata[H.SIZE]) ?? null;
7098
}
7199

100+
getSymlinkTarget(file: Path): ?string {
101+
const fileMetadata = this._getFileData(file);
102+
if (fileMetadata == null) {
103+
return null;
104+
}
105+
return typeof fileMetadata[H.SYMLINK] === 'string'
106+
? fileMetadata[H.SYMLINK]
107+
: null;
108+
}
109+
72110
getType(file: Path): ?('f' | 'l') {
73111
const fileMetadata = this._getFileData(file);
74112
if (fileMetadata == null) {

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,20 +1491,17 @@ describe('HasteMap', () => {
14911491

14921492
hm_it('does not emit duplicate change events', async hm => {
14931493
const e = mockEmitters[path.join('/', 'project', 'fruits')];
1494-
mockFs[path.join('/', 'project', 'fruits', 'Tomato.js')] = `
1495-
// Tomato!
1496-
`;
14971494
e.emit(
14981495
'all',
14991496
'change',
1500-
'Tomato.js',
1497+
'tomato.js',
15011498
path.join('/', 'project', 'fruits'),
15021499
MOCK_CHANGE_FILE,
15031500
);
15041501
e.emit(
15051502
'all',
15061503
'change',
1507-
'Tomato.js',
1504+
'tomato.js',
15081505
path.join('/', 'project', 'fruits'),
15091506
MOCK_CHANGE_FILE,
15101507
);
@@ -1724,11 +1721,8 @@ describe('HasteMap', () => {
17241721
);
17251722
});
17261723

1727-
hm_it('ignore directory events (even with file-ish names)', async hm => {
1724+
hm_it('ignore directories', async hm => {
17281725
const e = mockEmitters[path.join('/', 'project', 'fruits')];
1729-
mockFs[path.join('/', 'project', 'fruits', 'tomato.js', 'index.js')] = `
1730-
// Tomato!
1731-
`;
17321726
e.emit(
17331727
'all',
17341728
'change',
@@ -1739,8 +1733,8 @@ describe('HasteMap', () => {
17391733
e.emit(
17401734
'all',
17411735
'change',
1742-
path.join('tomato.js', 'index.js'),
1743-
path.join('/', 'project', 'fruits'),
1736+
'tomato.js',
1737+
path.join('/', 'project', 'fruits', 'tomato.js', 'index.js'),
17441738
MOCK_CHANGE_FILE,
17451739
);
17461740
const {eventsQueue} = await waitForItToChange(hm);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export interface FileSystem {
161161
getModuleName(file: Path): ?string;
162162
getSerializableSnapshot(): FileData;
163163
getSha1(file: Path): ?string;
164+
getSymlinkTarget(file: Path): ?string;
164165
getType(file: Path): ?('f' | 'l');
165166

166167
matchFiles(pattern: RegExp | string): Array<Path>;
@@ -215,6 +216,7 @@ export interface MutableFileSystem extends FileSystem {
215216
remove(filePath: Path): void;
216217
addOrModify(filePath: Path, fileMetadata: FileMetaData): void;
217218
bulkAddOrModify(addedOrModifiedFiles: FileData): void;
219+
setVisitMetadata(filePath: Path, metadata: $ReadOnly<VisitMetadata>): void;
218220
}
219221

220222
export type Path = string;
@@ -236,6 +238,13 @@ export type ReadOnlyRawModuleMap = $ReadOnly<{
236238
mocks: $ReadOnlyMap<string, Path>,
237239
}>;
238240

241+
export type VisitMetadata = {
242+
hasteId?: string,
243+
sha1?: ?string,
244+
dependencies?: string,
245+
symlinkTarget?: string,
246+
};
247+
239248
export type WatchmanClockSpec =
240249
| string
241250
| $ReadOnly<{scm: $ReadOnly<{'mergebase-with': string}>}>;

0 commit comments

Comments
 (0)