Skip to content

Add support for watching symlinks that resolve to paths outside the watch folder #231

@bartvandenende-wm

Description

@bartvandenende-wm

Feature request

Watchpack followSymlinks option always resolves the directory / file paths to final link target. This can create unwanted side-effects if the target is outside of the watched directory and/or if ignored filters.

It would be great to have an option that would transparently follow symlinks without resolving to the target path.

What is the expected behavior?

I would expect the below to work:

Example 1
  1. Create a directory structure like below
./ app
    file1.js
./ src 
    file2.js
    app -> ../app
  1. Watch the ./src directory
  2. Trigger changes on both ./src/file2.js and ./src/app/file1.js

Observe that only files in src are monitored, but not files in src/app as Watchpack resolves it to ./app/file1.js.

Changing the watch directory to the project root ./ fixes this, but is not always an option.

Example 2

A similar example can be presented for the ignore filter.

  1. Create a directory structure like below
./ app
    file1.js
./ src 
    file2.js
    app -> ../app
  1. Watch the ./ directory and set an ignore filter to ignore everything except files / folders starting with the path ./src
  2. Trigger changes on both ./src/file2.js and ./src/app/file1.js

Observe that only files in src are monitored, but not files in src/app as the Watchpack 'ignored' filter exposes the pathname as the resolved path of ./app/file1.js instead of ./src/app/file1.js

What is motivation or use case for adding/changing the behavior?

Users should be able to use watchpack with symlinks without having to depend on detailed knownledge of the final symlink resolve path.

How should this be implemented in your opinion?

A potential non-breaking direction is to providing an new option followSymlinksPreservePath that would not use the LinkResolver but instead changes fs.lstat to fs.stat in DirectoryWatcher.js to transparently resolve symlinks and watch nested files without changing the paths:

fs.lstat(filePath, (err, stats) => {

Are you willing to work on this yourself?

yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions