-
Notifications
You must be signed in to change notification settings - Fork 127
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
feat: include only some files #8
base: master
Are you sure you want to change the base?
Conversation
@@ -31,7 +39,7 @@ const watchChanges = (dir, lastTimestamp) => { | |||
|
|||
timestampForFilesInDirectory (dir).then (timestamp => { | |||
|
|||
if (!lastTimestamp || (lastTimestamp === timestamp)) { | |||
if (!timestamp || !lastTimestamp || (lastTimestamp === timestamp)) { |
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.
In what cases timestamp
is nonexistent?
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.
@xpl Since we generate timestamp
from the set of files filtered by includes
, if none of the included files exist, it may end up an empty string (''
from join
ing []
), which is falsy. In this case, since none of the required files exist, we want to execute the timeout again, to wait for them to exist before reloading.
files.map (f => f.name + f.lastModifiedDate).join ()) | ||
const timestampForFilesInDirectory = dir => { | ||
return filesInDirectory (dir).then (files => { | ||
if (includes.length && !includes.every(i => files.some(f => i === f.name))) return; |
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.
Can you please clarify what that line does?
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.
@xpl It checks if the user has specified any required includes
, and if so, checks if not all of the files specified for inclusion actually exist in this timeout cycle - if any of the specified includes don't exist, it short-circuits so that we will wait for the next cycle to check again, hoping all the required files will exist then.
@AndersDJohnson Thanks for the PR! Sorry for the stupid questions, just don't have the time neither to check if it's working, nor for reviewing the code thoroughly ( In particular, it is not clear whether that line is necessary, as it seems redundant to me and should be removed:
If there are no files is in
Also, I am not sure that it is right to do that thing:
I suggest to change it to:
Because the purpose of the previous I haven't checked anything I've just written, so pardon for my silliness in advance :) |
@xpl I'm not sure if it's written correctly or minimally, but I think the |
@AndersDJohnson Thanks for the explanation. I somehow missed your initial premise that you need to ensure that all those files should actually exist before reloading, and thought that you simply want to implement a filtering for the file list needs to be watched, so I was confused of that additional checks' meaning. Then I need to understand better the actual use case of that. Is it only for |
@xpl Hard-coding for |
But then they would need to enumerate all those generated files explicity in That would work if a build tool first erases all files and then re-emits them — then your Do you have any information on how that is usually executed by various build tools? |
Yes for this to work for those use cases, I was assuming the files would be erased first, such as with the CleanWebpackPlugin. I wonder if there is another way? |
We could implement some debouncing logic (like in The downside is that it would complicate the implementation and will also hurt the UX, as the reaction time of the reloading trigger would be slower, you would need to wait an additional second every time... |
I created a simple version for myself that only uses a local exclude list (in
|
Adds a function
include
exported that you can call after importing which will limit the files that are considered for changes, and require all of them and only them to be present before reloading. Implementing it this way makes it backward compatible and non-intrusive.I found this helpful in my extension where I was manually copying
manifest.json
after webpack build completed - it didn't exist right away when other webpack entry files ae written, which causes an extension reload error.I partially figured this out anyway by enabling the
copyUnmodified: true
option with theCopyPlugin
and usingwebpack --watch
for development, but it still fails on a fresh start ofwebpack --watch
, so I think this addition might be useful anyway.Fixes #7, except does not support
exclude
.