metro-file-map 0.84.0 → 0.84.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.d.ts +77 -0
- package/src/cache/DiskCacheManager.d.ts +49 -0
- package/src/constants.d.ts +22 -0
- package/src/crawlers/node/hasNativeFindSupport.d.ts +19 -0
- package/src/crawlers/node/index.d.ts +23 -0
- package/src/crawlers/watchman/index.d.ts +30 -0
- package/src/flow-types.d.ts +411 -0
- package/src/flow-types.js.flow +1 -1
- package/src/index.d.ts +182 -0
- package/src/index.js +10 -12
- package/src/index.js.flow +10 -15
- package/src/lib/FileProcessor.d.ts +60 -0
- package/src/lib/RootPathUtils.d.ts +30 -0
- package/src/lib/TreeFS.d.ts +166 -0
- package/src/lib/checkWatchmanCapabilities.d.ts +20 -0
- package/src/lib/normalizePathSeparatorsToPosix.d.ts +20 -0
- package/src/lib/normalizePathSeparatorsToSystem.d.ts +20 -0
- package/src/lib/rootRelativeCacheKeys.d.ts +24 -0
- package/src/lib/sorting.d.ts +23 -0
- package/src/plugins/DependencyPlugin.d.ts +63 -0
- package/src/plugins/DependencyPlugin.js +1 -1
- package/src/plugins/DependencyPlugin.js.flow +1 -1
- package/src/plugins/HastePlugin.d.ts +77 -0
- package/src/plugins/HastePlugin.js +1 -1
- package/src/plugins/HastePlugin.js.flow +1 -1
- package/src/plugins/MockPlugin.d.ts +50 -0
- package/src/plugins/MockPlugin.js +2 -2
- package/src/plugins/MockPlugin.js.flow +2 -2
- package/src/plugins/dependencies/dependencyExtractor.d.ts +1 -1
- package/src/plugins/haste/DuplicateHasteCandidatesError.d.ts +31 -0
- package/src/plugins/haste/HasteConflictsError.d.ts +23 -0
- package/src/plugins/haste/computeConflicts.d.ts +34 -0
- package/src/plugins/haste/getPlatformExtension.d.ts +21 -0
- package/src/plugins/mocks/getMockName.d.ts +20 -0
- package/src/watchers/AbstractWatcher.d.ts +41 -0
- package/src/watchers/FallbackWatcher.d.ts +28 -0
- package/src/watchers/NativeWatcher.d.ts +55 -0
- package/src/watchers/RecrawlWarning.d.ts +32 -0
- package/src/watchers/WatchmanWatcher.d.ts +34 -0
- package/src/watchers/common.d.ts +68 -0
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<33bbe77b6d139e247ee97f706bbe485d>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro-file-map/src/index.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {
|
|
19
|
+
BuildParameters,
|
|
20
|
+
BuildResult,
|
|
21
|
+
CacheData,
|
|
22
|
+
CacheManagerFactory,
|
|
23
|
+
ChangeEventMetadata,
|
|
24
|
+
Console,
|
|
25
|
+
FileData,
|
|
26
|
+
FileMapPlugin,
|
|
27
|
+
FileSystem,
|
|
28
|
+
HasteMapData,
|
|
29
|
+
HasteMapItem,
|
|
30
|
+
HType,
|
|
31
|
+
PerfLoggerFactory,
|
|
32
|
+
} from './flow-types';
|
|
33
|
+
|
|
34
|
+
import EventEmitter from 'events';
|
|
35
|
+
|
|
36
|
+
export type {
|
|
37
|
+
BuildParameters,
|
|
38
|
+
BuildResult,
|
|
39
|
+
CacheData,
|
|
40
|
+
ChangeEventMetadata,
|
|
41
|
+
FileData,
|
|
42
|
+
FileMap,
|
|
43
|
+
FileSystem,
|
|
44
|
+
HasteMapData,
|
|
45
|
+
HasteMapItem,
|
|
46
|
+
};
|
|
47
|
+
export type InputOptions = Readonly<{
|
|
48
|
+
computeSha1?: null | undefined | boolean;
|
|
49
|
+
enableSymlinks?: null | undefined | boolean;
|
|
50
|
+
extensions: ReadonlyArray<string>;
|
|
51
|
+
forceNodeFilesystemAPI?: null | undefined | boolean;
|
|
52
|
+
ignorePattern?: null | undefined | RegExp;
|
|
53
|
+
plugins?: ReadonlyArray<AnyFileMapPlugin>;
|
|
54
|
+
retainAllFiles: boolean;
|
|
55
|
+
rootDir: string;
|
|
56
|
+
roots: ReadonlyArray<string>;
|
|
57
|
+
cacheManagerFactory?: null | undefined | CacheManagerFactory;
|
|
58
|
+
console?: Console;
|
|
59
|
+
healthCheck: HealthCheckOptions;
|
|
60
|
+
maxFilesPerWorker?: null | undefined | number;
|
|
61
|
+
maxWorkers: number;
|
|
62
|
+
perfLoggerFactory?: null | undefined | PerfLoggerFactory;
|
|
63
|
+
resetCache?: null | undefined | boolean;
|
|
64
|
+
useWatchman?: null | undefined | boolean;
|
|
65
|
+
watch?: null | undefined | boolean;
|
|
66
|
+
watchmanDeferStates?: ReadonlyArray<string>;
|
|
67
|
+
}>;
|
|
68
|
+
type HealthCheckOptions = Readonly<{
|
|
69
|
+
enabled: boolean;
|
|
70
|
+
interval: number;
|
|
71
|
+
timeout: number;
|
|
72
|
+
filePrefix: string;
|
|
73
|
+
}>;
|
|
74
|
+
type AnyFileMapPlugin = FileMapPlugin<any, any>;
|
|
75
|
+
export {DiskCacheManager} from './cache/DiskCacheManager';
|
|
76
|
+
export {default as DependencyPlugin} from './plugins/DependencyPlugin';
|
|
77
|
+
export type {DependencyPluginOptions} from './plugins/DependencyPlugin';
|
|
78
|
+
export {DuplicateHasteCandidatesError} from './plugins/haste/DuplicateHasteCandidatesError';
|
|
79
|
+
export {HasteConflictsError} from './plugins/haste/HasteConflictsError';
|
|
80
|
+
export {default as HastePlugin} from './plugins/HastePlugin';
|
|
81
|
+
export type {HasteMap} from './flow-types';
|
|
82
|
+
export type {HealthCheckResult} from './Watcher';
|
|
83
|
+
export type {
|
|
84
|
+
CacheManager,
|
|
85
|
+
CacheManagerFactory,
|
|
86
|
+
CacheManagerFactoryOptions,
|
|
87
|
+
CacheManagerWriteOptions,
|
|
88
|
+
ChangeEvent,
|
|
89
|
+
DependencyExtractor,
|
|
90
|
+
WatcherStatus,
|
|
91
|
+
} from './flow-types';
|
|
92
|
+
/**
|
|
93
|
+
* FileMap includes a JavaScript implementation of Facebook's haste module system.
|
|
94
|
+
*
|
|
95
|
+
* This implementation is inspired by https://github.com/facebook/node-haste
|
|
96
|
+
* and was built with for high-performance in large code repositories with
|
|
97
|
+
* hundreds of thousands of files. This implementation is scalable and provides
|
|
98
|
+
* predictable performance.
|
|
99
|
+
*
|
|
100
|
+
* Because the file map creation and synchronization is critical to startup
|
|
101
|
+
* performance and most tasks are blocked by I/O this class makes heavy use of
|
|
102
|
+
* synchronous operations. It uses worker processes for parallelizing file
|
|
103
|
+
* access and metadata extraction.
|
|
104
|
+
*
|
|
105
|
+
* The data structures created by `metro-file-map` can be used directly from the
|
|
106
|
+
* cache without further processing. The metadata objects in the `files` and
|
|
107
|
+
* `map` objects contain cross-references: a metadata object from one can look
|
|
108
|
+
* up the corresponding metadata object in the other map. Note that in most
|
|
109
|
+
* projects, the number of files will be greater than the number of haste
|
|
110
|
+
* modules one module can refer to many files based on platform extensions.
|
|
111
|
+
*
|
|
112
|
+
* type CacheData = {
|
|
113
|
+
* clocks: WatchmanClocks,
|
|
114
|
+
* files: {[filepath: string]: FileMetadata},
|
|
115
|
+
* map: {[id: string]: HasteMapItem},
|
|
116
|
+
* mocks: {[id: string]: string},
|
|
117
|
+
* }
|
|
118
|
+
*
|
|
119
|
+
* // Watchman clocks are used for query synchronization and file system deltas.
|
|
120
|
+
* type WatchmanClocks = {[filepath: string]: string};
|
|
121
|
+
*
|
|
122
|
+
* type FileMetadata = {
|
|
123
|
+
* id: ?string, // used to look up module metadata objects in `map`.
|
|
124
|
+
* mtime: number, // check for outdated files.
|
|
125
|
+
* size: number, // size of the file in bytes.
|
|
126
|
+
* visited: boolean, // whether the file has been parsed or not.
|
|
127
|
+
* dependencies: Array<string>, // all relative dependencies of this file.
|
|
128
|
+
* sha1: ?string, // SHA-1 of the file, if requested via options.
|
|
129
|
+
* symlink: ?(1 | 0 | string), // Truthy if symlink, string is target
|
|
130
|
+
* };
|
|
131
|
+
*
|
|
132
|
+
* // Modules can be targeted to a specific platform based on the file name.
|
|
133
|
+
* // Example: platform.ios.js and Platform.android.js will both map to the same
|
|
134
|
+
* // `Platform` module. The platform should be specified during resolution.
|
|
135
|
+
* type HasteMapItem = {[platform: string]: ModuleMetadata};
|
|
136
|
+
*
|
|
137
|
+
* //
|
|
138
|
+
* type ModuleMetadata = {
|
|
139
|
+
* path: string, // the path to look up the file object in `files`.
|
|
140
|
+
* type: string, // the module type (either `package` or `module`).
|
|
141
|
+
* };
|
|
142
|
+
*
|
|
143
|
+
* Note that the data structures described above are conceptual only. The actual
|
|
144
|
+
* implementation uses arrays and constant keys for metadata storage. Instead of
|
|
145
|
+
* `{id: 'flatMap', mtime: 3421, size: 42, visited: true, dependencies: []}` the real
|
|
146
|
+
* representation is similar to `['flatMap', 3421, 42, 1, []]` to save storage space
|
|
147
|
+
* and reduce parse and write time of a big JSON blob.
|
|
148
|
+
*
|
|
149
|
+
* The FileMap is created as follows:
|
|
150
|
+
* 1. read data from the cache or create an empty structure.
|
|
151
|
+
*
|
|
152
|
+
* 2. crawl the file system.
|
|
153
|
+
* * empty cache: crawl the entire file system.
|
|
154
|
+
* * cache available:
|
|
155
|
+
* * if watchman is available: get file system delta changes.
|
|
156
|
+
* * if watchman is unavailable: crawl the entire file system.
|
|
157
|
+
* * build metadata objects for every file. This builds the `files` part of
|
|
158
|
+
* the `FileMap`.
|
|
159
|
+
*
|
|
160
|
+
* 3. visit and extract metadata from changed files, including sha1,
|
|
161
|
+
* depedendencies, and any plugins.
|
|
162
|
+
* * this is done in parallel over worker processes to improve performance.
|
|
163
|
+
* * the worst case is to visit all files.
|
|
164
|
+
* * the best case is no file system access and retrieving all data from
|
|
165
|
+
* the cache.
|
|
166
|
+
* * the average case is a small number of changed files.
|
|
167
|
+
*
|
|
168
|
+
* 4. serialize the new `FileMap` in a cache file.
|
|
169
|
+
*
|
|
170
|
+
*/
|
|
171
|
+
declare class FileMap extends EventEmitter {
|
|
172
|
+
static create(options: InputOptions): FileMap;
|
|
173
|
+
constructor(options: InputOptions);
|
|
174
|
+
build(): Promise<BuildResult>;
|
|
175
|
+
/**
|
|
176
|
+
* 1. read data from the cache or create an empty structure.
|
|
177
|
+
*/
|
|
178
|
+
read(): Promise<null | undefined | CacheData>;
|
|
179
|
+
end(): Promise<void>;
|
|
180
|
+
static H: HType;
|
|
181
|
+
}
|
|
182
|
+
export default FileMap;
|
package/src/index.js
CHANGED
|
@@ -458,18 +458,16 @@ class FileMap extends _events.default {
|
|
|
458
458
|
fileSystem.bulkAddOrModify(changedFiles);
|
|
459
459
|
this.#startupPerfLogger?.point("applyFileDelta_add_end");
|
|
460
460
|
this.#startupPerfLogger?.point("applyFileDelta_updatePlugins_start");
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}),
|
|
472
|
-
]);
|
|
461
|
+
plugins.forEach(({ plugin, dataIdx }) => {
|
|
462
|
+
const mapFn =
|
|
463
|
+
dataIdx != null
|
|
464
|
+
? ([relativePath, fileData]) => [relativePath, fileData[dataIdx]]
|
|
465
|
+
: ([relativePath, fileData]) => [relativePath, null];
|
|
466
|
+
plugin.bulkUpdate({
|
|
467
|
+
addedOrModified: mapIterator(changedFiles.entries(), mapFn),
|
|
468
|
+
removed: mapIterator(removed.values(), mapFn),
|
|
469
|
+
});
|
|
470
|
+
});
|
|
473
471
|
this.#startupPerfLogger?.point("applyFileDelta_updatePlugins_end");
|
|
474
472
|
this.#startupPerfLogger?.point("applyFileDelta_end");
|
|
475
473
|
}
|
package/src/index.js.flow
CHANGED
|
@@ -667,21 +667,16 @@ export default class FileMap extends EventEmitter {
|
|
|
667
667
|
this.#startupPerfLogger?.point('applyFileDelta_add_end');
|
|
668
668
|
|
|
669
669
|
this.#startupPerfLogger?.point('applyFileDelta_updatePlugins_start');
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
[
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
addedOrModified: mapIterator(changedFiles.entries(), mapFn),
|
|
681
|
-
removed: mapIterator(removed.values(), mapFn),
|
|
682
|
-
});
|
|
683
|
-
}),
|
|
684
|
-
]);
|
|
670
|
+
plugins.forEach(({plugin, dataIdx}) => {
|
|
671
|
+
const mapFn: ([CanonicalPath, FileMetadata]) => [CanonicalPath, unknown] =
|
|
672
|
+
dataIdx != null
|
|
673
|
+
? ([relativePath, fileData]) => [relativePath, fileData[dataIdx]]
|
|
674
|
+
: ([relativePath, fileData]) => [relativePath, null];
|
|
675
|
+
plugin.bulkUpdate({
|
|
676
|
+
addedOrModified: mapIterator(changedFiles.entries(), mapFn),
|
|
677
|
+
removed: mapIterator(removed.values(), mapFn),
|
|
678
|
+
});
|
|
679
|
+
});
|
|
685
680
|
this.#startupPerfLogger?.point('applyFileDelta_updatePlugins_end');
|
|
686
681
|
this.#startupPerfLogger?.point('applyFileDelta_end');
|
|
687
682
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<2ea213f753eef5de14cb8a27f68b9fa2>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro-file-map/src/lib/FileProcessor.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {
|
|
19
|
+
FileMapPluginWorker,
|
|
20
|
+
FileMetadata,
|
|
21
|
+
PerfLogger,
|
|
22
|
+
} from '../flow-types';
|
|
23
|
+
|
|
24
|
+
type ProcessFileRequest = Readonly<{
|
|
25
|
+
/**
|
|
26
|
+
* Populate metadata[H.SHA1] with the SHA1 of the file's contents.
|
|
27
|
+
*/
|
|
28
|
+
computeSha1: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Only if processing has already required reading the file's contents, return
|
|
31
|
+
* the contents as a Buffer - null otherwise. Not supported for batches.
|
|
32
|
+
*/
|
|
33
|
+
maybeReturnContent: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
interface MaybeCodedError extends Error {
|
|
36
|
+
code?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare class FileProcessor {
|
|
39
|
+
constructor(
|
|
40
|
+
opts: Readonly<{
|
|
41
|
+
maxFilesPerWorker?: null | undefined | number;
|
|
42
|
+
maxWorkers: number;
|
|
43
|
+
pluginWorkers: null | undefined | ReadonlyArray<FileMapPluginWorker>;
|
|
44
|
+
perfLogger: null | undefined | PerfLogger;
|
|
45
|
+
rootDir: string;
|
|
46
|
+
}>,
|
|
47
|
+
);
|
|
48
|
+
processBatch(
|
|
49
|
+
files: ReadonlyArray<[string, FileMetadata]>,
|
|
50
|
+
req: ProcessFileRequest,
|
|
51
|
+
): Promise<{
|
|
52
|
+
errors: Array<{normalFilePath: string; error: MaybeCodedError}>;
|
|
53
|
+
}>;
|
|
54
|
+
processRegularFile(
|
|
55
|
+
normalPath: string,
|
|
56
|
+
fileMetadata: FileMetadata,
|
|
57
|
+
req: ProcessFileRequest,
|
|
58
|
+
): null | undefined | {content: null | undefined | Buffer};
|
|
59
|
+
end(): Promise<void>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @generated SignedSource<<5ecdb559fce5f5c6ed50df6e4eaebf20>>
|
|
9
|
+
*
|
|
10
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
11
|
+
* Original file: packages/metro-file-map/src/lib/RootPathUtils.js
|
|
12
|
+
* To regenerate, run:
|
|
13
|
+
* js1 build metro-ts-defs (internal) OR
|
|
14
|
+
* yarn run build-ts-defs (OSS)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export declare class RootPathUtils {
|
|
18
|
+
constructor(rootDir: string);
|
|
19
|
+
getBasenameOfNthAncestor(n: number): string;
|
|
20
|
+
getParts(): ReadonlyArray<string>;
|
|
21
|
+
absoluteToNormal(absolutePath: string): string;
|
|
22
|
+
normalToAbsolute(normalPath: string): string;
|
|
23
|
+
relativeToNormal(relativePath: string): string;
|
|
24
|
+
getAncestorOfRootIdx(normalPath: string): null | undefined | number;
|
|
25
|
+
joinNormalToRelative(
|
|
26
|
+
normalPath: string,
|
|
27
|
+
relativePath: string,
|
|
28
|
+
): {normalPath: string; collapsedSegments: number};
|
|
29
|
+
relative(from: string, to: string): string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @generated SignedSource<<1f36861cea798d8cc2a5dc61293ecb1b>>
|
|
9
|
+
*
|
|
10
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
11
|
+
* Original file: packages/metro-file-map/src/lib/TreeFS.js
|
|
12
|
+
* To regenerate, run:
|
|
13
|
+
* js1 build metro-ts-defs (internal) OR
|
|
14
|
+
* yarn run build-ts-defs (OSS)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type {
|
|
18
|
+
CacheData,
|
|
19
|
+
FileData,
|
|
20
|
+
FileMetadata,
|
|
21
|
+
FileStats,
|
|
22
|
+
LookupResult,
|
|
23
|
+
MutableFileSystem,
|
|
24
|
+
Path,
|
|
25
|
+
ProcessFileFunction,
|
|
26
|
+
} from '../flow-types';
|
|
27
|
+
|
|
28
|
+
type DirectoryNode = Map<string, MixedNode>;
|
|
29
|
+
type FileNode = FileMetadata;
|
|
30
|
+
type MixedNode = FileNode | DirectoryNode;
|
|
31
|
+
type DeserializedSnapshotInput = {
|
|
32
|
+
rootDir: string;
|
|
33
|
+
fileSystemData: DirectoryNode;
|
|
34
|
+
processFile: ProcessFileFunction;
|
|
35
|
+
};
|
|
36
|
+
type TreeFSOptions = {
|
|
37
|
+
rootDir: Path;
|
|
38
|
+
files?: FileData;
|
|
39
|
+
processFile: ProcessFileFunction;
|
|
40
|
+
};
|
|
41
|
+
type MatchFilesOptions = Readonly<{
|
|
42
|
+
filter?: null | undefined | RegExp;
|
|
43
|
+
filterCompareAbsolute?: boolean;
|
|
44
|
+
filterComparePosix?: boolean;
|
|
45
|
+
follow?: boolean;
|
|
46
|
+
recursive?: boolean;
|
|
47
|
+
rootDir?: null | undefined | Path;
|
|
48
|
+
}>;
|
|
49
|
+
type MetadataIteratorOptions = Readonly<{
|
|
50
|
+
includeSymlinks: boolean;
|
|
51
|
+
includeNodeModules: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* OVERVIEW:
|
|
55
|
+
*
|
|
56
|
+
* TreeFS is Metro's in-memory representation of the file system. It is
|
|
57
|
+
* structured as a tree of non-empty maps and leaves (tuples), with the root
|
|
58
|
+
* node representing the given `rootDir`, typically Metro's _project root_
|
|
59
|
+
* (not a filesystem root). Map keys are path segments, and branches outside
|
|
60
|
+
* the project root are accessed via `'..'`.
|
|
61
|
+
*
|
|
62
|
+
* EXAMPLE:
|
|
63
|
+
*
|
|
64
|
+
* For a root dir '/data/project', the file '/data/other/app/index.js' would
|
|
65
|
+
* have metadata at #rootNode.get('..').get('other').get('app').get('index.js')
|
|
66
|
+
*
|
|
67
|
+
* SERIALISATION:
|
|
68
|
+
*
|
|
69
|
+
* #rootNode is designed to be directly serialisable and directly portable (for
|
|
70
|
+
* a given project) between different root directories and operating systems.
|
|
71
|
+
*
|
|
72
|
+
* SYMLINKS:
|
|
73
|
+
*
|
|
74
|
+
* Symlinks are represented as nodes whose metadata contains their literal
|
|
75
|
+
* target. Literal targets are resolved to normal paths at runtime, and cached.
|
|
76
|
+
* If a symlink is encountered during traversal, we restart traversal at the
|
|
77
|
+
* root node targeting join(normal symlink target, remaining path suffix).
|
|
78
|
+
*
|
|
79
|
+
* NODE TYPES:
|
|
80
|
+
*
|
|
81
|
+
* - A directory (including a parent directory at '..') is represented by a
|
|
82
|
+
* `Map` of basenames to any other node type.
|
|
83
|
+
* - A file is represented by an `Array` (tuple) of metadata, of which:
|
|
84
|
+
* - A regular file has node[H.SYMLINK] === 0
|
|
85
|
+
* - A symlink has node[H.SYMLINK] === 1 or
|
|
86
|
+
* typeof node[H.SYMLINK] === 'string', where a string is the literal
|
|
87
|
+
* content of the symlink (i.e. from readlink), if known.
|
|
88
|
+
*
|
|
89
|
+
* TERMINOLOGY:
|
|
90
|
+
*
|
|
91
|
+
* - mixedPath
|
|
92
|
+
* A root-relative or absolute path
|
|
93
|
+
* - relativePath
|
|
94
|
+
* A root-relative path
|
|
95
|
+
* - normalPath
|
|
96
|
+
* A root-relative, normalised path (no extraneous '.' or '..'), may have a
|
|
97
|
+
* single trailing slash
|
|
98
|
+
* - canonicalPath
|
|
99
|
+
* A root-relative, normalised, real path (no symlinks in dirname), never has
|
|
100
|
+
* a trailing slash
|
|
101
|
+
*/
|
|
102
|
+
declare class TreeFS implements MutableFileSystem {
|
|
103
|
+
constructor(opts: TreeFSOptions);
|
|
104
|
+
getSerializableSnapshot(): CacheData['fileSystemData'];
|
|
105
|
+
static fromDeserializedSnapshot(args: DeserializedSnapshotInput): TreeFS;
|
|
106
|
+
getSize(mixedPath: Path): null | undefined | number;
|
|
107
|
+
getDifference(files: FileData): {
|
|
108
|
+
changedFiles: FileData;
|
|
109
|
+
removedFiles: Set<string>;
|
|
110
|
+
};
|
|
111
|
+
getSha1(mixedPath: Path): null | undefined | string;
|
|
112
|
+
getOrComputeSha1(
|
|
113
|
+
mixedPath: Path,
|
|
114
|
+
): Promise<null | undefined | {sha1: string; content?: Buffer}>;
|
|
115
|
+
exists(mixedPath: Path): boolean;
|
|
116
|
+
lookup(mixedPath: Path): LookupResult;
|
|
117
|
+
getAllFiles(): Array<Path>;
|
|
118
|
+
linkStats(mixedPath: Path): null | undefined | FileStats;
|
|
119
|
+
/**
|
|
120
|
+
* Given a search context, return a list of file paths matching the query.
|
|
121
|
+
* The query matches against normalized paths which start with `./`,
|
|
122
|
+
* for example: `a/b.js` -> `./a/b.js`
|
|
123
|
+
*/
|
|
124
|
+
matchFiles(opts: MatchFilesOptions): Iterable<Path>;
|
|
125
|
+
addOrModify(mixedPath: Path, metadata: FileMetadata): void;
|
|
126
|
+
bulkAddOrModify(addedOrModifiedFiles: FileData): void;
|
|
127
|
+
remove(mixedPath: Path): null | undefined | FileMetadata;
|
|
128
|
+
/**
|
|
129
|
+
* Given a start path (which need not exist), a subpath and type, and
|
|
130
|
+
* optionally a 'breakOnSegment', performs the following:
|
|
131
|
+
*
|
|
132
|
+
* X = mixedStartPath
|
|
133
|
+
* do
|
|
134
|
+
* if basename(X) === opts.breakOnSegment
|
|
135
|
+
* return null
|
|
136
|
+
* if X + subpath exists and has type opts.subpathType
|
|
137
|
+
* return {
|
|
138
|
+
* absolutePath: realpath(X + subpath)
|
|
139
|
+
* containerRelativePath: relative(mixedStartPath, X)
|
|
140
|
+
* }
|
|
141
|
+
* X = dirname(X)
|
|
142
|
+
* while X !== dirname(X)
|
|
143
|
+
*
|
|
144
|
+
* If opts.invalidatedBy is given, collects all absolute, real paths that if
|
|
145
|
+
* added or removed may invalidate this result.
|
|
146
|
+
*
|
|
147
|
+
* Useful for finding the closest package scope (subpath: package.json,
|
|
148
|
+
* type f, breakOnSegment: node_modules) or closest potential package root
|
|
149
|
+
* (subpath: node_modules/pkg, type: d) in Node.js resolution.
|
|
150
|
+
*/
|
|
151
|
+
hierarchicalLookup(
|
|
152
|
+
mixedStartPath: string,
|
|
153
|
+
subpath: string,
|
|
154
|
+
opts: {
|
|
155
|
+
breakOnSegment: null | undefined | string;
|
|
156
|
+
invalidatedBy: null | undefined | Set<string>;
|
|
157
|
+
subpathType: 'f' | 'd';
|
|
158
|
+
},
|
|
159
|
+
): null | undefined | {absolutePath: string; containerRelativePath: string};
|
|
160
|
+
metadataIterator(opts: MetadataIteratorOptions): Iterator<{
|
|
161
|
+
baseName: string;
|
|
162
|
+
canonicalPath: string;
|
|
163
|
+
metadata: FileMetadata;
|
|
164
|
+
}>;
|
|
165
|
+
}
|
|
166
|
+
export default TreeFS;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @generated SignedSource<<f72d8f0c4d8f513383584a02f36795ef>>
|
|
9
|
+
*
|
|
10
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
11
|
+
* Original file: packages/metro-file-map/src/lib/checkWatchmanCapabilities.js
|
|
12
|
+
* To regenerate, run:
|
|
13
|
+
* js1 build metro-ts-defs (internal) OR
|
|
14
|
+
* yarn run build-ts-defs (OSS)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
declare function checkWatchmanCapabilities(
|
|
18
|
+
requiredCapabilities: ReadonlyArray<string>,
|
|
19
|
+
): Promise<{version: string}>;
|
|
20
|
+
export default checkWatchmanCapabilities;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @generated SignedSource<<30b5e6d2308dde108c136f95a59e3740>>
|
|
9
|
+
*
|
|
10
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
11
|
+
* Original file: packages/metro-file-map/src/lib/normalizePathSeparatorsToPosix.js
|
|
12
|
+
* To regenerate, run:
|
|
13
|
+
* js1 build metro-ts-defs (internal) OR
|
|
14
|
+
* yarn run build-ts-defs (OSS)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
declare const $$EXPORT_DEFAULT_DECLARATION$$: (filePath: string) => string;
|
|
18
|
+
declare type $$EXPORT_DEFAULT_DECLARATION$$ =
|
|
19
|
+
typeof $$EXPORT_DEFAULT_DECLARATION$$;
|
|
20
|
+
export default $$EXPORT_DEFAULT_DECLARATION$$;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @generated SignedSource<<719a82b7670f09ecb97e007293fddfc6>>
|
|
9
|
+
*
|
|
10
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
11
|
+
* Original file: packages/metro-file-map/src/lib/normalizePathSeparatorsToSystem.js
|
|
12
|
+
* To regenerate, run:
|
|
13
|
+
* js1 build metro-ts-defs (internal) OR
|
|
14
|
+
* yarn run build-ts-defs (OSS)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
declare const $$EXPORT_DEFAULT_DECLARATION$$: (filePath: string) => string;
|
|
18
|
+
declare type $$EXPORT_DEFAULT_DECLARATION$$ =
|
|
19
|
+
typeof $$EXPORT_DEFAULT_DECLARATION$$;
|
|
20
|
+
export default $$EXPORT_DEFAULT_DECLARATION$$;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<f82cf1eeac38c409c5bf891686c2e828>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro-file-map/src/lib/rootRelativeCacheKeys.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {BuildParameters} from '../flow-types';
|
|
19
|
+
|
|
20
|
+
declare function rootRelativeCacheKeys(buildParameters: BuildParameters): {
|
|
21
|
+
rootDirHash: string;
|
|
22
|
+
relativeConfigHash: string;
|
|
23
|
+
};
|
|
24
|
+
export default rootRelativeCacheKeys;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @generated SignedSource<<8805bc71542c6b43e940f8c5761ff187>>
|
|
9
|
+
*
|
|
10
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
11
|
+
* Original file: packages/metro-file-map/src/lib/sorting.js
|
|
12
|
+
* To regenerate, run:
|
|
13
|
+
* js1 build metro-ts-defs (internal) OR
|
|
14
|
+
* yarn run build-ts-defs (OSS)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export declare function compareStrings(
|
|
18
|
+
a: null | string,
|
|
19
|
+
b: null | string,
|
|
20
|
+
): number;
|
|
21
|
+
export declare function chainComparators<T>(
|
|
22
|
+
...comparators: Array<(a: T, b: T) => number>
|
|
23
|
+
): (a: T, b: T) => number;
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<71361b3fd04f54f55665031c66465dd7>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro-file-map/src/plugins/DependencyPlugin.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {
|
|
19
|
+
FileMapDelta,
|
|
20
|
+
FileMapPlugin,
|
|
21
|
+
FileMapPluginInitOptions,
|
|
22
|
+
FileMapPluginWorker,
|
|
23
|
+
Path,
|
|
24
|
+
} from '../flow-types';
|
|
25
|
+
|
|
26
|
+
export type DependencyPluginOptions = Readonly<{
|
|
27
|
+
/** Path to custom dependency extractor module */
|
|
28
|
+
dependencyExtractor: null | undefined | string;
|
|
29
|
+
/** Whether to compute dependencies (performance optimization) */
|
|
30
|
+
computeDependencies: boolean;
|
|
31
|
+
rootDir: Path;
|
|
32
|
+
}>;
|
|
33
|
+
declare class DependencyPlugin
|
|
34
|
+
implements FileMapPlugin<null, ReadonlyArray<string> | null>
|
|
35
|
+
{
|
|
36
|
+
readonly name: 'dependencies';
|
|
37
|
+
constructor(options: DependencyPluginOptions);
|
|
38
|
+
initialize(
|
|
39
|
+
initOptions: FileMapPluginInitOptions<null, ReadonlyArray<string> | null>,
|
|
40
|
+
): Promise<void>;
|
|
41
|
+
getSerializableSnapshot(): null;
|
|
42
|
+
bulkUpdate(
|
|
43
|
+
delta: FileMapDelta<null | undefined | ReadonlyArray<string>>,
|
|
44
|
+
): void;
|
|
45
|
+
onNewOrModifiedFile(
|
|
46
|
+
relativeFilePath: string,
|
|
47
|
+
pluginData: null | undefined | ReadonlyArray<string>,
|
|
48
|
+
): void;
|
|
49
|
+
onRemovedFile(
|
|
50
|
+
relativeFilePath: string,
|
|
51
|
+
pluginData: null | undefined | ReadonlyArray<string>,
|
|
52
|
+
): void;
|
|
53
|
+
assertValid(): void;
|
|
54
|
+
getCacheKey(): string;
|
|
55
|
+
getWorker(): FileMapPluginWorker;
|
|
56
|
+
/**
|
|
57
|
+
* Get the list of dependencies for a given file.
|
|
58
|
+
* @param mixedPath Absolute or project-relative path to the file
|
|
59
|
+
* @returns Array of dependency module names, or null if the file doesn't exist
|
|
60
|
+
*/
|
|
61
|
+
getDependencies(mixedPath: Path): null | undefined | ReadonlyArray<string>;
|
|
62
|
+
}
|
|
63
|
+
export default DependencyPlugin;
|