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

Symlink handling is inconsistent #211

Open
charlag opened this issue Sep 7, 2021 · 3 comments
Open

Symlink handling is inconsistent #211

charlag opened this issue Sep 7, 2021 · 3 comments

Comments

@charlag
Copy link
Contributor

charlag commented Sep 7, 2021

When some part of the code is behind a symlink (e.g. file: url in package.json) then compiling this code will resolve module IDs to be real filesystem path.
However when symlink path is passed to invalidate() of the bundle the symlink is not resolved so the file in question will not be invalidated and rebuilding will not work.

Easy fix would be to call fs.realpath() from onAddWatchFile().

@PepsRyuu
Copy link
Owner

PepsRyuu commented Sep 7, 2021

Just so I understand it fully, do you have the steps / code on how to reproduce this? What OS is this running on as well?

@charlag
Copy link
Contributor Author

charlag commented Sep 8, 2021

Hey
It's Linux. I tried to create a reproducer but so far I could not achieve it.
Here's the scenario: in one of our projects we depend on another of our projects. Normally they are linked via package.json and commit hash but when we develop locally we put file:../path/to/project in package.json as a version. This makes npm create a symlink inside node_modules like node_modules/some_project -> ../some_project.
We are setting up a chokidar watcher on that node_modules/some_project. Events which we are getting from chokidar have the symlink in them (so the path in the event is /path/to/another_project/node_modules/some_project/some_file). But nollup has registered some files in NollupContext.files as not having a symlink (as path/to/some_project/some_file) so when we call invalidate on the path with node_modules inside of it nothing happens because it doesn't match what Nollup is tracking internally.

I can't seem to reproduce it because with simple example Nollup still tracks file via the symlink and I don't know how to influence it.
Here's some code where I try to reproduce it (but do not succeed): https://github.com/tutao/nollup-bug/tree/symlink

@PepsRyuu
Copy link
Owner

Does your original code in which you're encountering this problem, resolve the symlink using something like fs.realpath before passing it into invalidate()? Is there potentially a plugin doing some something before calling addWatchFiles?

Question comes down to whether both invalidate() and addWatchFile() should internally resolve the symlink as much as possible using fs.realpath. I don't think it will cause issues. Would be good if you can confirm if the above is what is happening in your code before proceeding to any fix.

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