metro-file-map 0.81.1 → 0.81.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -2
- package/src/cache/DiskCacheManager.d.ts +4 -3
- package/src/cache/DiskCacheManager.js +71 -13
- package/src/cache/DiskCacheManager.js.flow +91 -17
- package/src/flow-types.d.ts +38 -5
- package/src/flow-types.js.flow +105 -12
- package/src/index.js +217 -216
- package/src/index.js.flow +257 -288
- package/src/lib/FileProcessor.js +164 -0
- package/src/lib/FileProcessor.js.flow +243 -0
- package/src/lib/TreeFS.js +39 -2
- package/src/lib/TreeFS.js.flow +56 -2
- package/src/{lib/MutableHasteMap.js → plugins/HastePlugin.js} +43 -14
- package/src/{lib/MutableHasteMap.js.flow → plugins/HastePlugin.js.flow} +57 -29
- package/src/plugins/MockPlugin.js +171 -0
- package/src/{lib/MockMap.js.flow → plugins/MockPlugin.js.flow} +82 -26
- package/src/{lib → plugins/haste}/DuplicateHasteCandidatesError.js +1 -1
- package/src/{lib → plugins/haste}/DuplicateHasteCandidatesError.js.flow +2 -2
- package/src/{lib → plugins/haste}/HasteConflictsError.js.flow +1 -1
- package/src/{lib → plugins/haste}/computeConflicts.js +2 -2
- package/src/{lib → plugins/haste}/computeConflicts.js.flow +3 -3
- package/src/watchers/WatchmanWatcher.js +13 -4
- package/src/watchers/WatchmanWatcher.js.flow +14 -4
- package/src/worker.js +14 -21
- package/src/worker.js.flow +5 -16
- package/src/lib/MockMap.js +0 -128
- /package/src/{lib → plugins/haste}/HasteConflictsError.js +0 -0
- /package/src/{lib → plugins/haste}/getPlatformExtension.js +0 -0
- /package/src/{lib → plugins/haste}/getPlatformExtension.js.flow +0 -0
- /package/src/{getMockName.js → plugins/mocks/getMockName.js} +0 -0
- /package/src/{getMockName.js.flow → plugins/mocks/getMockName.js.flow} +0 -0
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro-file-map",
|
|
3
|
-
"version": "0.81.
|
|
3
|
+
"version": "0.81.2",
|
|
4
4
|
"description": "[Experimental] - 🚇 File crawling, watching and mapping for Metro",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.js",
|
|
8
|
+
"./package.json": "./package.json",
|
|
9
|
+
"./private/*": "./src/*.js",
|
|
10
|
+
"./src": "./src/index.js",
|
|
11
|
+
"./src/*.js": "./src/*.js",
|
|
12
|
+
"./src/*": "./src/*.js"
|
|
13
|
+
},
|
|
6
14
|
"repository": {
|
|
7
15
|
"type": "git",
|
|
8
16
|
"url": "git@github.com:facebook/metro.git"
|
|
@@ -18,7 +26,7 @@
|
|
|
18
26
|
"flow-enums-runtime": "^0.0.6",
|
|
19
27
|
"graceful-fs": "^4.2.4",
|
|
20
28
|
"invariant": "^2.2.4",
|
|
21
|
-
"jest-worker": "^29.
|
|
29
|
+
"jest-worker": "^29.7.0",
|
|
22
30
|
"micromatch": "^4.0.4",
|
|
23
31
|
"nullthrows": "^1.1.1",
|
|
24
32
|
"walker": "^1.0.7"
|
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
BuildParameters,
|
|
13
13
|
CacheData,
|
|
14
14
|
CacheManager,
|
|
15
|
-
|
|
15
|
+
CacheManagerWriteOptions,
|
|
16
16
|
} from '../flow-types';
|
|
17
17
|
|
|
18
18
|
export interface DiskCacheConfig {
|
|
@@ -31,7 +31,8 @@ export class DiskCacheManager implements CacheManager {
|
|
|
31
31
|
getCacheFilePath(): string;
|
|
32
32
|
read(): Promise<CacheData | null>;
|
|
33
33
|
write(
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
getSnapshot: () => CacheData,
|
|
35
|
+
opts: CacheManagerWriteOptions,
|
|
36
36
|
): Promise<void>;
|
|
37
|
+
end(): Promise<void>;
|
|
37
38
|
}
|
|
@@ -7,22 +7,42 @@ exports.DiskCacheManager = void 0;
|
|
|
7
7
|
var _rootRelativeCacheKeys = _interopRequireDefault(
|
|
8
8
|
require("../lib/rootRelativeCacheKeys")
|
|
9
9
|
);
|
|
10
|
-
var
|
|
10
|
+
var _fs = require("fs");
|
|
11
11
|
var _os = require("os");
|
|
12
12
|
var _path = _interopRequireDefault(require("path"));
|
|
13
|
+
var _timers = require("timers");
|
|
13
14
|
var _v = require("v8");
|
|
14
15
|
function _interopRequireDefault(e) {
|
|
15
16
|
return e && e.__esModule ? e : { default: e };
|
|
16
17
|
}
|
|
18
|
+
const debug = require("debug")("Metro:FileMapCache");
|
|
17
19
|
const DEFAULT_PREFIX = "metro-file-map";
|
|
18
20
|
const DEFAULT_DIRECTORY = (0, _os.tmpdir)();
|
|
21
|
+
const DEFAULT_AUTO_SAVE_DEBOUNCE_MS = 5000;
|
|
19
22
|
class DiskCacheManager {
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
#autoSaveOpts;
|
|
24
|
+
#cachePath;
|
|
25
|
+
#debounceTimeout = null;
|
|
26
|
+
#writePromise = Promise.resolve();
|
|
27
|
+
#hasUnwrittenChanges = false;
|
|
28
|
+
#tryWrite;
|
|
29
|
+
#stopListening;
|
|
30
|
+
constructor(
|
|
31
|
+
{ buildParameters },
|
|
32
|
+
{ autoSave = {}, cacheDirectory, cacheFilePrefix }
|
|
33
|
+
) {
|
|
34
|
+
this.#cachePath = DiskCacheManager.getCacheFilePath(
|
|
22
35
|
buildParameters,
|
|
23
36
|
cacheFilePrefix,
|
|
24
37
|
cacheDirectory
|
|
25
38
|
);
|
|
39
|
+
if (autoSave) {
|
|
40
|
+
const { debounceMs = DEFAULT_AUTO_SAVE_DEBOUNCE_MS } =
|
|
41
|
+
autoSave === true ? {} : autoSave;
|
|
42
|
+
this.#autoSaveOpts = {
|
|
43
|
+
debounceMs,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
26
46
|
}
|
|
27
47
|
static getCacheFilePath(buildParameters, cacheFilePrefix, cacheDirectory) {
|
|
28
48
|
const { rootDirHash, relativeConfigHash } = (0,
|
|
@@ -35,13 +55,11 @@ class DiskCacheManager {
|
|
|
35
55
|
);
|
|
36
56
|
}
|
|
37
57
|
getCacheFilePath() {
|
|
38
|
-
return this
|
|
58
|
+
return this.#cachePath;
|
|
39
59
|
}
|
|
40
60
|
async read() {
|
|
41
61
|
try {
|
|
42
|
-
return (0, _v.deserialize)(
|
|
43
|
-
(0, _gracefulFs.readFileSync)(this._cachePath)
|
|
44
|
-
);
|
|
62
|
+
return (0, _v.deserialize)(await _fs.promises.readFile(this.#cachePath));
|
|
45
63
|
} catch (e) {
|
|
46
64
|
if (e?.code === "ENOENT") {
|
|
47
65
|
return null;
|
|
@@ -49,13 +67,53 @@ class DiskCacheManager {
|
|
|
49
67
|
throw e;
|
|
50
68
|
}
|
|
51
69
|
}
|
|
52
|
-
async write(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
70
|
+
async write(
|
|
71
|
+
getSnapshot,
|
|
72
|
+
{ changedSinceCacheRead, eventSource, onWriteError }
|
|
73
|
+
) {
|
|
74
|
+
const tryWrite = (this.#tryWrite = () => {
|
|
75
|
+
this.#writePromise = this.#writePromise
|
|
76
|
+
.then(async () => {
|
|
77
|
+
if (!this.#hasUnwrittenChanges) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const data = getSnapshot();
|
|
81
|
+
this.#hasUnwrittenChanges = false;
|
|
82
|
+
await _fs.promises.writeFile(
|
|
83
|
+
this.#cachePath,
|
|
84
|
+
(0, _v.serialize)(data)
|
|
85
|
+
);
|
|
86
|
+
debug("Written cache to %s", this.#cachePath);
|
|
87
|
+
})
|
|
88
|
+
.catch(onWriteError);
|
|
89
|
+
return this.#writePromise;
|
|
90
|
+
});
|
|
91
|
+
if (this.#autoSaveOpts) {
|
|
92
|
+
const autoSave = this.#autoSaveOpts;
|
|
93
|
+
this.#stopListening?.();
|
|
94
|
+
this.#stopListening = eventSource.onChange(() => {
|
|
95
|
+
this.#hasUnwrittenChanges = true;
|
|
96
|
+
if (this.#debounceTimeout) {
|
|
97
|
+
this.#debounceTimeout.refresh();
|
|
98
|
+
} else {
|
|
99
|
+
this.#debounceTimeout = (0, _timers.setTimeout)(
|
|
100
|
+
() => tryWrite(),
|
|
101
|
+
autoSave.debounceMs
|
|
102
|
+
).unref();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (changedSinceCacheRead) {
|
|
107
|
+
this.#hasUnwrittenChanges = true;
|
|
108
|
+
await tryWrite();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async end() {
|
|
112
|
+
if (this.#debounceTimeout) {
|
|
113
|
+
(0, _timers.clearTimeout)(this.#debounceTimeout);
|
|
58
114
|
}
|
|
115
|
+
this.#stopListening?.();
|
|
116
|
+
await this.#tryWrite?.();
|
|
59
117
|
}
|
|
60
118
|
}
|
|
61
119
|
exports.DiskCacheManager = DiskCacheManager;
|
|
@@ -12,38 +12,59 @@
|
|
|
12
12
|
import type {
|
|
13
13
|
BuildParameters,
|
|
14
14
|
CacheData,
|
|
15
|
-
CacheDelta,
|
|
16
15
|
CacheManager,
|
|
16
|
+
CacheManagerFactoryOptions,
|
|
17
|
+
CacheManagerWriteOptions,
|
|
17
18
|
} from '../flow-types';
|
|
18
19
|
|
|
19
20
|
import rootRelativeCacheKeys from '../lib/rootRelativeCacheKeys';
|
|
20
|
-
import {
|
|
21
|
+
import {promises as fsPromises} from 'fs';
|
|
21
22
|
import {tmpdir} from 'os';
|
|
22
23
|
import path from 'path';
|
|
24
|
+
import {Timeout, clearTimeout, setTimeout} from 'timers';
|
|
23
25
|
import {deserialize, serialize} from 'v8';
|
|
24
26
|
|
|
27
|
+
const debug = require('debug')('Metro:FileMapCache');
|
|
28
|
+
|
|
29
|
+
type AutoSaveOptions = $ReadOnly<{
|
|
30
|
+
debounceMs: number,
|
|
31
|
+
}>;
|
|
32
|
+
|
|
25
33
|
type DiskCacheConfig = {
|
|
26
|
-
|
|
34
|
+
autoSave?: Partial<AutoSaveOptions> | boolean,
|
|
27
35
|
cacheFilePrefix?: ?string,
|
|
28
36
|
cacheDirectory?: ?string,
|
|
29
37
|
};
|
|
30
38
|
|
|
31
39
|
const DEFAULT_PREFIX = 'metro-file-map';
|
|
32
40
|
const DEFAULT_DIRECTORY = tmpdir();
|
|
41
|
+
const DEFAULT_AUTO_SAVE_DEBOUNCE_MS = 5000;
|
|
33
42
|
|
|
34
43
|
export class DiskCacheManager implements CacheManager {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
+#autoSaveOpts: ?AutoSaveOptions;
|
|
45
|
+
+#cachePath: string;
|
|
46
|
+
#debounceTimeout: ?Timeout = null;
|
|
47
|
+
#writePromise: Promise<void> = Promise.resolve();
|
|
48
|
+
#hasUnwrittenChanges: boolean = false;
|
|
49
|
+
#tryWrite: ?() => Promise<void>;
|
|
50
|
+
#stopListening: ?() => void;
|
|
51
|
+
|
|
52
|
+
constructor(
|
|
53
|
+
{buildParameters}: CacheManagerFactoryOptions,
|
|
54
|
+
{autoSave = {}, cacheDirectory, cacheFilePrefix}: DiskCacheConfig,
|
|
55
|
+
) {
|
|
56
|
+
this.#cachePath = DiskCacheManager.getCacheFilePath(
|
|
43
57
|
buildParameters,
|
|
44
58
|
cacheFilePrefix,
|
|
45
59
|
cacheDirectory,
|
|
46
60
|
);
|
|
61
|
+
|
|
62
|
+
// Normalise auto-save options.
|
|
63
|
+
if (autoSave) {
|
|
64
|
+
const {debounceMs = DEFAULT_AUTO_SAVE_DEBOUNCE_MS} =
|
|
65
|
+
autoSave === true ? {} : autoSave;
|
|
66
|
+
this.#autoSaveOpts = {debounceMs};
|
|
67
|
+
}
|
|
47
68
|
}
|
|
48
69
|
|
|
49
70
|
static getCacheFilePath(
|
|
@@ -63,12 +84,12 @@ export class DiskCacheManager implements CacheManager {
|
|
|
63
84
|
}
|
|
64
85
|
|
|
65
86
|
getCacheFilePath(): string {
|
|
66
|
-
return this
|
|
87
|
+
return this.#cachePath;
|
|
67
88
|
}
|
|
68
89
|
|
|
69
90
|
async read(): Promise<?CacheData> {
|
|
70
91
|
try {
|
|
71
|
-
return deserialize(
|
|
92
|
+
return deserialize(await fsPromises.readFile(this.#cachePath));
|
|
72
93
|
} catch (e) {
|
|
73
94
|
if (e?.code === 'ENOENT') {
|
|
74
95
|
// Cache file not found - not considered an error.
|
|
@@ -80,11 +101,64 @@ export class DiskCacheManager implements CacheManager {
|
|
|
80
101
|
}
|
|
81
102
|
|
|
82
103
|
async write(
|
|
83
|
-
|
|
84
|
-
{
|
|
104
|
+
getSnapshot: () => CacheData,
|
|
105
|
+
{
|
|
106
|
+
changedSinceCacheRead,
|
|
107
|
+
eventSource,
|
|
108
|
+
onWriteError,
|
|
109
|
+
}: CacheManagerWriteOptions,
|
|
85
110
|
): Promise<void> {
|
|
86
|
-
|
|
87
|
-
|
|
111
|
+
// Initialise a writer function using a promise queue to ensure writes are
|
|
112
|
+
// sequenced.
|
|
113
|
+
const tryWrite = (this.#tryWrite = () => {
|
|
114
|
+
this.#writePromise = this.#writePromise
|
|
115
|
+
.then(async () => {
|
|
116
|
+
if (!this.#hasUnwrittenChanges) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const data = getSnapshot();
|
|
120
|
+
this.#hasUnwrittenChanges = false;
|
|
121
|
+
await fsPromises.writeFile(this.#cachePath, serialize(data));
|
|
122
|
+
debug('Written cache to %s', this.#cachePath);
|
|
123
|
+
})
|
|
124
|
+
.catch(onWriteError);
|
|
125
|
+
return this.#writePromise;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Set up auto-save on changes, if enabled.
|
|
129
|
+
if (this.#autoSaveOpts) {
|
|
130
|
+
const autoSave = this.#autoSaveOpts;
|
|
131
|
+
this.#stopListening?.();
|
|
132
|
+
this.#stopListening = eventSource.onChange(() => {
|
|
133
|
+
this.#hasUnwrittenChanges = true;
|
|
134
|
+
if (this.#debounceTimeout) {
|
|
135
|
+
this.#debounceTimeout.refresh();
|
|
136
|
+
} else {
|
|
137
|
+
this.#debounceTimeout = setTimeout(
|
|
138
|
+
() => tryWrite(),
|
|
139
|
+
autoSave.debounceMs,
|
|
140
|
+
).unref();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
88
143
|
}
|
|
144
|
+
|
|
145
|
+
// Write immediately if state has changed since the cache was read.
|
|
146
|
+
if (changedSinceCacheRead) {
|
|
147
|
+
this.#hasUnwrittenChanges = true;
|
|
148
|
+
await tryWrite();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async end() {
|
|
153
|
+
// Clear any timers
|
|
154
|
+
if (this.#debounceTimeout) {
|
|
155
|
+
clearTimeout(this.#debounceTimeout);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Remove event listeners
|
|
159
|
+
this.#stopListening?.();
|
|
160
|
+
|
|
161
|
+
// Flush unwritten changes to disk (no-op if no changes)
|
|
162
|
+
await this.#tryWrite?.();
|
|
89
163
|
}
|
|
90
164
|
}
|
package/src/flow-types.d.ts
CHANGED
|
@@ -42,22 +42,55 @@ export interface BuildResult {
|
|
|
42
42
|
|
|
43
43
|
export interface CacheData {
|
|
44
44
|
readonly clocks: WatchmanClocks;
|
|
45
|
-
readonly
|
|
46
|
-
readonly
|
|
45
|
+
readonly fileSystemData: unknown;
|
|
46
|
+
readonly plugins: ReadonlyMap<string, unknown>;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export interface CacheManager {
|
|
50
|
+
/**
|
|
51
|
+
* Called during startup to load initial state, if available. Provided to
|
|
52
|
+
* a crawler, which will return the delta between the initial state and the
|
|
53
|
+
* current file system state.
|
|
54
|
+
*/
|
|
50
55
|
read(): Promise<CacheData | null>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Called when metro-file-map `build()` has applied changes returned by the
|
|
59
|
+
* crawler - i.e. internal state reflects the current file system state.
|
|
60
|
+
*
|
|
61
|
+
* getSnapshot may be retained and called at any time before end(), such as
|
|
62
|
+
* in response to eventSource 'change' events.
|
|
63
|
+
*/
|
|
51
64
|
write(
|
|
52
|
-
|
|
53
|
-
|
|
65
|
+
getSnapshot: () => CacheData,
|
|
66
|
+
opts: CacheManagerWriteOptions,
|
|
54
67
|
): Promise<void>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The last call that will be made to this CacheManager. Any handles should
|
|
71
|
+
* be closed by the time this settles.
|
|
72
|
+
*/
|
|
73
|
+
end(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface CacheManagerEventSource {
|
|
77
|
+
onChange(listener: () => void): () => void /* unsubscribe */;
|
|
55
78
|
}
|
|
56
79
|
|
|
57
80
|
export type CacheManagerFactory = (
|
|
58
|
-
|
|
81
|
+
options: CacheManagerFactoryOptions,
|
|
59
82
|
) => CacheManager;
|
|
60
83
|
|
|
84
|
+
export type CacheManagerFactoryOptions = {
|
|
85
|
+
buildParameters: BuildParameters;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type CacheManagerWriteOptions = {
|
|
89
|
+
changedSinceCacheRead: boolean;
|
|
90
|
+
eventSource: CacheManagerEventSource;
|
|
91
|
+
onWriteError: (e: Error) => void;
|
|
92
|
+
};
|
|
93
|
+
|
|
61
94
|
export interface ChangeEvent {
|
|
62
95
|
logger: RootPerfLogger | null;
|
|
63
96
|
eventsQueue: EventsQueue;
|
package/src/flow-types.js.flow
CHANGED
|
@@ -47,24 +47,55 @@ export type BuildResult = {
|
|
|
47
47
|
|
|
48
48
|
export type CacheData = $ReadOnly<{
|
|
49
49
|
clocks: WatchmanClocks,
|
|
50
|
-
mocks: ?RawMockMap,
|
|
51
50
|
fileSystemData: mixed,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
export type CacheDelta = $ReadOnly<{
|
|
55
|
-
changed: $ReadOnlyMap<CanonicalPath, FileMetaData>,
|
|
56
|
-
removed: $ReadOnlySet<CanonicalPath>,
|
|
51
|
+
plugins: $ReadOnlyMap<string, mixed>,
|
|
57
52
|
}>;
|
|
58
53
|
|
|
59
54
|
export interface CacheManager {
|
|
55
|
+
/**
|
|
56
|
+
* Called during startup to load initial state, if available. Provided to
|
|
57
|
+
* a crawler, which will return the delta between the initial state and the
|
|
58
|
+
* current file system state.
|
|
59
|
+
*/
|
|
60
60
|
read(): Promise<?CacheData>;
|
|
61
|
-
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Called when metro-file-map `build()` has applied changes returned by the
|
|
64
|
+
* crawler - i.e. internal state reflects the current file system state.
|
|
65
|
+
*
|
|
66
|
+
* getSnapshot may be retained and called at any time before end(), such as
|
|
67
|
+
* in response to eventSource 'change' events.
|
|
68
|
+
*/
|
|
69
|
+
write(
|
|
70
|
+
getSnapshot: () => CacheData,
|
|
71
|
+
opts: CacheManagerWriteOptions,
|
|
72
|
+
): Promise<void>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The last call that will be made to this CacheManager. Any handles should
|
|
76
|
+
* be closed by the time this settles.
|
|
77
|
+
*/
|
|
78
|
+
end(): Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface CacheManagerEventSource {
|
|
82
|
+
onChange(listener: () => void): () => void /* unsubscribe */;
|
|
62
83
|
}
|
|
63
84
|
|
|
64
85
|
export type CacheManagerFactory = (
|
|
65
|
-
|
|
86
|
+
options: CacheManagerFactoryOptions,
|
|
66
87
|
) => CacheManager;
|
|
67
88
|
|
|
89
|
+
export type CacheManagerFactoryOptions = $ReadOnly<{
|
|
90
|
+
buildParameters: BuildParameters,
|
|
91
|
+
}>;
|
|
92
|
+
|
|
93
|
+
export type CacheManagerWriteOptions = $ReadOnly<{
|
|
94
|
+
changedSinceCacheRead: boolean,
|
|
95
|
+
eventSource: CacheManagerEventSource,
|
|
96
|
+
onWriteError: Error => void,
|
|
97
|
+
}>;
|
|
98
|
+
|
|
68
99
|
// A path that is
|
|
69
100
|
// - Relative to the contextual `rootDir`
|
|
70
101
|
// - Normalised (no extraneous '.' or '..')
|
|
@@ -128,6 +159,46 @@ export type EventsQueue = Array<{
|
|
|
128
159
|
type: string,
|
|
129
160
|
}>;
|
|
130
161
|
|
|
162
|
+
export type FileMapDelta = $ReadOnly<{
|
|
163
|
+
removed: Iterable<[CanonicalPath, FileMetaData]>,
|
|
164
|
+
addedOrModified: Iterable<[CanonicalPath, FileMetaData]>,
|
|
165
|
+
}>;
|
|
166
|
+
|
|
167
|
+
interface FileSystemState {
|
|
168
|
+
metadataIterator(
|
|
169
|
+
opts: $ReadOnly<{
|
|
170
|
+
includeNodeModules: boolean,
|
|
171
|
+
includeSymlinks: boolean,
|
|
172
|
+
}>,
|
|
173
|
+
): Iterable<{
|
|
174
|
+
baseName: string,
|
|
175
|
+
canonicalPath: string,
|
|
176
|
+
metadata: FileMetaData,
|
|
177
|
+
}>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type FileMapPluginInitOptions<SerializableState> = $ReadOnly<{
|
|
181
|
+
files: FileSystemState,
|
|
182
|
+
pluginState: ?SerializableState,
|
|
183
|
+
}>;
|
|
184
|
+
|
|
185
|
+
type V8Serializable = interface {};
|
|
186
|
+
|
|
187
|
+
export interface FileMapPlugin<SerializableState = V8Serializable> {
|
|
188
|
+
+name: string;
|
|
189
|
+
initialize(
|
|
190
|
+
initOptions: FileMapPluginInitOptions<SerializableState>,
|
|
191
|
+
): Promise<void>;
|
|
192
|
+
assertValid(): void;
|
|
193
|
+
bulkUpdate(delta: FileMapDelta): Promise<void>;
|
|
194
|
+
getSerializableSnapshot(): SerializableState;
|
|
195
|
+
onRemovedFile(relativeFilePath: string, fileMetadata: FileMetaData): void;
|
|
196
|
+
onNewOrModifiedFile(
|
|
197
|
+
relativeFilePath: string,
|
|
198
|
+
fileMetadata: FileMetaData,
|
|
199
|
+
): void;
|
|
200
|
+
}
|
|
201
|
+
|
|
131
202
|
export type HType = {
|
|
132
203
|
ID: 0,
|
|
133
204
|
MTIME: 1,
|
|
@@ -177,6 +248,7 @@ export interface FileSystem {
|
|
|
177
248
|
getModuleName(file: Path): ?string;
|
|
178
249
|
getSerializableSnapshot(): CacheData['fileSystemData'];
|
|
179
250
|
getSha1(file: Path): ?string;
|
|
251
|
+
getOrComputeSha1(file: Path): Promise<?{sha1: string, content?: Buffer}>;
|
|
180
252
|
|
|
181
253
|
/**
|
|
182
254
|
* Given a start path (which need not exist), a subpath and type, and
|
|
@@ -311,14 +383,28 @@ export interface MutableFileSystem extends FileSystem {
|
|
|
311
383
|
|
|
312
384
|
export type Path = string;
|
|
313
385
|
|
|
386
|
+
export type ProcessFileFunction = (
|
|
387
|
+
absolutePath: string,
|
|
388
|
+
metadata: FileMetaData,
|
|
389
|
+
request: $ReadOnly<{computeSha1: boolean}>,
|
|
390
|
+
) => Promise<?Buffer>;
|
|
391
|
+
|
|
314
392
|
export type RawMockMap = $ReadOnly<{
|
|
315
|
-
duplicates: Map<
|
|
316
|
-
|
|
393
|
+
duplicates: Map<
|
|
394
|
+
string, // posix-separated mock name
|
|
395
|
+
Set<string>, // posix-separated, project-relative paths
|
|
396
|
+
>,
|
|
397
|
+
mocks: Map<
|
|
398
|
+
string, // posix-separated mock name
|
|
399
|
+
Path, // posix-separated, project-relative path
|
|
400
|
+
>,
|
|
401
|
+
version: number,
|
|
317
402
|
}>;
|
|
318
403
|
|
|
319
404
|
export type ReadOnlyRawMockMap = $ReadOnly<{
|
|
320
405
|
duplicates: $ReadOnlyMap<string, $ReadOnlySet<string>>,
|
|
321
406
|
mocks: $ReadOnlyMap<string, Path>,
|
|
407
|
+
version: number,
|
|
322
408
|
}>;
|
|
323
409
|
|
|
324
410
|
export interface WatcherBackend {
|
|
@@ -329,15 +415,22 @@ export interface WatcherBackend {
|
|
|
329
415
|
stopWatching(): Promise<void>;
|
|
330
416
|
}
|
|
331
417
|
|
|
418
|
+
export type ChangeEventClock = [
|
|
419
|
+
string /* absolute watch root */,
|
|
420
|
+
string /* opaque clock */,
|
|
421
|
+
];
|
|
422
|
+
|
|
332
423
|
export type WatcherBackendChangeEvent =
|
|
333
424
|
| $ReadOnly<{
|
|
334
425
|
event: 'touch',
|
|
426
|
+
clock?: ChangeEventClock,
|
|
335
427
|
relativePath: string,
|
|
336
428
|
root: string,
|
|
337
429
|
metadata: ChangeEventMetadata,
|
|
338
430
|
}>
|
|
339
431
|
| $ReadOnly<{
|
|
340
432
|
event: 'delete',
|
|
433
|
+
clock?: ChangeEventClock,
|
|
341
434
|
relativePath: string,
|
|
342
435
|
root: string,
|
|
343
436
|
metadata?: void,
|
|
@@ -353,14 +446,14 @@ export type WorkerMessage = $ReadOnly<{
|
|
|
353
446
|
computeSha1: boolean,
|
|
354
447
|
dependencyExtractor?: ?string,
|
|
355
448
|
enableHastePackages: boolean,
|
|
356
|
-
rootDir: string,
|
|
357
449
|
filePath: string,
|
|
358
450
|
hasteImplModulePath?: ?string,
|
|
451
|
+
maybeReturnContent: boolean,
|
|
359
452
|
}>;
|
|
360
453
|
|
|
361
454
|
export type WorkerMetadata = $ReadOnly<{
|
|
362
455
|
dependencies?: ?$ReadOnlyArray<string>,
|
|
363
456
|
id?: ?string,
|
|
364
|
-
module?: ?HasteMapItemMetaData,
|
|
365
457
|
sha1?: ?string,
|
|
458
|
+
content?: ?Buffer,
|
|
366
459
|
}>;
|