Comparing version 3.2.2 to 3.2.3
69
index.js
'use strict'; | ||
const { EventEmitter } = require('events'); | ||
const fs = require('fs'); | ||
const sysPath = require('path'); | ||
const { promisify } = require('util'); | ||
const readdirp = require('readdirp'); | ||
@@ -11,3 +13,2 @@ const anymatch = require('anymatch').default; | ||
const normalizePath = require('normalize-path'); | ||
const { promisify } = require('util'); | ||
@@ -92,5 +93,5 @@ const NodeFsHandler = require('./lib/nodefs-handler'); | ||
*/ | ||
let paths = flatten(arrify(paths_)); | ||
const paths = flatten(arrify(paths_)); | ||
if (!paths.every(p => typeof p === STRING_TYPE)) { | ||
throw new TypeError('Non-string provided as watch path: ' + paths); | ||
throw new TypeError(`Non-string provided as watch path: ${paths}`); | ||
} | ||
@@ -120,7 +121,7 @@ return paths.map(normalizePathToUnix); | ||
return path; | ||
} else if (path[0] === BANG) { | ||
} | ||
if (path[0] === BANG) { | ||
return BANG + sysPath.join(cwd, path.substring(1)); | ||
} else { | ||
return sysPath.join(cwd, path); | ||
} | ||
return sysPath.join(cwd, path); | ||
}; | ||
@@ -180,3 +181,3 @@ | ||
if (!items) return; | ||
return Array.from(items.values()); | ||
return [...items.values()]; | ||
} | ||
@@ -303,3 +304,2 @@ | ||
// Set up default options. | ||
@@ -343,3 +343,3 @@ if (undef(opts, 'persistent')) opts.persistent = true; | ||
if (envInterval) { | ||
opts.interval = parseInt(envInterval); | ||
opts.interval = Number.parseInt(envInterval, 10); | ||
} | ||
@@ -408,5 +408,4 @@ | ||
return absPath; | ||
} else { | ||
return normalizePath(absPath); | ||
} | ||
return normalizePath(absPath); | ||
}); | ||
@@ -420,13 +419,13 @@ } | ||
return false; | ||
} else { | ||
// if a path is being added that was previously ignored, stop ignoring it | ||
this._ignoredPaths.delete(path); | ||
this._ignoredPaths.delete(path + SLASH_GLOBSTAR); | ||
} | ||
// reset the cached userIgnored anymatch fn | ||
// to make ignoredPaths changes effective | ||
this._userIgnored = undefined; | ||
// if a path is being added that was previously ignored, stop ignoring it | ||
this._ignoredPaths.delete(path); | ||
this._ignoredPaths.delete(path + SLASH_GLOBSTAR); | ||
return true; | ||
} | ||
// reset the cached userIgnored anymatch fn | ||
// to make ignoredPaths changes effective | ||
this._userIgnored = undefined; | ||
return true; | ||
}); | ||
@@ -465,4 +464,4 @@ | ||
if (this.closed) return this; | ||
let paths = unifyPaths(paths_); | ||
const cwd = this.options.cwd; | ||
const paths = unifyPaths(paths_); | ||
const {cwd} = this.options; | ||
@@ -508,3 +507,3 @@ paths.forEach((path) => { | ||
['closers', 'watched', 'streams', 'symlinkPaths', 'throttled'].forEach(key => { | ||
this['_' + key].clear(); | ||
this[`_${key}`].clear(); | ||
}); | ||
@@ -573,5 +572,6 @@ return this; | ||
}); | ||
}, typeof opts.atomic === "number" ? opts.atomic : 100); | ||
}, typeof opts.atomic === 'number' ? opts.atomic : 100); | ||
return this; | ||
} else if (event === EV_ADD && this._pendingUnlinks.has(path)) { | ||
} | ||
if (event === EV_ADD && this._pendingUnlinks.has(path)) { | ||
event = args[0] = EV_CHANGE; | ||
@@ -673,3 +673,3 @@ this._pendingUnlinks.delete(path); | ||
timeoutObject = setTimeout(clear, timeout); | ||
const thr = {timeoutObject: timeoutObject, clear: clear, count: 0}; | ||
const thr = {timeoutObject, clear, count: 0}; | ||
action.set(path, thr); | ||
@@ -710,3 +710,3 @@ return thr; | ||
if (prevStat && curStat.size != prevStat.size) { | ||
if (prevStat && curStat.size !== prevStat.size) { | ||
this._pendingWrites.get(path).lastChange = now; | ||
@@ -747,3 +747,3 @@ } | ||
_getGlobIgnored() { | ||
return Array.from(this._ignoredPaths.values()); | ||
return [...this._ignoredPaths.values()]; | ||
} | ||
@@ -760,3 +760,3 @@ | ||
if (!this._userIgnored) { | ||
const cwd = this.options.cwd; | ||
const {cwd} = this.options; | ||
const ign = this.options.ignored; | ||
@@ -812,3 +812,3 @@ | ||
* Check for read permissions. | ||
* Based on this answer on SO: http://stackoverflow.com/a/11781404/1358405 | ||
* Based on this answer on SO: https://stackoverflow.com/a/11781404/1358405 | ||
* @param {fs.Stats} stats - object, result of fs_stat | ||
@@ -821,5 +821,5 @@ * @returns {Boolean} indicates whether the file can be read | ||
// stats.mode may be bigint | ||
const md = stats && Number.parseInt(stats.mode); | ||
const md = stats && Number.parseInt(stats.mode, 10); | ||
const st = md & 0o777; | ||
const it = parseInt(st.toString(8)[0], 10); | ||
const it = Number.parseInt(st.toString(8)[0], 10); | ||
return Boolean(4 & it); | ||
@@ -892,7 +892,6 @@ } | ||
_closePath(path) { | ||
let closers = this._closers.get(path); | ||
const closers = this._closers.get(path); | ||
if (!closers) return; | ||
closers.forEach(closer => closer()); | ||
this._closers.delete(path); | ||
closers = []; | ||
const dir = sysPath.dirname(path); | ||
@@ -919,3 +918,3 @@ this._getWatchedDir(dir).remove(sysPath.basename(path)); | ||
if (this.closed) return; | ||
const options = Object.assign({type: EV_ALL, alwaysStat: true, lstat: true}, opts); | ||
const options = {type: EV_ALL, alwaysStat: true, lstat: true, ...opts}; | ||
let stream = readdirp(root, options); | ||
@@ -922,0 +921,0 @@ this._streams.add(stream); |
@@ -0,2 +1,5 @@ | ||
'use strict'; | ||
const {sep} = require('path'); | ||
const {platform} = process; | ||
@@ -31,9 +34,9 @@ exports.EV_ALL = 'all'; | ||
exports.DOT_SLASH = '.' + sep; | ||
exports.DOT_SLASH = `.${sep}`; | ||
exports.BACK_SLASH_RE = /\\/g; | ||
exports.DOUBLE_SLASH_RE = /\/\//; | ||
exports.SLASH_OR_BACK_SLASH_RE = /[\/\\]/; | ||
exports.DOT_RE = /\..*\.(sw[px])$|\~$|\.subl.*\.tmp/; | ||
exports.REPLACER_RE = /^\.[\/\\]/; | ||
exports.SLASH_OR_BACK_SLASH_RE = /[/\\]/; | ||
exports.DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/; | ||
exports.REPLACER_RE = /^\.[/\\]/; | ||
@@ -45,5 +48,6 @@ exports.SLASH = '/'; | ||
exports.TWO_DOTS = '..'; | ||
exports.STAR = '*'; | ||
exports.GLOBSTAR = '**'; | ||
exports.ROOT_GLOBSTAR = '/**/*'; | ||
exports.SLASH_GLOBSTAR = '/**'; | ||
exports.GLOBSTAR = '**'; | ||
exports.DIR_SUFFIX = 'Dir'; | ||
@@ -55,6 +59,5 @@ exports.ANYMATCH_OPTS = {dot: true}; | ||
exports.EMPTY_FN = () => {}; | ||
exports.IDENTITY_FN = (val => val); | ||
exports.IDENTITY_FN = val => val; | ||
const {platform} = process; | ||
exports.isWindows = platform === 'win32'; | ||
exports.isMacos = platform === 'darwin'; |
@@ -14,6 +14,6 @@ 'use strict'; | ||
// TODO: real check | ||
let mtch = process.version.match(/v(\d+)\.(\d+)/); | ||
const mtch = process.version.match(/v(\d+)\.(\d+)/); | ||
if (mtch && mtch[1] && mtch[2]) { | ||
let maj = Number.parseInt(mtch[1]); | ||
let min = Number.parseInt(mtch[2]); | ||
const maj = Number.parseInt(mtch[1], 10); | ||
const min = Number.parseInt(mtch[2], 10); | ||
if (maj === 8 && min < 16) { | ||
@@ -148,3 +148,3 @@ fsevents = undefined; | ||
listeners: new Set([filteredListener]), | ||
rawEmitter: rawEmitter, | ||
rawEmitter, | ||
watcher: createFSEventsInstance(watchPath, (fullPath, flags) => { | ||
@@ -223,6 +223,6 @@ if (fsw.closed) return; | ||
return true; | ||
} else { | ||
ipaths.delete(path); | ||
ipaths.delete(path + ROOT_GLOBSTAR); | ||
} | ||
ipaths.delete(path); | ||
ipaths.delete(path + ROOT_GLOBSTAR); | ||
} | ||
@@ -269,7 +269,7 @@ | ||
return this._addToFsEvents(path, false, true, curDepth); | ||
} else { | ||
// track new paths | ||
// (other than symlinks being followed, which will be tracked soon) | ||
this.fsw._getWatchedDir(parent).add(item); | ||
} | ||
// track new paths | ||
// (other than symlinks being followed, which will be tracked soon) | ||
this.fsw._getWatchedDir(parent).add(item); | ||
} | ||
@@ -473,3 +473,3 @@ /** | ||
const joinedPath = sysPath.join(wh.watchPath, entry.path); | ||
const fullPath = entry.fullPath; | ||
const {fullPath} = entry; | ||
@@ -476,0 +476,0 @@ if (wh.followSymlinks && entry.stats.isSymbolicLink()) { |
@@ -5,4 +5,4 @@ 'use strict'; | ||
const sysPath = require('path'); | ||
const { promisify } = require('util'); | ||
const isBinaryPath = require('is-binary-path'); | ||
const { promisify } = require('util'); | ||
const { | ||
@@ -21,3 +21,5 @@ isWindows, | ||
STR_DATA, | ||
STR_END | ||
STR_END, | ||
BRACE_START, | ||
STAR | ||
} = require('./constants'); | ||
@@ -191,3 +193,3 @@ | ||
rawEmitters: rawEmitter, | ||
watcher: watcher | ||
watcher | ||
}; | ||
@@ -233,5 +235,6 @@ FsWatchInstances.set(fullPath, cont); | ||
const setFsWatchFileListener = (path, fullPath, options, handlers) => { | ||
const listener = handlers.listener; | ||
const rawEmitter = handlers.rawEmitter; | ||
const {listener, rawEmitter} = handlers; | ||
let cont = FsWatchFileInstances.get(fullPath); | ||
/* eslint-disable no-unused-vars, prefer-destructuring */ | ||
let listeners = new Set(); | ||
@@ -252,2 +255,4 @@ let rawEmitters = new Set(); | ||
/* eslint-enable no-unused-vars, prefer-destructuring */ | ||
if (cont) { | ||
@@ -263,3 +268,3 @@ addAndConvert(cont, KEY_LISTENERS, listener); | ||
rawEmitters: rawEmitter, | ||
options: options, | ||
options, | ||
watcher: fs.watchFile(fullPath, options, (curr, prev) => { | ||
@@ -327,3 +332,3 @@ foreach(cont.rawEmitters, (rawEmitter) => { | ||
closer = setFsWatchFileListener(path, absolutePath, options, { | ||
listener: listener, | ||
listener, | ||
rawEmitter: this.fsw._emitRaw | ||
@@ -333,3 +338,3 @@ }); | ||
closer = setFsWatchListener(path, absolutePath, options, { | ||
listener: listener, | ||
listener, | ||
errHandler: this._boundHandleError, | ||
@@ -365,3 +370,3 @@ rawEmitter: this.fsw._emitRaw | ||
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return; | ||
if (!newStats || newStats && newStats.mtimeMs === 0) { | ||
if (!newStats || newStats.mtimeMs === 0) { | ||
try { | ||
@@ -439,5 +444,5 @@ const newStats = await stat(file); | ||
return true; | ||
} else { | ||
this.fsw._symlinkPaths.set(full, true); | ||
} | ||
this.fsw._symlinkPaths.set(full, true); | ||
} | ||
@@ -450,4 +455,4 @@ | ||
if (!wh.hasGlob) { | ||
// throttler = this.fsw._throttle('readdir', directory, 1000); | ||
// if (!throttler) return; | ||
throttler = this.fsw._throttle('readdir', directory, 1000); | ||
if (!throttler) return; | ||
} | ||
@@ -461,3 +466,3 @@ | ||
directoryFilter: entry => wh.filterDir(entry), | ||
depth: 0, | ||
depth: 0 | ||
}).on(STR_DATA, async (entry) => { | ||
@@ -533,3 +538,3 @@ if (this.fsw.closed) { | ||
* @param {Number} depth relative to user-supplied path | ||
* @param {String} target child path targetted for watch | ||
* @param {String} target child path targeted for watch | ||
* @param {Object} wh Common watch helpers for this path | ||
@@ -550,4 +555,2 @@ * @param {String} realpath | ||
let throttler; | ||
let closer; | ||
@@ -578,3 +581,3 @@ | ||
* @param {Object} priorWh depth relative to user-supplied path | ||
* @param {Number} depth Child path actually targetted for watch | ||
* @param {Number} depth Child path actually targeted for watch | ||
* @param {String=} target Child path actually targeted for watch | ||
@@ -590,3 +593,3 @@ * @returns {Promise} | ||
let wh = this.fsw._getWatchHelpers(path, depth); | ||
const wh = this.fsw._getWatchHelpers(path, depth); | ||
if (!wh.hasGlob && priorWh) { | ||
@@ -608,3 +611,3 @@ wh.hasGlob = priorWh.hasGlob; | ||
const follow = this.fsw.options.followSymlinks && !path.includes("*") && !path.includes("{"); | ||
const follow = this.fsw.options.followSymlinks && !path.includes(STAR) && !path.includes(BRACE_START); | ||
let closer; | ||
@@ -611,0 +614,0 @@ if (stats.isDirectory()) { |
{ | ||
"name": "chokidar", | ||
"description": "A neat wrapper around node.js fs.watch / fs.watchFile / fsevents.", | ||
"version": "3.2.2", | ||
"version": "3.2.3", | ||
"homepage": "https://github.com/paulmillr/chokidar", | ||
@@ -12,4 +12,5 @@ "author": "Paul Miller (https://paulmillr.com)", | ||
"engines": { | ||
"node": ">= 8" | ||
"node": ">= 8.10.0" | ||
}, | ||
"main": "index.js", | ||
"dependencies": { | ||
@@ -30,15 +31,14 @@ "anymatch": "~3.1.1", | ||
"chai": "^4.2", | ||
"coveralls": "^3", | ||
"dtslint": "0.4.1", | ||
"jshint": "^2.10.1", | ||
"mocha": "^6.1.3", | ||
"nyc": "^14.0.0", | ||
"rimraf": "^2.6.3", | ||
"sinon": "^7.3.1", | ||
"dtslint": "0.9.9", | ||
"eslint": "^6.6.0", | ||
"mocha": "^6.2.2", | ||
"nyc": "^14.1.1", | ||
"rimraf": "^3.0.0", | ||
"sinon": "^7.5.0", | ||
"sinon-chai": "^3.3.0", | ||
"upath": "^1.1.2" | ||
"upath": "^1.2.0" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"lib/", | ||
"lib/*.js", | ||
"types/index.d.ts" | ||
@@ -48,3 +48,3 @@ ], | ||
"type": "git", | ||
"url": "https://github.com/paulmillr/chokidar.git" | ||
"url": "git+https://github.com/paulmillr/chokidar.git" | ||
}, | ||
@@ -56,7 +56,6 @@ "bugs": { | ||
"scripts": { | ||
"test": "nyc mocha --exit", | ||
"mocha": "mocha", | ||
"lint": "jshint index.js lib", | ||
"coveralls": "nyc report --reporter=text-lcov | coveralls", | ||
"dtslint": "dtslint types" | ||
"dtslint": "dtslint types", | ||
"lint": "eslint --report-unused-disable-directives --ignore-path .gitignore .", | ||
"mocha": "mocha --exit", | ||
"test": "npm run lint && npm run mocha" | ||
}, | ||
@@ -73,13 +72,61 @@ "keywords": [ | ||
"types": "./types/index.d.ts", | ||
"jshintConfig": { | ||
"node": true, | ||
"curly": false, | ||
"bitwise": false, | ||
"mocha": true, | ||
"expr": true, | ||
"esversion": 9, | ||
"predef": [ | ||
"toString" | ||
"eslintConfig": { | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 9, | ||
"sourceType": "script" | ||
}, | ||
"env": { | ||
"node": true, | ||
"es6": true | ||
}, | ||
"rules": { | ||
"array-callback-return": "error", | ||
"no-empty": [ | ||
"error", | ||
{ | ||
"allowEmptyCatch": true | ||
} | ||
], | ||
"object-shorthand": "error", | ||
"prefer-arrow-callback": [ | ||
"error", | ||
{ | ||
"allowNamedFunctions": true | ||
} | ||
], | ||
"prefer-const": [ | ||
"error", | ||
{ | ||
"ignoreReadBeforeAssign": true | ||
} | ||
], | ||
"prefer-destructuring": [ | ||
"error", | ||
{ | ||
"object": true, | ||
"array": false | ||
} | ||
], | ||
"prefer-spread": "error", | ||
"prefer-template": "error", | ||
"radix": "error", | ||
"strict": "error", | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"no-var": "error" | ||
} | ||
}, | ||
"nyc": { | ||
"include": [ | ||
"index.js", | ||
"lib/*.js" | ||
], | ||
"reporter": [ | ||
"html", | ||
"text" | ||
] | ||
} | ||
} |
# Chokidar [![Weekly downloads](https://img.shields.io/npm/dw/chokidar.svg)](https://github.com/paulmillr/chokidar) [![Yearly downloads](https://img.shields.io/npm/dy/chokidar.svg)](https://github.com/paulmillr/chokidar) | ||
> A neat wrapper around node.js fs.watch / fs.watchFile / FSEvents. | ||
> A neat wrapper around Node.js fs.watch / fs.watchFile / FSEvents. | ||
@@ -10,2 +10,3 @@ [![NPM](https://nodei.co/npm/chokidar.png)](https://www.npmjs.com/package/chokidar) | ||
## Why? | ||
Node.js `fs.watch`: | ||
@@ -27,14 +28,15 @@ | ||
Initially made for **[Brunch](http://brunch.io)** (an ultra-swift web app build tool), it is now used in | ||
Initially made for **[Brunch](https://brunch.io/)** (an ultra-swift web app build tool), it is now used in | ||
[Microsoft's Visual Studio Code](https://github.com/microsoft/vscode), | ||
[gulp](https://github.com/gulpjs/gulp/), | ||
[karma](http://karma-runner.github.io), | ||
[karma](https://karma-runner.github.io/), | ||
[PM2](https://github.com/Unitech/PM2), | ||
[browserify](http://browserify.org/), | ||
[webpack](http://webpack.github.io/), | ||
[BrowserSync](http://www.browsersync.io/), | ||
and [many others](https://www.npmjs.org/browse/depended/chokidar/). | ||
[webpack](https://webpack.github.io/), | ||
[BrowserSync](https://www.browsersync.io/), | ||
and [many others](https://www.npmjs.com/browse/depended/chokidar). | ||
It has proven itself in production environments. | ||
## How? | ||
Chokidar does still rely on the Node.js core `fs` module, but when using | ||
@@ -56,2 +58,3 @@ `fs.watch` and `fs.watchFile` for watching, it normalizes the events it | ||
## Getting started | ||
Install with npm: | ||
@@ -104,3 +107,3 @@ | ||
// 'add', 'addDir' and 'change' events also receive stat() results as second | ||
// argument when available: http://nodejs.org/api/fs.html#fs_class_fs_stats | ||
// argument when available: https://nodejs.org/api/fs.html#fs_class_fs_stats | ||
watcher.on('change', (path, stats) => { | ||
@@ -175,3 +178,3 @@ if (stats) console.log(`File ${path} changed size to ${stats.size}`); | ||
time with two arguments (the path and the | ||
[`fs.Stats`](http://nodejs.org/api/fs.html#fs_class_fs_stats) | ||
[`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) | ||
object of that path). | ||
@@ -209,3 +212,3 @@ * `ignoreInitial` (default: `false`). If set to `false` then `add`/`addDir` events are also emitted for matching paths while | ||
* `alwaysStat` (default: `false`). If relying upon the | ||
[`fs.Stats`](http://nodejs.org/api/fs.html#fs_class_fs_stats) | ||
[`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) | ||
object that may get passed with `add`, `addDir`, and `change` events, set | ||
@@ -235,2 +238,3 @@ this to `true` to ensure it is provided even in cases where it wasn't | ||
#### Errors | ||
* `ignorePermissionErrors` (default: `false`). Indicates whether to watch files | ||
@@ -301,2 +305,2 @@ that don't have read permissions if possible. If watching fails due to `EPERM` | ||
MIT (c) Paul Miller (https://paulmillr.com), see LICENSE file. | ||
MIT (c) Paul Miller <https://paulmillr.com>, see LICENSE file. |
@@ -48,3 +48,3 @@ // TypeScript Version: 3.0 | ||
/** | ||
* Error occured | ||
* Error occurred | ||
*/ | ||
@@ -77,7 +77,7 @@ on(event: 'error', listener: (error: Error) => void): this; | ||
/** | ||
* ([anymatch](https://github.com/es128/anymatch)-compatible definition) Defines files/paths to | ||
* ([anymatch](https://github.com/micromatch/anymatch)-compatible definition) Defines files/paths to | ||
* be ignored. The whole relative or absolute path is tested, not just filename. If a function | ||
* with two arguments is provided, it gets called twice per path - once with a single argument | ||
* (the path), second time with two arguments (the path and the | ||
* [`fs.Stats`](http://nodejs.org/api/fs.html#fs_class_fs_stats) object of that path). | ||
* [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object of that path). | ||
*/ | ||
@@ -127,3 +127,3 @@ ignored?: any; | ||
/** | ||
* If relying upon the [`fs.Stats`](http://nodejs.org/api/fs.html#fs_class_fs_stats) object that | ||
* If relying upon the [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object that | ||
* may get passed with `add`, `addDir`, and `change` events, set this to `true` to ensure it is | ||
@@ -130,0 +130,0 @@ * provided even in cases where it wasn't already available from the underlying watch events. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87585
10
299
2