@eduardo191labs/watcher 0.0.0-stage → 2.6.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.
- package/CMakeLists.txt +82 -0
- package/LICENSE +21 -0
- package/README.md +135 -2
- package/binding.gyp +125 -0
- package/index.d.ts +49 -0
- package/index.js +55 -0
- package/index.js.flow +45 -0
- package/package.json +61 -3
- package/scripts/build-from-source.js +16 -0
- package/src/Backend.cc +186 -0
- package/src/Backend.hh +37 -0
- package/src/Debounce.cc +113 -0
- package/src/Debounce.hh +49 -0
- package/src/DirTree.cc +164 -0
- package/src/DirTree.hh +50 -0
- package/src/Event.hh +109 -0
- package/src/Glob.cc +22 -0
- package/src/Glob.hh +34 -0
- package/src/PromiseRunner.hh +101 -0
- package/src/Signal.hh +46 -0
- package/src/Watcher.cc +241 -0
- package/src/Watcher.hh +73 -0
- package/src/binding.cc +268 -0
- package/src/kqueue/KqueueBackend.cc +306 -0
- package/src/kqueue/KqueueBackend.hh +35 -0
- package/src/linux/InotifyBackend.cc +236 -0
- package/src/linux/InotifyBackend.hh +34 -0
- package/src/macos/FSEventsBackend.cc +338 -0
- package/src/macos/FSEventsBackend.hh +20 -0
- package/src/shared/BruteForceBackend.cc +41 -0
- package/src/shared/BruteForceBackend.hh +25 -0
- package/src/unix/fts.cc +50 -0
- package/src/unix/legacy.cc +77 -0
- package/src/wasm/WasmBackend.cc +132 -0
- package/src/wasm/WasmBackend.hh +34 -0
- package/src/wasm/include.h +74 -0
- package/src/watchman/BSER.cc +302 -0
- package/src/watchman/BSER.hh +69 -0
- package/src/watchman/IPC.hh +175 -0
- package/src/watchman/WatchmanBackend.cc +342 -0
- package/src/watchman/WatchmanBackend.hh +35 -0
- package/src/windows/WindowsBackend.cc +282 -0
- package/src/windows/WindowsBackend.hh +18 -0
- package/src/windows/win_utils.cc +44 -0
- package/src/windows/win_utils.hh +11 -0
- package/wrapper.js +88 -0
package/CMakeLists.txt
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Android/Bionic build of the @parcel/watcher N-API addon.
|
|
2
|
+
#
|
|
3
|
+
# Desktop builds keep using `node-gyp rebuild` (binding.gyp). This file exists
|
|
4
|
+
# because Android has no node-gyp toolchain: the addon is cross-compiled with
|
|
5
|
+
# the NDK's clang through its CMake toolchain file, the same way Android apps
|
|
6
|
+
# build native code.
|
|
7
|
+
#
|
|
8
|
+
# cmake -S . -B build-android \
|
|
9
|
+
# -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake \
|
|
10
|
+
# -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-24 \
|
|
11
|
+
# -DNODE_ADDON_INCLUDE_DIR=... -DNODE_API_INCLUDE_DIR=...
|
|
12
|
+
#
|
|
13
|
+
# The result is `watcher.node`, a MODULE that resolves napi_* symbols from the
|
|
14
|
+
# host runtime (Node or Bun). Bionic folds pthread into libc, so no -pthread or
|
|
15
|
+
# -lrt is needed, and watchman is left out: there is no watchman daemon on
|
|
16
|
+
# Android.
|
|
17
|
+
|
|
18
|
+
cmake_minimum_required(VERSION 3.20)
|
|
19
|
+
project(watcher_addon CXX)
|
|
20
|
+
|
|
21
|
+
if(NOT ANDROID)
|
|
22
|
+
message(FATAL_ERROR "CMakeLists.txt is the Android build. Use `node-gyp rebuild` for desktop targets.")
|
|
23
|
+
endif()
|
|
24
|
+
|
|
25
|
+
if(NOT NODE_ADDON_INCLUDE_DIR OR NOT NODE_API_INCLUDE_DIR)
|
|
26
|
+
message(
|
|
27
|
+
FATAL_ERROR
|
|
28
|
+
"Set NODE_ADDON_INCLUDE_DIR (node-addon-api) and NODE_API_INCLUDE_DIR (node-api-headers/include).")
|
|
29
|
+
endif()
|
|
30
|
+
|
|
31
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
32
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
33
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
34
|
+
if(NOT CMAKE_BUILD_TYPE)
|
|
35
|
+
set(CMAKE_BUILD_TYPE Release)
|
|
36
|
+
endif()
|
|
37
|
+
|
|
38
|
+
# Same sources as the binding.gyp "android" condition: inotify plus the brute
|
|
39
|
+
# force tree reader that inotify backends inherit from.
|
|
40
|
+
set(WATCHER_SOURCES
|
|
41
|
+
src/binding.cc
|
|
42
|
+
src/Watcher.cc
|
|
43
|
+
src/Backend.cc
|
|
44
|
+
src/DirTree.cc
|
|
45
|
+
src/Glob.cc
|
|
46
|
+
src/Debounce.cc
|
|
47
|
+
src/shared/BruteForceBackend.cc
|
|
48
|
+
src/linux/InotifyBackend.cc
|
|
49
|
+
src/unix/legacy.cc)
|
|
50
|
+
|
|
51
|
+
add_library(watcher MODULE ${WATCHER_SOURCES})
|
|
52
|
+
|
|
53
|
+
target_include_directories(watcher PRIVATE
|
|
54
|
+
${NODE_ADDON_INCLUDE_DIR}
|
|
55
|
+
${NODE_API_INCLUDE_DIR}
|
|
56
|
+
${CMAKE_CURRENT_SOURCE_DIR}/src)
|
|
57
|
+
|
|
58
|
+
# INOTIFY/BRUTE_FORCE select the backends in Backend.cc; WATCHMAN is absent on
|
|
59
|
+
# Android and would only add a useless popen("watchman ...") probe.
|
|
60
|
+
target_compile_definitions(watcher PRIVATE
|
|
61
|
+
NAPI_DISABLE_CPP_EXCEPTIONS
|
|
62
|
+
INOTIFY
|
|
63
|
+
BRUTE_FORCE)
|
|
64
|
+
|
|
65
|
+
target_compile_options(watcher PRIVATE -fstack-protector-strong)
|
|
66
|
+
|
|
67
|
+
# napi_* stay undefined on purpose: the embedding runtime (Node or Bun)
|
|
68
|
+
# exports them. The NDK toolchain links shared libraries with `-z defs`
|
|
69
|
+
# (--no-undefined) by default, which fails on every napi_* reference, so the
|
|
70
|
+
# build passes ANDROID_ALLOW_UNDEFINED_SYMBOLS=ON. That variable is honoured by
|
|
71
|
+
# the NDK's own toolchain file; plain `-Wl,--no-undefined`/`-z undefs` flags do
|
|
72
|
+
# not win because lld applies the first `-z` it sees.
|
|
73
|
+
if(NOT ANDROID_ALLOW_UNDEFINED_SYMBOLS)
|
|
74
|
+
message(
|
|
75
|
+
FATAL_ERROR
|
|
76
|
+
"Configure with -DANDROID_ALLOW_UNDEFINED_SYMBOLS=ON: an N-API addon must keep napi_* undefined.")
|
|
77
|
+
endif()
|
|
78
|
+
|
|
79
|
+
set_target_properties(watcher PROPERTIES
|
|
80
|
+
PREFIX ""
|
|
81
|
+
OUTPUT_NAME "watcher"
|
|
82
|
+
SUFFIX ".node")
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present Devon Govett
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,136 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @parcel/watcher
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A native C++ Node module for querying and subscribing to filesystem events. Used by [Parcel 2](https://github.com/parcel-bundler/parcel).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Watch** - subscribe to realtime recursive directory change notifications when files or directories are created, updated, or deleted.
|
|
8
|
+
- **Query** - performantly query for historical change events in a directory, even when your program is not running.
|
|
9
|
+
- **Native** - implemented in C++ for performance and low-level integration with the operating system.
|
|
10
|
+
- **Cross platform** - includes backends for macOS, Linux, Windows, FreeBSD, and Watchman.
|
|
11
|
+
- **Performant** - events are throttled in C++ so the JavaScript thread is not overwhelmed during large filesystem changes (e.g. `git checkout` or `npm install`).
|
|
12
|
+
- **Scalable** - tens of thousands of files can be watched or queried at once with good performance.
|
|
13
|
+
|
|
14
|
+
## Example
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
const watcher = require('@parcel/watcher');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
|
|
20
|
+
// Subscribe to events
|
|
21
|
+
let subscription = await watcher.subscribe(process.cwd(), (err, events) => {
|
|
22
|
+
console.log(events);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// later on...
|
|
26
|
+
await subscription.unsubscribe();
|
|
27
|
+
|
|
28
|
+
// Get events since some saved snapshot in the past
|
|
29
|
+
let snapshotPath = path.join(process.cwd(), 'snapshot.txt');
|
|
30
|
+
let events = await watcher.getEventsSince(process.cwd(), snapshotPath);
|
|
31
|
+
|
|
32
|
+
// Save a snapshot for later
|
|
33
|
+
await watcher.writeSnapshot(process.cwd(), snapshotPath);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Watching
|
|
37
|
+
|
|
38
|
+
`@parcel/watcher` supports subscribing to realtime notifications of changes in a directory. It works recursively, so changes in sub-directories will also be emitted.
|
|
39
|
+
|
|
40
|
+
Events are throttled and coalesced for performance during large changes like `git checkout` or `npm install`, and a single notification will be emitted with all of the events at the end.
|
|
41
|
+
|
|
42
|
+
Only one notification will be emitted per file. For example, if a file was both created and updated since the last event, you'll get only a `create` event. If a file is both created and deleted, you will not be notifed of that file. Renames cause two events: a `delete` for the old name, and a `create` for the new name.
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
let subscription = await watcher.subscribe(process.cwd(), (err, events) => {
|
|
46
|
+
console.log(events);
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Events have two properties:
|
|
51
|
+
|
|
52
|
+
- `type` - the event type: `create`, `update`, or `delete`.
|
|
53
|
+
- `path` - the absolute path to the file or directory.
|
|
54
|
+
|
|
55
|
+
To unsubscribe from change notifications, call the `unsubscribe` method on the returned subscription object.
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
await subscription.unsubscribe();
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`@parcel/watcher` has the following watcher backends, listed in priority order:
|
|
62
|
+
|
|
63
|
+
- [FSEvents](https://developer.apple.com/documentation/coreservices/file_system_events) on macOS
|
|
64
|
+
- [Watchman](https://facebook.github.io/watchman/) if installed
|
|
65
|
+
- [inotify](http://man7.org/linux/man-pages/man7/inotify.7.html) on Linux
|
|
66
|
+
- [ReadDirectoryChangesW](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365465%28v%3Dvs.85%29.aspx) on Windows
|
|
67
|
+
- [kqueue](https://man.freebsd.org/cgi/man.cgi?kqueue) on FreeBSD, or as an alternative to FSEvents on macOS
|
|
68
|
+
|
|
69
|
+
You can specify the exact backend you wish to use by passing the `backend` option. If that backend is not available on the current platform, the default backend will be used instead. See below for the list of backend names that can be passed to the options.
|
|
70
|
+
|
|
71
|
+
## Querying
|
|
72
|
+
|
|
73
|
+
`@parcel/watcher` also supports querying for historical changes made in a directory, even when your program is not running. This makes it easy to invalidate a cache and re-build only the files that have changed, for example. It can be **significantly** faster than traversing the entire filesystem to determine what files changed, depending on the platform.
|
|
74
|
+
|
|
75
|
+
In order to query for historical changes, you first need a previous snapshot to compare to. This can be saved to a file with the `writeSnapshot` function, e.g. just before your program exits.
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
await watcher.writeSnapshot(dirPath, snapshotPath);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
When your program starts up, you can query for changes that have occurred since that snapshot using the `getEventsSince` function.
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
let events = await watcher.getEventsSince(dirPath, snapshotPath);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The events returned are exactly the same as the events that would be passed to the `subscribe` callback (see above).
|
|
88
|
+
|
|
89
|
+
`@parcel/watcher` has the following watcher backends, listed in priority order:
|
|
90
|
+
|
|
91
|
+
- [FSEvents](https://developer.apple.com/documentation/coreservices/file_system_events) on macOS
|
|
92
|
+
- [Watchman](https://facebook.github.io/watchman/) if installed
|
|
93
|
+
- [fts](http://man7.org/linux/man-pages/man3/fts.3.html) (brute force) on Linux and FreeBSD
|
|
94
|
+
- [FindFirstFile](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilea) (brute force) on Windows
|
|
95
|
+
|
|
96
|
+
The FSEvents (macOS) and Watchman backends are significantly more performant than the brute force backends used by default on Linux and Windows, for example returning results in miliseconds instead of seconds for large directory trees. This is because a background daemon monitoring filesystem changes on those platforms allows us to query cached data rather than traversing the filesystem manually (brute force).
|
|
97
|
+
|
|
98
|
+
macOS has good performance with FSEvents by default. For the best performance on other platforms, install [Watchman](https://facebook.github.io/watchman/) and it will be used by `@parcel/watcher` automatically.
|
|
99
|
+
|
|
100
|
+
You can specify the exact backend you wish to use by passing the `backend` option. If that backend is not available on the current platform, the default backend will be used instead. See below for the list of backend names that can be passed to the options.
|
|
101
|
+
|
|
102
|
+
## Options
|
|
103
|
+
|
|
104
|
+
All of the APIs in `@parcel/watcher` support the following options, which are passed as an object as the last function argument.
|
|
105
|
+
|
|
106
|
+
- `ignore` - an array of paths or glob patterns to ignore. uses [`is-glob`](https://github.com/micromatch/is-glob) to distinguish paths from globs. glob patterns are parsed with [`picomatch`](https://github.com/micromatch/picomatch) (see [features](https://github.com/micromatch/picomatch#globbing-features)).
|
|
107
|
+
- paths can be relative or absolute and can either be files or directories. No events will be emitted about these files or directories or their children.
|
|
108
|
+
- glob patterns match on relative paths from the root that is watched. No events will be emitted for matching paths.
|
|
109
|
+
- `backend` - the name of an explicitly chosen backend to use. Allowed options are `"fs-events"`, `"watchman"`, `"inotify"`, `"kqueue"`, `"windows"`, or `"brute-force"` (only for querying). If the specified backend is not available on the current platform, the default backend will be used instead.
|
|
110
|
+
|
|
111
|
+
## WASM
|
|
112
|
+
|
|
113
|
+
The `@parcel/watcher-wasm` package can be used in place of `@parcel/watcher` on unsupported platforms. It relies on the Node `fs` module, so in non-Node environments such as browsers, an `fs` polyfill will be needed.
|
|
114
|
+
|
|
115
|
+
**Note**: the WASM implementation is significantly less efficient than the native implementations because it must crawl the file system to watch each directory individually. Use the native `@parcel/watcher` package wherever possible.
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
import {subscribe} from '@parcel/watcher-wasm';
|
|
119
|
+
|
|
120
|
+
// Use the module as documented above.
|
|
121
|
+
subscribe(/* ... */);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Who is using this?
|
|
125
|
+
|
|
126
|
+
- [Parcel 2](https://parceljs.org/)
|
|
127
|
+
- [VSCode](https://code.visualstudio.com/updates/v1_62#_file-watching-changes)
|
|
128
|
+
- [Tailwind CSS Intellisense](https://github.com/tailwindlabs/tailwindcss-intellisense)
|
|
129
|
+
- [Gatsby Cloud](https://twitter.com/chatsidhartha/status/1435647412828196867)
|
|
130
|
+
- [Nx](https://nx.dev)
|
|
131
|
+
- [Nuxt](https://nuxt.com)
|
|
132
|
+
- [Meteor](https://github.com/meteor/meteor)
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
MIT
|
package/binding.gyp
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "watcher",
|
|
5
|
+
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
|
|
6
|
+
"sources": [ "src/binding.cc", "src/Watcher.cc", "src/Backend.cc", "src/DirTree.cc", "src/Glob.cc", "src/Debounce.cc" ],
|
|
7
|
+
"include_dirs" : ["<!(node -p \"require('node-addon-api').include_dir\")"],
|
|
8
|
+
'cflags!': [ '-fno-exceptions', '-std=c++17' ],
|
|
9
|
+
'cflags_cc!': [ '-fno-exceptions', '-std=c++17' ],
|
|
10
|
+
'cflags': [ '-fstack-protector-strong' ],
|
|
11
|
+
"conditions": [
|
|
12
|
+
['OS=="mac"', {
|
|
13
|
+
"sources": [
|
|
14
|
+
"src/watchman/BSER.cc",
|
|
15
|
+
"src/watchman/WatchmanBackend.cc",
|
|
16
|
+
"src/shared/BruteForceBackend.cc",
|
|
17
|
+
"src/unix/fts.cc",
|
|
18
|
+
"src/macos/FSEventsBackend.cc",
|
|
19
|
+
"src/kqueue/KqueueBackend.cc"
|
|
20
|
+
],
|
|
21
|
+
"link_settings": {
|
|
22
|
+
"libraries": ["CoreServices.framework"]
|
|
23
|
+
},
|
|
24
|
+
"defines": [
|
|
25
|
+
"WATCHMAN",
|
|
26
|
+
"BRUTE_FORCE",
|
|
27
|
+
"FS_EVENTS",
|
|
28
|
+
"KQUEUE"
|
|
29
|
+
],
|
|
30
|
+
"xcode_settings": {
|
|
31
|
+
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
|
|
32
|
+
}
|
|
33
|
+
}],
|
|
34
|
+
['OS=="mac" and target_arch=="arm64"', {
|
|
35
|
+
"xcode_settings": {
|
|
36
|
+
"ARCHS": ["arm64"]
|
|
37
|
+
}
|
|
38
|
+
}],
|
|
39
|
+
['OS=="linux"', {
|
|
40
|
+
"sources": [
|
|
41
|
+
"src/watchman/BSER.cc",
|
|
42
|
+
"src/watchman/WatchmanBackend.cc",
|
|
43
|
+
"src/shared/BruteForceBackend.cc",
|
|
44
|
+
"src/linux/InotifyBackend.cc",
|
|
45
|
+
"src/unix/legacy.cc"
|
|
46
|
+
],
|
|
47
|
+
"defines": [
|
|
48
|
+
"WATCHMAN",
|
|
49
|
+
"INOTIFY",
|
|
50
|
+
"BRUTE_FORCE"
|
|
51
|
+
]
|
|
52
|
+
}],
|
|
53
|
+
# Android/Bionic runs inotify and no watchman daemon exists there, so
|
|
54
|
+
# the watchman backend is left out: compiling it would only add a
|
|
55
|
+
# popen("watchman ...") probe that always fails. iOS-style gyp hosts
|
|
56
|
+
# also never define OS=="android", so this branch is only reached by
|
|
57
|
+
# an explicit --target_os=android build.
|
|
58
|
+
['OS=="android"', {
|
|
59
|
+
"sources": [
|
|
60
|
+
"src/shared/BruteForceBackend.cc",
|
|
61
|
+
"src/linux/InotifyBackend.cc",
|
|
62
|
+
"src/unix/legacy.cc"
|
|
63
|
+
],
|
|
64
|
+
"defines": [
|
|
65
|
+
"INOTIFY",
|
|
66
|
+
"BRUTE_FORCE"
|
|
67
|
+
]
|
|
68
|
+
}],
|
|
69
|
+
['OS=="win"', {
|
|
70
|
+
"sources": [
|
|
71
|
+
"src/watchman/BSER.cc",
|
|
72
|
+
"src/watchman/WatchmanBackend.cc",
|
|
73
|
+
"src/shared/BruteForceBackend.cc",
|
|
74
|
+
"src/windows/WindowsBackend.cc",
|
|
75
|
+
"src/windows/win_utils.cc"
|
|
76
|
+
],
|
|
77
|
+
"defines": [
|
|
78
|
+
"WATCHMAN",
|
|
79
|
+
"WINDOWS",
|
|
80
|
+
"BRUTE_FORCE"
|
|
81
|
+
],
|
|
82
|
+
"msvs_settings": {
|
|
83
|
+
"VCCLCompilerTool": {
|
|
84
|
+
"ExceptionHandling": 1, # /EHsc
|
|
85
|
+
"AdditionalOptions": [
|
|
86
|
+
"-std:c++17",
|
|
87
|
+
"/guard:cf",
|
|
88
|
+
"/W3",
|
|
89
|
+
"/we4146",
|
|
90
|
+
"/w34244",
|
|
91
|
+
"/we4267",
|
|
92
|
+
"/sdl",
|
|
93
|
+
"/ZH:SHA_256"
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
"VCLinkerTool": {
|
|
97
|
+
"AdditionalOptions": [
|
|
98
|
+
"/DYNAMICBASE",
|
|
99
|
+
"/guard:cf"
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}],
|
|
104
|
+
['OS=="freebsd"', {
|
|
105
|
+
"sources": [
|
|
106
|
+
"src/watchman/BSER.cc",
|
|
107
|
+
"src/watchman/WatchmanBackend.cc",
|
|
108
|
+
"src/shared/BruteForceBackend.cc",
|
|
109
|
+
"src/unix/fts.cc",
|
|
110
|
+
"src/kqueue/KqueueBackend.cc"
|
|
111
|
+
],
|
|
112
|
+
"defines": [
|
|
113
|
+
"WATCHMAN",
|
|
114
|
+
"BRUTE_FORCE",
|
|
115
|
+
"KQUEUE"
|
|
116
|
+
]
|
|
117
|
+
}]
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
],
|
|
121
|
+
"variables": {
|
|
122
|
+
"openssl_fips": "",
|
|
123
|
+
"node_use_dtrace": "false"
|
|
124
|
+
}
|
|
125
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
declare type FilePath = string;
|
|
2
|
+
declare type GlobPattern = string;
|
|
3
|
+
|
|
4
|
+
declare namespace ParcelWatcher {
|
|
5
|
+
export type BackendType =
|
|
6
|
+
| 'fs-events'
|
|
7
|
+
| 'watchman'
|
|
8
|
+
| 'inotify'
|
|
9
|
+
| 'windows'
|
|
10
|
+
| 'brute-force';
|
|
11
|
+
export type EventType = 'create' | 'update' | 'delete';
|
|
12
|
+
export interface Options {
|
|
13
|
+
ignore?: (FilePath | GlobPattern | RegExp)[];
|
|
14
|
+
backend?: BackendType;
|
|
15
|
+
}
|
|
16
|
+
export type SubscribeCallback = (
|
|
17
|
+
err: Error | null,
|
|
18
|
+
events: Event[],
|
|
19
|
+
) => unknown;
|
|
20
|
+
export interface AsyncSubscription {
|
|
21
|
+
unsubscribe(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export interface Event {
|
|
24
|
+
path: FilePath;
|
|
25
|
+
type: EventType;
|
|
26
|
+
}
|
|
27
|
+
export function getEventsSince(
|
|
28
|
+
dir: FilePath,
|
|
29
|
+
snapshot: FilePath,
|
|
30
|
+
opts?: Options,
|
|
31
|
+
): Promise<Event[]>;
|
|
32
|
+
export function subscribe(
|
|
33
|
+
dir: FilePath,
|
|
34
|
+
fn: SubscribeCallback,
|
|
35
|
+
opts?: Options,
|
|
36
|
+
): Promise<AsyncSubscription>;
|
|
37
|
+
export function unsubscribe(
|
|
38
|
+
dir: FilePath,
|
|
39
|
+
fn: SubscribeCallback,
|
|
40
|
+
opts?: Options,
|
|
41
|
+
): Promise<void>;
|
|
42
|
+
export function writeSnapshot(
|
|
43
|
+
dir: FilePath,
|
|
44
|
+
snapshot: FilePath,
|
|
45
|
+
opts?: Options,
|
|
46
|
+
): Promise<FilePath>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export = ParcelWatcher;
|
package/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const {createWrapper} = require('./wrapper');
|
|
2
|
+
|
|
3
|
+
let name = `@parcel/watcher-${process.platform}-${process.arch}`;
|
|
4
|
+
let android = false;
|
|
5
|
+
if (process.platform === 'linux') {
|
|
6
|
+
const {MUSL, familySync} = require('detect-libc');
|
|
7
|
+
const family = familySync();
|
|
8
|
+
if (family === MUSL) {
|
|
9
|
+
name += '-musl';
|
|
10
|
+
} else {
|
|
11
|
+
name += '-glibc';
|
|
12
|
+
}
|
|
13
|
+
} else if (process.platform === 'android') {
|
|
14
|
+
// detect-libc describes glibc/musl and has nothing to say about Bionic, so
|
|
15
|
+
// there is no libc suffix. The npm scope @parcel cannot be published to, so
|
|
16
|
+
// the fork ships the same addon unscoped and it is tried second.
|
|
17
|
+
android = true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let binding;
|
|
21
|
+
try {
|
|
22
|
+
binding = require(name);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
handleError(err);
|
|
25
|
+
try {
|
|
26
|
+
binding = android ? require(`watcher-android-${process.arch}`) : require('./build/Release/watcher.node');
|
|
27
|
+
} catch (err) {
|
|
28
|
+
handleError(err);
|
|
29
|
+
try {
|
|
30
|
+
binding = require('./build/Release/watcher.node');
|
|
31
|
+
} catch (err) {
|
|
32
|
+
handleError(err);
|
|
33
|
+
try {
|
|
34
|
+
binding = require('./build/Debug/watcher.node');
|
|
35
|
+
} catch (err) {
|
|
36
|
+
handleError(err);
|
|
37
|
+
throw new Error(
|
|
38
|
+
`No prebuild or local build of @parcel/watcher found. Tried ${name}. Please ensure it is installed (don't use --no-optional when installing with npm). Otherwise it is possible we don't support your platform yet. If this is the case, please report an issue to https://github.com/parcel-bundler/watcher.`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function handleError(err) {
|
|
46
|
+
if (err?.code !== 'MODULE_NOT_FOUND') {
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const wrapper = createWrapper(binding);
|
|
52
|
+
exports.writeSnapshot = wrapper.writeSnapshot;
|
|
53
|
+
exports.getEventsSince = wrapper.getEventsSince;
|
|
54
|
+
exports.subscribe = wrapper.subscribe;
|
|
55
|
+
exports.unsubscribe = wrapper.unsubscribe;
|
package/index.js.flow
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
declare type FilePath = string;
|
|
3
|
+
declare type GlobPattern = string;
|
|
4
|
+
|
|
5
|
+
export type BackendType =
|
|
6
|
+
| 'fs-events'
|
|
7
|
+
| 'watchman'
|
|
8
|
+
| 'inotify'
|
|
9
|
+
| 'windows'
|
|
10
|
+
| 'brute-force';
|
|
11
|
+
export type EventType = 'create' | 'update' | 'delete';
|
|
12
|
+
export interface Options {
|
|
13
|
+
ignore?: Array<FilePath | GlobPattern | RegExp>;
|
|
14
|
+
backend?: BackendType;
|
|
15
|
+
}
|
|
16
|
+
export type SubscribeCallback = (err: ?Error, events: Array<Event>) => mixed;
|
|
17
|
+
export interface AsyncSubscription {
|
|
18
|
+
unsubscribe(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface Event {
|
|
21
|
+
path: FilePath;
|
|
22
|
+
type: EventType;
|
|
23
|
+
}
|
|
24
|
+
declare module.exports: {
|
|
25
|
+
getEventsSince(
|
|
26
|
+
dir: FilePath,
|
|
27
|
+
snapshot: FilePath,
|
|
28
|
+
opts?: Options,
|
|
29
|
+
): Promise<Array<Event>>,
|
|
30
|
+
subscribe(
|
|
31
|
+
dir: FilePath,
|
|
32
|
+
fn: SubscribeCallback,
|
|
33
|
+
opts?: Options,
|
|
34
|
+
): Promise<AsyncSubscription>,
|
|
35
|
+
unsubscribe(
|
|
36
|
+
dir: FilePath,
|
|
37
|
+
fn: SubscribeCallback,
|
|
38
|
+
opts?: Options,
|
|
39
|
+
): Promise<void>,
|
|
40
|
+
writeSnapshot(
|
|
41
|
+
dir: FilePath,
|
|
42
|
+
snapshot: FilePath,
|
|
43
|
+
opts?: Options,
|
|
44
|
+
): Promise<FilePath>,
|
|
45
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eduardo191labs/watcher",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.6.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"types": "index.d.ts",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/eduardo191-star/watcher.git"
|
|
9
|
+
},
|
|
10
|
+
"description": "A native C++ Node module for querying and subscribing to filesystem events. Used by Parcel 2.",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"funding": {
|
|
16
|
+
"type": "opencollective",
|
|
17
|
+
"url": "https://opencollective.com/parcel"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"index.js",
|
|
21
|
+
"index.js.flow",
|
|
22
|
+
"index.d.ts",
|
|
23
|
+
"wrapper.js",
|
|
24
|
+
"package.json",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE",
|
|
27
|
+
"src",
|
|
28
|
+
"scripts/build-from-source.js",
|
|
29
|
+
"binding.gyp",
|
|
30
|
+
"CMakeLists.txt"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"prebuild": "prebuildify --napi --strip --tag-libc",
|
|
34
|
+
"format": "prettier --write \"./**/*.{js,mjs,json,md,ts,flow}\"",
|
|
35
|
+
"build": "node-gyp rebuild",
|
|
36
|
+
"install": "node scripts/build-from-source.js",
|
|
37
|
+
"test": "mocha"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">= 10.0.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"detect-libc": "^2.0.3",
|
|
44
|
+
"is-glob": "^4.0.3",
|
|
45
|
+
"node-addon-api": "^7.0.0",
|
|
46
|
+
"picomatch": "^4.0.4"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"esbuild": "^0.19.8",
|
|
50
|
+
"fs-extra": "^10.0.0",
|
|
51
|
+
"husky": "^7.0.2",
|
|
52
|
+
"lint-staged": "^11.1.2",
|
|
53
|
+
"mocha": "^9.1.1",
|
|
54
|
+
"napi-wasm": "^1.1.0",
|
|
55
|
+
"prebuildify": "^6.0.1",
|
|
56
|
+
"prettier": "^2.3.2"
|
|
57
|
+
},
|
|
58
|
+
"binary": {
|
|
59
|
+
"napi_versions": [
|
|
60
|
+
3
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"optionalDependencies": {}
|
|
6
64
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const {spawn} = require('child_process');
|
|
4
|
+
|
|
5
|
+
if (process.env.npm_config_build_from_source === 'true') {
|
|
6
|
+
build();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function build() {
|
|
10
|
+
spawn('node-gyp', ['rebuild'], {stdio: 'inherit', shell: true}).on(
|
|
11
|
+
'exit',
|
|
12
|
+
function (code) {
|
|
13
|
+
process.exit(code);
|
|
14
|
+
},
|
|
15
|
+
);
|
|
16
|
+
}
|