first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
import type { WatcherBackend, WatcherBackendChangeEvent, WatcherBackendOptions } from "../flow-types";
export interface Listeners {
readonly onFileEvent: (event: WatcherBackendChangeEvent) => void;
readonly onError: (error: Error) => void;
}
export declare class AbstractWatcher implements WatcherBackend {
readonly root: string;
readonly ignored: null | undefined | RegExp;
readonly globs: ReadonlyArray<string>;
readonly dot: boolean;
readonly doIgnore: (path: string) => boolean;
constructor(dir: string, $$PARAM_1$$: WatcherBackendOptions);
onFileEvent(listener: (event: WatcherBackendChangeEvent) => void): () => void;
onError(listener: (error: Error) => void): () => void;
startWatching(): Promise<void>;
stopWatching(): Promise<void>;
emitFileEvent(event: Omit<WatcherBackendChangeEvent, "root">): void;
emitError(error: Error): void;
getPauseReason(): null | undefined | string;
}

View File

@@ -0,0 +1,2 @@
module.exports = require("metro-file-map/private/watchers/AbstractWatcher");
module.exports.default = module.exports;

View File

@@ -0,0 +1,44 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
/**
* Originally vendored from https://github.com/amasad/sane/blob/64ff3a870c42e84f744086884bf55a4f9c22d376/src/node_watcher.js
*/
import type { ChangeEventMetadata, WatcherBackendChangeEvent } from "../flow-types";
import type { FSWatcher } from "node:fs";
import { AbstractWatcher } from "./AbstractWatcher";
declare class FallbackWatcher extends AbstractWatcher {
readonly _changeTimers: Map<string, NodeJS.Timeout>;
readonly _dirRegistry: {
[directory: string]: {
[file: string]: true;
};
};
readonly watched: {
[key: string]: FSWatcher;
};
startWatching(): Promise<void>;
_register(filepath: string, type: ChangeEventMetadata["type"]): boolean;
_unregister(filepath: string): void;
_unregisterDir(dirpath: string): void;
_registered(fullpath: string): boolean;
_checkedEmitError: (error: Error) => void;
_watchdir: ($$PARAM_0$$: string) => boolean;
_stopWatching(dir: string): Promise<void>;
stopWatching(): Promise<void>;
_detectChangedFile(dir: string, event: string, callback: (file: string) => void): void;
_normalizeChange(dir: string, event: string, file: string): void;
_processChange(dir: string, event: string, file: string): Promise<void>;
_emitEvent(change: Omit<WatcherBackendChangeEvent, "root">): void;
getPauseReason(): null | undefined | string;
}
export default FallbackWatcher;

View File

@@ -0,0 +1 @@
module.exports = require("metro-file-map/private/watchers/FallbackWatcher");

View File

@@ -0,0 +1,43 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
import { AbstractWatcher } from "./AbstractWatcher";
/**
* NativeWatcher uses Node's native fs.watch API with recursive: true.
*
* Supported on macOS (and potentially Windows), because both natively have a
* concept of recurisve watching, via FSEvents and ReadDirectoryChangesW
* respectively. Notably Linux lacks this capability at the OS level.
*
* Node.js has at times supported the `recursive` option to fs.watch on Linux
* by walking the directory tree and creating a watcher on each directory, but
* this fits poorly with the synchronous `watch` API - either it must block for
* arbitrarily large IO, or it may drop changes after `watch` returns. See:
* https://github.com/nodejs/node/issues/48437
*
* Therefore, we retain a fallback to our own application-level recursive
* FallbackWatcher for Linux, which has async `startWatching`.
*
* On Windows, this watcher could be used in principle, but needs work around
* some Windows-specific edge cases handled in FallbackWatcher, like
* deduping file change events, ignoring directory changes, and handling EPERM.
*/
declare class NativeWatcher extends AbstractWatcher {
static isSupported(): boolean;
constructor(dir: string, opts: {
readonly ignored?: null | RegExp;
readonly globs: ReadonlyArray<string>;
readonly dot: boolean;
});
startWatching(): Promise<void>;
stopWatching(): Promise<void>;
_handleEvent(relativePath: string): Promise<void>;
}
export default NativeWatcher;

View File

@@ -0,0 +1 @@
module.exports = require("metro-file-map/private/watchers/NativeWatcher");

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
/**
* Originally vendored from
* https://github.com/amasad/sane/blob/64ff3a870c42e84f744086884bf55a4f9c22d376/src/utils/recrawl-warning-dedupe.js
*/
declare class RecrawlWarning {
static RECRAWL_WARNINGS: Array<RecrawlWarning>;
static REGEXP: RegExp;
root: string;
count: number;
constructor(root: string, count: number);
static findByRoot(root: string): null | undefined | RecrawlWarning;
static isRecrawlWarningDupe(warningMessage: any): boolean;
}
export default RecrawlWarning;

View File

@@ -0,0 +1 @@
module.exports = require("metro-file-map/private/watchers/RecrawlWarning");

View File

@@ -0,0 +1,34 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
import type { WatcherOptions } from "./common";
import type { Client, WatchmanFileChange, WatchmanSubscriptionEvent } from "fb-watchman";
import { AbstractWatcher } from "./AbstractWatcher";
/**
* Watches `dir`.
*/
declare class WatchmanWatcher extends AbstractWatcher {
client: Client;
readonly subscriptionName: string;
watchProjectInfo: null | undefined | {
readonly relativePath: string;
readonly root: string;
};
readonly watchmanDeferStates: ReadonlyArray<string>;
constructor(dir: string, $$PARAM_1$$: WatcherOptions);
startWatching(): Promise<void>;
_init(onReady: () => void, onError: (error: Error) => void): void;
_handleChangeEvent(resp: WatchmanSubscriptionEvent): void;
_handleFileChange(changeDescriptor: WatchmanFileChange, rawClock: WatchmanSubscriptionEvent["clock"]): void;
stopWatching(): Promise<void>;
getPauseReason(): null | undefined | string;
}
export default WatchmanWatcher;

View File

@@ -0,0 +1 @@
module.exports = require("metro-file-map/private/watchers/WatchmanWatcher");

View File

@@ -0,0 +1,48 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
/**
* Originally vendored from
* https://github.com/amasad/sane/blob/64ff3a870c42e84f744086884bf55a4f9c22d376/src/common.js
*/
import type { ChangeEventMetadata } from "../flow-types";
import type { Stats } from "node:fs";
/**
* Constants
*/
export declare const DELETE_EVENT: "delete";
export declare const TOUCH_EVENT: "touch";
export declare const ALL_EVENT: "all";
export interface WatcherOptions {
readonly globs: ReadonlyArray<string>;
readonly dot: boolean;
readonly ignored?: null | RegExp;
readonly watchmanDeferStates: ReadonlyArray<string>;
readonly watchman?: any;
readonly watchmanPath?: string;
}
/**
* Checks a file relative path against the globs array.
*/
export declare function includedByGlob(type: null | undefined | ("f" | "l" | "d"), globs: ReadonlyArray<string>, dot: boolean, relativePath: string): boolean;
/**
* Whether the given filePath matches the given RegExp, after converting
* (on Windows only) system separators to posix separators.
*
* Conversion to posix is for backwards compatibility with the previous
* anymatch matcher, which normlises all inputs[1]. This may not be consistent
* with other parts of metro-file-map.
*
* [1]: https://github.com/micromatch/anymatch/blob/3.1.1/index.js#L50
*/
export declare const posixPathMatchesPattern: (pattern: RegExp, filePath: string) => boolean;
export declare function typeFromStat(stat: Stats): null | undefined | ChangeEventMetadata["type"];

View File

@@ -0,0 +1,2 @@
module.exports = require("metro-file-map/private/watchers/common");
module.exports.default = module.exports;