| /* | ||
| MIT License http://www.opensource.org/licenses/mit-license.php | ||
| Author Tobias Koppers @sokra | ||
| */ | ||
| "use strict"; | ||
| const path = require("path"); | ||
| const DirectoryWatcher = require("./DirectoryWatcher"); | ||
| class WatcherManager { | ||
| constructor(options) { | ||
| this.options = options; | ||
| this.directoryWatchers = new Map(); | ||
| } | ||
| getDirectoryWatcher(directory) { | ||
| const watcher = this.directoryWatchers.get(directory); | ||
| if (watcher === undefined) { | ||
| const newWatcher = new DirectoryWatcher(this, directory, this.options); | ||
| this.directoryWatchers.set(directory, newWatcher); | ||
| newWatcher.on("closed", () => { | ||
| this.directoryWatchers.delete(directory); | ||
| }); | ||
| return newWatcher; | ||
| } | ||
| return watcher; | ||
| } | ||
| watchFile(p, startTime) { | ||
| const directory = path.dirname(p); | ||
| if (directory === p) return null; | ||
| return this.getDirectoryWatcher(directory).watch(p, startTime); | ||
| } | ||
| watchDirectory(directory, startTime) { | ||
| return this.getDirectoryWatcher(directory).watch(directory, startTime); | ||
| } | ||
| } | ||
| const watcherManagers = new WeakMap(); | ||
| module.exports = options => { | ||
| const watcherManager = watcherManagers.get(options); | ||
| if (watcherManager !== undefined) return watcherManager; | ||
| const newWatcherManager = new WatcherManager(options); | ||
| watcherManagers.set(options, newWatcherManager); | ||
| return newWatcherManager; | ||
| }; | ||
| module.exports.WatcherManager = WatcherManager; |
+31
-17
@@ -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; |
+26
-24
@@ -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); |
+2
-2
| { | ||
| "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" | ||
| } | ||
| } |
| /* | ||
| MIT License http://www.opensource.org/licenses/mit-license.php | ||
| Author Tobias Koppers @sokra | ||
| */ | ||
| "use strict"; | ||
| const path = require("path"); | ||
| let DirectoryWatcher; | ||
| class WatcherManager { | ||
| constructor() { | ||
| this.directoryWatchers = new Map(); | ||
| } | ||
| getDirectoryWatcher(directory, options) { | ||
| if (DirectoryWatcher === undefined) { | ||
| DirectoryWatcher = require("./DirectoryWatcher"); | ||
| } | ||
| options = options || {}; | ||
| const key = directory + " " + JSON.stringify(options); | ||
| const watcher = this.directoryWatchers.get(key); | ||
| if (watcher === undefined) { | ||
| const newWatcher = new DirectoryWatcher(directory, options); | ||
| this.directoryWatchers.set(key, newWatcher); | ||
| newWatcher.on("closed", () => { | ||
| this.directoryWatchers.delete(key); | ||
| }); | ||
| return newWatcher; | ||
| } | ||
| return watcher; | ||
| } | ||
| watchFile(p, options, startTime) { | ||
| const directory = path.dirname(p); | ||
| if (directory === p) return null; | ||
| return this.getDirectoryWatcher(directory, options).watch(p, startTime); | ||
| } | ||
| watchDirectory(directory, options, startTime) { | ||
| return this.getDirectoryWatcher(directory, options).watch( | ||
| directory, | ||
| startTime | ||
| ); | ||
| } | ||
| } | ||
| module.exports = new WatcherManager(); |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
35782
2.73%1000
1.52%