-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Detect files added to/removed from directories. #2615
Detect files added to/removed from directories. #2615
Conversation
@DeMoorJasper @sainthkh what's the state of this PR? If I can jump in and contribute, I will. This fix is extremely important for a tool I'm building with Parcel! 👍 |
@chrisdmacrae tests are failing so it won't get merged untill that's fixed. There was a similar PR to this here: #2211 that had every test passing, so might be an inspiration for improving this. But I think it's just a simple timeout in the tests |
No one reviewed code. So I simply abandoned it and wait for opinions. I guessed that the parcel team is too busy to check this PR. |
When they show interest, I'm ready to fix the tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the failing tests
I used old Now, that the most of the code inside EDIT: We're all green again! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you expand this to also add watch support for glob imports?
@DeMoorJasper You mean things like |
@sainthkh yes |
Before we make glob require/import, we should decide how parcel should behave in some situations. TL;DR; Isn't glob watching in 1. Duplicate names.Let's think about this file tree and codes.
// a.js
exports.add = function (a, b) {
return a + b;
} // b.js
exports.add = function (a, b, c) {
return a + b + c;
} // c.js
var { add } = require('./*.js'); // or
import { add } from './*.js';
// ... code that uses add function. In 2. Cannot get Visual Studio Code syntax assist.Glob file names like We may need to write some code for VS Code plugin for this. 3. It's an error in TypeScript.When we write code like below: VS Code will show us a red line below import { Local } from './*.ts';
export function count() {
let local = new Local(1, 2);
return local.a + local.b;
} Because compiler cannot find './*.ts' file. The only solution is to turn off VS Code typescript plugin. That's too much. 4. Cyclic dependency.Let's think about this simple file tree.
// a.js
var { f } = require('./*.js');
exports.g = function() {
f();
console.log("do something");
} // b.js
var { g } = require('./*.js');
exports.g = function() {
g();
console.log("do something");
} In this case, it's obvious. But when we have dozens of files and we aren't careful, we may meet this problem often. 5. What should we do when a glob is removed?Let's say a user removed We might need to create a hash table of files that have glob imports and check these globs are safely there and when the contents of those files are changed. And some globs are removed, we need to loop through all the files related with this glob and remove them from chokidar. The things will become more complicated when a file that imports a glob imports a file or files that import another glob or globs. If we don't handle them carefully, then parcel will create weird bundle. Conclusion: Do we really need it?I made this feature because we sometimes need to compile some files when it is not For example:
We can solve these problems by starting parcel like And I guess that the With these reasons, I think adding glob watching is more harmful than useful. Or am I missing some crucial use cases? I want your opinions. |
Then, we can say that this PR is done. Right? |
↪️ Pull Request
Currently, when you start parcel with glob like
./src/*
, parcel watches every change insrc
directory. But when we add a new file likegood-button.scss
tosrc
directory, parcel cannot detect it.To do that, we need to restart parcel manually. This PR fixes that problem.
It closes old issues like #667, #2211.
💻 Examples
./src/*
, or./src/*.js
🚨 Test instructions
There are 4 test cases.
✔️ PR Todo