Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

watchpack

Package Overview
Dependencies
Maintainers
2
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

watchpack - npm Package Compare versions

Comparing version
2.4.2
to
2.4.3
+43
-5
lib/watchEventSource.js

@@ -16,4 +16,6 @@ /*

// Use 20 for OSX to make `FSWatcher.close` faster
// https://github.com/nodejs/node/issues/29949
const watcherLimit =
+process.env.WATCHPACK_WATCHER_LIMIT || (IS_OSX ? 2000 : 10000);
+process.env.WATCHPACK_WATCHER_LIMIT || (IS_OSX ? 20 : 10000);

@@ -38,2 +40,29 @@ const recursiveWatcherLogging = !!process.env

function createEPERMError(filePath) {
const error = new Error(`Operation not permitted: ${filePath}`);
error.code = "EPERM";
return error;
}
function createHandleChangeEvent(watcher, filePath, handleChangeEvent) {
return (type, filename) => {
// TODO: After Node.js v22, fs.watch(dir) and deleting a dir will trigger the rename change event.
// Here we just ignore it and keep the same behavior as before v22
// https://github.com/libuv/libuv/pull/4376
if (
type === "rename" &&
path.isAbsolute(filename) &&
path.basename(filename) === path.basename(filePath)
) {
if (!IS_OSX) {
// Before v22, windows will throw EPERM error
watcher.emit("error", createEPERMError(filename));
}
// Before v22, macos nothing to do
return;
}
handleChangeEvent(type, filename);
};
}
class DirectWatcher {

@@ -46,8 +75,14 @@ constructor(filePath) {

const watcher = fs.watch(filePath);
this.watcher = watcher;
watcher.on("change", (type, filename) => {
for (const w of this.watchers) {
w.emit("change", type, filename);
const handleChangeEvent = createHandleChangeEvent(
watcher,
filePath,
(type, filename) => {
for (const w of this.watchers) {
w.emit("change", type, filename);
}
}
});
);
watcher.on("change", handleChangeEvent);
watcher.on("error", error => {

@@ -337,1 +372,4 @@ for (const w of this.watchers) {

};
exports.createHandleChangeEvent = createHandleChangeEvent;
exports.watcherLimit = watcherLimit;
+1
-1
{
"name": "watchpack",
"version": "2.4.2",
"version": "2.4.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "./lib/watchpack.js",

@@ -73,3 +73,3 @@ # watchpack

// assumed to exist, when directory is not found without further information a remove event is emitted
// missing: can be files or directorees,
// missing: can be files or directories,
// only existence changes are tracked

@@ -76,0 +76,0 @@ // expected to not exist, no remove event is emitted when not found initially