diff --git a/packages/metro-file-map/API.md b/packages/metro-file-map/API.md index f9415e41fe..b956aa0d17 100644 --- a/packages/metro-file-map/API.md +++ b/packages/metro-file-map/API.md @@ -182,7 +182,6 @@ interface FileSystem_2 { filesToStat: Map; }; getOrComputeSha1(file: Path): Promise; - getSerializableSnapshot(): CacheData['fileSystemData']; getSha1(file: Path): null | undefined | string; hierarchicalLookup( mixedStartPath: string, diff --git a/packages/metro-file-map/src/flow-types.js b/packages/metro-file-map/src/flow-types.js index 6dbb969016..695938e0cd 100644 --- a/packages/metro-file-map/src/flow-types.js +++ b/packages/metro-file-map/src/flow-types.js @@ -394,8 +394,6 @@ export interface FileSystem { removedFiles: Set, filesToStat: Map, }; - // 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; @@ -610,8 +608,8 @@ export interface ReadonlyFileSystemChanges { 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; diff --git a/packages/metro-file-map/src/lib/TreeFS.js b/packages/metro-file-map/src/lib/TreeFS.js index c05a8088e8..0593f85fa5 100644 --- a/packages/metro-file-map/src/lib/TreeFS.js +++ b/packages/metro-file-map/src/lib/TreeFS.js @@ -206,10 +206,6 @@ export default class TreeFS implements MutableFileSystem { } } - getSerializableSnapshot(): CacheData['fileSystemData'] { - return this.#cloneTree(this.#rootNode); - } - getSerializableState(): CacheData['fileSystemData'] { return this.#rootNode; } @@ -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; - } } diff --git a/packages/metro-file-map/src/lib/__tests__/TreeFS-test.js b/packages/metro-file-map/src/lib/__tests__/TreeFS-test.js index 243a62f584..1fe26c2ea1 100644 --- a/packages/metro-file-map/src/lib/__tests__/TreeFS-test.js +++ b/packages/metro-file-map/src/lib/__tests__/TreeFS-test.js @@ -111,7 +111,7 @@ 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'); }, @@ -119,13 +119,10 @@ describe.each([['win32'], ['posix']])('TreeFS on %s', platform => { 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()', () => { @@ -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: () => {