Skip to content
Open
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
1 change: 0 additions & 1 deletion packages/metro-file-map/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ interface FileSystem_2 {
filesToStat: Map<string, number>;
};
getOrComputeSha1(file: Path): Promise<null | undefined | {sha1: string; content?: Buffer | undefined}>;
getSerializableSnapshot(): CacheData['fileSystemData'];
getSha1(file: Path): null | undefined | string;
hierarchicalLookup(
mixedStartPath: string,
Expand Down
6 changes: 2 additions & 4 deletions packages/metro-file-map/src/flow-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,6 @@ export interface FileSystem {
removedFiles: Set<string>,
filesToStat: Map<string, number>,
};
// A copy of the file system's data, which later changes don't affect.
getSerializableSnapshot(): CacheData['fileSystemData'];
getSha1(file: Path): ?string;
getOrComputeSha1(file: Path): Promise<?{sha1: string, content?: Buffer}>;

Expand Down Expand Up @@ -610,8 +608,8 @@ export interface ReadonlyFileSystemChanges<out T = FileMetadata> {
export interface MutableFileSystem extends FileSystem {
/**
* The file system's own data, not a copy, so it changes with the file
* system. Serialize it synchronously (see `CacheManager.write`), or use
* `getSerializableSnapshot()` for a copy.
* system. Serialize it synchronously (see `CacheManager.write`), or copy it
* to keep it.
*/
getSerializableState(): CacheData['fileSystemData'];
remove(filePath: Path, listener?: FileSystemListener): void;
Expand Down
16 changes: 0 additions & 16 deletions packages/metro-file-map/src/lib/TreeFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ export default class TreeFS implements MutableFileSystem {
}
}

getSerializableSnapshot(): CacheData['fileSystemData'] {
return this.#cloneTree(this.#rootNode);
}

getSerializableState(): CacheData['fileSystemData'] {
return this.#rootNode;
}
Expand Down Expand Up @@ -1554,16 +1550,4 @@ export default class TreeFS implements MutableFileSystem {
}
return result.node;
}

#cloneTree(root: DirectoryNode): DirectoryNode {
const clone: DirectoryNode = new Map();
for (const [name, node] of root) {
if (isDirectory(node)) {
clone.set(name, this.#cloneTree(node));
} else {
clone.set(name, [...node]);
}
}
return clone;
}
}
13 changes: 5 additions & 8 deletions packages/metro-file-map/src/lib/__tests__/TreeFS-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,18 @@ describe.each([['win32'], ['posix']])('TreeFS on %s', platform => {
const {deserialize, serialize} = require('node:v8');
const deserialized = TreeFS.fromDeserializedSnapshot({
rootDir: p('/project'),
fileSystemData: deserialize(serialize(tfs.getSerializableSnapshot())),
fileSystemData: deserialize(serialize(tfs.getSerializableState())),
processFile: () => {
throw new Error('Not implemented');
},
});
expect(deserialized.exists(p('/project/foo/another.js'))).toBe(true);
});

test('getSerializableSnapshot returns a copy, getSerializableState does not', () => {
const snapshot = tfs.getSerializableSnapshot();
test('getSerializableState returns the live tree, not a copy', () => {
const state = tfs.getSerializableState();
expect(snapshot).toEqual(state);
tfs.addOrModify(p('/project/foo/new.js'), [0, 1, 0, null, 0, null]);
expect(snapshot).not.toEqual(tfs.getSerializableSnapshot());
expect(state).toEqual(tfs.getSerializableSnapshot());
expect(state).toEqual(tfs.getSerializableState());
});

test('implements linkStats()', () => {
Expand Down Expand Up @@ -2202,13 +2199,13 @@ describe('snapshot portability between operating systems', () => {
processFile: () => {
throw new Error('Not implemented');
},
}).getSerializableSnapshot();
}).getSerializableState();

const TreeFSTo = loadTreeFS(to);
const loaded = TreeFSTo.fromDeserializedSnapshot({
rootDir: rootFor(to),
// Snapshots are typed opaquely for the cache; this one came from
// getSerializableSnapshot, so it is a DirectoryNode.
// getSerializableState, so it is a DirectoryNode.
// $FlowFixMe[incompatible-type]
fileSystemData: snapshot,
processFile: () => {
Expand Down
Loading