fsevents 2.1.1 → 2.2.1

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.
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, Paul Miller
4
+ Copyright (C) 2010-2020 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
@@ -30,13 +30,13 @@ stop(); // To end observation
30
30
  The callback passed as the second parameter to `.watch` get's called whenever the operating system detects a
31
31
  a change in the file system. It takes three arguments:
32
32
 
33
- ###### `fsevents.watch(dirname: string, (path: string, flags: number, id: string) => void): Function`
33
+ ###### `fsevents.watch(dirname: string, (path: string, flags: number, id: string) => void): () => Promise<undefined>`
34
34
 
35
35
  * `path: string` - the item in the filesystem that have been changed
36
36
  * `flags: number` - a numeric value describing what the change was
37
37
  * `id: string` - an unique-id identifying this specific event
38
-
39
- Returns closer callback.
38
+
39
+ Returns closer callback which when called returns a Promise resolving when the watcher process has been shut down.
40
40
 
41
41
  ###### `fsevents.getInfo(path: string, flags: number, id: string): FsEventInfo`
42
42
 
@@ -47,12 +47,12 @@ The `FsEventsInfo` has the following shape:
47
47
 
48
48
  ```js
49
49
  /**
50
- * @typedef {'created'|'modified'|'deleted'|'moved'|'root-changed'|'unknown'} FsEventsEvent
50
+ * @typedef {'created'|'modified'|'deleted'|'moved'|'root-changed'|'cloned'|'unknown'} FsEventsEvent
51
51
  * @typedef {'file'|'directory'|'symlink'} FsEventsType
52
52
  */
53
53
  {
54
- "event": "created",
55
- "path": "file.txt", // {FsEventsEvent}
54
+ "event": "created", // {FsEventsEvent}
55
+ "path": "file.txt",
56
56
  "type": "file", // {FsEventsType}
57
57
  "changes": {
58
58
  "inode": true, // Had iNode Meta-Information changed
@@ -64,8 +64,19 @@ The `FsEventsInfo` has the following shape:
64
64
  }
65
65
  ```
66
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
+
73
+ ## Troubleshooting
74
+
75
+ - I'm getting `EBADPLATFORM` `Unsupported platform for fsevents` error.
76
+ - It's fine, nothing is broken. fsevents is macos-only. Other platforms are skipped. If you want to hide this warning, report a bug to NPM bugtracker asking them to hide ebadplatform warnings by default.
77
+
67
78
  ## License
68
79
 
69
- The MIT License Copyright (C) 2010-2019 by Philipp Dunkel, Ben Noordhuis, Elan Shankar, Paul Miller — see LICENSE file.
80
+ The MIT License Copyright (C) 2010-2020 by Philipp Dunkel, Ben Noordhuis, Elan Shankar, Paul Miller — see LICENSE file.
70
81
 
71
82
  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,46 @@
1
+ declare type Event = "created" | "cloned" | "modified" | "deleted" | "moved" | "root-changed" | "unknown";
2
+ declare type Type = "file" | "directory" | "symlink";
3
+ declare type FileChanges = {
4
+ inode: boolean;
5
+ finder: boolean;
6
+ access: boolean;
7
+ xattrs: boolean;
8
+ };
9
+ declare type Info = {
10
+ event: Event;
11
+ path: string;
12
+ type: Type;
13
+ changes: FileChanges;
14
+ flags: number;
15
+ };
16
+ declare type WatchHandler = (path: string, flags: number, id: string) => void;
17
+ export declare function watch(path: string, handler: WatchHandler): () => Promise<void>;
18
+ export declare function watch(path: string, since: number, handler: WatchHandler);
19
+ export declare function getInfo(path: string, flags: number): Info;
20
+ export declare const constants: {
21
+ None: 0x00000000;
22
+ MustScanSubDirs: 0x00000001;
23
+ UserDropped: 0x00000002;
24
+ KernelDropped: 0x00000004;
25
+ EventIdsWrapped: 0x00000008;
26
+ HistoryDone: 0x00000010;
27
+ RootChanged: 0x00000020;
28
+ Mount: 0x00000040;
29
+ Unmount: 0x00000080;
30
+ ItemCreated: 0x00000100;
31
+ ItemRemoved: 0x00000200;
32
+ ItemInodeMetaMod: 0x00000400;
33
+ ItemRenamed: 0x00000800;
34
+ ItemModified: 0x00001000;
35
+ ItemFinderInfoMod: 0x00002000;
36
+ ItemChangeOwner: 0x00004000;
37
+ ItemXattrMod: 0x00008000;
38
+ ItemIsFile: 0x00010000;
39
+ ItemIsDir: 0x00020000;
40
+ ItemIsSymlink: 0x00040000;
41
+ ItemIsHardlink: 0x00100000;
42
+ ItemIsLastHardlink: 0x00200000;
43
+ OwnEvent: 0x00080000;
44
+ ItemCloned: 0x00400000;
45
+ };
46
+ export {};
package/fsevents.js CHANGED
@@ -1,31 +1,38 @@
1
1
  /*
2
- ** © 2018 by Philipp Dunkel, Ben Noordhuis, Elan Shankar, Paul Miller
2
+ ** © 2020 by Philipp Dunkel, Ben Noordhuis, Elan Shankar, Paul Miller
3
3
  ** Licensed under MIT License.
4
4
  */
5
5
 
6
6
  /* jshint node:true */
7
- 'use strict';
7
+ "use strict";
8
8
 
9
- if (process.platform !== 'darwin') {
9
+ if (process.platform !== "darwin") {
10
10
  throw new Error(`Module 'fsevents' is not compatible with platform '${process.platform}'`);
11
11
  }
12
12
 
13
- const Native = require('./fsevents.node');
13
+ const Native = require("./fsevents.node");
14
14
  const events = Native.constants;
15
15
 
16
- function watch(path, handler) {
17
- if (typeof path !== 'string') {
16
+ function watch(path, since, handler) {
17
+ if (typeof path !== "string") {
18
18
  throw new TypeError(`fsevents argument 1 must be a string and not a ${typeof path}`);
19
19
  }
20
- if (typeof handler !== 'function') {
21
- throw new TypeError(`fsevents argument 2 must be a function and not a ${typeof handler}`);
20
+ if ("function" === typeof since && "undefined" === typeof handler) {
21
+ handler = since;
22
+ since = Native.flags.SinceNow;
23
+ }
24
+ if (typeof since !== "number") {
25
+ throw new TypeError(`fsevents argument 2 must be a number and not a ${typeof since}`);
26
+ }
27
+ if (typeof handler !== "function") {
28
+ throw new TypeError(`fsevents argument 3 must be a function and not a ${typeof handler}`);
22
29
  }
23
30
 
24
- let instance = Native.start(path, handler);
31
+ let instance = Native.start(Native.global, path, since, handler);
25
32
  if (!instance) throw new Error(`could not watch: ${path}`);
26
33
  return () => {
27
- const result = instance ? Promise.resolve(instance).then(Native.stop) : null;
28
- instance = null;
34
+ const result = instance ? Promise.resolve(instance).then(Native.stop) : Promise.resolve(undefined);
35
+ instance = undefined;
29
36
  return result;
30
37
  };
31
38
  }
@@ -36,14 +43,14 @@ function getInfo(path, flags) {
36
43
  flags,
37
44
  event: getEventType(flags),
38
45
  type: getFileType(flags),
39
- changes: getFileChanges(flags)
46
+ changes: getFileChanges(flags),
40
47
  };
41
48
  }
42
49
 
43
50
  function getFileType(flags) {
44
- if (events.ItemIsFile & flags) return 'file';
45
- if (events.ItemIsDir & flags) return 'directory';
46
- if (events.ItemIsSymlink & flags) return 'symlink';
51
+ if (events.ItemIsFile & flags) return "file";
52
+ if (events.ItemIsDir & flags) return "directory";
53
+ if (events.ItemIsSymlink & flags) return "symlink";
47
54
  }
48
55
  function anyIsTrue(obj) {
49
56
  for (let key in obj) {
@@ -52,21 +59,21 @@ function anyIsTrue(obj) {
52
59
  return false;
53
60
  }
54
61
  function getEventType(flags) {
55
- if (events.ItemRemoved & flags) return 'deleted';
56
- if (events.ItemRenamed & flags) return 'moved';
57
- if (events.ItemCreated & flags) return 'created';
58
- if (events.ItemModified & flags) return 'modified';
59
- if (events.RootChanged & flags) return 'root-changed';
60
- if (events.ItemCloned & flags) return 'cloned';
61
- if (anyIsTrue(flags)) return 'modified';
62
- return 'unknown';
62
+ if (events.ItemRemoved & flags) return "deleted";
63
+ if (events.ItemRenamed & flags) return "moved";
64
+ if (events.ItemCreated & flags) return "created";
65
+ if (events.ItemModified & flags) return "modified";
66
+ if (events.RootChanged & flags) return "root-changed";
67
+ if (events.ItemCloned & flags) return "cloned";
68
+ if (anyIsTrue(flags)) return "modified";
69
+ return "unknown";
63
70
  }
64
71
  function getFileChanges(flags) {
65
72
  return {
66
73
  inode: !!(events.ItemInodeMetaMod & flags),
67
74
  finder: !!(events.ItemFinderInfoMod & flags),
68
75
  access: !!(events.ItemChangeOwner & flags),
69
- xattrs: !!(events.ItemXattrMod & flags)
76
+ xattrs: !!(events.ItemXattrMod & flags),
70
77
  };
71
78
  }
72
79
 
package/fsevents.node CHANGED
Binary file
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "fsevents",
3
- "version": "2.1.1",
3
+ "version": "2.2.1",
4
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
  ],
9
- "files": ["fsevents.js", "fsevents.node"],
10
+ "files": [
11
+ "fsevents.d.ts",
12
+ "fsevents.js",
13
+ "fsevents.node"
14
+ ],
10
15
  "engines": {
11
16
  "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
12
17
  },
@@ -50,5 +55,8 @@
50
55
  "bugs": {
51
56
  "url": "https://github.com/fsevents/fsevents/issues"
52
57
  },
53
- "homepage": "https://github.com/fsevents/fsevents"
58
+ "homepage": "https://github.com/fsevents/fsevents",
59
+ "devDependencies": {
60
+ "node-gyp": "^6.1.0"
61
+ }
54
62
  }