Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chokidar 3.1.1 no longer react to file changes #888

Closed
ryanelian opened this issue Sep 20, 2019 · 14 comments
Closed

Chokidar 3.1.1 no longer react to file changes #888

ryanelian opened this issue Sep 20, 2019 · 14 comments
Labels

Comments

@ryanelian
Copy link

ryanelian commented Sep 20, 2019

Describe the bug
I am using code like this:

        watch(this.finder.scssGlob, {
            ignoreInitial: true
        })
            .on('add', file => {
                file = upath.toUnix(file);
                Shout.sass(chalk.grey('tracking new file:', file));
                debounce();
            })
            .on('change', file => {
                file = upath.toUnix(file);
                Shout.sass(chalk.grey('updating file:', file));
                debounce();
            })
            .on('unlink', file => {
                file = upath.toUnix(file);
                Shout.sass(chalk.grey('removing file:', file));
                debounce();
            });
        watch(this.sourceStore.typeCheckGlobs, {
            ignoreInitial: true
        })
            .on('add', (file: string) => {
                this.sourceStore.loadFile(file).then(changed => {
                    Shout.typescript(chalk.grey('tracking new file:', file));
                    debounce();
                });
            })
            .on('change', (file: string) => {
                this.sourceStore.loadFile(file).then(changed => {
                    if (changed) {
                        Shout.typescript(chalk.grey('updating file:', file));
                        debounce();
                    }
                });
            })
            .on('unlink', (file: string) => {
                let deleted = this.sourceStore.removeFile(file);
                if (deleted) {
                    Shout.typescript(chalk.grey('removing file:', file));
                    debounce();
                }
            });

The glob pattern is something like this:

    /**
     * /project/client/css/\*\*\/*.scss
     */
    get scssGlob(): string {
        return upath.join(this.cssInputFolder, '**', '*.scss');
    }
    get typeCheckGlobs() {
        return this._typeCheckGlobs;
    }

        let tsGlobs = upath.join(folder, '**', '*.ts');
        let tsxGlobs = upath.join(folder, '**', '*.tsx');
        let vueGlobs = upath.join(folder, '**', '*.vue');

The chokidar event no longer fires. Version 3.0.2 works just fine.

Versions (please complete the following information):

  • Chokidar version 3.1.1
  • Node version 12.9.1
  • OS version: Windows 10 1903 Build 18362.365

To Reproduce

Use something like above code / glob to detect file changes.

Expected behavior

File change triggers.

Additional context

EDIT: off-topic, just realized this issue number is 888. lucky? 😄

ryanelian added a commit to ryanelian/instapack that referenced this issue Sep 20, 2019
@paulmillr
Copy link
Owner

Please try it with chokidar 3.1.0, not 3.1.1.

@ryanelian
Copy link
Author

Just now, confirmed that 3.1.0 work:

image

But 3.1.1 does not... (Also re-checked just now)

image

@paulmillr
Copy link
Owner

I think you're using wrong globs or something like that. We've changed path handling in 3.1.1. Will investigate.

@ryanelian
Copy link
Author

ryanelian commented Sep 23, 2019

In all above examples, I am using blob string: C:/something/like/this/**/*.ext (without backslash even on Windows thanks to upath library)

What would be the proper blob string for cases like that then?

@frigus02
Copy link

frigus02 commented Sep 23, 2019

I can reproduce the issue on Windows 10 with Node v12.10.0 with the example.js from the repo. I changed to first line to

global.watcher = require('./').watch('./lib/*.js', {

Then I ran node .\example.js and changed any file in the lib folder. This is the full output (no changes logged):

C:\code\chokidar> node .\example.js
Ready

I played a bit around. The following line changes the paths from [ './lib/*.js' ] to [ 'lib\\*.js' ]:

paths = paths.map(path => sysPath.normalize(path));

I tried changing it to use normalizePathToUnix to instead of sysPath.normalize and ran the example again. This time it seemed to work:

C:\code\chokidar> node .\example.js
add lib\fsevents-handler.js
add lib\nodefs-handler.js
Ready
change lib\nodefs-handler.js

If you think this fix is acceptable, I'm happy to submit a PR for it.

Would be great to have a test for this as well, but I had trouble getting the tests to run properly on Windows. Are there any known issues here?

@frigus02
Copy link

I looked a bit more into this. Using normalizePathToUnix does solve the issue for globs. But it changes the behavior for other tests slightly.

  • Before, when you watch a path like C:\files\todo.txt, chokidar emits change events for C:\files\todo.txt.
  • With normalizePathToUnix, when you watch a path like C:\files\todo.txt, chokidar emits change events for C:/files/todo.txt.

See here, which tests would be affected by the change: master...frigus02:fix-watching-windows. Notice that I also had to normalize paths in unwatch, otherwise paths wouldn't match.

I'm not sure what the best course of action here is. I don't fully understand the issue #871, which was fixed by normalizing paths. Normalizing paths does not fix the "Expected pattern to be a non-empty string" error for me. I can still reproduce that with a path like ./ on both Windows and Linux. I'm however unable to reproduce the issue with a path like ./package.json, even without normalizing paths.

I wonder if the issue #871 has been fixed by something else and we can just revert the change here and not normalize paths. I feel like that's all I can do here. Need @paulmillr's help now 🙂.

@ryanelian
Copy link
Author

ryanelian commented Sep 28, 2019

I just saw the commits, it seems paulmillr has fixed the issue?
048f935

I personally don't mind if the emitted path become UNIX-like on Windows because upath library makes my app path handling behavior consistent without backslashes. I hate hidden surprises when dealing with mixed path. (cough TypeScript compiler service cough).

... But hey, that's just my opinion. 😄

@paulmillr
Copy link
Owner

Not really — Still debugging this shit

countnazgul added a commit to countnazgul/qlBuilder that referenced this issue Sep 30, 2019
* v1.0.0
* refractofing watch mode
* downgrade chokidar version due to paulmillr/chokidar#888
* added option to stop auto error check (the detaulf is ON)
@paulmillr
Copy link
Owner

@ryanelian fixed in master, I think

@paulmillr
Copy link
Owner

Could someone test this?

@ryanelian
Copy link
Author

Sure.

I tried using yarn add https://github.com/paulmillr/chokidar.git in my compiler tool project.

Looks like it's working on Windows. Haven't tested on other platforms.

@paulmillr
Copy link
Owner

@countnazgul how's your project doing?

@XhmikosR
Copy link
Contributor

XhmikosR commented Oct 1, 2019

@paulmillr it seems it's working again.

@countnazgul
Copy link

@paulmillr just tested with v3.2.0 and it seems to work nicely! Thanks for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants