metro-file-map 0.76.0 → 0.76.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 +2 -3
- package/src/ModuleMap.d.ts +33 -0
- package/src/Watcher.d.ts +24 -0
- package/src/Watcher.js +2 -0
- package/src/Watcher.js.flow +5 -0
- package/src/cache/DiskCacheManager.d.ts +37 -0
- package/src/crawlers/node/index.js +9 -1
- package/src/crawlers/node/index.js.flow +12 -1
- package/src/crawlers/watchman/index.js +5 -2
- package/src/crawlers/watchman/index.js.flow +7 -3
- package/src/flow-types.d.ts +272 -0
- package/src/flow-types.js.flow +1 -0
- package/src/index.d.ts +94 -0
- package/src/index.js +16 -20
- package/src/index.js.flow +23 -20
- package/src/lib/DuplicateHasteCandidatesError.d.ts +24 -0
- package/src/lib/TreeFS.js +170 -111
- package/src/lib/TreeFS.js.flow +170 -98
- package/src/HasteFS.js +0 -220
- package/src/HasteFS.js.flow +0 -216
package/src/HasteFS.js.flow
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @format
|
|
8
|
-
* @flow strict-local
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type {
|
|
12
|
-
FileData,
|
|
13
|
-
FileMetaData,
|
|
14
|
-
FileStats,
|
|
15
|
-
Glob,
|
|
16
|
-
MutableFileSystem,
|
|
17
|
-
Path,
|
|
18
|
-
} from './flow-types';
|
|
19
|
-
|
|
20
|
-
import H from './constants';
|
|
21
|
-
import * as fastPath from './lib/fast_path';
|
|
22
|
-
import invariant from 'invariant';
|
|
23
|
-
import * as path from 'path';
|
|
24
|
-
import {globsToMatcher, replacePathSepForGlob} from 'jest-util';
|
|
25
|
-
|
|
26
|
-
export default class HasteFS implements MutableFileSystem {
|
|
27
|
-
+#rootDir: Path;
|
|
28
|
-
+#files: FileData;
|
|
29
|
-
|
|
30
|
-
constructor({rootDir, files}: {rootDir: Path, files: FileData}) {
|
|
31
|
-
this.#rootDir = rootDir;
|
|
32
|
-
this.#files = files;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
_normalizePath(relativeOrAbsolutePath: Path): string {
|
|
36
|
-
return path.isAbsolute(relativeOrAbsolutePath)
|
|
37
|
-
? fastPath.relative(this.#rootDir, relativeOrAbsolutePath)
|
|
38
|
-
: path.normalize(relativeOrAbsolutePath);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
remove(filePath: Path): ?FileMetaData {
|
|
42
|
-
const normalPath = this._normalizePath(filePath);
|
|
43
|
-
const fileMetadata = this.#files.get(normalPath);
|
|
44
|
-
if (!fileMetadata) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
this.#files.delete(normalPath);
|
|
48
|
-
return fileMetadata;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
bulkAddOrModify(changedFiles: FileData) {
|
|
52
|
-
for (const [relativePath, metadata] of changedFiles) {
|
|
53
|
-
this.#files.set(relativePath, metadata);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
addOrModify(filePath: Path, metadata: FileMetaData) {
|
|
58
|
-
this.#files.set(this._normalizePath(filePath), metadata);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
getSerializableSnapshot(): FileData {
|
|
62
|
-
return new Map(
|
|
63
|
-
Array.from(this.#files.entries(), ([k, v]: [Path, FileMetaData]) => [
|
|
64
|
-
k,
|
|
65
|
-
[...v],
|
|
66
|
-
]),
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
getModuleName(file: Path): ?string {
|
|
71
|
-
const fileMetadata = this._getFileData(file);
|
|
72
|
-
return (fileMetadata && fileMetadata[H.ID]) ?? null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
getSize(file: Path): ?number {
|
|
76
|
-
const fileMetadata = this._getFileData(file);
|
|
77
|
-
return (fileMetadata && fileMetadata[H.SIZE]) ?? null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
getDependencies(file: Path): ?Array<string> {
|
|
81
|
-
const fileMetadata = this._getFileData(file);
|
|
82
|
-
|
|
83
|
-
if (fileMetadata) {
|
|
84
|
-
return fileMetadata[H.DEPENDENCIES]
|
|
85
|
-
? fileMetadata[H.DEPENDENCIES].split(H.DEPENDENCY_DELIM)
|
|
86
|
-
: [];
|
|
87
|
-
} else {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
getSha1(file: Path): ?string {
|
|
93
|
-
const fileMetadata = this._getFileData(file);
|
|
94
|
-
return (fileMetadata && fileMetadata[H.SHA1]) ?? null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
exists(file: Path): boolean {
|
|
98
|
-
return this._getFileData(file) != null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
getAllFiles(): Array<Path> {
|
|
102
|
-
return Array.from(this.getAbsoluteFileIterator());
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
getFileIterator(): Iterable<Path> {
|
|
106
|
-
return this.#files.keys();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
*getAbsoluteFileIterator(): Iterable<Path> {
|
|
110
|
-
for (const file of this.getFileIterator()) {
|
|
111
|
-
yield fastPath.resolve(this.#rootDir, file);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
linkStats(file: Path): ?FileStats {
|
|
116
|
-
const fileMetadata = this._getFileData(file);
|
|
117
|
-
if (fileMetadata == null) {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
const fileType = fileMetadata[H.SYMLINK] === 0 ? 'f' : 'l';
|
|
121
|
-
const modifiedTime = fileMetadata[H.MTIME];
|
|
122
|
-
invariant(
|
|
123
|
-
typeof modifiedTime === 'number',
|
|
124
|
-
'File in HasteFS missing modified time',
|
|
125
|
-
);
|
|
126
|
-
return {
|
|
127
|
-
fileType,
|
|
128
|
-
modifiedTime,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
matchFiles(pattern: RegExp | string): Array<Path> {
|
|
133
|
-
const regexpPattern =
|
|
134
|
-
pattern instanceof RegExp ? pattern : new RegExp(pattern);
|
|
135
|
-
const files = [];
|
|
136
|
-
for (const file of this.getAbsoluteFileIterator()) {
|
|
137
|
-
if (regexpPattern.test(file)) {
|
|
138
|
-
files.push(file);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return files;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Given a search context, return a list of file paths matching the query.
|
|
146
|
-
* The query matches against normalized paths which start with `./`,
|
|
147
|
-
* for example: `a/b.js` -> `./a/b.js`
|
|
148
|
-
*/
|
|
149
|
-
matchFilesWithContext(
|
|
150
|
-
root: Path,
|
|
151
|
-
context: $ReadOnly<{
|
|
152
|
-
/* Should search for files recursively. */
|
|
153
|
-
recursive: boolean,
|
|
154
|
-
/* Filter relative paths against a pattern. */
|
|
155
|
-
filter: RegExp,
|
|
156
|
-
}>,
|
|
157
|
-
): Array<Path> {
|
|
158
|
-
const files = [];
|
|
159
|
-
const prefix = './';
|
|
160
|
-
|
|
161
|
-
for (const file of this.getAbsoluteFileIterator()) {
|
|
162
|
-
const filePath = fastPath.relative(root, file);
|
|
163
|
-
|
|
164
|
-
const isUnderRoot = filePath && !filePath.startsWith('..');
|
|
165
|
-
// Ignore everything outside of the provided `root`.
|
|
166
|
-
if (!isUnderRoot) {
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Prevent searching in child directories during a non-recursive search.
|
|
171
|
-
if (!context.recursive && filePath.includes(path.sep)) {
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
context.filter.test(
|
|
177
|
-
// NOTE(EvanBacon): Ensure files start with `./` for matching purposes
|
|
178
|
-
// this ensures packages work across Metro and Webpack (ex: Storybook for React DOM / React Native).
|
|
179
|
-
// `a/b.js` -> `./a/b.js`
|
|
180
|
-
prefix + filePath.replace(/\\/g, '/'),
|
|
181
|
-
)
|
|
182
|
-
) {
|
|
183
|
-
files.push(file);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return files;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
matchFilesWithGlob(globs: $ReadOnlyArray<Glob>, root: ?Path): Set<Path> {
|
|
191
|
-
const files = new Set<string>();
|
|
192
|
-
const matcher = globsToMatcher(globs);
|
|
193
|
-
|
|
194
|
-
for (const file of this.getAbsoluteFileIterator()) {
|
|
195
|
-
const filePath = root != null ? fastPath.relative(root, file) : file;
|
|
196
|
-
if (matcher(replacePathSepForGlob(filePath))) {
|
|
197
|
-
files.add(file);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return files;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
_getFileData(filePath: Path): void | FileMetaData {
|
|
204
|
-
// Shortcut to avoid any file path parsing if the given path is already
|
|
205
|
-
// normalised.
|
|
206
|
-
const optimisticMetadata = this.#files.get(filePath);
|
|
207
|
-
if (optimisticMetadata) {
|
|
208
|
-
return optimisticMetadata;
|
|
209
|
-
}
|
|
210
|
-
return this.#files.get(this._normalizePath(filePath));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
getRealPath(filePath: Path): Path {
|
|
214
|
-
throw new Error('HasteFS.getRealPath() is not implemented.');
|
|
215
|
-
}
|
|
216
|
-
}
|