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

Remote sources fix watch #1071

Merged
merged 3 commits into from
Aug 7, 2019
Merged

Remote sources fix watch #1071

merged 3 commits into from
Aug 7, 2019

Conversation

eysi09
Copy link
Collaborator

@eysi09 eysi09 commented Aug 5, 2019

What this PR does / why we need it:

First of all, it fixes an issue where Garden wasn't watching linked sources (when you do garden link my-module /to/some/path). We fix this by simply including all linked paths when initialising the Watcher class.

Second, it refactors the test-project-ext-module-sources and test-project-ext-project-sources test projects. Before, they would contain mock-dot-garden and mock-local-path directories. We then did a lot of stubbing to make Garden think these were the .garden dir and /some/local/project/dir, respectively.

Instead of all this, we now initialise these projects with a proper .garden directory that contains the sources and git init them, just like Garden would expect in the "real world". We also remove the mock-local-path dirs and instead use test-project-local-*-sources projects when testing the linking functionality.

Which issue(s) this PR fixes:

Fixes #965

@eysi09 eysi09 requested a review from edvald August 5, 2019 10:33
@eysi09 eysi09 changed the title Remote sources fix watch [WIP] Remote sources fix watch Aug 5, 2019
@eysi09 eysi09 force-pushed the remote-sources-fix-watch branch 3 times, most recently from 398c0c5 to a9d924a Compare August 5, 2019 15:19
@eysi09 eysi09 changed the title [WIP] Remote sources fix watch Remote sources fix watch Aug 5, 2019
@@ -21,7 +21,8 @@ import { VcsHandler } from "../vcs/vcs"
const VALID_CONFIG_FILENAMES = ["garden.yml", "garden.yaml"]
const metadataFilename = "metadata.json"
export const defaultDotIgnoreFiles = [".gitignore", ".gardenignore"]
export const fixedExcludes = [".git", ".garden", "debug-info-*"]
// FIXME: We should use `garden.gardenDirPath` instead of ".garden" since the dir name can be variable
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't quite understand this comment

Copy link
Collaborator Author

@eysi09 eysi09 Aug 6, 2019

Choose a reason for hiding this comment

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

We stopped using .garden as a global constant and removed all references to it at some point. Instead the path is a property on the Garden class that we set when we initialise it. So you could technically do new Garden({ gardenDirPath: ".foo" }). We use this for the system Garden class (although it's nested within .garden).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. I'd then rather explicitly add that path to the excludes list in Garden.factory() or the constructor, and keep the fixedExcludes constant as-is.

// The process hangs after tests if we don't do this
registerCleanupFunction("stop watcher", () => {
// Export so that we can clean up the global watcher instance when running tests
export function cleanUp() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest a more descriptive name in that case


if (watcher === undefined) {
watcher = watch(projectRoot, {
watcher = watch(paths, {
Copy link
Collaborator

@edvald edvald Aug 5, 2019

Choose a reason for hiding this comment

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

This basically means that the watcher will not work right if you add a new source while watching. That was okay(ish) when it was just the project root, but may be problematic now. I think it's fairly simple to solve though. We just need to keep track of which paths are currently being watched (or read that from the existing watcher if it exists) and add/remove as necessary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, you can just get a list of currently watched paths (if any), and reconcile that against the paths we want to watch: https://github.com/paulmillr/chokidar#methods--events

Copy link
Collaborator Author

@eysi09 eysi09 Aug 6, 2019

Choose a reason for hiding this comment

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

Do you mean when you run the link / unlink commands while Garden is already running in watch mode?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, more thinking of when you add a source in your project config while watching for changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, didn't think of that. However, you'd still need to link it (even if it's local), which is a separate command. So the assumption is still that the user would kill the running process, run garden link and then start it again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Linking basically updates the .garden/local-config.yml file and I'm not sure if a running process will handle changes to that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could also treat that as a config change and watch that file, I suppose

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I guess. Wondering if there are any unwanted side effects since Garden updates this file programmatically. And not just for setting/removing linked sources. But I guess in any case you'd want to trigger a config change event.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could also special-case the particular variables in the config. But I'd suggest creating a separate issue for that.

Copy link
Collaborator

@edvald edvald left a comment

Choose a reason for hiding this comment

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

Approved, but please create an issue for the watcher paths thing to track it ^

@eysi09
Copy link
Collaborator Author

eysi09 commented Aug 6, 2019

Here's the issue for the watcher paths thing: #1082

@eysi09 eysi09 force-pushed the remote-sources-fix-watch branch from 24c718d to 8f918c4 Compare August 6, 2019 19:42
@eysi09
Copy link
Collaborator Author

eysi09 commented Aug 6, 2019

Just realised I didn't push my commit for this:

I'd then rather explicitly add that path to the excludes list in Garden.factory() or the constructor, and keep the fixedExcludes constant as-is.

It's there now and I'll squash if you approve.

@eysi09 eysi09 force-pushed the remote-sources-fix-watch branch from 716671a to a186f60 Compare August 7, 2019 08:16
@eysi09 eysi09 merged commit 3c3afc9 into master Aug 7, 2019
@eysi09 eysi09 deleted the remote-sources-fix-watch branch August 7, 2019 09:06
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.

Watch mode does not work for linked remote sources
2 participants