Socket
Socket
Sign inDemoInstall

watchpack

Package Overview
Dependencies
3
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-beta.8 to 2.0.0-beta.9

lib/getWatcherManager.js

48

lib/DirectoryWatcher.js

@@ -12,4 +12,2 @@ /*

const watcherManager = require("./watcherManager");
const EXISTANCE_ONLY_TIME_ENTRY = Object.freeze({});

@@ -36,2 +34,3 @@

this.startTime = startTime && +startTime;
this._cachedTimeInfoEntries = undefined;
}

@@ -51,3 +50,3 @@

class DirectoryWatcher extends EventEmitter {
constructor(directoryPath, options) {
constructor(watcherManager, directoryPath, options) {
super();

@@ -57,2 +56,3 @@ if (FORCE_POLLING) {

}
this.watcherManager = watcherManager;
this.options = options;

@@ -130,2 +130,4 @@ this.path = directoryPath;

setMissing(itemPath, initial, type) {
this._cachedTimeInfoEntries = undefined;
if (this.initialScan) {

@@ -184,2 +186,3 @@ this.initialScanRemoved.add(itemPath);

});
this._cachedTimeInfoEntries = undefined;

@@ -215,2 +218,3 @@ if (!old) {

this._cachedTimeInfoEntries = undefined;
if (this.nestedWatching) {

@@ -244,8 +248,5 @@ this.createNestedWatcher(directoryPath);

createNestedWatcher(directoryPath) {
const watcher = watcherManager.watchDirectory(
directoryPath,
this.options,
1
);
const watcher = this.watcherManager.watchDirectory(directoryPath, 1);
watcher.on("change", (filePath, mtime, type) => {
this._cachedTimeInfoEntries = undefined;
this.forEachWatcher(this.path, w => {

@@ -263,2 +264,3 @@ if (w.checkStartTime(mtime, false)) {

this.nestedWatching = !!flag;
this._cachedTimeInfoEntries = undefined;
if (this.nestedWatching) {

@@ -287,2 +289,6 @@ for (const directory of this.directories.keys()) {

watcher.on("closed", () => {
if (--this.refs <= 0) {
this.close();
return;
}
watchers.delete(watcher);

@@ -293,3 +299,2 @@ if (watchers.size === 0) {

}
if (--this.refs <= 0) this.close();
});

@@ -314,10 +319,15 @@ watchers.add(watcher);

}
process.nextTick(() => {
if (this.closed) return;
if (safeTime) {
if (safeTime >= startTime) watcher.emit("change", safeTime);
} else if (this.initialScan && this.initialScanRemoved.has(filePath)) {
if (safeTime) {
if (safeTime >= startTime) {
process.nextTick(() => {
if (this.closed) return;
watcher.emit("change", safeTime);
});
}
} else if (this.initialScan && this.initialScanRemoved.has(filePath)) {
process.nextTick(() => {
if (this.closed) return;
watcher.emit("remove");
}
});
});
}
return watcher;

@@ -371,2 +381,3 @@ }

this.lastWatchEvent = Date.now();
this._cachedTimeInfoEntries = undefined;
if (!stats) {

@@ -443,3 +454,3 @@ this.setMissing(filePath, false, eventType);

this.parentWatcher = watcherManager.watchFile(this.path, this.options, 1);
this.parentWatcher = this.watcherManager.watchFile(this.path, 1);
this.parentWatcher.on("change", (mtime, type) => {

@@ -607,2 +618,4 @@ if (this.closed) return;

getTimeInfoEntries() {
if (this._cachedTimeInfoEntries !== undefined)
return this._cachedTimeInfoEntries;
const map = new Map();

@@ -644,2 +657,3 @@ let safeTime = this.lastWatchEvent;

}
this._cachedTimeInfoEntries = map;
}

@@ -646,0 +660,0 @@ return map;

@@ -7,3 +7,3 @@ /*

const watcherManager = require("./watcherManager");
const getWatcherManager = require("./getWatcherManager");
const LinkResolver = require("./LinkResolver");

@@ -43,2 +43,19 @@ const EventEmitter = require("events").EventEmitter;

const normalizeOptions = options => {
return {
followSymlinks: !!options.followSymlinks,
ignored: ignoredToRegexp(options.ignored),
poll: options.poll
};
};
const normalizeCache = new WeakMap();
const cachedNormalizeOptions = options => {
const cacheEntry = normalizeCache.get(options);
if (cacheEntry !== undefined) return cacheEntry;
const normalized = normalizeOptions(options);
normalizeCache.set(options, normalized);
return normalized;
};
class Watchpack extends EventEmitter {

@@ -50,7 +67,4 @@ constructor(options) {

this.options = options;
this.watcherOptions = {
followSymlinks: !!options.followSymlinks,
ignored: ignoredToRegexp(options.ignored),
poll: options.poll
};
this.watcherOptions = cachedNormalizeOptions(options);
this.watcherManager = getWatcherManager(this.watcherOptions);
this.fileWatchers = [];

@@ -80,10 +94,6 @@ this.dirWatchers = [];

for (const innerFile of resolver.resolve(file)) {
if (filter(innerFile)) {
if (file === innerFile || filter(innerFile)) {
const watcher = this._fileWatcher(
file,
watcherManager.watchFile(
innerFile,
this.watcherOptions,
startTime
)
this.watcherManager.watchFile(innerFile, startTime)
);

@@ -103,12 +113,4 @@ if (watcher) this.fileWatchers.push(watcher);

first
? watcherManager.watchDirectory(
innerItem,
this.watcherOptions,
startTime
)
: watcherManager.watchFile(
innerItem,
this.watcherOptions,
startTime
)
? this.watcherManager.watchDirectory(innerItem, startTime)
: this.watcherManager.watchFile(innerItem, startTime)
);

@@ -126,3 +128,3 @@ if (watcher) this.dirWatchers.push(watcher);

file,
watcherManager.watchFile(file, this.watcherOptions, startTime)
this.watcherManager.watchFile(file, startTime)
);

@@ -136,3 +138,3 @@ if (watcher) this.fileWatchers.push(watcher);

dir,
watcherManager.watchDirectory(dir, this.watcherOptions, startTime)
this.watcherManager.watchDirectory(dir, startTime)
);

@@ -139,0 +141,0 @@ if (watcher) this.dirWatchers.push(watcher);

{
"name": "watchpack",
"version": "2.0.0-beta.8",
"version": "2.0.0-beta.9",
"description": "",

@@ -47,4 +47,4 @@ "main": "./lib/watchpack.js",

"engines": {
"node": ">=6.11.5"
"node": ">=10.13.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc