@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,404 @@
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 type { PerfLogger, RootPerfLogger } from '@expo/metro/metro-config';
8
+ import type { HType, HTypeValue } from './constants';
9
+ export type { HType, HTypeValue };
10
+ export type { PerfLoggerFactory, PerfLogger } from '@expo/metro/metro-config';
11
+ export interface BuildParameters {
12
+ readonly computeSha1: boolean;
13
+ readonly enableSymlinks: boolean;
14
+ readonly extensions: readonly string[];
15
+ /** @deprecated */
16
+ readonly forceNodeFilesystemAPI?: boolean;
17
+ readonly ignorePattern: RegExp;
18
+ readonly plugins: readonly InputFileMapPlugin[];
19
+ readonly retainAllFiles: boolean;
20
+ readonly rootDir: string;
21
+ readonly roots: readonly string[];
22
+ readonly cacheBreaker: string;
23
+ }
24
+ export interface BuildResult {
25
+ fileSystem: FileSystem;
26
+ }
27
+ export interface CacheData {
28
+ readonly clocks: WatchmanClocks;
29
+ readonly fileSystemData: unknown;
30
+ readonly plugins: ReadonlyMap<string, void | V8Serializable>;
31
+ }
32
+ export interface CacheManager {
33
+ /**
34
+ * Called during startup to load initial state, if available. Provided to
35
+ * a crawler, which will return the delta between the initial state and the
36
+ * current file system state.
37
+ */
38
+ read(): Promise<CacheData | undefined | null>;
39
+ /**
40
+ * Called when metro-file-map `build()` has applied changes returned by the
41
+ * crawler - i.e. internal state reflects the current file system state.
42
+ *
43
+ * getSnapshot may be retained and called at any time before end(), such as
44
+ * in response to eventSource 'change' events.
45
+ */
46
+ write(getSnapshot: () => CacheData, opts: CacheManagerWriteOptions): Promise<void>;
47
+ /**
48
+ * The last call that will be made to this CacheManager. Any handles should
49
+ * be closed by the time this settles.
50
+ */
51
+ end(): Promise<void>;
52
+ }
53
+ export interface CacheManagerEventSource {
54
+ onChange(listener: () => void): () => void;
55
+ }
56
+ export type CacheManagerFactory = (options: CacheManagerFactoryOptions) => CacheManager;
57
+ export interface CacheManagerFactoryOptions {
58
+ readonly buildParameters: BuildParameters;
59
+ }
60
+ export interface CacheManagerWriteOptions {
61
+ readonly changedSinceCacheRead: boolean;
62
+ readonly eventSource: CacheManagerEventSource;
63
+ readonly onWriteError: (error: Error) => void;
64
+ }
65
+ export type CanonicalPath = string;
66
+ export interface ChangedFileMetadata {
67
+ readonly isSymlink: boolean;
68
+ readonly modifiedTime?: number | undefined | null;
69
+ }
70
+ export interface ChangeEvent {
71
+ readonly logger: RootPerfLogger | undefined | null;
72
+ readonly changes: ReadonlyFileSystemChanges<ChangedFileMetadata>;
73
+ readonly rootDir: string;
74
+ }
75
+ export interface ChangeEventMetadata {
76
+ modifiedTime: number | undefined | null;
77
+ size: number | undefined | null;
78
+ type: 'f' | 'd' | 'l';
79
+ }
80
+ export type Console = typeof globalThis.console;
81
+ interface CrawlerPreviousState {
82
+ readonly clocks: ReadonlyMap<CanonicalPath, WatchmanClockSpec>;
83
+ readonly fileSystem: FileSystem;
84
+ }
85
+ export interface CrawlerOptions {
86
+ abortSignal: AbortSignal | undefined | null;
87
+ computeSha1: boolean;
88
+ console: Console;
89
+ extensions: readonly string[];
90
+ /** @deprecated */
91
+ forceNodeFilesystemAPI?: boolean;
92
+ ignore: IgnoreMatcher;
93
+ includeSymlinks: boolean;
94
+ perfLogger?: PerfLogger | null | undefined;
95
+ previousState: CrawlerPreviousState;
96
+ rootDir: string;
97
+ roots: readonly string[];
98
+ onStatus: (status: WatcherStatus) => void;
99
+ subpath?: string;
100
+ }
101
+ export type CrawlResult = {
102
+ changedFiles: FileData;
103
+ removedFiles: Set<Path>;
104
+ clocks: WatchmanClocks;
105
+ } | {
106
+ changedFiles: FileData;
107
+ removedFiles: Set<Path>;
108
+ };
109
+ export type DependencyExtractor = {
110
+ extract: (content: string, absoluteFilePath: string, defaultExtractor?: DependencyExtractor['extract']) => Set<string>;
111
+ getCacheKey: () => string;
112
+ };
113
+ export type WatcherStatus = {
114
+ type: 'watchman_slow_command';
115
+ timeElapsed: number;
116
+ command: 'watch-project' | 'query';
117
+ } | {
118
+ type: 'watchman_slow_command_complete';
119
+ timeElapsed: number;
120
+ command: 'watch-project' | 'query';
121
+ } | {
122
+ type: 'watchman_warning';
123
+ warning: unknown;
124
+ command: 'watch-project' | 'query';
125
+ };
126
+ export type DuplicatesSet = Map<string, /* type */ number>;
127
+ export type DuplicatesIndex = Map<string, Map<string, DuplicatesSet>>;
128
+ interface FileMapPluginInitOptionsFiles<PerFileData = undefined> {
129
+ fileIterator(opts: Readonly<{
130
+ includeNodeModules: boolean;
131
+ includeSymlinks: boolean;
132
+ }>): Iterable<{
133
+ baseName: string;
134
+ canonicalPath: string;
135
+ readonly pluginData: PerFileData | null | undefined;
136
+ }>;
137
+ lookup(mixedPath: string): {
138
+ exists: false;
139
+ } | {
140
+ exists: true;
141
+ type: 'f';
142
+ readonly pluginData: PerFileData;
143
+ } | {
144
+ exists: true;
145
+ type: 'd';
146
+ };
147
+ }
148
+ export interface FileMapPluginInitOptions<SerializableState, PerFileData = undefined> {
149
+ readonly files: FileMapPluginInitOptionsFiles<PerFileData>;
150
+ readonly pluginState: SerializableState | undefined | null;
151
+ }
152
+ interface FileMapPluginWorkerOptions {
153
+ readonly modulePath: string;
154
+ readonly setupArgs: JsonData;
155
+ }
156
+ export interface FileMapPluginWorker {
157
+ readonly worker: FileMapPluginWorkerOptions;
158
+ readonly filter: (input: {
159
+ normalPath: string;
160
+ isNodeModules: boolean;
161
+ }) => boolean;
162
+ }
163
+ export type V8Serializable = string | number | boolean | null | readonly V8Serializable[] | ReadonlySet<V8Serializable> | ReadonlyMap<string, V8Serializable> | Readonly<{
164
+ [key: string]: V8Serializable;
165
+ }>;
166
+ export interface FileMapPlugin<SerializableState extends undefined | V8Serializable = undefined | V8Serializable, PerFileData extends undefined | V8Serializable = undefined | V8Serializable> {
167
+ readonly name: string;
168
+ initialize(initOptions: FileMapPluginInitOptions<SerializableState, PerFileData>): Promise<void>;
169
+ assertValid(): void;
170
+ onChanged(changes: ReadonlyFileSystemChanges<PerFileData | undefined | null>): void;
171
+ getSerializableSnapshot(): void | V8Serializable;
172
+ getCacheKey(): string;
173
+ getWorker(): FileMapPluginWorker | undefined | null;
174
+ }
175
+ export type InputFileMapPlugin = FileMapPlugin<never, never>;
176
+ export interface MetadataWorkerParams {
177
+ getContent(): Promise<Buffer>;
178
+ }
179
+ export interface MetadataWorker {
180
+ processFile(message: WorkerMessage, params: MetadataWorkerParams): V8Serializable | Promise<V8Serializable>;
181
+ }
182
+ export type IgnoreMatcher = (item: string) => boolean;
183
+ export type FileData = Map<CanonicalPath, FileMetadata>;
184
+ export type FileMetadata = [
185
+ mtime: number | null,
186
+ size: number,
187
+ visited: 0 | 1,
188
+ sha1: string | null,
189
+ symlink: 0 | 1 | string,
190
+ ...any[]
191
+ ];
192
+ export interface FileStats {
193
+ readonly fileType: 'f' | 'l';
194
+ readonly modifiedTime: number | undefined | null;
195
+ readonly size: number | undefined | null;
196
+ }
197
+ export interface FileSystem {
198
+ exists(file: Path): boolean;
199
+ getAllFiles(): Path[];
200
+ /**
201
+ * Given a map of files, determine which of them are new or modified
202
+ * (changedFiles), and which of them are missing from the input
203
+ * (removedFiles), vs the current state of this instance of FileSystem.
204
+ */
205
+ getDifference(files: FileData, options?: Readonly<{
206
+ /**
207
+ * Only consider files under this subpath (which should be a directory)
208
+ * when computing removedFiles. If not provided, all files in the file
209
+ * system are considered.
210
+ */
211
+ subpath?: string;
212
+ }>): {
213
+ changedFiles: FileData;
214
+ removedFiles: Set<string>;
215
+ };
216
+ getSerializableSnapshot(): CacheData['fileSystemData'];
217
+ getMtimeByNormalPath(file: Path): number | undefined | null;
218
+ getSha1(file: Path): string | undefined | null;
219
+ getOrComputeSha1(file: Path): Promise<{
220
+ sha1: string;
221
+ content?: Buffer;
222
+ } | undefined | null>;
223
+ /**
224
+ * Given a start path (which need not exist), a subpath and type, and
225
+ * optionally a 'breakOnSegment', performs the following:
226
+ *
227
+ * X = mixedStartPath
228
+ * do
229
+ * if basename(X) === opts.breakOnSegment
230
+ * return null
231
+ * if X + subpath exists and has type opts.subpathType
232
+ * return {
233
+ * absolutePath: realpath(X + subpath)
234
+ * containerRelativePath: relative(mixedStartPath, X)
235
+ * }
236
+ * X = dirname(X)
237
+ * while X !== dirname(X)
238
+ *
239
+ * If opts.invalidatedBy is given, collects all absolute, real paths that if
240
+ * added or removed may invalidate this result.
241
+ *
242
+ * Useful for finding the closest package scope (subpath: package.json,
243
+ * type f, breakOnSegment: node_modules) or closest potential package root
244
+ * (subpath: node_modules/pkg, type: d) in Node.js resolution.
245
+ */
246
+ hierarchicalLookup(mixedStartPath: string, subpath: string, opts: {
247
+ breakOnSegment: string | undefined | null;
248
+ invalidatedBy: Set<string> | undefined | null;
249
+ subpathType: 'f' | 'd';
250
+ }): {
251
+ absolutePath: string;
252
+ containerRelativePath: string;
253
+ } | undefined | null;
254
+ /**
255
+ * Analogous to posix lstat. If the file at `file` is a symlink, return
256
+ * information about the symlink without following it.
257
+ */
258
+ linkStats(file: Path): FileStats | undefined | null;
259
+ /**
260
+ * Return information about the given path, whether a directory or file.
261
+ * Always follow symlinks, and return a real path if it exists.
262
+ */
263
+ lookup(mixedPath: Path): LookupResult;
264
+ matchFiles(opts: {
265
+ filter?: RegExp | null | undefined;
266
+ filterCompareAbsolute?: boolean | undefined;
267
+ filterComparePosix?: boolean | undefined;
268
+ follow?: boolean | undefined;
269
+ recursive?: boolean | undefined;
270
+ rootDir?: Path | null | undefined;
271
+ }): Iterable<Path>;
272
+ }
273
+ export type Glob = string;
274
+ export type JsonData = string | number | boolean | null | JsonData[] | {
275
+ [key: string]: JsonData;
276
+ };
277
+ export type LookupResult = {
278
+ exists: false;
279
+ links: ReadonlySet<string>;
280
+ missing: string;
281
+ } | {
282
+ exists: true;
283
+ links: ReadonlySet<string>;
284
+ realPath: string;
285
+ type: 'd';
286
+ } | {
287
+ exists: true;
288
+ links: ReadonlySet<string>;
289
+ realPath: string;
290
+ type: 'f';
291
+ metadata: FileMetadata;
292
+ };
293
+ export interface MockMap {
294
+ getMockModule(name: string): Path | undefined | null;
295
+ }
296
+ export interface HasteConflict {
297
+ id: string;
298
+ platform: string | null;
299
+ absolutePaths: string[];
300
+ type: 'duplicate' | 'shadowing';
301
+ }
302
+ export interface HasteMap {
303
+ getModule(name: string, platform?: string | undefined | null, supportsNativePlatform?: boolean | undefined | null, type?: HTypeValue | undefined | null): Path | undefined | null;
304
+ getModuleNameByPath(file: Path): string | undefined | null;
305
+ getPackage(name: string, platform: string | undefined | null, _supportsNativePlatform: boolean | undefined | null): Path | undefined | null;
306
+ computeConflicts(): HasteConflict[];
307
+ }
308
+ export type HasteMapData = Map<string, HasteMapItem>;
309
+ export type HasteMapItem = {
310
+ [platform: string]: HasteMapItemMetadata;
311
+ };
312
+ export type HasteMapItemMetadata = [/* path */ string, /* type */ number];
313
+ export interface FileSystemListener {
314
+ directoryAdded(canonicalPath: CanonicalPath): void;
315
+ directoryRemoved(canonicalPath: CanonicalPath): void;
316
+ fileAdded(canonicalPath: CanonicalPath, data: FileMetadata): void;
317
+ fileModified(canonicalPath: CanonicalPath, oldData: FileMetadata, newData: FileMetadata): void;
318
+ fileRemoved(canonicalPath: CanonicalPath, data: FileMetadata): void;
319
+ }
320
+ export interface ReadonlyFileSystemChanges<T = FileMetadata> {
321
+ readonly addedDirectories: Iterable<CanonicalPath>;
322
+ readonly removedDirectories: Iterable<CanonicalPath>;
323
+ readonly addedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
324
+ readonly modifiedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
325
+ readonly removedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
326
+ }
327
+ export interface MutableFileSystem extends FileSystem {
328
+ remove(filePath: Path, listener?: FileSystemListener | undefined): void;
329
+ addOrModify(filePath: Path, fileMetadata: FileMetadata, listener?: FileSystemListener | undefined): void;
330
+ bulkAddOrModify(addedOrModifiedFiles: FileData, listener?: FileSystemListener | undefined): void;
331
+ }
332
+ export type Path = string;
333
+ type DirectoryNode = Map<string, MixedNode | null>;
334
+ type MixedNode = FileMetadata | DirectoryNode;
335
+ export interface FallbackFilesystem {
336
+ lookup(normalPath: Path, absolutePath: string, prevNode: MixedNode | null | undefined): MixedNode | null;
337
+ readdir(normalPath: Path, absolutePath: string, dirNode: DirectoryNode | null | undefined): DirectoryNode | null;
338
+ }
339
+ export type ProcessFileFunction = (normalPath: string, metadata: FileMetadata, request: Readonly<{
340
+ computeSha1: boolean;
341
+ }>) => Promise<Buffer | undefined | null>;
342
+ export type RawMockMap = {
343
+ /** posix-separated mock name to posix-separated project-relative paths */
344
+ readonly duplicates: Map<string, Set<string>>;
345
+ /** posix-separated mock name to posix-separated project-relative path */
346
+ readonly mocks: Map<string, Path>;
347
+ readonly version: number;
348
+ };
349
+ export interface ReadOnlyRawMockMap {
350
+ readonly duplicates: ReadonlyMap<string, ReadonlySet<string>>;
351
+ readonly mocks: ReadonlyMap<string, Path>;
352
+ readonly version: number;
353
+ }
354
+ export interface WatcherBackend {
355
+ getPauseReason(): string | undefined | null;
356
+ onError(listener: (error: Error) => void): () => void;
357
+ onFileEvent(listener: (event: WatcherBackendChangeEvent) => void): () => void;
358
+ startWatching(): Promise<void>;
359
+ stopWatching(): Promise<void>;
360
+ }
361
+ export type ChangeEventClock = [absoluteWatchRoot: string, opaqueClock: string];
362
+ export type WatcherBackendChangeEvent = {
363
+ readonly event: 'touch';
364
+ readonly clock?: ChangeEventClock | undefined;
365
+ readonly relativePath: string;
366
+ readonly root: string;
367
+ readonly metadata: ChangeEventMetadata;
368
+ } | {
369
+ readonly event: 'delete';
370
+ readonly clock?: ChangeEventClock | undefined;
371
+ readonly relativePath: string;
372
+ readonly root: string;
373
+ readonly metadata?: undefined;
374
+ } | {
375
+ readonly event: 'recrawl';
376
+ readonly clock?: ChangeEventClock | undefined;
377
+ readonly relativePath: string;
378
+ readonly root: string;
379
+ };
380
+ export interface WatcherBackendOptions {
381
+ readonly ignored: RegExp | undefined | null;
382
+ readonly globs: readonly string[];
383
+ readonly dot: boolean;
384
+ }
385
+ export type WatchmanClockSpec = string | {
386
+ readonly scm: {
387
+ readonly 'mergebase-with': string;
388
+ };
389
+ };
390
+ export type WatchmanClocks = Map<Path, WatchmanClockSpec>;
391
+ export interface WorkerMessage {
392
+ readonly computeSha1: boolean;
393
+ readonly filePath: string;
394
+ readonly maybeReturnContent: boolean;
395
+ readonly pluginsToRun: readonly number[];
396
+ }
397
+ export interface WorkerMetadata {
398
+ readonly sha1?: string | undefined | null;
399
+ readonly content?: Buffer | undefined | null;
400
+ readonly pluginData?: readonly V8Serializable[];
401
+ }
402
+ export interface WorkerSetupArgs {
403
+ readonly plugins?: readonly FileMapPluginWorker['worker'][];
404
+ }
package/build/types.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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
+ import type { WatcherBackend, WatcherBackendChangeEvent, WatcherBackendOptions } from '../types';
8
+ type EachOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
9
+ export type WatcherBackendChangeEventWithoutRoot = EachOmit<WatcherBackendChangeEvent, 'root'>;
10
+ export interface Listeners {
11
+ onFileEvent(event: WatcherBackendChangeEvent): void;
12
+ onError(error: Error): void;
13
+ }
14
+ export declare class AbstractWatcher implements WatcherBackend {
15
+ #private;
16
+ readonly root: string;
17
+ readonly ignored: RegExp | undefined | null;
18
+ readonly globs: readonly string[];
19
+ readonly dot: boolean;
20
+ readonly doIgnore: (path: string) => boolean;
21
+ constructor(dir: string, opts: WatcherBackendOptions);
22
+ onFileEvent(listener: (event: WatcherBackendChangeEvent) => void): () => void;
23
+ onError(listener: (error: Error) => void): () => void;
24
+ startWatching(): Promise<void>;
25
+ stopWatching(): Promise<void>;
26
+ emitFileEvent(event: WatcherBackendChangeEventWithoutRoot): void;
27
+ emitError(error: Error): void;
28
+ getPauseReason(): string | undefined | null;
29
+ }
30
+ export {};
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __importDefault = (this && this.__importDefault) || function (mod) {
42
+ return (mod && mod.__esModule) ? mod : { "default": mod };
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.AbstractWatcher = void 0;
46
+ const events_1 = __importDefault(require("events"));
47
+ const path = __importStar(require("path"));
48
+ const common_1 = require("./common");
49
+ class AbstractWatcher {
50
+ root;
51
+ ignored;
52
+ globs;
53
+ dot;
54
+ doIgnore;
55
+ #emitter = new events_1.default();
56
+ constructor(dir, opts) {
57
+ const { ignored, globs, dot } = opts;
58
+ this.dot = dot || false;
59
+ this.ignored = ignored;
60
+ this.globs = globs;
61
+ this.doIgnore = ignored
62
+ ? (filePath) => (0, common_1.posixPathMatchesPattern)(ignored, filePath)
63
+ : () => false;
64
+ this.root = path.resolve(dir);
65
+ }
66
+ onFileEvent(listener) {
67
+ this.#emitter.on('fileevent', listener);
68
+ return () => {
69
+ this.#emitter.removeListener('fileevent', listener);
70
+ };
71
+ }
72
+ onError(listener) {
73
+ this.#emitter.on('error', listener);
74
+ return () => {
75
+ this.#emitter.removeListener('error', listener);
76
+ };
77
+ }
78
+ async startWatching() {
79
+ // Must be implemented by subclasses
80
+ }
81
+ async stopWatching() {
82
+ this.#emitter.removeAllListeners();
83
+ }
84
+ emitFileEvent(event) {
85
+ this.#emitter.emit('fileevent', {
86
+ ...event,
87
+ root: this.root,
88
+ });
89
+ }
90
+ emitError(error) {
91
+ this.#emitter.emit('error', error);
92
+ }
93
+ getPauseReason() {
94
+ return null;
95
+ }
96
+ }
97
+ exports.AbstractWatcher = AbstractWatcher;
@@ -0,0 +1,18 @@
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
+ */
9
+ import { AbstractWatcher } from './AbstractWatcher';
10
+ export default class FallbackWatcher extends AbstractWatcher {
11
+ #private;
12
+ startWatching(): Promise<void>;
13
+ /**
14
+ * End watching.
15
+ */
16
+ stopWatching(): Promise<void>;
17
+ getPauseReason(): string | undefined | null;
18
+ }