Skip to content

svelte-check's --watch mode incorrectly ignores directories because of regression from #2807 #2855

@abrahamguo

Description

@abrahamguo

Describe the bug

in #2807 (@jasonlyu123) (specifically, in refactor(check): clarify snapshot callback and simplify directory watching; ignore .crush), @aewing introduced a regression that can cause svelte-check's watch mode to inadvertently ignore directories.

In that commit, this code was added:

        // If new dir is a parent of existing ones, unwatch children
        const toRemove: string[] = [];
        for (const existing of this.currentWatchedDirs) {
            if (this.isSubdir(existing, dir)) {
                toRemove.push(existing);
            }
        }
        if (toRemove.length) {
            this.watcher.unwatch(toRemove);

this.watcher refers to a chokidar watcher instance.

It's not explicitly documented in Chokidar's documentation, but unwatching a child absolute path, followed by adding a parent absolute path, causes the child paths to remain ignored.

Reproduction

import { watch } from 'chokidar';

const { dirname } = import.meta;
const a = `${dirname}/a`;
const b = `${a}/b`;
watch(b).unwatch(b).add(a).on(`change`, () => console.log(`change!`));

Note that the change handler runs for everything in the a directory, except for changes that happen in the b subdirectory.

Expected behaviour

svelte-check should properly handle parent and child directories when passing to chokidar.

System Info

  • OS: macOS

Which package is the issue about?

svelte-check

Additional Information, eg. Screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions