@expo/metro-file-map 55.0.0-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.
Files changed (82) hide show
  1. package/README.md +1 -0
  2. package/build/Watcher.d.ts +53 -0
  3. package/build/Watcher.js +249 -0
  4. package/build/cache/DiskCacheManager.d.ts +25 -0
  5. package/build/cache/DiskCacheManager.js +110 -0
  6. package/build/constants.d.ts +23 -0
  7. package/build/constants.js +27 -0
  8. package/build/crawlers/node/fallback.d.ts +20 -0
  9. package/build/crawlers/node/fallback.js +148 -0
  10. package/build/crawlers/node/index.d.ts +10 -0
  11. package/build/crawlers/node/index.js +152 -0
  12. package/build/crawlers/watchman/index.d.ts +8 -0
  13. package/build/crawlers/watchman/index.js +288 -0
  14. package/build/crawlers/watchman/planQuery.d.ts +31 -0
  15. package/build/crawlers/watchman/planQuery.js +99 -0
  16. package/build/index.d.ts +140 -0
  17. package/build/index.js +836 -0
  18. package/build/lib/FileProcessor.d.ts +42 -0
  19. package/build/lib/FileProcessor.js +180 -0
  20. package/build/lib/FileSystemChangeAggregator.d.ts +18 -0
  21. package/build/lib/FileSystemChangeAggregator.js +114 -0
  22. package/build/lib/RootPathUtils.d.ts +24 -0
  23. package/build/lib/RootPathUtils.js +311 -0
  24. package/build/lib/TreeFS.d.ts +161 -0
  25. package/build/lib/TreeFS.js +1006 -0
  26. package/build/lib/checkWatchmanCapabilities.d.ts +9 -0
  27. package/build/lib/checkWatchmanCapabilities.js +50 -0
  28. package/build/lib/normalizePathSeparatorsToPosix.d.ts +8 -0
  29. package/build/lib/normalizePathSeparatorsToPosix.js +20 -0
  30. package/build/lib/normalizePathSeparatorsToSystem.d.ts +8 -0
  31. package/build/lib/normalizePathSeparatorsToSystem.js +20 -0
  32. package/build/lib/removeOverlappingRoots.d.ts +10 -0
  33. package/build/lib/removeOverlappingRoots.js +37 -0
  34. package/build/lib/rootRelativeCacheKeys.d.ts +11 -0
  35. package/build/lib/rootRelativeCacheKeys.js +56 -0
  36. package/build/lib/sorting.d.ts +8 -0
  37. package/build/lib/sorting.js +31 -0
  38. package/build/plugins/DependencyPlugin.d.ts +23 -0
  39. package/build/plugins/DependencyPlugin.js +61 -0
  40. package/build/plugins/FileDataPlugin.d.ts +28 -0
  41. package/build/plugins/FileDataPlugin.js +46 -0
  42. package/build/plugins/HastePlugin.d.ts +32 -0
  43. package/build/plugins/HastePlugin.js +358 -0
  44. package/build/plugins/MockPlugin.d.ts +27 -0
  45. package/build/plugins/MockPlugin.js +157 -0
  46. package/build/plugins/dependencies/dependencyExtractor.d.ts +7 -0
  47. package/build/plugins/dependencies/dependencyExtractor.js +66 -0
  48. package/build/plugins/dependencies/worker.d.ts +18 -0
  49. package/build/plugins/dependencies/worker.js +30 -0
  50. package/build/plugins/haste/DuplicateHasteCandidatesError.d.ts +14 -0
  51. package/build/plugins/haste/DuplicateHasteCandidatesError.js +51 -0
  52. package/build/plugins/haste/HasteConflictsError.d.ts +12 -0
  53. package/build/plugins/haste/HasteConflictsError.js +49 -0
  54. package/build/plugins/haste/computeConflicts.d.ts +19 -0
  55. package/build/plugins/haste/computeConflicts.js +74 -0
  56. package/build/plugins/haste/getPlatformExtension.d.ts +7 -0
  57. package/build/plugins/haste/getPlatformExtension.js +19 -0
  58. package/build/plugins/haste/worker.d.ts +16 -0
  59. package/build/plugins/haste/worker.js +48 -0
  60. package/build/plugins/mocks/getMockName.d.ts +8 -0
  61. package/build/plugins/mocks/getMockName.js +17 -0
  62. package/build/ts-declarations/fb-watchman.d.ts +20 -0
  63. package/build/ts-declarations/fb-watchman.js +2 -0
  64. package/build/types.d.ts +404 -0
  65. package/build/types.js +8 -0
  66. package/build/watchers/AbstractWatcher.d.ts +30 -0
  67. package/build/watchers/AbstractWatcher.js +97 -0
  68. package/build/watchers/FallbackWatcher.d.ts +18 -0
  69. package/build/watchers/FallbackWatcher.js +411 -0
  70. package/build/watchers/NativeWatcher.d.ts +39 -0
  71. package/build/watchers/NativeWatcher.js +156 -0
  72. package/build/watchers/RecrawlWarning.d.ts +18 -0
  73. package/build/watchers/RecrawlWarning.js +59 -0
  74. package/build/watchers/WatchmanWatcher.d.ts +22 -0
  75. package/build/watchers/WatchmanWatcher.js +263 -0
  76. package/build/watchers/common.d.ts +39 -0
  77. package/build/watchers/common.js +60 -0
  78. package/build/worker.d.ts +24 -0
  79. package/build/worker.js +80 -0
  80. package/build/workerExclusionList.d.ts +8 -0
  81. package/build/workerExclusionList.js +57 -0
  82. package/package.json +54 -0
@@ -0,0 +1,140 @@
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
+ import EventEmitter from 'events';
8
+ import type { BuildParameters, BuildResult, CacheData, CacheManagerFactory, ChangeEventMetadata, Console, FileData, FileSystem, HasteMapData, HasteMapItem, HType, InputFileMapPlugin, PerfLoggerFactory } from './types';
9
+ export type { BuildParameters, BuildResult, CacheData, ChangeEventMetadata, FileData, FileMap, FileSystem, HasteMapData, HasteMapItem, InputFileMapPlugin, };
10
+ export interface InputOptions {
11
+ readonly computeSha1?: boolean | undefined | null;
12
+ readonly enableFallback?: boolean | undefined | null;
13
+ readonly enableSymlinks?: boolean | undefined | null;
14
+ readonly extensions: readonly string[];
15
+ readonly forceNodeFilesystemAPI?: boolean | undefined | null;
16
+ readonly ignorePattern?: RegExp | undefined | null;
17
+ readonly plugins?: readonly InputFileMapPlugin[] | undefined;
18
+ readonly retainAllFiles: boolean;
19
+ readonly rootDir: string;
20
+ readonly roots: readonly string[];
21
+ readonly scopeFallback?: boolean | undefined | null;
22
+ readonly serverRoot?: string | undefined | null;
23
+ readonly cacheManagerFactory?: CacheManagerFactory | undefined | null;
24
+ readonly console?: Console;
25
+ readonly healthCheck: HealthCheckOptions;
26
+ readonly maxFilesPerWorker?: number | undefined | null;
27
+ readonly maxWorkers: number;
28
+ readonly perfLoggerFactory?: PerfLoggerFactory | undefined | null;
29
+ readonly resetCache?: boolean | undefined | null;
30
+ readonly useWatchman?: boolean | undefined | null;
31
+ readonly watch?: boolean | undefined | null;
32
+ readonly watchmanDeferStates?: readonly string[];
33
+ }
34
+ interface HealthCheckOptions {
35
+ readonly enabled: boolean;
36
+ readonly interval: number;
37
+ readonly timeout: number;
38
+ readonly filePrefix: string;
39
+ }
40
+ export { DiskCacheManager } from './cache/DiskCacheManager';
41
+ export { default as DependencyPlugin } from './plugins/DependencyPlugin';
42
+ export type { DependencyPluginOptions } from './plugins/DependencyPlugin';
43
+ export { DuplicateHasteCandidatesError } from './plugins/haste/DuplicateHasteCandidatesError';
44
+ export { HasteConflictsError } from './plugins/haste/HasteConflictsError';
45
+ export { default as HastePlugin } from './plugins/HastePlugin';
46
+ export type { HasteMap } from './types';
47
+ export type { HealthCheckResult } from './Watcher';
48
+ export type { CacheManager, CacheManagerFactory, CacheManagerFactoryOptions, CacheManagerWriteOptions, ChangeEvent, DependencyExtractor, WatcherStatus, } from './types';
49
+ /**
50
+ * FileMap includes a JavaScript implementation of Facebook's haste module system.
51
+ *
52
+ * This implementation is inspired by https://github.com/facebook/node-haste
53
+ * and was built with for high-performance in large code repositories with
54
+ * hundreds of thousands of files. This implementation is scalable and provides
55
+ * predictable performance.
56
+ *
57
+ * Because the file map creation and synchronization is critical to startup
58
+ * performance and most tasks are blocked by I/O this class makes heavy use of
59
+ * synchronous operations. It uses worker processes for parallelizing file
60
+ * access and metadata extraction.
61
+ *
62
+ * The data structures created by `metro-file-map` can be used directly from the
63
+ * cache without further processing. The metadata objects in the `files` and
64
+ * `map` objects contain cross-references: a metadata object from one can look
65
+ * up the corresponding metadata object in the other map. Note that in most
66
+ * projects, the number of files will be greater than the number of haste
67
+ * modules one module can refer to many files based on platform extensions.
68
+ *
69
+ * type CacheData = {
70
+ * clocks: WatchmanClocks,
71
+ * files: {[filepath: string]: FileMetadata},
72
+ * map: {[id: string]: HasteMapItem},
73
+ * mocks: {[id: string]: string},
74
+ * }
75
+ *
76
+ * // Watchman clocks are used for query synchronization and file system deltas.
77
+ * type WatchmanClocks = {[filepath: string]: string};
78
+ *
79
+ * type FileMetadata = {
80
+ * id: ?string, // used to look up module metadata objects in `map`.
81
+ * mtime: number, // check for outdated files.
82
+ * size: number, // size of the file in bytes.
83
+ * visited: boolean, // whether the file has been parsed or not.
84
+ * dependencies: Array<string>, // all relative dependencies of this file.
85
+ * sha1: ?string, // SHA-1 of the file, if requested via options.
86
+ * symlink: ?(1 | 0 | string), // Truthy if symlink, string is target
87
+ * };
88
+ *
89
+ * // Modules can be targeted to a specific platform based on the file name.
90
+ * // Example: platform.ios.js and Platform.android.js will both map to the same
91
+ * // `Platform` module. The platform should be specified during resolution.
92
+ * type HasteMapItem = {[platform: string]: ModuleMetadata};
93
+ *
94
+ * //
95
+ * type ModuleMetadata = {
96
+ * path: string, // the path to look up the file object in `files`.
97
+ * type: string, // the module type (either `package` or `module`).
98
+ * };
99
+ *
100
+ * Note that the data structures described above are conceptual only. The actual
101
+ * implementation uses arrays and constant keys for metadata storage. Instead of
102
+ * `{id: 'flatMap', mtime: 3421, size: 42, visited: true, dependencies: []}` the real
103
+ * representation is similar to `['flatMap', 3421, 42, 1, []]` to save storage space
104
+ * and reduce parse and write time of a big JSON blob.
105
+ *
106
+ * The FileMap is created as follows:
107
+ * 1. read data from the cache or create an empty structure.
108
+ *
109
+ * 2. crawl the file system.
110
+ * * empty cache: crawl the entire file system.
111
+ * * cache available:
112
+ * * if watchman is available: get file system delta changes.
113
+ * * if watchman is unavailable: crawl the entire file system.
114
+ * * build metadata objects for every file. This builds the `files` part of
115
+ * the `FileMap`.
116
+ *
117
+ * 3. visit and extract metadata from changed files, including sha1,
118
+ * depedendencies, and any plugins.
119
+ * * this is done in parallel over worker processes to improve performance.
120
+ * * the worst case is to visit all files.
121
+ * * the best case is no file system access and retrieving all data from
122
+ * the cache.
123
+ * * the average case is a small number of changed files.
124
+ *
125
+ * 4. serialize the new `FileMap` in a cache file.
126
+ *
127
+ */
128
+ export default class FileMap extends EventEmitter {
129
+ #private;
130
+ readonly __expo = true;
131
+ static create(options: InputOptions): FileMap;
132
+ constructor(options: InputOptions);
133
+ build(): Promise<BuildResult>;
134
+ /**
135
+ * 1. read data from the cache or create an empty structure.
136
+ */
137
+ read(): Promise<CacheData | undefined | null>;
138
+ end(): Promise<void>;
139
+ static H: HType;
140
+ }