Socket
Socket
Sign inDemoInstall

watchpack

Package Overview
Dependencies
Maintainers
1
Versions
56
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.0.0-beta.9 to 2.0.0-beta.10

65

lib/DirectoryWatcher.js

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

this.initialScanRemoved = new Set();
this.initialScanFinished = undefined;
/** @type {Map<string, Set<Watcher>>} */
this.watchers = new Map();

@@ -316,6 +318,16 @@ this.parentWatcher = null;

}
} else if (this.initialScan && this.initialScanRemoved.has(filePath)) {
} else if (this.initialScan) {
if (this.initialScanRemoved.has(filePath)) {
process.nextTick(() => {
if (this.closed) return;
watcher.emit("remove");
});
}
} else if (
!this.directories.has(filePath) &&
watcher.checkStartTime(this.initialScanFinished, false)
) {
process.nextTick(() => {
if (this.closed) return;
watcher.emit("remove");
watcher.emit("initial-missing", "watch (missing on attach)");
});

@@ -365,3 +377,3 @@ }

if (!fs.existsSync(this.path)) {
this.onDirectoryRemoved();
this.onDirectoryRemoved("stat failed");
}

@@ -408,3 +420,3 @@ }

}
this.onDirectoryRemoved();
this.onDirectoryRemoved("watch error");
}

@@ -425,12 +437,14 @@ }

onDirectoryRemoved() {
onDirectoryRemoved(reason) {
if (this.watcher) {
this.watcher.close(), (this.watcher = null);
this.watcher.close();
this.watcher = null;
}
this.watchInParentDirectory();
const type = `directory-removed (${reason})`;
for (const directory of this.directories.keys()) {
this.setMissing(directory, null, "directory-removed");
this.setMissing(directory, null, type);
}
for (const file of this.files.keys()) {
this.setMissing(file, null, "directory-removed");
this.setMissing(file, null, type);
}

@@ -468,3 +482,3 @@ }

this.parentWatcher.on("remove", () => {
this.onDirectoryRemoved();
this.onDirectoryRemoved("parent directory removed");
});

@@ -489,3 +503,3 @@ }

if (err.code === "ENOENT" || err.code === "EPERM") {
this.onDirectoryRemoved();
this.onDirectoryRemoved("scan readdir failed");
} else {

@@ -495,2 +509,15 @@ this.onScanError(err);

this.initialScan = false;
this.initialScanFinished = Date.now();
if (initial) {
for (const watchers of this.watchers.values()) {
for (const watcher of watchers) {
if (watcher.checkStartTime(this.initialScanFinished, false)) {
watcher.emit(
"initial-missing",
"scan (parent directory missing in initial scan)"
);
}
}
}
}
if (this.scanAgain) {

@@ -568,2 +595,20 @@ this.scanAgain = false;

this.initialScanRemoved = null;
this.initialScanFinished = Date.now();
if (initial) {
const missingWatchers = new Map(this.watchers);
missingWatchers.delete(withoutCase(this.path));
for (const item of itemPaths) {
missingWatchers.delete(withoutCase(item));
}
for (const watchers of missingWatchers.values()) {
for (const watcher of watchers) {
if (watcher.checkStartTime(this.initialScanFinished, false)) {
watcher.emit(
"initial-missing",
"scan (missing in initial scan)"
);
}
}
}
}
if (this.scanAgain) {

@@ -570,0 +615,0 @@ this.scanAgain = false;

99

lib/watchpack.js

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

const EMPTY_ARRAY = [];
function addWatchersToSet(watchers, set) {

@@ -68,4 +70,3 @@ for (const w of watchers) {

this.watcherManager = getWatcherManager(this.watcherOptions);
this.fileWatchers = [];
this.dirWatchers = [];
this.watchers = [];
this.paused = false;

@@ -78,6 +79,19 @@ this.aggregatedChanges = new Set();

watch(files, directories, startTime) {
watch(arg1, arg2, arg3) {
let files, directories, missing, startTime;
if (!arg2) {
({
files = EMPTY_ARRAY,
directories = EMPTY_ARRAY,
missing = EMPTY_ARRAY,
startTime
} = arg1);
} else {
files = arg1;
directories = arg2;
missing = EMPTY_ARRAY;
startTime = arg3;
}
this.paused = false;
const oldFileWatchers = this.fileWatchers;
const oldDirWatchers = this.dirWatchers;
const oldWatchers = this.watchers;
const ignored = this.watcherOptions.ignored;

@@ -87,4 +101,3 @@ const filter = ignored

: () => true;
this.fileWatchers = [];
this.dirWatchers = [];
this.watchers = [];
if (this.watcherOptions.followSymlinks) {

@@ -100,3 +113,3 @@ const resolver = new LinkResolver();

);
if (watcher) this.fileWatchers.push(watcher);
if (watcher) this.watchers.push(watcher);
}

@@ -106,2 +119,15 @@ }

}
for (const file of missing) {
if (filter(file)) {
for (const innerFile of resolver.resolve(file)) {
if (file === innerFile || filter(innerFile)) {
const watcher = this._missingWatcher(
file,
this.watcherManager.watchFile(innerFile, startTime)
);
if (watcher) this.watchers.push(watcher);
}
}
}
}
for (const dir of directories) {

@@ -118,3 +144,3 @@ if (filter(dir)) {

);
if (watcher) this.dirWatchers.push(watcher);
if (watcher) this.watchers.push(watcher);
}

@@ -132,5 +158,14 @@ first = false;

);
if (watcher) this.fileWatchers.push(watcher);
if (watcher) this.watchers.push(watcher);
}
}
for (const file of missing) {
if (filter(file)) {
const watcher = this._missingWatcher(
file,
this.watcherManager.watchFile(file, startTime)
);
if (watcher) this.watchers.push(watcher);
}
}
for (const dir of directories) {

@@ -142,8 +177,7 @@ if (filter(dir)) {

);
if (watcher) this.dirWatchers.push(watcher);
if (watcher) this.watchers.push(watcher);
}
}
}
for (const w of oldFileWatchers) w.close();
for (const w of oldDirWatchers) w.close();
for (const w of oldWatchers) w.close();
}

@@ -154,6 +188,4 @@

if (this.aggregateTimeout) clearTimeout(this.aggregateTimeout);
for (const w of this.fileWatchers) w.close();
for (const w of this.dirWatchers) w.close();
this.fileWatchers.length = 0;
this.dirWatchers.length = 0;
for (const w of this.watchers) w.close();
this.watchers.length = 0;
}

@@ -168,4 +200,3 @@

const directoryWatchers = new Set();
addWatchersToSet(this.fileWatchers, directoryWatchers);
addWatchersToSet(this.dirWatchers, directoryWatchers);
addWatchersToSet(this.watchers, directoryWatchers);
const obj = Object.create(null);

@@ -185,4 +216,3 @@ for (const w of directoryWatchers) {

const directoryWatchers = new Set();
addWatchersToSet(this.fileWatchers, directoryWatchers);
addWatchersToSet(this.dirWatchers, directoryWatchers);
addWatchersToSet(this.watchers, directoryWatchers);
const map = new Map();

@@ -207,4 +237,19 @@ for (const w of directoryWatchers) {

_missingWatcher(file, watcher) {
if (watcher) {
watcher.on("change", (mtime, type) => {
this._onChange(file, mtime, file, type);
});
watcher.on("remove", type => {
this._onRemove(file, file, type);
});
}
return watcher;
}
_fileWatcher(file, watcher) {
if (watcher) {
watcher.on("initial-missing", type => {
this._onRemove(file, file, type);
});
watcher.on("change", (mtime, type) => {

@@ -221,5 +266,11 @@ this._onChange(file, mtime, file, type);

_dirWatcher(item, watcher) {
watcher.on("initial-missing", type => {
this._onRemove(item, item, type);
});
watcher.on("change", (file, mtime, type) => {
this._onChange(item, mtime, file, type);
});
watcher.on("remove", type => {
this._onRemove(item, item, type);
});
return watcher;

@@ -233,2 +284,3 @@ }

if (this.aggregateTimeout) clearTimeout(this.aggregateTimeout);
this.aggregatedRemovals.delete(item);
this.aggregatedChanges.add(item);

@@ -241,7 +293,8 @@ this.aggregateTimeout = setTimeout(

_onRemove(item, file) {
_onRemove(item, file, type) {
file = file || item;
if (this.paused) return;
this.emit("remove", item);
this.emit("remove", file, type);
if (this.aggregateTimeout) clearTimeout(this.aggregateTimeout);
this.aggregatedChanges.delete(item);
this.aggregatedRemovals.add(item);

@@ -248,0 +301,0 @@ this.aggregateTimeout = setTimeout(

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

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

@@ -54,13 +54,38 @@ # watchpack

// Watchpack.prototype.watch(files: Iterable<string>, directories: Iterable<string>, startTime?: number)
wp.watch(listOfFiles, listOfDirectories, Date.now() - 10000);
// Watchpack.prototype.watch({
// files: Iterable<string>,
// directories: Iterable<string>,
// missing: Iterable<string>,
// startTime?: number
// })
wp.watch({
files: listOfFiles,
directories: listOfDirectories,
missing: listOfNotExistingItems,
startTime: Date.now() - 10000
});
// starts watching these files and directories
// calling this again will override the files and directories
// files: can be files or directories, for files: content and existance changes are tracked
// for directories: only existance and timestamp changes are tracked
// directories: only directories, directory content (and content of children, ...) and
// existance changes are tracked.
// assumed to exist, when directory is not found without futher information a remove event is emitted
// missing: can be files or directores,
// only existance changes are tracked
// expected to not exist, no remove event is emitted when not found initially
// files and directories are assumed to exist, when they are not found without futher information a remove event is emitted
// missing is assumed to not exist and no remove event is emitted
wp.on("change", function(filePath, mtime) {
wp.on("change", function(filePath, mtime, explanation) {
// filePath: the changed file
// mtime: last modified time for the changed file (null if file was removed)
// for folders it's a time before that all changes in the directory happened
// mtime: last modified time for the changed file
// explanation: textual information how this change was detected
});
wp.on("remove", function(filePath, explanation) {
// filePath: the removed file or directory
// explanation: textual information how this change was detected
});
wp.on("aggregated", function(changes, removals) {

@@ -67,0 +92,0 @@ // changes: a Set of all changed files

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc