Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: paulmillr/chokidar
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.4.3
Choose a base ref
...
head repository: paulmillr/chokidar
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3.5.0
Choose a head ref
  • 9 commits
  • 7 files changed
  • 4 contributors

Commits on Nov 3, 2020

  1. Update fsevents to ~2.2.0

    pipobscure committed Nov 3, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e82a305 View commit details
  2. Merge pull request #1045 from pipobscure/fseventsupdate

    Update fsevents to ~2.2.0
    paulmillr authored Nov 3, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2ba408b View commit details

Commits on Nov 8, 2020

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    2217b50 View commit details
  2. Merge pull request #1046 from valera-rozuvan/patch-1

    Simplify conditional check
    paulmillr authored Nov 8, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e1753dd View commit details

Commits on Dec 14, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f318bb5 View commit details
  2. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    ebfce1a View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7369c5c View commit details
  4. Merge pull request #1055 from CuddlySheep/bugfix/#1042

    Merge bugfix/#1042 into paulmillr/chokidar:master
    paulmillr authored Dec 14, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0d367dd View commit details

Commits on Jan 6, 2021

  1. Release 3.5.0.

    paulmillr committed Jan 6, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b8b3639 View commit details
Showing with 113 additions and 60 deletions.
  1. +50 −0 .eslintrc
  2. +4 −0 .github/full_changelog.md
  3. +6 −5 README.md
  4. +9 −0 index.js
  5. +1 −2 lib/fsevents-handler.js
  6. +3 −53 package.json
  7. +40 −0 test.js
50 changes: 50 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "script"
},
"env": {
"node": true,
"es6": true
},
"rules": {
"array-callback-return": "error",
"no-empty": [
"error",
{
"allowEmptyCatch": true
}
],
"no-lonely-if": "error",
"no-var": "error",
"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"
]
}
}
4 changes: 4 additions & 0 deletions .github/full_changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Chokidar 3.5.0 (Jan 6, 2021)
- Support for ARM Macs with Apple Silicon.
- Fixed missing removal of symlinks when the target path was deleted (#1042)

### Chokidar 3.4.3 (Oct 13, 2020)
* Circular symlinks that point to some parent directory are no longer watched.
This prevents infinite loops.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# 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.
> Minimal and efficient cross-platform file watching library
[![NPM](https://nodei.co/npm/chokidar.png)](https://www.npmjs.com/package/chokidar)

Version 3 is out! Check out our blog post about it: [Chokidar 3: How to save 32TB of traffic every week](https://paulmillr.com/posts/chokidar-3-save-32tb-of-traffic/)

## Why?

Node.js `fs.watch`:
@@ -35,6 +33,8 @@ Initially made for **[Brunch](https://brunch.io/)** (an ultra-swift web app buil
and [many others](https://www.npmjs.com/browse/depended/chokidar).
It has proven itself in production environments.

Version 3 is out! Check out our blog post about it: [Chokidar 3: How to save 32TB of traffic every week](https://paulmillr.com/posts/chokidar-3-save-32tb-of-traffic/)

## How?

Chokidar does still rely on the Node.js core `fs` module, but when using
@@ -74,7 +74,7 @@ chokidar.watch('.').on('all', (event, path) => {
## API

```javascript
// Example of a more typical implementation structure:
// Example of a more typical implementation structure

// Initialize watcher.
const watcher = chokidar.watch('file, dir, glob, or array', {
@@ -286,7 +286,8 @@ execute a command on each change, or get a stdio stream of change events.
## Changelog

For more detailed changelog, see [`full_changelog.md`](.github/full_changelog.md).
- **v3.4 (Apr 26, 2020):** Support for directory-based symlinks. Macos file replacement fixes.
- **v3.5 (Jan 6, 2021):** Support for ARM Macs with Apple Silicon. Fixes for deleted symlinks.
- **v3.4 (Apr 26, 2020):** Support for directory-based symlinks. Fixes for macos file replacement.
- **v3.3 (Nov 2, 2019):** `FSWatcher#close()` method became async. That fixes IO race conditions related to close method.
- **v3.2 (Oct 1, 2019):** Improve Linux RAM usage by 50%. Race condition fixes. Windows glob fixes. Improve stability by using tight range of dependency versions.
- **v3.1 (Sep 16, 2019):** dotfiles are no longer filtered out by default. Use `ignored` option if needed. Improve initial Linux scan time by 50%.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -864,6 +864,15 @@ _remove(directory, item, isDirectory) {
const wasTracked = parent.has(item);
parent.remove(item);

// Fixes issue #1042 -> Relative paths were detected and added as symlinks
// (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
// but never removed from the map in case the path was deleted.
// This leads to an incorrect state if the path was recreated:
// https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
if (this._symlinkPaths.has(fullPath)) {
this._symlinkPaths.delete(fullPath);
}

// If we wait for this file to be fully written, cancel the wait.
let relPath = path;
if (this.options.cwd) relPath = sysPath.relative(this.options.cwd, path);
3 changes: 1 addition & 2 deletions lib/fsevents-handler.js
Original file line number Diff line number Diff line change
@@ -299,8 +299,7 @@ handleEvent(event, path, fullPath, realPath, parent, watchedDir, item, info, opt
* @returns {Function} closer for the watcher instance
*/
_watchWithFsEvents(watchPath, realPath, transform, globFilter) {
if (this.fsw.closed) return;
if (this.fsw._isIgnored(watchPath)) return;
if (this.fsw.closed || this.fsw._isIgnored(watchPath)) return;
const opts = this.fsw.options;
const watchCallback = async (fullPath, flags, info) => {
if (this.fsw.closed) return;
56 changes: 3 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chokidar",
"description": "A neat wrapper around node.js fs.watch / fs.watchFile / fsevents.",
"version": "3.4.3",
"description": "Minimal and efficient cross-platform file watching library",
"version": "3.5.0",
"homepage": "https://github.com/paulmillr/chokidar",
"author": "Paul Miller (https://paulmillr.com)",
"contributors": [
@@ -22,7 +22,7 @@
"readdirp": "~3.5.0"
},
"optionalDependencies": {
"fsevents": "~2.1.2"
"fsevents": "~2.3.1"
},
"devDependencies": {
"@types/node": "^14",
@@ -65,56 +65,6 @@
"fsevents"
],
"types": "./types/index.d.ts",
"eslintConfig": {
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "script"
},
"env": {
"node": true,
"es6": true
},
"rules": {
"array-callback-return": "error",
"no-empty": [
"error",
{
"allowEmptyCatch": true
}
],
"no-lonely-if": "error",
"no-var": "error",
"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"
]
}
},
"nyc": {
"include": [
"index.js",
40 changes: 40 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -2102,6 +2102,46 @@ const runTests = (baseopts) => {
});
}
});
describe('reproduction of bug in issue #1024', () => {
it('should detect changes to folders, even if they were deleted before', async () => {
const id = subdirId.toString();
const relativeWatcherDir = sysPath.join(FIXTURES_PATH_REL, id, 'test');
const watcher = chokidar.watch(relativeWatcherDir, {
persistent: true,
});
try {
const events = [];
watcher.on('all', (event, path) =>
events.push(`[ALL] ${event}: ${path}`)
);
const testSubDir = sysPath.join(relativeWatcherDir, 'dir');
const testSubDirFile = sysPath.join(relativeWatcherDir, 'dir', 'file');

// Command sequence from https://github.com/paulmillr/chokidar/issues/1042.
await delay();
await fs_mkdir(relativeWatcherDir);
await fs_mkdir(testSubDir);
// The following delay is essential otherwise the call of mkdir and rmdir will be equalize
await delay(300);
await fs_rmdir(testSubDir);
// The following delay is essential otherwise the call of rmdir and mkdir will be equalize
await delay(300);
await fs_mkdir(testSubDir);
await write(testSubDirFile, '');
await delay(300);

chai.assert.deepStrictEqual(events, [
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test')}`,
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test', 'dir')}`,
`[ALL] unlinkDir: ${sysPath.join('test-fixtures', id, 'test', 'dir')}`,
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test', 'dir')}`,
`[ALL] add: ${sysPath.join('test-fixtures', id, 'test', 'dir', 'file')}`,
]);
} finally {
watcher.close();
}
});
});
};

describe('chokidar', () => {