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

Implements custom recursive watch for linux #39

Merged
merged 2 commits into from
Feb 11, 2020

Conversation

lukejacksonn
Copy link
Owner

Hopefully fixes #36 (haven't got a linux machine to test it on).

servor.js Outdated
@@ -132,6 +139,6 @@ module.exports = async ({
root,
protocol,
port,
ips
ips,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukejacksonn do we need this dangling comma?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps this is an editor config? there are a lot of dangling commas in the code now. 🙈

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh I realised.. this is generally my personal preference (for browser based projects at least).. when was this supported in node do you know? Is it likely to cause issues?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just reverted that change.. it didn't belong in this PR 😅 now the servor.js diff is all relevant to the fix!

servor.js Outdated
const watch = (path, cb) => {
if (fs.statSync(path).isDirectory()) {
fs.watch(path, cb);
fs.readdirSync(path).forEach(entry => watch(`${path}/${entry}`, cb));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this might become too expensive. I use servor at the root of repository, which has lot of directories in .git, node_modules, etc.

maybe, we should consider being able to configure what to watch?, something like:

servor --watch dist --watch src <...other options>

also this way the watch/reload become less aggressive/chatty...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have considered this too! I'm not sure exactly how expensive this is.. but apparently the native { recursive: true } is much more efficient, to the point where you can do:

// watch the whole disk
fs.watch('/', { recursive: true })

Source: https://www.npmjs.com/package/node-watch

So I am going to put a ternary in that will use this for linux and native recursive fs.watch on windows and mac (then we shouldn't see any regression on existing perf).

Regards you wanting to watch only certain things I'm playing with the idea of a config file to put all these harder to define inline kind of options in. As I have mentioned before I want to keep the CLI and node API as simple as possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more alternative you might want to consider:

Screen Shot 2020-01-30 at 2 58 51 PM

Although this involves much more complicated options forwarding through CLI.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather keep options to to a minimum as branching like this creates more and more cases that require testing etc. I have been on vacation the past week and only just getting getting a chance to go through GitHub notifications. Will push the native/custom watch switch change asap. Thanks for your patience @thisguychris and @osdevisnot 🙇

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have pushed the change now so @osdevisnot you should not notice any difference in the way servor works and @thisguychris it should still work for you on linux! 🤞

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukejacksonn confirming that it works, more details on #36

@lukejacksonn lukejacksonn merged commit 11b31b5 into master Feb 11, 2020
@lukejacksonn lukejacksonn deleted the custom-recursive-watch branch February 11, 2020 15:50
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

Successfully merging this pull request may close these issues.

Doesn't detect change in nested files (on Linux)
3 participants