You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@parcel/watcher

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@parcel/watcher - npm Package Compare versions

Comparing version
2.5.1
to
2.5.4
+2
-1
index.js

@@ -5,3 +5,4 @@ const {createWrapper} = require('./wrapper');

if (process.platform === 'linux') {
const { MUSL, family } = require('detect-libc');
const { MUSL, familySync } = require('detect-libc');
const family = familySync();
if (family === MUSL) {

@@ -8,0 +9,0 @@ name += '-musl';

{
"name": "@parcel/watcher",
"version": "2.5.1",
"version": "2.5.4",
"main": "index.js",

@@ -53,6 +53,6 @@ "types": "index.d.ts",

"dependencies": {
"detect-libc": "^1.0.3",
"detect-libc": "^2.0.3",
"is-glob": "^4.0.3",
"micromatch": "^4.0.5",
"node-addon-api": "^7.0.0"
"node-addon-api": "^7.0.0",
"picomatch": "^4.0.3"
},

@@ -75,16 +75,16 @@ "devDependencies": {

"optionalDependencies": {
"@parcel/watcher-darwin-x64": "2.5.1",
"@parcel/watcher-darwin-arm64": "2.5.1",
"@parcel/watcher-win32-x64": "2.5.1",
"@parcel/watcher-win32-arm64": "2.5.1",
"@parcel/watcher-win32-ia32": "2.5.1",
"@parcel/watcher-linux-x64-glibc": "2.5.1",
"@parcel/watcher-linux-x64-musl": "2.5.1",
"@parcel/watcher-linux-arm64-glibc": "2.5.1",
"@parcel/watcher-linux-arm64-musl": "2.5.1",
"@parcel/watcher-linux-arm-glibc": "2.5.1",
"@parcel/watcher-linux-arm-musl": "2.5.1",
"@parcel/watcher-android-arm64": "2.5.1",
"@parcel/watcher-freebsd-x64": "2.5.1"
"@parcel/watcher-darwin-x64": "2.5.4",
"@parcel/watcher-darwin-arm64": "2.5.4",
"@parcel/watcher-win32-x64": "2.5.4",
"@parcel/watcher-win32-arm64": "2.5.4",
"@parcel/watcher-win32-ia32": "2.5.4",
"@parcel/watcher-linux-x64-glibc": "2.5.4",
"@parcel/watcher-linux-x64-musl": "2.5.4",
"@parcel/watcher-linux-arm64-glibc": "2.5.4",
"@parcel/watcher-linux-arm64-musl": "2.5.4",
"@parcel/watcher-linux-arm-glibc": "2.5.4",
"@parcel/watcher-linux-arm-musl": "2.5.4",
"@parcel/watcher-android-arm64": "2.5.4",
"@parcel/watcher-freebsd-x64": "2.5.4"
}
}

@@ -106,3 +106,3 @@ # @parcel/watcher

- `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 [`micromatch`](https://github.com/micromatch/micromatch) (see [features](https://github.com/micromatch/micromatch#matching-features)).
- `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)).
- 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.

@@ -133,2 +133,3 @@ - glob patterns match on relative paths from the root that is watched. No events will be emitted for matching paths.

- [Nuxt](https://nuxt.com)
- [Meteor](https://github.com/meteor/meteor)

@@ -135,0 +136,0 @@ ## License

@@ -24,3 +24,7 @@ #ifdef FS_EVENTS

static std::unordered_map<std::string, std::shared_ptr<Backend>> sharedBackends;
static std::unordered_map<std::string, std::shared_ptr<Backend>>& getSharedBackends() {
static std::unordered_map<std::string, std::shared_ptr<Backend>>* sharedBackends =
new std::unordered_map<std::string, std::shared_ptr<Backend>>();
return *sharedBackends;
}

@@ -69,4 +73,4 @@ std::shared_ptr<Backend> getBackend(std::string backend) {

std::shared_ptr<Backend> Backend::getShared(std::string backend) {
auto found = sharedBackends.find(backend);
if (found != sharedBackends.end()) {
auto found = getSharedBackends().find(backend);
if (found != getSharedBackends().end()) {
return found->second;

@@ -81,3 +85,3 @@ }

result->run();
sharedBackends.emplace(backend, result);
getSharedBackends().emplace(backend, result);
return result;

@@ -87,5 +91,5 @@ }

void removeShared(Backend *backend) {
for (auto it = sharedBackends.begin(); it != sharedBackends.end(); it++) {
for (auto it = getSharedBackends().begin(); it != getSharedBackends().end(); it++) {
if (it->second.get() == backend) {
sharedBackends.erase(it);
getSharedBackends().erase(it);
break;

@@ -96,4 +100,4 @@ }

// Free up memory.
if (sharedBackends.size() == 0) {
sharedBackends.rehash(0);
if (getSharedBackends().size() == 0) {
getSharedBackends().rehash(0);
}

@@ -153,3 +157,3 @@ }

mSubscriptions.insert(watcher);
} catch (std::exception &err) {
} catch (std::exception&) {
unref();

@@ -156,0 +160,0 @@ throw;

@@ -21,3 +21,3 @@ #include <unordered_set>

for (size_t i = 0; i < items.Length(); i++) {
Value item = items.Get(Number::New(env, i));
Value item = items.Get(Number::New(env, static_cast<double>(i)));
if (item.IsString()) {

@@ -41,3 +41,3 @@ result.insert(std::string(item.As<String>().Utf8Value().c_str()));

for (size_t i = 0; i < items.Length(); i++) {
Value item = items.Get(Number::New(env, i));
Value item = items.Get(Number::New(env, static_cast<double>(i)));
if (item.IsString()) {

@@ -129,3 +129,3 @@ auto key = item.As<String>().Utf8Value();

Array eventsArray = Array::New(env, events.size());
size_t i = 0;
uint32_t i = 0;
for (auto it = events.begin(); it != events.end(); it++) {

@@ -189,3 +189,3 @@ eventsArray.Set(i++, it->toJS(env));

backend->watch(watcher);
} catch (std::exception &err) {
} catch (std::exception&) {
watcher->destroy();

@@ -192,0 +192,0 @@ throw;

#include "DirTree.hh"
#include <inttypes.h>
static std::mutex mDirCacheMutex;
static std::unordered_map<std::string, std::weak_ptr<DirTree>> dirTreeCache;
// "Meyer's singleton", construction is ordered by use, likewise (reverse) for destruction.
// https://stackoverflow.com/a/17713799
// https://laristra.github.io/flecsi/src/developer-guide/patterns/meyers_singleton.html
static std::mutex& mDirCacheMutex() {
static std::mutex mutex;
return mutex;
}
static std::unordered_map<std::string, std::weak_ptr<DirTree>>& dirTreeCache() {
static std::unordered_map<std::string, std::weak_ptr<DirTree>> cache;
return cache;
}
struct DirTreeDeleter {
void operator()(DirTree *tree) {
std::lock_guard<std::mutex> lock(mDirCacheMutex);
dirTreeCache.erase(tree->root);
std::lock_guard<std::mutex> lock(mDirCacheMutex());
std::unordered_map<std::string, std::weak_ptr<DirTree>> &cache = dirTreeCache();
cache.erase(tree->root);
delete tree;
// Free up memory.
if (dirTreeCache.size() == 0) {
dirTreeCache.rehash(0);
if (cache.size() == 0) {
cache.rehash(0);
}

@@ -21,13 +32,14 @@ }

std::shared_ptr<DirTree> DirTree::getCached(std::string root) {
std::lock_guard<std::mutex> lock(mDirCacheMutex);
std::lock_guard<std::mutex> lock(mDirCacheMutex());
std::unordered_map<std::string, std::weak_ptr<DirTree>> &cache = dirTreeCache();
auto found = dirTreeCache.find(root);
auto found = cache.find(root);
std::shared_ptr<DirTree> tree;
// Use cached tree, or create an empty one.
if (found != dirTreeCache.end()) {
if (found != cache.end()) {
tree = found->second.lock();
} else {
tree = std::shared_ptr<DirTree>(new DirTree(root), DirTreeDeleter());
dirTreeCache.emplace(root, tree);
cache.emplace(root, tree);
}

@@ -59,3 +71,3 @@

DirEntry *DirTree::add(std::string path, uint64_t mtime, bool isDir) {
std::lock_guard<std::mutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mDirCacheMutex());

@@ -68,3 +80,3 @@ DirEntry entry(path, mtime, isDir);

DirEntry *DirTree::find(std::string path) {
std::lock_guard<std::mutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mDirCacheMutex());
return _find(path);

@@ -74,3 +86,3 @@ }

DirEntry *DirTree::update(std::string path, uint64_t mtime) {
std::lock_guard<std::mutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mDirCacheMutex());

@@ -86,3 +98,3 @@ DirEntry *found = _find(path);

void DirTree::remove(std::string path) {
std::lock_guard<std::mutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mDirCacheMutex());

@@ -107,3 +119,3 @@ DirEntry *found = _find(path);

void DirTree::write(FILE *f) {
std::lock_guard<std::mutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mDirCacheMutex());

@@ -117,3 +129,3 @@ fprintf(f, "%zu\n", entries.size());

void DirTree::getChanges(DirTree *snapshot, EventList &events) {
std::lock_guard<std::mutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mDirCacheMutex());
std::lock_guard<std::mutex> snapshotLock(snapshot->mMutex);

@@ -120,0 +132,0 @@

@@ -173,3 +173,5 @@ #include <memory>

// https://github.com/parcel-bundler/watcher/issues/76
lstat(path.c_str(), &st);
if (lstat(path.c_str(), &st) != 0) {
return false;
}
DirEntry *entry = sub->tree->add(path, CONVERT_TIME(st.st_mtim), S_ISDIR(st.st_mode));

@@ -188,3 +190,5 @@

struct stat st;
stat(path.c_str(), &st);
if (stat(path.c_str(), &st) != 0) {
return false;
}
sub->tree->update(path, CONVERT_TIME(st.st_mtim));

@@ -191,0 +195,0 @@ } else if (event->mask & (IN_DELETE | IN_DELETE_SELF | IN_MOVED_FROM | IN_MOVE_SELF)) {

@@ -18,12 +18,16 @@ #include "Watcher.hh"

static std::unordered_set<WatcherRef , WatcherHash, WatcherCompare> sharedWatchers;
static std::unordered_set<WatcherRef , WatcherHash, WatcherCompare>& getSharedWatchers() {
static std::unordered_set<WatcherRef , WatcherHash, WatcherCompare>* sharedWatchers =
new std::unordered_set<WatcherRef , WatcherHash, WatcherCompare>();
return *sharedWatchers;
}
WatcherRef Watcher::getShared(std::string dir, std::unordered_set<std::string> ignorePaths, std::unordered_set<Glob> ignoreGlobs) {
WatcherRef watcher = std::make_shared<Watcher>(dir, ignorePaths, ignoreGlobs);
auto found = sharedWatchers.find(watcher);
if (found != sharedWatchers.end()) {
auto found = getSharedWatchers().find(watcher);
if (found != getSharedWatchers().end()) {
return *found;
}
sharedWatchers.insert(watcher);
getSharedWatchers().insert(watcher);
return watcher;

@@ -33,5 +37,5 @@ }

void removeShared(Watcher *watcher) {
for (auto it = sharedWatchers.begin(); it != sharedWatchers.end(); it++) {
for (auto it = getSharedWatchers().begin(); it != getSharedWatchers().end(); it++) {
if (it->get() == watcher) {
sharedWatchers.erase(it);
getSharedWatchers().erase(it);
break;

@@ -42,4 +46,4 @@ }

// Free up memory.
if (sharedWatchers.size() == 0) {
sharedWatchers.rehash(0);
if (getSharedWatchers().size() == 0) {
getSharedWatchers().rehash(0);
}

@@ -90,3 +94,3 @@ }

Array arr = Array::New(env, events.size());
size_t currentEventIndex = 0;
uint32_t currentEventIndex = 0;
for (auto eventIterator = events.begin(); eventIterator != events.end(); eventIterator++) {

@@ -93,0 +97,0 @@ arr.Set(currentEventIndex++, eventIterator->toJS(env));

@@ -101,3 +101,3 @@ #include <stdint.h>

}
BSER::Array arrayValue() override {

@@ -188,3 +188,3 @@ return value;

void encode(std::ostream &oss) override {
int8_t t = value == true ? BSER_BOOL_TRUE : BSER_BOOL_FALSE;
int8_t t = value == true ? static_cast<int8_t>(BSER_BOOL_TRUE) : static_cast<int8_t>(BSER_BOOL_FALSE);
oss.write(reinterpret_cast<char*>(&t), sizeof(t));

@@ -300,3 +300,3 @@ }

res.write("\x00\x01", 2);
BSERInteger(oss.str().size()).encode(res);

@@ -303,0 +303,0 @@ res << oss.str();

@@ -24,3 +24,3 @@ #include <string>

char buffer[256];
int r;
size_t r;
int64_t len = -1;

@@ -50,3 +50,7 @@ do {

#ifdef _WIN32
FILE *fp = popen("watchman --output-encoding=bser get-sockname", "r");
#else
FILE *fp = popen("watchman --output-encoding=bser get-sockname 2>/dev/null", "r");
#endif
if (fp == NULL || errno == ECHILD) {

@@ -109,3 +113,3 @@ throw std::runtime_error("Failed to execute watchman");

return true;
} catch (std::exception &err) {
} catch (std::exception&) {
return false;

@@ -112,0 +116,0 @@ }

@@ -8,7 +8,7 @@ #include "./win_utils.hh"

std::wstring res(output);
delete output;
delete[] output;
return res;
}
std::string utf16ToUtf8(const WCHAR *input, size_t length) {
std::string utf16ToUtf8(const WCHAR *input, DWORD length) {
unsigned int len = WideCharToMultiByte(CP_UTF8, 0, input, length, NULL, 0, NULL, NULL);

@@ -19,3 +19,3 @@ char *output = new char[len + 1];

std::string res(output);
delete output;
delete[] output;
return res;

@@ -29,3 +29,3 @@ }

// Get the required length for the output
unsigned int len = GetLongPathNameW(p.data(), NULL, 0);
DWORD len = GetLongPathNameW(p.data(), NULL, 0);
if (!len) {

@@ -39,3 +39,3 @@ return path;

if (!len) {
delete output;
delete[] output;
return path;

@@ -46,4 +46,4 @@ }

std::string res = utf16ToUtf8(output + 4, len - 4);
delete output;
delete[] output;
return res;
}
const path = require('path');
const micromatch = require('micromatch');
const picomatch = require('picomatch');
const isGlob = require('is-glob');

@@ -17,3 +17,3 @@

const regex = micromatch.makeRe(value, {
const regex = picomatch.makeRe(value, {
// We set `dot: true` to workaround an issue with the

@@ -24,6 +24,3 @@ // regular expression on Linux where the resulting

dot: true,
// C++ does not support lookbehind regex patterns, they
// were only added later to JavaScript engines
// (https://bit.ly/3V7S6UL)
lookbehinds: false
windows: process.platform === 'win32',
});

@@ -30,0 +27,0 @@ opts.ignoreGlobs.push(regex.source);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet