Repository navigation
metro-file-map: Give plugins getOrComputeFileData, record observed content - #1951
Conversation
79d24cb to
f249690
Compare
71974ca to
94702e2
Compare
94702e2 to
9e9232f
Compare
9e9232f to
2204ff8
Compare
2204ff8 to
1f33985
Compare
1f33985 to
b559e11
Compare
b559e11 to
4f7c473
Compare
a8afbec to
3837704
Compare
…ntent #1944 lets `FileSystem.lookup` record what it observed, but a file found only goes in `existence`. A plugin's per-file data is derived from the file's contents, so reading it should be recorded in `content`, which is also invalidated by modification. Plugins currently read their data from `lookup()`'s `pluginData`, and a lazy plugin calls `processFile` when that's `undefined`. Recording on either wouldn't be enough - on a warm start, or any read after the first, the data is already stored and `processFile` never runs. This replaces both with `getOrComputeFileData(path, observations?)`, on plugin init options and `FileDataPlugin`. It returns the stored data, or for a lazy plugin runs the worker in-band on a miss, and records the file in `content` either way. A missing path or directory is a result rather than an error, so a caller falling back to something else has still recorded it. Plugin `lookup` no longer returns data, so `getOrComputeFileData` is the only per-file read. The motivation is `package.json`, which Metro currently reads with `fs` outside the file map, leaving nothing to record: https://github.com/react/metro/blob/32ff3c9993384580ca40310f3c4024e5f250837b/packages/metro/src/node-haste/PackageCache.js#L24-L25 Changelog: Internal Test plan: New unit tests. Nothing passes observations to this yet, so it's only reachable from tests until the `package.json` plugin follows.
3837704 to
e8ab103
Compare
|
What if the observations created via both shouldn't we then move the file path from "existence" to "content"? |
7d694df to
e8ab103
Compare
Compute whether a plugin is lazy once per plugin at initialization, rather than on every miss in getOrComputeFileData. A non-lazy plugin misses on every read of a file its filter excludes. Correct the TreeFS comment that said a path belongs in only one of existence and content, and document on Observations.content that a path may be in both without changing what invalidates the result.
Yeah good question - there's an argument for that, but I think it's easiest + most performant if we treat all of these sets as write-only during file map access. I've change a comment that suggested they were mutually exclusive. |
TreeFS.lookup now returns the canonicalPath it found, and getOrComputeFileData adds it to observations.content after a plain lookup. This removes lookupContent, leaving TreeFS with one lookup method. A file read is now recorded in existence as well as content, which is redundant but doesn't change what invalidates the result.
|
Modified this a bit further - |
#1944 lets
FileSystem.lookuprecord what it observed, but a file found only goes inexistence. A plugin's per-file data is derived from the file's contents, so reading it should be recorded incontent, which is also invalidated by modification.Plugins currently read their data from
lookup()'spluginData, and a lazy plugin callsprocessFilewhen that'sundefined. Recording on either wouldn't be enough - on a warm start, or any read after the first, the data is already stored andprocessFilenever runs.This replaces both with
getOrComputeFileData(path, observations?), on plugin init options andFileDataPlugin. It returns the stored data, or for a lazy plugin runs the worker in-band on a miss, and records the file incontenteither way. A missing path or directory is a result rather than an error, so a caller falling back to something else has still recorded it. Pluginlookupno longer returns data, sogetOrComputeFileDatais the only per-file read.The motivation is
package.json, which Metro currently reads withfsoutside the file map, leaving nothing to record:metro/packages/metro/src/node-haste/PackageCache.js
Lines 24 to 25 in 32ff3c9
Changelog: Internal
Test plan:
New unit tests. Nothing passes observations to this yet, so it's only reachable from tests until the
package.jsonplugin follows.