metro-file-map 0.83.3 → 0.84.0
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 +4 -3
- package/src/Watcher.js +59 -52
- package/src/Watcher.js.flow +39 -39
- package/src/cache/DiskCacheManager.js.flow +3 -3
- package/src/constants.js +9 -8
- package/src/constants.js.flow +6 -18
- package/src/crawlers/node/index.js +27 -25
- package/src/crawlers/node/index.js.flow +6 -8
- package/src/crawlers/watchman/index.js +26 -22
- package/src/crawlers/watchman/index.js.flow +3 -4
- package/src/crawlers/watchman/planQuery.d.ts +24 -0
- package/src/crawlers/watchman/planQuery.js.flow +4 -4
- package/src/flow-types.js.flow +125 -87
- package/src/index.js +267 -235
- package/src/index.js.flow +269 -275
- package/src/lib/FileProcessor.js +76 -54
- package/src/lib/FileProcessor.js.flow +93 -72
- package/src/lib/RootPathUtils.js +25 -21
- package/src/lib/RootPathUtils.js.flow +4 -4
- package/src/lib/TreeFS.js +72 -77
- package/src/lib/TreeFS.js.flow +104 -124
- package/src/lib/checkWatchmanCapabilities.js.flow +4 -4
- package/src/lib/dependencyExtractor.d.ts +14 -0
- package/src/lib/normalizePathSeparatorsToPosix.js +25 -21
- package/src/lib/normalizePathSeparatorsToPosix.js.flow +3 -3
- package/src/lib/normalizePathSeparatorsToSystem.js +25 -21
- package/src/lib/normalizePathSeparatorsToSystem.js.flow +3 -3
- package/src/lib/rootRelativeCacheKeys.js +0 -20
- package/src/lib/rootRelativeCacheKeys.js.flow +1 -23
- package/src/plugins/DependencyPlugin.js +75 -0
- package/src/plugins/DependencyPlugin.js.flow +144 -0
- package/src/plugins/HastePlugin.js +83 -38
- package/src/plugins/HastePlugin.js.flow +105 -51
- package/src/plugins/MockPlugin.js +7 -4
- package/src/plugins/MockPlugin.js.flow +24 -15
- package/src/plugins/dependencies/dependencyExtractor.d.ts +14 -0
- package/src/{lib → plugins/dependencies}/dependencyExtractor.js.flow +3 -6
- package/src/plugins/dependencies/worker.d.ts +24 -0
- package/src/plugins/dependencies/worker.js +24 -0
- package/src/plugins/dependencies/worker.js.flow +53 -0
- package/src/plugins/haste/HasteConflictsError.js.flow +2 -2
- package/src/plugins/haste/computeConflicts.js +2 -1
- package/src/plugins/haste/computeConflicts.js.flow +11 -12
- package/src/plugins/haste/getPlatformExtension.js.flow +2 -2
- package/src/plugins/haste/worker.d.ts +24 -0
- package/src/plugins/haste/worker.js +35 -0
- package/src/plugins/haste/worker.js.flow +64 -0
- package/src/plugins/mocks/getMockName.js +27 -23
- package/src/plugins/mocks/getMockName.js.flow +2 -4
- package/src/watchers/AbstractWatcher.js +27 -22
- package/src/watchers/AbstractWatcher.js.flow +6 -5
- package/src/watchers/FallbackWatcher.js +88 -84
- package/src/watchers/FallbackWatcher.js.flow +65 -65
- package/src/watchers/NativeWatcher.js +25 -21
- package/src/watchers/NativeWatcher.js.flow +3 -3
- package/src/watchers/RecrawlWarning.js.flow +1 -1
- package/src/watchers/WatchmanWatcher.js +61 -53
- package/src/watchers/WatchmanWatcher.js.flow +39 -38
- package/src/watchers/common.js.flow +5 -5
- package/src/worker.d.ts +36 -0
- package/src/worker.js +16 -58
- package/src/worker.js.flow +19 -69
- package/src/workerExclusionList.d.ts +12 -0
- package/src/workerExclusionList.js.flow +1 -1
- package/src/Watcher.d.ts +0 -24
- package/src/cache/DiskCacheManager.d.ts +0 -38
- package/src/flow-types.d.ts +0 -353
- package/src/index.d.ts +0 -97
- package/src/lib/DuplicateHasteCandidatesError.d.ts +0 -24
- /package/src/{lib → plugins/dependencies}/dependencyExtractor.js +0 -0
package/src/lib/FileProcessor.js
CHANGED
|
@@ -6,40 +6,50 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.FileProcessor = void 0;
|
|
7
7
|
var _constants = _interopRequireDefault(require("../constants"));
|
|
8
8
|
var _worker = require("../worker");
|
|
9
|
+
var _RootPathUtils = require("./RootPathUtils");
|
|
9
10
|
var _jestWorker = require("jest-worker");
|
|
10
11
|
var _path = require("path");
|
|
11
12
|
function _interopRequireDefault(e) {
|
|
12
13
|
return e && e.__esModule ? e : { default: e };
|
|
13
14
|
}
|
|
14
15
|
const debug = require("debug")("Metro:FileMap");
|
|
15
|
-
const
|
|
16
|
+
const NODE_MODULES_SEP = "node_modules" + _path.sep;
|
|
16
17
|
const MAX_FILES_PER_WORKER = 100;
|
|
17
18
|
class FileProcessor {
|
|
18
|
-
#dependencyExtractor;
|
|
19
|
-
#enableHastePackages;
|
|
20
|
-
#hasteImplModulePath;
|
|
21
|
-
#enableWorkerThreads;
|
|
22
19
|
#maxFilesPerWorker;
|
|
23
20
|
#maxWorkers;
|
|
24
21
|
#perfLogger;
|
|
25
|
-
#
|
|
22
|
+
#pluginWorkers;
|
|
26
23
|
#inBandWorker;
|
|
24
|
+
#rootPathUtils;
|
|
27
25
|
constructor(opts) {
|
|
28
|
-
this.#dependencyExtractor = opts.dependencyExtractor;
|
|
29
|
-
this.#enableHastePackages = opts.enableHastePackages;
|
|
30
|
-
this.#enableWorkerThreads = opts.enableWorkerThreads;
|
|
31
|
-
this.#hasteImplModulePath = opts.hasteImplModulePath;
|
|
32
26
|
this.#maxFilesPerWorker = opts.maxFilesPerWorker ?? MAX_FILES_PER_WORKER;
|
|
33
27
|
this.#maxWorkers = opts.maxWorkers;
|
|
34
|
-
this.#
|
|
35
|
-
this.#inBandWorker = new _worker.Worker(
|
|
28
|
+
this.#pluginWorkers = opts.pluginWorkers ?? [];
|
|
29
|
+
this.#inBandWorker = new _worker.Worker({
|
|
30
|
+
plugins: this.#pluginWorkers.map((plugin) => plugin.worker),
|
|
31
|
+
});
|
|
36
32
|
this.#perfLogger = opts.perfLogger;
|
|
33
|
+
this.#rootPathUtils = new _RootPathUtils.RootPathUtils(opts.rootDir);
|
|
37
34
|
}
|
|
38
35
|
async processBatch(files, req) {
|
|
39
36
|
const errors = [];
|
|
37
|
+
const workerJobs = files
|
|
38
|
+
.map(([normalFilePath, fileMetadata]) => {
|
|
39
|
+
const maybeWorkerInput = this.#getWorkerInput(
|
|
40
|
+
normalFilePath,
|
|
41
|
+
fileMetadata,
|
|
42
|
+
req,
|
|
43
|
+
);
|
|
44
|
+
if (!maybeWorkerInput) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return [maybeWorkerInput, fileMetadata];
|
|
48
|
+
})
|
|
49
|
+
.filter(Boolean);
|
|
40
50
|
const numWorkers = Math.min(
|
|
41
51
|
this.#maxWorkers,
|
|
42
|
-
Math.ceil(
|
|
52
|
+
Math.ceil(workerJobs.length / this.#maxFilesPerWorker),
|
|
43
53
|
);
|
|
44
54
|
const batchWorker = this.#getBatchWorker(numWorkers);
|
|
45
55
|
if (req.maybeReturnContent) {
|
|
@@ -48,21 +58,17 @@ class FileProcessor {
|
|
|
48
58
|
);
|
|
49
59
|
}
|
|
50
60
|
await Promise.all(
|
|
51
|
-
|
|
52
|
-
const maybeWorkerInput = this.#getWorkerInput(
|
|
53
|
-
absolutePath,
|
|
54
|
-
fileMetadata,
|
|
55
|
-
req,
|
|
56
|
-
);
|
|
57
|
-
if (!maybeWorkerInput) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
61
|
+
workerJobs.map(([workerInput, fileMetadata]) => {
|
|
60
62
|
return batchWorker
|
|
61
|
-
.processFile(
|
|
62
|
-
.then((reply) =>
|
|
63
|
+
.processFile(workerInput)
|
|
64
|
+
.then((reply) =>
|
|
65
|
+
processWorkerReply(reply, workerInput.pluginsToRun, fileMetadata),
|
|
66
|
+
)
|
|
63
67
|
.catch((error) =>
|
|
64
68
|
errors.push({
|
|
65
|
-
|
|
69
|
+
normalFilePath: this.#rootPathUtils.absoluteToNormal(
|
|
70
|
+
workerInput.filePath,
|
|
71
|
+
),
|
|
66
72
|
error: normalizeWorkerError(error),
|
|
67
73
|
}),
|
|
68
74
|
);
|
|
@@ -73,43 +79,60 @@ class FileProcessor {
|
|
|
73
79
|
errors,
|
|
74
80
|
};
|
|
75
81
|
}
|
|
76
|
-
processRegularFile(
|
|
77
|
-
const workerInput = this.#getWorkerInput(
|
|
82
|
+
processRegularFile(normalPath, fileMetadata, req) {
|
|
83
|
+
const workerInput = this.#getWorkerInput(normalPath, fileMetadata, req);
|
|
78
84
|
return workerInput
|
|
79
85
|
? {
|
|
80
86
|
content: processWorkerReply(
|
|
81
87
|
this.#inBandWorker.processFile(workerInput),
|
|
88
|
+
workerInput.pluginsToRun,
|
|
82
89
|
fileMetadata,
|
|
83
90
|
),
|
|
84
91
|
}
|
|
85
92
|
: null;
|
|
86
93
|
}
|
|
87
|
-
#getWorkerInput(
|
|
94
|
+
#getWorkerInput(normalPath, fileMetadata, req) {
|
|
95
|
+
if (fileMetadata[_constants.default.SYMLINK] !== 0) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
88
98
|
const computeSha1 =
|
|
89
99
|
req.computeSha1 && fileMetadata[_constants.default.SHA1] == null;
|
|
90
|
-
const {
|
|
91
|
-
|
|
100
|
+
const { maybeReturnContent } = req;
|
|
101
|
+
const nodeModulesIdx = normalPath.indexOf(NODE_MODULES_SEP);
|
|
102
|
+
const isNodeModules =
|
|
103
|
+
nodeModulesIdx === 0 ||
|
|
104
|
+
(nodeModulesIdx > 0 && normalPath[nodeModulesIdx - 1] === _path.sep);
|
|
105
|
+
const pluginsToRun =
|
|
106
|
+
this.#pluginWorkers?.reduce((prev, plugin, idx) => {
|
|
107
|
+
if (
|
|
108
|
+
plugin.filter({
|
|
109
|
+
isNodeModules,
|
|
110
|
+
normalPath,
|
|
111
|
+
})
|
|
112
|
+
) {
|
|
113
|
+
prev.push(idx);
|
|
114
|
+
}
|
|
115
|
+
return prev;
|
|
116
|
+
}, []) ?? [];
|
|
117
|
+
if (!computeSha1 && pluginsToRun.length === 0) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
if (isNodeModules) {
|
|
92
121
|
if (computeSha1) {
|
|
93
122
|
return {
|
|
94
|
-
computeDependencies: false,
|
|
95
123
|
computeSha1: true,
|
|
96
|
-
|
|
97
|
-
enableHastePackages: false,
|
|
98
|
-
filePath: absolutePath,
|
|
99
|
-
hasteImplModulePath: null,
|
|
124
|
+
filePath: this.#rootPathUtils.normalToAbsolute(normalPath),
|
|
100
125
|
maybeReturnContent,
|
|
126
|
+
pluginsToRun,
|
|
101
127
|
};
|
|
102
128
|
}
|
|
103
129
|
return null;
|
|
104
130
|
}
|
|
105
131
|
return {
|
|
106
|
-
computeDependencies,
|
|
107
132
|
computeSha1,
|
|
108
|
-
|
|
109
|
-
enableHastePackages: this.#enableHastePackages,
|
|
110
|
-
filePath: absolutePath,
|
|
111
|
-
hasteImplModulePath: this.#hasteImplModulePath,
|
|
133
|
+
filePath: this.#rootPathUtils.normalToAbsolute(normalPath),
|
|
112
134
|
maybeReturnContent,
|
|
135
|
+
pluginsToRun,
|
|
113
136
|
};
|
|
114
137
|
}
|
|
115
138
|
#getBatchWorker(numWorkers) {
|
|
@@ -120,21 +143,21 @@ class FileProcessor {
|
|
|
120
143
|
};
|
|
121
144
|
}
|
|
122
145
|
const workerPath = require.resolve("../worker");
|
|
123
|
-
debug(
|
|
124
|
-
"Creating worker farm of %d worker %s",
|
|
125
|
-
numWorkers,
|
|
126
|
-
this.#enableWorkerThreads ? "threads" : "processes",
|
|
127
|
-
);
|
|
146
|
+
debug("Creating worker farm of %d worker threads", numWorkers);
|
|
128
147
|
this.#perfLogger?.point("initWorkers_start");
|
|
129
148
|
const jestWorker = new _jestWorker.Worker(workerPath, {
|
|
130
149
|
exposedMethods: ["processFile"],
|
|
131
150
|
maxRetries: 3,
|
|
132
151
|
numWorkers,
|
|
133
|
-
enableWorkerThreads:
|
|
152
|
+
enableWorkerThreads: true,
|
|
134
153
|
forkOptions: {
|
|
135
154
|
execArgv: [],
|
|
136
155
|
},
|
|
137
|
-
setupArgs: [
|
|
156
|
+
setupArgs: [
|
|
157
|
+
{
|
|
158
|
+
plugins: this.#pluginWorkers.map((plugin) => plugin.worker),
|
|
159
|
+
},
|
|
160
|
+
],
|
|
138
161
|
});
|
|
139
162
|
this.#perfLogger?.point("initWorkers_end");
|
|
140
163
|
this.#perfLogger = null;
|
|
@@ -143,15 +166,14 @@ class FileProcessor {
|
|
|
143
166
|
async end() {}
|
|
144
167
|
}
|
|
145
168
|
exports.FileProcessor = FileProcessor;
|
|
146
|
-
function processWorkerReply(metadata, fileMetadata) {
|
|
169
|
+
function processWorkerReply(metadata, pluginsRun, fileMetadata) {
|
|
147
170
|
fileMetadata[_constants.default.VISITED] = 1;
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
150
|
-
|
|
171
|
+
const pluginData = metadata.pluginData;
|
|
172
|
+
if (pluginData) {
|
|
173
|
+
for (const [i, pluginIdx] of pluginsRun.entries()) {
|
|
174
|
+
fileMetadata[_constants.default.PLUGINDATA + pluginIdx] = pluginData[i];
|
|
175
|
+
}
|
|
151
176
|
}
|
|
152
|
-
fileMetadata[_constants.default.DEPENDENCIES] = metadata.dependencies
|
|
153
|
-
? metadata.dependencies.join(_constants.default.DEPENDENCY_DELIM)
|
|
154
|
-
: "";
|
|
155
177
|
if (metadata.sha1 != null) {
|
|
156
178
|
fileMetadata[_constants.default.SHA1] = metadata.sha1;
|
|
157
179
|
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type {
|
|
13
|
+
FileMapPluginWorker,
|
|
13
14
|
FileMetadata,
|
|
14
15
|
PerfLogger,
|
|
15
16
|
WorkerMessage,
|
|
@@ -19,22 +20,18 @@ import type {
|
|
|
19
20
|
|
|
20
21
|
import H from '../constants';
|
|
21
22
|
import {Worker} from '../worker';
|
|
23
|
+
import {RootPathUtils} from './RootPathUtils';
|
|
22
24
|
import {Worker as JestWorker} from 'jest-worker';
|
|
23
25
|
import {sep} from 'path';
|
|
24
26
|
|
|
25
27
|
// eslint-disable-next-line import/no-commonjs
|
|
26
28
|
const debug = require('debug')('Metro:FileMap');
|
|
27
29
|
|
|
28
|
-
type ProcessFileRequest =
|
|
30
|
+
type ProcessFileRequest = Readonly<{
|
|
29
31
|
/**
|
|
30
32
|
* Populate metadata[H.SHA1] with the SHA1 of the file's contents.
|
|
31
33
|
*/
|
|
32
34
|
computeSha1: boolean,
|
|
33
|
-
/**
|
|
34
|
-
* Populate metadata[H.DEPENDENCIES] with unresolved dependency specifiers
|
|
35
|
-
* using the dependencyExtractor provided to the constructor.
|
|
36
|
-
*/
|
|
37
|
-
computeDependencies: boolean,
|
|
38
35
|
/**
|
|
39
36
|
* Only if processing has already required reading the file's contents, return
|
|
40
37
|
* the contents as a Buffer - null otherwise. Not supported for batches.
|
|
@@ -51,55 +48,64 @@ interface MaybeCodedError extends Error {
|
|
|
51
48
|
code?: string;
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
const
|
|
51
|
+
const NODE_MODULES_SEP = 'node_modules' + sep;
|
|
55
52
|
const MAX_FILES_PER_WORKER = 100;
|
|
56
53
|
|
|
57
54
|
export class FileProcessor {
|
|
58
|
-
#dependencyExtractor: ?string;
|
|
59
|
-
#enableHastePackages: boolean;
|
|
60
|
-
#hasteImplModulePath: ?string;
|
|
61
|
-
#enableWorkerThreads: boolean;
|
|
62
55
|
#maxFilesPerWorker: number;
|
|
63
56
|
#maxWorkers: number;
|
|
64
57
|
#perfLogger: ?PerfLogger;
|
|
65
|
-
#
|
|
58
|
+
#pluginWorkers: ReadonlyArray<FileMapPluginWorker>;
|
|
66
59
|
#inBandWorker: Worker;
|
|
60
|
+
#rootPathUtils: RootPathUtils;
|
|
67
61
|
|
|
68
62
|
constructor(
|
|
69
|
-
opts:
|
|
70
|
-
dependencyExtractor: ?string,
|
|
71
|
-
enableHastePackages: boolean,
|
|
72
|
-
enableWorkerThreads: boolean,
|
|
73
|
-
hasteImplModulePath: ?string,
|
|
63
|
+
opts: Readonly<{
|
|
74
64
|
maxFilesPerWorker?: ?number,
|
|
75
65
|
maxWorkers: number,
|
|
66
|
+
pluginWorkers: ?ReadonlyArray<FileMapPluginWorker>,
|
|
76
67
|
perfLogger: ?PerfLogger,
|
|
68
|
+
rootDir: string,
|
|
77
69
|
}>,
|
|
78
70
|
) {
|
|
79
|
-
this.#dependencyExtractor = opts.dependencyExtractor;
|
|
80
|
-
this.#enableHastePackages = opts.enableHastePackages;
|
|
81
|
-
this.#enableWorkerThreads = opts.enableWorkerThreads;
|
|
82
|
-
this.#hasteImplModulePath = opts.hasteImplModulePath;
|
|
83
71
|
this.#maxFilesPerWorker = opts.maxFilesPerWorker ?? MAX_FILES_PER_WORKER;
|
|
84
72
|
this.#maxWorkers = opts.maxWorkers;
|
|
85
|
-
this.#
|
|
86
|
-
this.#inBandWorker = new Worker(
|
|
73
|
+
this.#pluginWorkers = opts.pluginWorkers ?? [];
|
|
74
|
+
this.#inBandWorker = new Worker({
|
|
75
|
+
plugins: this.#pluginWorkers.map(plugin => plugin.worker),
|
|
76
|
+
});
|
|
87
77
|
this.#perfLogger = opts.perfLogger;
|
|
78
|
+
this.#rootPathUtils = new RootPathUtils(opts.rootDir);
|
|
88
79
|
}
|
|
89
80
|
|
|
90
81
|
async processBatch(
|
|
91
|
-
files:
|
|
82
|
+
files: ReadonlyArray<[string /*relativePath*/, FileMetadata]>,
|
|
92
83
|
req: ProcessFileRequest,
|
|
93
84
|
): Promise<{
|
|
94
85
|
errors: Array<{
|
|
95
|
-
|
|
86
|
+
normalFilePath: string,
|
|
96
87
|
error: MaybeCodedError,
|
|
97
88
|
}>,
|
|
98
89
|
}> {
|
|
99
90
|
const errors = [];
|
|
91
|
+
|
|
92
|
+
const workerJobs = files
|
|
93
|
+
.map(([normalFilePath, fileMetadata]) => {
|
|
94
|
+
const maybeWorkerInput = this.#getWorkerInput(
|
|
95
|
+
normalFilePath,
|
|
96
|
+
fileMetadata,
|
|
97
|
+
req,
|
|
98
|
+
);
|
|
99
|
+
if (!maybeWorkerInput) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
return [maybeWorkerInput, fileMetadata];
|
|
103
|
+
})
|
|
104
|
+
.filter(Boolean);
|
|
105
|
+
|
|
100
106
|
const numWorkers = Math.min(
|
|
101
107
|
this.#maxWorkers,
|
|
102
|
-
Math.ceil(
|
|
108
|
+
Math.ceil(workerJobs.length / this.#maxFilesPerWorker),
|
|
103
109
|
);
|
|
104
110
|
const batchWorker = this.#getBatchWorker(numWorkers);
|
|
105
111
|
|
|
@@ -110,20 +116,19 @@ export class FileProcessor {
|
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
await Promise.all(
|
|
113
|
-
|
|
114
|
-
const maybeWorkerInput = this.#getWorkerInput(
|
|
115
|
-
absolutePath,
|
|
116
|
-
fileMetadata,
|
|
117
|
-
req,
|
|
118
|
-
);
|
|
119
|
-
if (!maybeWorkerInput) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
119
|
+
workerJobs.map(([workerInput, fileMetadata]) => {
|
|
122
120
|
return batchWorker
|
|
123
|
-
.processFile(
|
|
124
|
-
.then(reply =>
|
|
121
|
+
.processFile(workerInput)
|
|
122
|
+
.then(reply =>
|
|
123
|
+
processWorkerReply(reply, workerInput.pluginsToRun, fileMetadata),
|
|
124
|
+
)
|
|
125
125
|
.catch(error =>
|
|
126
|
-
errors.push({
|
|
126
|
+
errors.push({
|
|
127
|
+
normalFilePath: this.#rootPathUtils.absoluteToNormal(
|
|
128
|
+
workerInput.filePath,
|
|
129
|
+
),
|
|
130
|
+
error: normalizeWorkerError(error),
|
|
131
|
+
}),
|
|
127
132
|
);
|
|
128
133
|
}),
|
|
129
134
|
);
|
|
@@ -132,15 +137,16 @@ export class FileProcessor {
|
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
processRegularFile(
|
|
135
|
-
|
|
140
|
+
normalPath: string,
|
|
136
141
|
fileMetadata: FileMetadata,
|
|
137
142
|
req: ProcessFileRequest,
|
|
138
143
|
): ?{content: ?Buffer} {
|
|
139
|
-
const workerInput = this.#getWorkerInput(
|
|
144
|
+
const workerInput = this.#getWorkerInput(normalPath, fileMetadata, req);
|
|
140
145
|
return workerInput
|
|
141
146
|
? {
|
|
142
147
|
content: processWorkerReply(
|
|
143
148
|
this.#inBandWorker.processFile(workerInput),
|
|
149
|
+
workerInput.pluginsToRun,
|
|
144
150
|
fileMetadata,
|
|
145
151
|
),
|
|
146
152
|
}
|
|
@@ -148,43 +154,60 @@ export class FileProcessor {
|
|
|
148
154
|
}
|
|
149
155
|
|
|
150
156
|
#getWorkerInput(
|
|
151
|
-
|
|
157
|
+
normalPath: string,
|
|
152
158
|
fileMetadata: FileMetadata,
|
|
153
159
|
req: ProcessFileRequest,
|
|
154
160
|
): ?WorkerMessage {
|
|
161
|
+
if (fileMetadata[H.SYMLINK] !== 0) {
|
|
162
|
+
// Only process regular files
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
|
|
155
166
|
const computeSha1 = req.computeSha1 && fileMetadata[H.SHA1] == null;
|
|
167
|
+
const {maybeReturnContent} = req;
|
|
168
|
+
|
|
169
|
+
const nodeModulesIdx = normalPath.indexOf(NODE_MODULES_SEP);
|
|
170
|
+
// Path may begin 'node_modules/' or contain '/node_modules/'.
|
|
171
|
+
const isNodeModules =
|
|
172
|
+
nodeModulesIdx === 0 ||
|
|
173
|
+
(nodeModulesIdx > 0 && normalPath[nodeModulesIdx - 1] === sep);
|
|
174
|
+
|
|
175
|
+
// Indices of plugins with a passing filter
|
|
176
|
+
const pluginsToRun =
|
|
177
|
+
this.#pluginWorkers?.reduce((prev, plugin, idx) => {
|
|
178
|
+
if (plugin.filter({isNodeModules, normalPath})) {
|
|
179
|
+
prev.push(idx);
|
|
180
|
+
}
|
|
181
|
+
return prev;
|
|
182
|
+
}, [] as Array<number>) ?? [];
|
|
156
183
|
|
|
157
|
-
|
|
184
|
+
if (!computeSha1 && pluginsToRun.length === 0) {
|
|
185
|
+
// Nothing to process
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
158
188
|
|
|
159
|
-
// Use a cheaper worker configuration for node_modules files, because
|
|
160
|
-
//
|
|
161
|
-
// modules or packages.
|
|
189
|
+
// Use a cheaper worker configuration for node_modules files, because
|
|
190
|
+
// they may never be Haste modules or packages.
|
|
162
191
|
//
|
|
163
192
|
// Note that we'd only expect node_modules files to reach this point if
|
|
164
193
|
// retainAllFiles is true, or they're touched during watch mode.
|
|
165
|
-
if (
|
|
194
|
+
if (isNodeModules) {
|
|
166
195
|
if (computeSha1) {
|
|
167
196
|
return {
|
|
168
|
-
computeDependencies: false,
|
|
169
197
|
computeSha1: true,
|
|
170
|
-
|
|
171
|
-
enableHastePackages: false,
|
|
172
|
-
filePath: absolutePath,
|
|
173
|
-
hasteImplModulePath: null,
|
|
198
|
+
filePath: this.#rootPathUtils.normalToAbsolute(normalPath),
|
|
174
199
|
maybeReturnContent,
|
|
200
|
+
pluginsToRun,
|
|
175
201
|
};
|
|
176
202
|
}
|
|
177
203
|
return null;
|
|
178
204
|
}
|
|
179
205
|
|
|
180
206
|
return {
|
|
181
|
-
computeDependencies,
|
|
182
207
|
computeSha1,
|
|
183
|
-
|
|
184
|
-
enableHastePackages: this.#enableHastePackages,
|
|
185
|
-
filePath: absolutePath,
|
|
186
|
-
hasteImplModulePath: this.#hasteImplModulePath,
|
|
208
|
+
filePath: this.#rootPathUtils.normalToAbsolute(normalPath),
|
|
187
209
|
maybeReturnContent,
|
|
210
|
+
pluginsToRun,
|
|
188
211
|
};
|
|
189
212
|
}
|
|
190
213
|
|
|
@@ -200,11 +223,7 @@ export class FileProcessor {
|
|
|
200
223
|
};
|
|
201
224
|
}
|
|
202
225
|
const workerPath = require.resolve('../worker');
|
|
203
|
-
debug(
|
|
204
|
-
'Creating worker farm of %d worker %s',
|
|
205
|
-
numWorkers,
|
|
206
|
-
this.#enableWorkerThreads ? 'threads' : 'processes',
|
|
207
|
-
);
|
|
226
|
+
debug('Creating worker farm of %d worker threads', numWorkers);
|
|
208
227
|
this.#perfLogger?.point('initWorkers_start');
|
|
209
228
|
const jestWorker = new JestWorker<{
|
|
210
229
|
processFile: WorkerMessage => Promise<WorkerMetadata>,
|
|
@@ -212,14 +231,18 @@ export class FileProcessor {
|
|
|
212
231
|
exposedMethods: ['processFile'],
|
|
213
232
|
maxRetries: 3,
|
|
214
233
|
numWorkers,
|
|
215
|
-
enableWorkerThreads:
|
|
234
|
+
enableWorkerThreads: true,
|
|
216
235
|
forkOptions: {
|
|
217
236
|
// Don't pass Node arguments down to workers. In particular, avoid
|
|
218
237
|
// unnecessarily registering Babel when we're running Metro from
|
|
219
238
|
// source (our worker is plain CommonJS).
|
|
220
239
|
execArgv: [],
|
|
221
240
|
},
|
|
222
|
-
setupArgs: [
|
|
241
|
+
setupArgs: [
|
|
242
|
+
{
|
|
243
|
+
plugins: this.#pluginWorkers.map(plugin => plugin.worker),
|
|
244
|
+
} as WorkerSetupArgs,
|
|
245
|
+
],
|
|
223
246
|
});
|
|
224
247
|
this.#perfLogger?.point('initWorkers_end');
|
|
225
248
|
// Only log worker init once
|
|
@@ -232,20 +255,18 @@ export class FileProcessor {
|
|
|
232
255
|
|
|
233
256
|
function processWorkerReply(
|
|
234
257
|
metadata: WorkerMetadata,
|
|
258
|
+
pluginsRun: ReadonlyArray<number>,
|
|
235
259
|
fileMetadata: FileMetadata,
|
|
236
260
|
) {
|
|
237
261
|
fileMetadata[H.VISITED] = 1;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
262
|
+
const pluginData = metadata.pluginData;
|
|
263
|
+
if (pluginData) {
|
|
264
|
+
for (const [i, pluginIdx] of pluginsRun.entries()) {
|
|
265
|
+
// $FlowFixMe[invalid-tuple-index]
|
|
266
|
+
fileMetadata[H.PLUGINDATA + pluginIdx] = pluginData[i];
|
|
267
|
+
}
|
|
243
268
|
}
|
|
244
269
|
|
|
245
|
-
fileMetadata[H.DEPENDENCIES] = metadata.dependencies
|
|
246
|
-
? metadata.dependencies.join(H.DEPENDENCY_DELIM)
|
|
247
|
-
: '';
|
|
248
|
-
|
|
249
270
|
if (metadata.sha1 != null) {
|
|
250
271
|
fileMetadata[H.SHA1] = metadata.sha1;
|
|
251
272
|
}
|
package/src/lib/RootPathUtils.js
CHANGED
|
@@ -6,28 +6,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.RootPathUtils = void 0;
|
|
7
7
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
8
8
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
function
|
|
10
|
-
if ("function"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var n = { __proto__: null },
|
|
24
|
-
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
25
|
-
for (var u in e)
|
|
26
|
-
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
27
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
28
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
9
|
+
function _interopRequireWildcard(e, t) {
|
|
10
|
+
if ("function" == typeof WeakMap)
|
|
11
|
+
var r = new WeakMap(),
|
|
12
|
+
n = new WeakMap();
|
|
13
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
14
|
+
if (!t && e && e.__esModule) return e;
|
|
15
|
+
var o,
|
|
16
|
+
i,
|
|
17
|
+
f = { __proto__: null, default: e };
|
|
18
|
+
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
19
|
+
return f;
|
|
20
|
+
if ((o = t ? n : r)) {
|
|
21
|
+
if (o.has(e)) return o.get(e);
|
|
22
|
+
o.set(e, f);
|
|
29
23
|
}
|
|
30
|
-
|
|
24
|
+
for (const t in e)
|
|
25
|
+
"default" !== t &&
|
|
26
|
+
{}.hasOwnProperty.call(e, t) &&
|
|
27
|
+
((i =
|
|
28
|
+
(o = Object.defineProperty) &&
|
|
29
|
+
Object.getOwnPropertyDescriptor(e, t)) &&
|
|
30
|
+
(i.get || i.set)
|
|
31
|
+
? o(f, t, i)
|
|
32
|
+
: (f[t] = e[t]));
|
|
33
|
+
return f;
|
|
34
|
+
})(e, t);
|
|
31
35
|
}
|
|
32
36
|
function _interopRequireDefault(e) {
|
|
33
37
|
return e && e.__esModule ? e : { default: e };
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @format
|
|
8
7
|
* @flow strict
|
|
8
|
+
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import invariant from 'invariant';
|
|
@@ -48,8 +48,8 @@ const CURRENT_FRAGMENT = '.' + path.sep;
|
|
|
48
48
|
|
|
49
49
|
export class RootPathUtils {
|
|
50
50
|
#rootDir: string;
|
|
51
|
-
#rootDirnames:
|
|
52
|
-
#rootParts:
|
|
51
|
+
#rootDirnames: ReadonlyArray<string>;
|
|
52
|
+
#rootParts: ReadonlyArray<string>;
|
|
53
53
|
#rootDepth: number;
|
|
54
54
|
|
|
55
55
|
constructor(rootDir: string) {
|
|
@@ -80,7 +80,7 @@ export class RootPathUtils {
|
|
|
80
80
|
return this.#rootParts[this.#rootParts.length - 1 - n];
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
getParts():
|
|
83
|
+
getParts(): ReadonlyArray<string> {
|
|
84
84
|
return this.#rootParts;
|
|
85
85
|
}
|
|
86
86
|
|