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

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

Open
bartvandenende-wm opened this issue Dec 19, 2023 · 3 comments

Comments

@bartvandenende-wm
Copy link

bartvandenende-wm commented Dec 19, 2023

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

@bartvandenende-wm
Copy link
Author

find a sample project to demonstrate the issue below:
https://github.com/bartvandenende-wm/watchpack-directory-symlink-issue

@bartvandenende-wm bartvandenende-wm changed the title Watchpack does not monitor files within a symlink folder Watchpack exposes resolved symlink paths on ignored option Dec 19, 2023
@bartvandenende-wm bartvandenende-wm changed the title Watchpack exposes resolved symlink paths on ignored option Add support for tracking non-resolved symlink paths Dec 19, 2023
@bartvandenende-wm bartvandenende-wm changed the title Add support for tracking non-resolved symlink paths Add support for watching symlinks that resolve to paths outside the watch folder Dec 19, 2023
@bartvandenende-wm
Copy link
Author

Related issue #190 (comment)

@alexander-akait
Copy link
Member

@bartvandenende-wm Sounds good for me, do you want to send a PR?

ArjhanToteck added a commit to ArjhanToteck/watchpack that referenced this issue Mar 7, 2024
Solves webpack#231 and updates the README to match.
ArjhanToteck added a commit to ArjhanToteck/watchpack that referenced this issue Mar 8, 2024
Solves webpack#231 and updates the README to match.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants