Skip to content

Commit

Permalink
Support fsevents watcher on Apple silicon
Browse files Browse the repository at this point in the history
  • Loading branch information
robhogan committed Sep 28, 2022
1 parent 556a4c1 commit a709f7a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
66 changes: 66 additions & 0 deletions flow-typed/fsevents.js
@@ -0,0 +1,66 @@
/**
* 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.
*
* @flow strict
* @format
* @oncall react_native
*/

declare module 'fsevents' {
declare type Event =
| 'created'
| 'cloned'
| 'modified'
| 'deleted'
| 'moved'
| 'root-changed'
| 'unknown';
declare type Type = 'file' | 'directory' | 'symlink';
declare type FileChanges = {
inode: boolean,
finder: boolean,
access: boolean,
xattrs: boolean,
};
declare type Info = {
event: Event,
path: string,
type: Type,
changes: FileChanges,
flags: number,
};
declare type WatchHandler = (path: string, flags: number, id: string) => void;
declare module.exports: {
watch(path: string, handler: WatchHandler): () => Promise<void>,
getInfo(path: string, flags: number): Info,
constants: {
None: 0x00000000,
MustScanSubDirs: 0x00000001,
UserDropped: 0x00000002,
KernelDropped: 0x00000004,
EventIdsWrapped: 0x00000008,
HistoryDone: 0x00000010,
RootChanged: 0x00000020,
Mount: 0x00000040,
Unmount: 0x00000080,
ItemCreated: 0x00000100,
ItemRemoved: 0x00000200,
ItemInodeMetaMod: 0x00000400,
ItemRenamed: 0x00000800,
ItemModified: 0x00001000,
ItemFinderInfoMod: 0x00002000,
ItemChangeOwner: 0x00004000,
ItemXattrMod: 0x00008000,
ItemIsFile: 0x00010000,
ItemIsDir: 0x00020000,
ItemIsSymlink: 0x00040000,
ItemIsHardlink: 0x00100000,
ItemIsLastHardlink: 0x00200000,
OwnEvent: 0x00080000,
ItemCloned: 0x00400000,
},
};
}
2 changes: 1 addition & 1 deletion packages/metro-file-map/package.json
Expand Up @@ -30,6 +30,6 @@
"slash": "^3.0.0"
},
"optionalDependencies": {
"fsevents": "^2.1.2"
"fsevents": "^2.3.2"
}
}
12 changes: 6 additions & 6 deletions packages/metro-file-map/src/watchers/FSEventsWatcher.js
Expand Up @@ -19,10 +19,11 @@ import walker from 'walker';
// $FlowFixMe[untyped-import] - micromatch
const micromatch = require('micromatch');

const debug = require('debug')('Metro:FSEventsWatcher');

type Matcher = typeof anymatch.Matcher;

// $FlowFixMe[unclear-type] - fsevents
let fsevents: any = null;
let fsevents = null;
try {
// $FlowFixMe[cannot-resolve-module] - Optional, Darwin only
fsevents = require('fsevents');
Expand Down Expand Up @@ -116,10 +117,9 @@ export default class FSEventsWatcher extends EventEmitter {
this.doIgnore = opts.ignored ? anymatch(opts.ignored) : () => false;

this.root = path.resolve(dir);
this.fsEventsWatchStopper = fsevents.watch(
this.root,
// $FlowFixMe[method-unbinding] - Refactor
this._handleEvent.bind(this),
debug('Instantiated FSEventsWatcher with root %s', this.root);
this.fsEventsWatchStopper = fsevents.watch(this.root, fsEvent =>
this._handleEvent(fsEvent),
);

this._tracked = new Set();
Expand Down

0 comments on commit a709f7a

Please sign in to comment.