fsevents 2.0.6 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
1
  MIT License
2
2
  -----------
3
3
 
4
- Copyright (C) 2010-2019 by Philipp Dunkel, Ben Noordhuis, Elan Shankar
4
+ Copyright (C) 2010-2019 by Philipp Dunkel, Ben Noordhuis, Elan Shankar, Paul Miller
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -11,6 +11,8 @@ uses fsevents, check out [Chokidar](https://github.com/paulmillr/chokidar).
11
11
 
12
12
  ## Installation
13
13
 
14
+ Supports only **Node.js v8.16 and higher**.
15
+
14
16
  ```sh
15
17
  npm install fsevents
16
18
  ```
@@ -28,13 +30,15 @@ stop(); // To end observation
28
30
  The callback passed as the second parameter to `.watch` get's called whenever the operating system detects a
29
31
  a change in the file system. It takes three arguments:
30
32
 
31
- `(path: String, flags: Number, id: String) => {}`
33
+ ###### `fsevents.watch(dirname: string, (path: string, flags: number, id: string) => void): () => Promise<undefined>`
34
+
35
+ * `path: string` - the item in the filesystem that have been changed
36
+ * `flags: number` - a numeric value describing what the change was
37
+ * `id: string` - an unique-id identifying this specific event
32
38
 
33
- * `path` - the item in the filesystem that have been changed
34
- * `flags` - a numeric value describing what the change was
35
- * `id` - an unique-id identifying this specific event
39
+ Returns closer callback which when called returns a Promise resolving when the watcher process has been shut down.
36
40
 
37
- ###### `fsevents.getInfo(path, flags, id): FsEventInfo => {}`
41
+ ###### `fsevents.getInfo(path: string, flags: number, id: string): FsEventInfo`
38
42
 
39
43
  The `getInfo` function takes the `path`, `flags` and `id` arguments and converts those parameters into a structure
40
44
  that is easier to digest to determine what the change was.
@@ -43,7 +47,7 @@ The `FsEventsInfo` has the following shape:
43
47
 
44
48
  ```js
45
49
  /**
46
- * @typedef {'created'|'modified'|'deleted'|'moved'|'root-changed'|'unknown'} FsEventsEvent
50
+ * @typedef {'created'|'modified'|'deleted'|'moved'|'root-changed'|'cloned'|'unknown'} FsEventsEvent
47
51
  * @typedef {'file'|'directory'|'symlink'} FsEventsType
48
52
  */
49
53
  {
@@ -60,8 +64,14 @@ The `FsEventsInfo` has the following shape:
60
64
  }
61
65
  ```
62
66
 
67
+ ## Engine compatibility
68
+
69
+ - v2 supports node 8.16+
70
+ - v1.2.8 supports node 6+
71
+ - v1.2.7 supports node 4+
72
+
63
73
  ## License
64
74
 
65
- The MIT License Copyright (C) 2010-2018 by Philipp Dunkel, Ben Noordhuis, Elan Shankar — see LICENSE file.
75
+ The MIT License Copyright (C) 2010-2019 by Philipp Dunkel, Ben Noordhuis, Elan Shankar, Paul Miller — see LICENSE file.
66
76
 
67
77
  Visit our [GitHub page](https://github.com/fsevents/fsevents) and [NPM Page](https://npmjs.org/package/fsevents)
package/fsevents.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ declare type Event =
2
+ | 'created'
3
+ | 'cloned'
4
+ | 'modified'
5
+ | 'deleted'
6
+ | 'moved'
7
+ | 'root-changed'
8
+ | 'unknown';
9
+ declare type Type = 'file' | 'directory' | 'symlink';
10
+ declare type FileChanges = {
11
+ inode: boolean;
12
+ finder: boolean;
13
+ access: boolean;
14
+ xattrs: boolean;
15
+ };
16
+ declare type Info = {
17
+ event: Event;
18
+ path: string;
19
+ type: Type;
20
+ changes: FileChanges;
21
+ flags: number;
22
+ };
23
+ declare type WatchHandler = (path: string, flags: number, id: string) => void;
24
+ export declare function watch(
25
+ path: string,
26
+ handler: WatchHandler,
27
+ ): () => Promise<void>;
28
+ export declare function getInfo(path: string, flags: number): Info;
29
+ export declare const constants: {
30
+ None: 0x00000000;
31
+ MustScanSubDirs: 0x00000001;
32
+ UserDropped: 0x00000002;
33
+ KernelDropped: 0x00000004;
34
+ EventIdsWrapped: 0x00000008;
35
+ HistoryDone: 0x00000010;
36
+ RootChanged: 0x00000020;
37
+ Mount: 0x00000040;
38
+ Unmount: 0x00000080;
39
+ ItemCreated: 0x00000100;
40
+ ItemRemoved: 0x00000200;
41
+ ItemInodeMetaMod: 0x00000400;
42
+ ItemRenamed: 0x00000800;
43
+ ItemModified: 0x00001000;
44
+ ItemFinderInfoMod: 0x00002000;
45
+ ItemChangeOwner: 0x00004000;
46
+ ItemXattrMod: 0x00008000;
47
+ ItemIsFile: 0x00010000;
48
+ ItemIsDir: 0x00020000;
49
+ ItemIsSymlink: 0x00040000;
50
+ ItemIsHardlink: 0x00100000;
51
+ ItemIsLastHardlink: 0x00200000;
52
+ OwnEvent: 0x00080000;
53
+ ItemCloned: 0x00400000;
54
+ };
55
+ export {}
package/fsevents.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
- ** © 2018 by Philipp Dunkel, Ben Noordhuis, Elan Shankar
3
- ** Licensed under MIT License.
4
- */
2
+ ** © 2018 by Philipp Dunkel, Ben Noordhuis, Elan Shankar, Paul Miller
3
+ ** Licensed under MIT License.
4
+ */
5
5
 
6
6
  /* jshint node:true */
7
7
  'use strict';
@@ -11,23 +11,31 @@ if (process.platform !== 'darwin') {
11
11
  }
12
12
 
13
13
  const Native = require('./fsevents.node');
14
- const con = Native.constants;
14
+ const events = Native.constants;
15
15
 
16
16
  function watch(path, handler) {
17
- if ('string' !== typeof path) throw new TypeError(`argument 1 must be a string and not a ${typeof path}`);
18
- if ('function' !== typeof handler) throw new TypeError(`argument 2 must be a function and not a ${typeof handler}`);
17
+ if (typeof path !== 'string') {
18
+ throw new TypeError(`fsevents argument 1 must be a string and not a ${typeof path}`);
19
+ }
20
+ if (typeof handler !== 'function') {
21
+ throw new TypeError(`fsevents argument 2 must be a function and not a ${typeof handler}`);
22
+ }
19
23
 
20
24
  let instance = Native.start(path, handler);
21
25
  if (!instance) throw new Error(`could not watch: ${path}`);
22
26
  return () => {
23
- const result = instance ? Promise.resolve(instance).then(Native.stop) : null;
24
- instance = null;
27
+ const result = instance
28
+ ? Promise.resolve(instance).then(Native.stop)
29
+ : Promise.resolve(undefined);
30
+ instance = undefined;
25
31
  return result;
26
32
  };
27
33
  }
34
+
28
35
  function getInfo(path, flags) {
29
36
  return {
30
- path, flags,
37
+ path,
38
+ flags,
31
39
  event: getEventType(flags),
32
40
  type: getFileType(flags),
33
41
  changes: getFileChanges(flags)
@@ -35,28 +43,35 @@ function getInfo(path, flags) {
35
43
  }
36
44
 
37
45
  function getFileType(flags) {
38
- if (con.kFSEventStreamEventFlagItemIsFile & flags) return 'file';
39
- if (con.kFSEventStreamEventFlagItemIsDir & flags) return 'directory';
40
- if (con.kFSEventStreamEventFlagItemIsSymlink & flags) return 'symlink';
46
+ if (events.ItemIsFile & flags) return 'file';
47
+ if (events.ItemIsDir & flags) return 'directory';
48
+ if (events.ItemIsSymlink & flags) return 'symlink';
49
+ }
50
+ function anyIsTrue(obj) {
51
+ for (let key in obj) {
52
+ if (obj[key]) return true;
53
+ }
54
+ return false;
41
55
  }
42
56
  function getEventType(flags) {
43
- if (con.kFSEventStreamEventFlagItemRemoved & flags) return 'deleted';
44
- if (con.kFSEventStreamEventFlagItemRenamed & flags) return 'moved';
45
- if (con.kFSEventStreamEventFlagItemCreated & flags) return 'created';
46
- if (con.kFSEventStreamEventFlagItemModified & flags) return 'modified';
47
- if (con.kFSEventStreamEventFlagRootChanged & flags) return 'root-changed';
48
-
57
+ if (events.ItemRemoved & flags) return 'deleted';
58
+ if (events.ItemRenamed & flags) return 'moved';
59
+ if (events.ItemCreated & flags) return 'created';
60
+ if (events.ItemModified & flags) return 'modified';
61
+ if (events.RootChanged & flags) return 'root-changed';
62
+ if (events.ItemCloned & flags) return 'cloned';
63
+ if (anyIsTrue(flags)) return 'modified';
49
64
  return 'unknown';
50
65
  }
51
66
  function getFileChanges(flags) {
52
67
  return {
53
- inode: !!(con.kFSEventStreamEventFlagItemInodeMetaMod & flags),
54
- finder: !!(con.kFSEventStreamEventFlagItemFinderInfoMod & flags),
55
- access: !!(con.kFSEventStreamEventFlagItemChangeOwner & flags),
56
- xattrs: !!(con.kFSEventStreamEventFlagItemXattrMod & flags)
68
+ inode: !!(events.ItemInodeMetaMod & flags),
69
+ finder: !!(events.ItemFinderInfoMod & flags),
70
+ access: !!(events.ItemChangeOwner & flags),
71
+ xattrs: !!(events.ItemXattrMod & flags)
57
72
  };
58
73
  }
59
74
 
60
75
  exports.watch = watch;
61
76
  exports.getInfo = getInfo;
62
- exports.constants = con;
77
+ exports.constants = events;
package/fsevents.node CHANGED
Binary file
package/package.json CHANGED
@@ -1,18 +1,25 @@
1
1
  {
2
2
  "name": "fsevents",
3
- "version": "2.0.6",
4
- "description": "Native Access to Mac OS-X FSEvents",
3
+ "version": "2.1.2",
4
+ "description": "Native Access to MacOS FSEvents",
5
5
  "main": "fsevents.js",
6
+ "types": "fsevents.d.ts",
6
7
  "os": [
7
8
  "darwin"
8
9
  ],
10
+ "files": [
11
+ "fsevents.d.ts",
12
+ "fsevents.js",
13
+ "fsevents.node"
14
+ ],
9
15
  "engines": {
10
16
  "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
11
17
  },
12
18
  "scripts": {
13
19
  "clean": "node-gyp clean && rm -f fsevents.node",
20
+ "build": "node-gyp clean && rm -f fsevents.node && node-gyp rebuild && node-gyp clean",
14
21
  "test": "/bin/bash ./test.sh 2>/dev/null",
15
- "prepublishOnly": "node-gyp clean && rm -f fsevents.node && node-gyp rebuild && node-gyp clean"
22
+ "prepublishOnly": "npm run build"
16
23
  },
17
24
  "repository": {
18
25
  "type": "git",
@@ -38,12 +45,15 @@
38
45
  {
39
46
  "name": "Miroslav Bajtoš",
40
47
  "email": "mbajtoss@gmail.com"
48
+ },
49
+ {
50
+ "name": "Paul Miller",
51
+ "url": "https://paulmillr.com"
41
52
  }
42
53
  ],
43
54
  "license": "MIT",
44
55
  "bugs": {
45
56
  "url": "https://github.com/fsevents/fsevents/issues"
46
57
  },
47
- "homepage": "https://github.com/fsevents/fsevents",
48
- "devDependencies": {}
58
+ "homepage": "https://github.com/fsevents/fsevents"
49
59
  }