metro-file-map 0.83.1 → 0.83.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 +1 -1
- package/src/Watcher.js +14 -14
- package/src/Watcher.js.flow +3 -2
- package/src/cache/DiskCacheManager.js +7 -9
- package/src/cache/DiskCacheManager.js.flow +3 -2
- package/src/constants.js +7 -7
- package/src/constants.js.flow +9 -7
- package/src/crawlers/node/index.js +19 -19
- package/src/crawlers/node/index.js.flow +5 -4
- package/src/crawlers/watchman/index.js +27 -21
- package/src/crawlers/watchman/index.js.flow +7 -8
- package/src/flow-types.js.flow +8 -10
- package/src/index.js +34 -34
- package/src/index.js.flow +4 -3
- package/src/lib/FileProcessor.js +7 -7
- package/src/lib/FileProcessor.js.flow +1 -0
- package/src/lib/RootPathUtils.js +4 -4
- package/src/lib/RootPathUtils.js.flow +2 -0
- package/src/lib/TreeFS.js +39 -39
- package/src/lib/TreeFS.js.flow +1 -1
- package/src/lib/checkWatchmanCapabilities.js +3 -5
- package/src/lib/dependencyExtractor.js +4 -4
- package/src/lib/dependencyExtractor.js.flow +3 -0
- package/src/lib/normalizePathSeparatorsToPosix.js +1 -1
- package/src/lib/normalizePathSeparatorsToSystem.js +1 -1
- package/src/lib/rootRelativeCacheKeys.js +4 -4
- package/src/plugins/HastePlugin.js +11 -11
- package/src/plugins/HastePlugin.js.flow +2 -0
- package/src/plugins/MockPlugin.js +10 -12
- package/src/plugins/haste/DuplicateHasteCandidatesError.js +2 -2
- package/src/plugins/haste/HasteConflictsError.js +5 -5
- package/src/plugins/haste/computeConflicts.js +2 -2
- package/src/plugins/mocks/getMockName.js +1 -1
- package/src/watchers/AbstractWatcher.js +1 -1
- package/src/watchers/FallbackWatcher.js +72 -36
- package/src/watchers/FallbackWatcher.js.flow +10 -10
- package/src/watchers/NativeWatcher.js +2 -2
- package/src/watchers/NativeWatcher.js.flow +1 -0
- package/src/watchers/RecrawlWarning.js.flow +0 -2
- package/src/watchers/WatchmanWatcher.js +16 -16
- package/src/watchers/WatchmanWatcher.js.flow +1 -0
- package/src/watchers/common.js +10 -6
- package/src/watchers/common.js.flow +2 -4
- package/src/worker.js +3 -3
- package/src/worker.js.flow +2 -0
- package/src/workerExclusionList.js.flow +3 -0
- package/src/lib/fast_path.js +0 -78
- package/src/lib/fast_path.js.flow +0 -78
package/package.json
CHANGED
package/src/Watcher.js
CHANGED
|
@@ -8,13 +8,13 @@ var _node = _interopRequireDefault(require("./crawlers/node"));
|
|
|
8
8
|
var _watchman = _interopRequireDefault(require("./crawlers/watchman"));
|
|
9
9
|
var _common = require("./watchers/common");
|
|
10
10
|
var _FallbackWatcher = _interopRequireDefault(
|
|
11
|
-
require("./watchers/FallbackWatcher")
|
|
11
|
+
require("./watchers/FallbackWatcher"),
|
|
12
12
|
);
|
|
13
13
|
var _NativeWatcher = _interopRequireDefault(
|
|
14
|
-
require("./watchers/NativeWatcher")
|
|
14
|
+
require("./watchers/NativeWatcher"),
|
|
15
15
|
);
|
|
16
16
|
var _WatchmanWatcher = _interopRequireDefault(
|
|
17
|
-
require("./watchers/WatchmanWatcher")
|
|
17
|
+
require("./watchers/WatchmanWatcher"),
|
|
18
18
|
);
|
|
19
19
|
var _events = _interopRequireDefault(require("events"));
|
|
20
20
|
var fs = _interopRequireWildcard(require("fs"));
|
|
@@ -42,7 +42,7 @@ function _interopRequireWildcard(e, r) {
|
|
|
42
42
|
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
43
43
|
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
44
44
|
}
|
|
45
|
-
return (n.default = e), t && t.set(e, n), n;
|
|
45
|
+
return ((n.default = e), t && t.set(e, n), n);
|
|
46
46
|
}
|
|
47
47
|
function _interopRequireDefault(e) {
|
|
48
48
|
return e && e.__esModule ? e : { default: e };
|
|
@@ -94,13 +94,13 @@ class Watcher extends _events.default {
|
|
|
94
94
|
"empty `.watchmanconfig` file in your project's root folder or " +
|
|
95
95
|
"initialize a git or hg repository in your project.\n" +
|
|
96
96
|
" " +
|
|
97
|
-
error.toString()
|
|
97
|
+
error.toString(),
|
|
98
98
|
);
|
|
99
99
|
return (0, _node.default)(crawlerOptions).catch((e) => {
|
|
100
100
|
throw new Error(
|
|
101
101
|
"Crawler retry failed:\n" +
|
|
102
102
|
` Original error: ${error.message}\n` +
|
|
103
|
-
` Retry error: ${e.message}\n
|
|
103
|
+
` Retry error: ${e.message}\n`,
|
|
104
104
|
);
|
|
105
105
|
});
|
|
106
106
|
}
|
|
@@ -112,7 +112,7 @@ class Watcher extends _events.default {
|
|
|
112
112
|
crawler,
|
|
113
113
|
delta.changedFiles.size,
|
|
114
114
|
delta.removedFiles.size,
|
|
115
|
-
delta.clocks?.size ?? 0
|
|
115
|
+
delta.clocks?.size ?? 0,
|
|
116
116
|
);
|
|
117
117
|
this._options.perfLogger?.point("crawl_end");
|
|
118
118
|
return delta;
|
|
@@ -129,8 +129,8 @@ class Watcher extends _events.default {
|
|
|
129
129
|
const WatcherImpl = useWatchman
|
|
130
130
|
? _WatchmanWatcher.default
|
|
131
131
|
: _NativeWatcher.default.isSupported()
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
? _NativeWatcher.default
|
|
133
|
+
: _FallbackWatcher.default;
|
|
134
134
|
let watcher = "fallback";
|
|
135
135
|
if (WatcherImpl === _WatchmanWatcher.default) {
|
|
136
136
|
watcher = "watchman";
|
|
@@ -159,7 +159,7 @@ class Watcher extends _events.default {
|
|
|
159
159
|
return new Promise(async (resolve, reject) => {
|
|
160
160
|
const rejectTimeout = setTimeout(
|
|
161
161
|
() => reject(new Error("Failed to start watch mode.")),
|
|
162
|
-
MAX_WAIT_TIME
|
|
162
|
+
MAX_WAIT_TIME,
|
|
163
163
|
);
|
|
164
164
|
watcher.onFileEvent((change) => {
|
|
165
165
|
const basename = path.basename(change.relativePath);
|
|
@@ -168,7 +168,7 @@ class Watcher extends _events.default {
|
|
|
168
168
|
debug(
|
|
169
169
|
"Observed possible health check cookie: %s in %s",
|
|
170
170
|
change.relativePath,
|
|
171
|
-
root
|
|
171
|
+
root,
|
|
172
172
|
);
|
|
173
173
|
this._handleHealthCheckObservation(basename);
|
|
174
174
|
}
|
|
@@ -182,7 +182,7 @@ class Watcher extends _events.default {
|
|
|
182
182
|
});
|
|
183
183
|
};
|
|
184
184
|
this._backends = await Promise.all(
|
|
185
|
-
this._options.roots.map(createWatcherBackend)
|
|
185
|
+
this._options.roots.map(createWatcherBackend),
|
|
186
186
|
);
|
|
187
187
|
}
|
|
188
188
|
_handleHealthCheckObservation(basename) {
|
|
@@ -213,7 +213,7 @@ class Watcher extends _events.default {
|
|
|
213
213
|
const healthCheckPath = path.join(this._options.rootDir, basename);
|
|
214
214
|
let result;
|
|
215
215
|
const timeoutPromise = new Promise((resolve) =>
|
|
216
|
-
setTimeout(resolve, timeout)
|
|
216
|
+
setTimeout(resolve, timeout),
|
|
217
217
|
).then(() => {
|
|
218
218
|
if (!result) {
|
|
219
219
|
result = {
|
|
@@ -256,7 +256,7 @@ class Watcher extends _events.default {
|
|
|
256
256
|
]);
|
|
257
257
|
this._pendingHealthChecks.delete(basename);
|
|
258
258
|
creationPromise.then(() =>
|
|
259
|
-
fs.promises.unlink(healthCheckPath).catch(() => {})
|
|
259
|
+
fs.promises.unlink(healthCheckPath).catch(() => {}),
|
|
260
260
|
);
|
|
261
261
|
debug("Health check result: %o", result);
|
|
262
262
|
return (0, _nullthrows.default)(result);
|
package/src/Watcher.js.flow
CHANGED
|
@@ -32,6 +32,7 @@ import nullthrows from 'nullthrows';
|
|
|
32
32
|
import * as path from 'path';
|
|
33
33
|
import {performance} from 'perf_hooks';
|
|
34
34
|
|
|
35
|
+
// eslint-disable-next-line import/no-commonjs
|
|
35
36
|
const debug = require('debug')('Metro:Watcher');
|
|
36
37
|
|
|
37
38
|
const MAX_WAIT_TIME = 240000;
|
|
@@ -124,7 +125,7 @@ export class Watcher extends EventEmitter {
|
|
|
124
125
|
' ' +
|
|
125
126
|
error.toString(),
|
|
126
127
|
);
|
|
127
|
-
// $FlowFixMe[
|
|
128
|
+
// $FlowFixMe[incompatible-type] Found when updating Promise type definition
|
|
128
129
|
return nodeCrawl(crawlerOptions).catch<CrawlResult>(e => {
|
|
129
130
|
throw new Error(
|
|
130
131
|
'Crawler retry failed:\n' +
|
|
@@ -151,7 +152,7 @@ export class Watcher extends EventEmitter {
|
|
|
151
152
|
|
|
152
153
|
debug('Beginning crawl with "%s".', crawler);
|
|
153
154
|
try {
|
|
154
|
-
// $FlowFixMe[incompatible-
|
|
155
|
+
// $FlowFixMe[incompatible-type] Found when updating Promise type definition
|
|
155
156
|
return crawl(crawlerOptions).catch<CrawlResult>(retry).then(logEnd);
|
|
156
157
|
} catch (error) {
|
|
157
158
|
return retry(error).then(logEnd);
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DiskCacheManager = void 0;
|
|
7
7
|
var _rootRelativeCacheKeys = _interopRequireDefault(
|
|
8
|
-
require("../lib/rootRelativeCacheKeys")
|
|
8
|
+
require("../lib/rootRelativeCacheKeys"),
|
|
9
9
|
);
|
|
10
10
|
var _fs = require("fs");
|
|
11
11
|
var _os = require("os");
|
|
@@ -29,12 +29,12 @@ class DiskCacheManager {
|
|
|
29
29
|
#stopListening;
|
|
30
30
|
constructor(
|
|
31
31
|
{ buildParameters },
|
|
32
|
-
{ autoSave = {}, cacheDirectory, cacheFilePrefix }
|
|
32
|
+
{ autoSave = {}, cacheDirectory, cacheFilePrefix },
|
|
33
33
|
) {
|
|
34
34
|
this.#cachePath = DiskCacheManager.getCacheFilePath(
|
|
35
35
|
buildParameters,
|
|
36
36
|
cacheFilePrefix,
|
|
37
|
-
cacheDirectory
|
|
37
|
+
cacheDirectory,
|
|
38
38
|
);
|
|
39
39
|
if (autoSave) {
|
|
40
40
|
const { debounceMs = DEFAULT_AUTO_SAVE_DEBOUNCE_MS } =
|
|
@@ -49,9 +49,7 @@ class DiskCacheManager {
|
|
|
49
49
|
_rootRelativeCacheKeys.default)(buildParameters);
|
|
50
50
|
return _path.default.join(
|
|
51
51
|
cacheDirectory ?? DEFAULT_DIRECTORY,
|
|
52
|
-
`${
|
|
53
|
-
cacheFilePrefix ?? DEFAULT_PREFIX
|
|
54
|
-
}-${rootDirHash}-${relativeConfigHash}`
|
|
52
|
+
`${cacheFilePrefix ?? DEFAULT_PREFIX}-${rootDirHash}-${relativeConfigHash}`,
|
|
55
53
|
);
|
|
56
54
|
}
|
|
57
55
|
getCacheFilePath() {
|
|
@@ -69,7 +67,7 @@ class DiskCacheManager {
|
|
|
69
67
|
}
|
|
70
68
|
async write(
|
|
71
69
|
getSnapshot,
|
|
72
|
-
{ changedSinceCacheRead, eventSource, onWriteError }
|
|
70
|
+
{ changedSinceCacheRead, eventSource, onWriteError },
|
|
73
71
|
) {
|
|
74
72
|
const tryWrite = (this.#tryWrite = () => {
|
|
75
73
|
this.#writePromise = this.#writePromise
|
|
@@ -81,7 +79,7 @@ class DiskCacheManager {
|
|
|
81
79
|
this.#hasUnwrittenChanges = false;
|
|
82
80
|
await _fs.promises.writeFile(
|
|
83
81
|
this.#cachePath,
|
|
84
|
-
(0, _v.serialize)(data)
|
|
82
|
+
(0, _v.serialize)(data),
|
|
85
83
|
);
|
|
86
84
|
debug("Written cache to %s", this.#cachePath);
|
|
87
85
|
})
|
|
@@ -98,7 +96,7 @@ class DiskCacheManager {
|
|
|
98
96
|
} else {
|
|
99
97
|
this.#debounceTimeout = (0, _timers.setTimeout)(
|
|
100
98
|
() => tryWrite(),
|
|
101
|
-
autoSave.debounceMs
|
|
99
|
+
autoSave.debounceMs,
|
|
102
100
|
).unref();
|
|
103
101
|
}
|
|
104
102
|
});
|
|
@@ -24,17 +24,18 @@ import path from 'path';
|
|
|
24
24
|
import {Timeout, clearTimeout, setTimeout} from 'timers';
|
|
25
25
|
import {deserialize, serialize} from 'v8';
|
|
26
26
|
|
|
27
|
+
// eslint-disable-next-line import/no-commonjs
|
|
27
28
|
const debug = require('debug')('Metro:FileMapCache');
|
|
28
29
|
|
|
29
30
|
type AutoSaveOptions = $ReadOnly<{
|
|
30
31
|
debounceMs: number,
|
|
31
32
|
}>;
|
|
32
33
|
|
|
33
|
-
type DiskCacheConfig = {
|
|
34
|
+
type DiskCacheConfig = $ReadOnly<{
|
|
34
35
|
autoSave?: Partial<AutoSaveOptions> | boolean,
|
|
35
36
|
cacheFilePrefix?: ?string,
|
|
36
37
|
cacheDirectory?: ?string,
|
|
37
|
-
}
|
|
38
|
+
}>;
|
|
38
39
|
|
|
39
40
|
const DEFAULT_PREFIX = 'metro-file-map';
|
|
40
41
|
const DEFAULT_DIRECTORY = tmpdir();
|
package/src/constants.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const constants = {
|
|
4
4
|
DEPENDENCY_DELIM: "\0",
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
MTIME: 0,
|
|
6
|
+
SIZE: 1,
|
|
7
|
+
VISITED: 2,
|
|
8
|
+
DEPENDENCIES: 3,
|
|
9
|
+
SHA1: 4,
|
|
10
|
+
SYMLINK: 5,
|
|
11
|
+
ID: 6,
|
|
12
12
|
PATH: 0,
|
|
13
13
|
TYPE: 1,
|
|
14
14
|
MODULE: 0,
|
package/src/constants.js.flow
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* @noformat - Flow comment syntax
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
/* eslint-disable import/no-commonjs */
|
|
12
|
+
|
|
11
13
|
/*
|
|
12
14
|
* This file exports a set of constants that are used for Jest's haste map
|
|
13
15
|
* serialization. On very large repositories, the haste map cache becomes very
|
|
@@ -28,13 +30,13 @@ const constants/*: HType */ = {
|
|
|
28
30
|
DEPENDENCY_DELIM: '\0',
|
|
29
31
|
|
|
30
32
|
/* file map attributes */
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
MTIME: 0,
|
|
34
|
+
SIZE: 1,
|
|
35
|
+
VISITED: 2,
|
|
36
|
+
DEPENDENCIES: 3,
|
|
37
|
+
SHA1: 4,
|
|
38
|
+
SYMLINK: 5,
|
|
39
|
+
ID: 6,
|
|
38
40
|
|
|
39
41
|
/* module map attributes */
|
|
40
42
|
PATH: 0,
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = nodeCrawl;
|
|
3
7
|
var _RootPathUtils = require("../../lib/RootPathUtils");
|
|
4
8
|
var _hasNativeFindSupport = _interopRequireDefault(
|
|
5
|
-
require("./hasNativeFindSupport")
|
|
9
|
+
require("./hasNativeFindSupport"),
|
|
6
10
|
);
|
|
7
11
|
var _child_process = require("child_process");
|
|
8
12
|
var fs = _interopRequireWildcard(require("graceful-fs"));
|
|
@@ -29,7 +33,7 @@ function _interopRequireWildcard(e, r) {
|
|
|
29
33
|
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
30
34
|
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
31
35
|
}
|
|
32
|
-
return (n.default = e), t && t.set(e, n), n;
|
|
36
|
+
return ((n.default = e), t && t.set(e, n), n);
|
|
33
37
|
}
|
|
34
38
|
function _interopRequireDefault(e) {
|
|
35
39
|
return e && e.__esModule ? e : { default: e };
|
|
@@ -42,7 +46,7 @@ function find(
|
|
|
42
46
|
includeSymlinks,
|
|
43
47
|
rootDir,
|
|
44
48
|
console,
|
|
45
|
-
callback
|
|
49
|
+
callback,
|
|
46
50
|
) {
|
|
47
51
|
const result = new Map();
|
|
48
52
|
let activeCalls = 0;
|
|
@@ -58,9 +62,7 @@ function find(
|
|
|
58
62
|
activeCalls--;
|
|
59
63
|
if (err) {
|
|
60
64
|
console.warn(
|
|
61
|
-
`Error "${
|
|
62
|
-
err.code ?? err.message
|
|
63
|
-
}" reading contents of "${directory}", skipping. Add this directory to your ignore list to exclude it.`
|
|
65
|
+
`Error "${err.code ?? err.message}" reading contents of "${directory}", skipping. Add this directory to your ignore list to exclude it.`,
|
|
64
66
|
);
|
|
65
67
|
} else {
|
|
66
68
|
entries.forEach((entry) => {
|
|
@@ -82,13 +84,13 @@ function find(
|
|
|
82
84
|
const ext = path.extname(file).substr(1);
|
|
83
85
|
if (stat.isSymbolicLink() || extensions.includes(ext)) {
|
|
84
86
|
result.set(pathUtils.absoluteToNormal(file), [
|
|
85
|
-
"",
|
|
86
87
|
stat.mtime.getTime(),
|
|
87
88
|
stat.size,
|
|
88
89
|
0,
|
|
89
90
|
"",
|
|
90
91
|
null,
|
|
91
92
|
stat.isSymbolicLink() ? 1 : 0,
|
|
93
|
+
"",
|
|
92
94
|
]);
|
|
93
95
|
}
|
|
94
96
|
}
|
|
@@ -101,7 +103,7 @@ function find(
|
|
|
101
103
|
if (activeCalls === 0) {
|
|
102
104
|
callback(result);
|
|
103
105
|
}
|
|
104
|
-
}
|
|
106
|
+
},
|
|
105
107
|
);
|
|
106
108
|
}
|
|
107
109
|
if (roots.length > 0) {
|
|
@@ -117,23 +119,21 @@ function findNative(
|
|
|
117
119
|
includeSymlinks,
|
|
118
120
|
rootDir,
|
|
119
121
|
console,
|
|
120
|
-
callback
|
|
122
|
+
callback,
|
|
121
123
|
) {
|
|
122
124
|
const extensionClause = extensions.length
|
|
123
125
|
? `( ${extensions.map((ext) => `-iname *.${ext}`).join(" -o ")} )`
|
|
124
126
|
: "";
|
|
125
|
-
const expression = `( ( -type f ${extensionClause} ) ${
|
|
126
|
-
includeSymlinks ? "-o -type l " : ""
|
|
127
|
-
})`;
|
|
127
|
+
const expression = `( ( -type f ${extensionClause} ) ${includeSymlinks ? "-o -type l " : ""})`;
|
|
128
128
|
const pathUtils = new _RootPathUtils.RootPathUtils(rootDir);
|
|
129
129
|
const child = (0, _child_process.spawn)(
|
|
130
130
|
"find",
|
|
131
|
-
roots.concat(expression.split(" "))
|
|
131
|
+
roots.concat(expression.split(" ")),
|
|
132
132
|
);
|
|
133
133
|
let stdout = "";
|
|
134
134
|
if (child.stdout == null) {
|
|
135
135
|
throw new Error(
|
|
136
|
-
"stdout is null - this should never happen. Please open up an issue at https://github.com/facebook/metro"
|
|
136
|
+
"stdout is null - this should never happen. Please open up an issue at https://github.com/facebook/metro",
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
139
|
child.stdout.setEncoding("utf-8");
|
|
@@ -152,13 +152,13 @@ function findNative(
|
|
|
152
152
|
fs.lstat(path, (err, stat) => {
|
|
153
153
|
if (!err && stat) {
|
|
154
154
|
result.set(pathUtils.absoluteToNormal(path), [
|
|
155
|
-
"",
|
|
156
155
|
stat.mtime.getTime(),
|
|
157
156
|
stat.size,
|
|
158
157
|
0,
|
|
159
158
|
"",
|
|
160
159
|
null,
|
|
161
160
|
stat.isSymbolicLink() ? 1 : 0,
|
|
161
|
+
"",
|
|
162
162
|
]);
|
|
163
163
|
}
|
|
164
164
|
if (--count === 0) {
|
|
@@ -169,7 +169,7 @@ function findNative(
|
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
|
-
|
|
172
|
+
async function nodeCrawl(options) {
|
|
173
173
|
const {
|
|
174
174
|
console,
|
|
175
175
|
previousState,
|
|
@@ -208,7 +208,7 @@ module.exports = async function nodeCrawl(options) {
|
|
|
208
208
|
includeSymlinks,
|
|
209
209
|
rootDir,
|
|
210
210
|
console,
|
|
211
|
-
callback
|
|
211
|
+
callback,
|
|
212
212
|
);
|
|
213
213
|
} else {
|
|
214
214
|
find(
|
|
@@ -218,8 +218,8 @@ module.exports = async function nodeCrawl(options) {
|
|
|
218
218
|
includeSymlinks,
|
|
219
219
|
rootDir,
|
|
220
220
|
console,
|
|
221
|
-
callback
|
|
221
|
+
callback,
|
|
222
222
|
);
|
|
223
223
|
}
|
|
224
224
|
});
|
|
225
|
-
}
|
|
225
|
+
}
|
|
@@ -24,6 +24,7 @@ import * as fs from 'graceful-fs';
|
|
|
24
24
|
import {platform} from 'os';
|
|
25
25
|
import * as path from 'path';
|
|
26
26
|
|
|
27
|
+
// eslint-disable-next-line import/no-commonjs
|
|
27
28
|
const debug = require('debug')('Metro:NodeCrawler');
|
|
28
29
|
|
|
29
30
|
type Callback = (result: FileData) => void;
|
|
@@ -75,13 +76,13 @@ function find(
|
|
|
75
76
|
const ext = path.extname(file).substr(1);
|
|
76
77
|
if (stat.isSymbolicLink() || extensions.includes(ext)) {
|
|
77
78
|
result.set(pathUtils.absoluteToNormal(file), [
|
|
78
|
-
'',
|
|
79
79
|
stat.mtime.getTime(),
|
|
80
80
|
stat.size,
|
|
81
81
|
0,
|
|
82
82
|
'',
|
|
83
83
|
null,
|
|
84
84
|
stat.isSymbolicLink() ? 1 : 0,
|
|
85
|
+
'',
|
|
85
86
|
]);
|
|
86
87
|
}
|
|
87
88
|
}
|
|
@@ -153,13 +154,13 @@ function findNative(
|
|
|
153
154
|
fs.lstat(path, (err, stat) => {
|
|
154
155
|
if (!err && stat) {
|
|
155
156
|
result.set(pathUtils.absoluteToNormal(path), [
|
|
156
|
-
'',
|
|
157
157
|
stat.mtime.getTime(),
|
|
158
158
|
stat.size,
|
|
159
159
|
0,
|
|
160
160
|
'',
|
|
161
161
|
null,
|
|
162
162
|
stat.isSymbolicLink() ? 1 : 0,
|
|
163
|
+
'',
|
|
163
164
|
]);
|
|
164
165
|
}
|
|
165
166
|
if (--count === 0) {
|
|
@@ -171,7 +172,7 @@ function findNative(
|
|
|
171
172
|
});
|
|
172
173
|
}
|
|
173
174
|
|
|
174
|
-
|
|
175
|
+
export default async function nodeCrawl(options: CrawlerOptions): Promise<{
|
|
175
176
|
removedFiles: Set<CanonicalPath>,
|
|
176
177
|
changedFiles: FileData,
|
|
177
178
|
}> {
|
|
@@ -235,4 +236,4 @@ module.exports = async function nodeCrawl(options: CrawlerOptions): Promise<{
|
|
|
235
236
|
);
|
|
236
237
|
}
|
|
237
238
|
});
|
|
238
|
-
}
|
|
239
|
+
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = watchmanCrawl;
|
|
3
7
|
var _normalizePathSeparatorsToPosix = _interopRequireDefault(
|
|
4
|
-
require("../../lib/normalizePathSeparatorsToPosix")
|
|
8
|
+
require("../../lib/normalizePathSeparatorsToPosix"),
|
|
5
9
|
);
|
|
6
10
|
var _normalizePathSeparatorsToSystem = _interopRequireDefault(
|
|
7
|
-
require("../../lib/normalizePathSeparatorsToSystem")
|
|
11
|
+
require("../../lib/normalizePathSeparatorsToSystem"),
|
|
8
12
|
);
|
|
9
13
|
var _RootPathUtils = require("../../lib/RootPathUtils");
|
|
10
14
|
var _planQuery = require("./planQuery");
|
|
15
|
+
var _fbWatchman = _interopRequireDefault(require("fb-watchman"));
|
|
11
16
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
12
17
|
var path = _interopRequireWildcard(require("path"));
|
|
13
18
|
var _perf_hooks = require("perf_hooks");
|
|
@@ -32,12 +37,11 @@ function _interopRequireWildcard(e, r) {
|
|
|
32
37
|
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
33
38
|
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
34
39
|
}
|
|
35
|
-
return (n.default = e), t && t.set(e, n), n;
|
|
40
|
+
return ((n.default = e), t && t.set(e, n), n);
|
|
36
41
|
}
|
|
37
42
|
function _interopRequireDefault(e) {
|
|
38
43
|
return e && e.__esModule ? e : { default: e };
|
|
39
44
|
}
|
|
40
|
-
const watchman = require("fb-watchman");
|
|
41
45
|
const WATCHMAN_WARNING_INITIAL_DELAY_MILLISECONDS = 10000;
|
|
42
46
|
const WATCHMAN_WARNING_INTERVAL_MILLISECONDS = 20000;
|
|
43
47
|
const watchmanURL = "https://facebook.github.io/watchman/docs/troubleshooting";
|
|
@@ -47,7 +51,7 @@ function makeWatchmanError(error) {
|
|
|
47
51
|
`is running for this project. See ${watchmanURL}.`;
|
|
48
52
|
return error;
|
|
49
53
|
}
|
|
50
|
-
|
|
54
|
+
async function watchmanCrawl({
|
|
51
55
|
abortSignal,
|
|
52
56
|
computeSha1,
|
|
53
57
|
extensions,
|
|
@@ -60,7 +64,7 @@ module.exports = async function watchmanCrawl({
|
|
|
60
64
|
roots,
|
|
61
65
|
}) {
|
|
62
66
|
abortSignal?.throwIfAborted();
|
|
63
|
-
const client = new
|
|
67
|
+
const client = new _fbWatchman.default.Client();
|
|
64
68
|
const pathUtils = new _RootPathUtils.RootPathUtils(rootDir);
|
|
65
69
|
abortSignal?.addEventListener("abort", () => client.end());
|
|
66
70
|
perfLogger?.point("watchmanCrawl_start");
|
|
@@ -84,14 +88,14 @@ module.exports = async function watchmanCrawl({
|
|
|
84
88
|
logWatchmanWaitMessage();
|
|
85
89
|
intervalOrTimeoutId = setInterval(
|
|
86
90
|
logWatchmanWaitMessage,
|
|
87
|
-
WATCHMAN_WARNING_INTERVAL_MILLISECONDS
|
|
91
|
+
WATCHMAN_WARNING_INTERVAL_MILLISECONDS,
|
|
88
92
|
);
|
|
89
93
|
}, WATCHMAN_WARNING_INITIAL_DELAY_MILLISECONDS);
|
|
90
94
|
try {
|
|
91
95
|
const response = await new Promise((resolve, reject) =>
|
|
92
96
|
client.command([command, ...args], (error, result) =>
|
|
93
|
-
error ? reject(makeWatchmanError(error)) : resolve(result)
|
|
94
|
-
)
|
|
97
|
+
error ? reject(makeWatchmanError(error)) : resolve(result),
|
|
98
|
+
),
|
|
95
99
|
);
|
|
96
100
|
if ("warning" in response) {
|
|
97
101
|
onStatus({
|
|
@@ -127,7 +131,7 @@ module.exports = async function watchmanCrawl({
|
|
|
127
131
|
watchmanRoots.set(response.watch, {
|
|
128
132
|
watcher: response.watcher,
|
|
129
133
|
directoryFilters: (existing?.directoryFilters || []).concat(
|
|
130
|
-
response.relative_path
|
|
134
|
+
response.relative_path,
|
|
131
135
|
),
|
|
132
136
|
});
|
|
133
137
|
} else {
|
|
@@ -137,7 +141,7 @@ module.exports = async function watchmanCrawl({
|
|
|
137
141
|
});
|
|
138
142
|
}
|
|
139
143
|
}
|
|
140
|
-
})
|
|
144
|
+
}),
|
|
141
145
|
);
|
|
142
146
|
perfLogger?.point("watchmanCrawl/getWatchmanRoots_end");
|
|
143
147
|
return watchmanRoots;
|
|
@@ -153,10 +157,10 @@ module.exports = async function watchmanCrawl({
|
|
|
153
157
|
(0, _normalizePathSeparatorsToPosix.default)(
|
|
154
158
|
pathUtils.absoluteToNormal(
|
|
155
159
|
(0, _normalizePathSeparatorsToSystem.default)(
|
|
156
|
-
posixSeparatedRoot
|
|
157
|
-
)
|
|
158
|
-
)
|
|
159
|
-
)
|
|
160
|
+
posixSeparatedRoot,
|
|
161
|
+
),
|
|
162
|
+
),
|
|
163
|
+
),
|
|
160
164
|
);
|
|
161
165
|
perfLogger?.annotate({
|
|
162
166
|
bool: {
|
|
@@ -185,8 +189,8 @@ module.exports = async function watchmanCrawl({
|
|
|
185
189
|
isFresh = isFresh || response.is_fresh_instance;
|
|
186
190
|
}
|
|
187
191
|
results.set(posixSeparatedRoot, response);
|
|
188
|
-
}
|
|
189
|
-
)
|
|
192
|
+
},
|
|
193
|
+
),
|
|
190
194
|
);
|
|
191
195
|
perfLogger?.point("watchmanCrawl/queryWatchmanForDirs_end");
|
|
192
196
|
return {
|
|
@@ -238,7 +242,9 @@ module.exports = async function watchmanCrawl({
|
|
|
238
242
|
const relativeFsRoot = pathUtils.absoluteToNormal(fsRoot);
|
|
239
243
|
newClocks.set(
|
|
240
244
|
(0, _normalizePathSeparatorsToPosix.default)(relativeFsRoot),
|
|
241
|
-
typeof response.clock === "string"
|
|
245
|
+
typeof response.clock === "string"
|
|
246
|
+
? response.clock
|
|
247
|
+
: response.clock.clock,
|
|
242
248
|
);
|
|
243
249
|
for (const fileData of response.files) {
|
|
244
250
|
const filePath =
|
|
@@ -254,7 +260,7 @@ module.exports = async function watchmanCrawl({
|
|
|
254
260
|
const { mtime_ms, size } = fileData;
|
|
255
261
|
(0, _invariant.default)(
|
|
256
262
|
mtime_ms != null && size != null,
|
|
257
|
-
"missing file data in watchman response"
|
|
263
|
+
"missing file data in watchman response",
|
|
258
264
|
);
|
|
259
265
|
const mtime =
|
|
260
266
|
typeof mtime_ms === "number" ? mtime_ms : mtime_ms.toNumber();
|
|
@@ -266,7 +272,7 @@ module.exports = async function watchmanCrawl({
|
|
|
266
272
|
if (fileData.type === "l") {
|
|
267
273
|
symlinkInfo = fileData["symlink_target"] ?? 1;
|
|
268
274
|
}
|
|
269
|
-
const nextData = [
|
|
275
|
+
const nextData = [mtime, size, 0, "", sha1hex ?? null, symlinkInfo, ""];
|
|
270
276
|
if (isFresh) {
|
|
271
277
|
freshFileData.set(relativeFilePath, nextData);
|
|
272
278
|
} else {
|
|
@@ -287,4 +293,4 @@ module.exports = async function watchmanCrawl({
|
|
|
287
293
|
removedFiles,
|
|
288
294
|
clocks: newClocks,
|
|
289
295
|
};
|
|
290
|
-
}
|
|
296
|
+
}
|
|
@@ -24,12 +24,11 @@ import normalizePathSeparatorsToPosix from '../../lib/normalizePathSeparatorsToP
|
|
|
24
24
|
import normalizePathSeparatorsToSystem from '../../lib/normalizePathSeparatorsToSystem';
|
|
25
25
|
import {RootPathUtils} from '../../lib/RootPathUtils';
|
|
26
26
|
import {planQuery} from './planQuery';
|
|
27
|
+
import watchman from 'fb-watchman';
|
|
27
28
|
import invariant from 'invariant';
|
|
28
29
|
import * as path from 'path';
|
|
29
30
|
import {performance} from 'perf_hooks';
|
|
30
31
|
|
|
31
|
-
const watchman = require('fb-watchman');
|
|
32
|
-
|
|
33
32
|
type WatchmanRoots = Map<
|
|
34
33
|
string, // Posix-separated absolute path
|
|
35
34
|
$ReadOnly<{directoryFilters: Array<string>, watcher: string}>,
|
|
@@ -47,7 +46,7 @@ function makeWatchmanError(error: Error): Error {
|
|
|
47
46
|
return error;
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
|
|
49
|
+
export default async function watchmanCrawl({
|
|
51
50
|
abortSignal,
|
|
52
51
|
computeSha1,
|
|
53
52
|
extensions,
|
|
@@ -103,7 +102,7 @@ module.exports = async function watchmanCrawl({
|
|
|
103
102
|
try {
|
|
104
103
|
const response = await new Promise<WatchmanQueryResponse>(
|
|
105
104
|
(resolve, reject) =>
|
|
106
|
-
// $FlowFixMe[incompatible-
|
|
105
|
+
// $FlowFixMe[incompatible-type] - dynamic call of command
|
|
107
106
|
client.command(
|
|
108
107
|
[command, ...args],
|
|
109
108
|
(error: ?Error, result: WatchmanQueryResponse) =>
|
|
@@ -117,10 +116,10 @@ module.exports = async function watchmanCrawl({
|
|
|
117
116
|
command,
|
|
118
117
|
});
|
|
119
118
|
}
|
|
120
|
-
// $FlowFixMe[incompatible-
|
|
119
|
+
// $FlowFixMe[incompatible-type]
|
|
121
120
|
return response;
|
|
122
121
|
} finally {
|
|
123
|
-
// $FlowFixMe[incompatible-
|
|
122
|
+
// $FlowFixMe[incompatible-type] clearInterval / clearTimeout are interchangeable
|
|
124
123
|
clearInterval(intervalOrTimeoutId);
|
|
125
124
|
if (didLogWatchmanWaitMessage) {
|
|
126
125
|
onStatus({
|
|
@@ -334,13 +333,13 @@ module.exports = async function watchmanCrawl({
|
|
|
334
333
|
}
|
|
335
334
|
|
|
336
335
|
const nextData: FileMetadata = [
|
|
337
|
-
'',
|
|
338
336
|
mtime,
|
|
339
337
|
size,
|
|
340
338
|
0,
|
|
341
339
|
'',
|
|
342
340
|
sha1hex ?? null,
|
|
343
341
|
symlinkInfo,
|
|
342
|
+
'',
|
|
344
343
|
];
|
|
345
344
|
|
|
346
345
|
// If watchman is fresh, the removed files map starts with all files
|
|
@@ -367,4 +366,4 @@ module.exports = async function watchmanCrawl({
|
|
|
367
366
|
removedFiles,
|
|
368
367
|
clocks: newClocks,
|
|
369
368
|
};
|
|
370
|
-
}
|
|
369
|
+
}
|