-
Notifications
You must be signed in to change notification settings - Fork 273
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
Remote sources fix watch #1071
Conversation
398c0c5
to
a9d924a
Compare
garden-service/src/util/fs.ts
Outdated
@@ -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 |
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.
I don't quite understand this comment
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.
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
).
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.
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.
garden-service/src/watch.ts
Outdated
// 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() { |
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.
I'd suggest a more descriptive name in that case
|
||
if (watcher === undefined) { | ||
watcher = watch(projectRoot, { | ||
watcher = watch(paths, { |
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.
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.
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.
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
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.
Do you mean when you run the link / unlink commands while Garden is already running in watch mode?
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.
No, more thinking of when you add a source in your project config while watching for changes.
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.
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.
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.
Linking basically updates the .garden/local-config.yml
file and I'm not sure if a running process will handle changes to that.
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.
We could also treat that as a config change and watch that file, I suppose
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.
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.
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.
We could also special-case the particular variables in the config. But I'd suggest creating a separate issue for that.
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.
Approved, but please create an issue for the watcher paths thing to track it ^
Here's the issue for the watcher paths thing: #1082 |
24c718d
to
8f918c4
Compare
Just realised I didn't push my commit for this:
It's there now and I'll squash if you approve. |
716671a
to
a186f60
Compare
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 theWatcher
class.Second, it refactors the
test-project-ext-module-sources
andtest-project-ext-project-sources
test projects. Before, they would containmock-dot-garden
andmock-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 themock-local-path
dirs and instead usetest-project-local-*-sources
projects when testing the linking functionality.Which issue(s) this PR fixes:
Fixes #965