Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: watch cwds of dependencies#10054

Open
43081j wants to merge 8 commits into
jdx:mainfrom
43081j:watch-cwds
Open

fix: watch cwds of dependencies#10054
43081j wants to merge 8 commits into
jdx:mainfrom
43081j:watch-cwds

Conversation

@43081j
Copy link
Copy Markdown

@43081j 43081j commented May 23, 2026

When I changed watch mode to also watch dependencies' sources, I didn't
take into account the fact that the sources will be used as-is (i.e.
not resolved to anything).

This meant the following would happen:

  • build:a has ["src/*.ts"]
  • build:b has ["lib/*.js"] and depends on build:a
  • We pass ["src/*.ts", "lib/*.js"] to watchexec in the directory of
    build:b

This made lib/*.js basically no-op, or worse, watch the wrong files.

This change resolves the paths to their owning directory so we end up
with ["wherever-builda-lives/src/*.ts", "wherever-buildb-lives/lib/*.js"].

Notable Changes:

  • Instead of passing relative globs to watchexec, we now pass resolved
    ones (relative to the root)
  • We now pass --project-origin to watchexec which comes with some perf
    gains but also means globs are now relative to it
  • We pass --watch {cwd} for the cwd of each dependency
  • This new resolve_source function is basically turning a source glob
    into a relative-to-the-root glob while retaining negations
  • The new common_ancestor function tries to find the common ancestor of two directories

cc @jdx i don't usually delve into rust so i'd love some help here if you can.

especially if there's a better way to find the common ancestor, or if you think we should deal with that differently.

basically, watchexec doesn't seem to support absolute paths, so we have to set the project-origin to something above all globs. which is why this new function tries to find a common root (if not the configured one)

43081j added 4 commits May 22, 2026 09:41
When I changed watch mode to also watch dependencies' sources, I didn't
take into account the fact that the `sources` will be used _as-is_ (i.e.
not resolved to anything).

This meant the following would happen:

- `build:a` has `["src/*.ts"]`
- `build:b` has `["lib/*.js"]` and depends on `build:a`
- We pass `["src/*.ts", "lib/*.js"]` to watchexec _in the directory of
  `build:b`_

This made `lib/*.js` basically no-op, or worse, watch the wrong files.

This change resolves the paths to their owning directory so we end up
with `["wherever-builda-lives/src/*.ts",
"wherever-buildb-lives/lib/*.js"]`.

**Notable Changes:**

- Instead of passing relative globs to watchexec, we now pass resolved
  ones (relative to the root)
- We now pass `--project-origin` to watchexec which comes with some perf
  gains but also means globs are now relative to it
- We pass `--watch {cwd}` for the cwd of each dependency
- This new `resolve_source` function is basically turning a source glob
  into a relative-to-the-root glob while retaining negations
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces logic to calculate a "filter anchor" for watchexec by determining the common ancestor of task working directories, ensuring glob filters are correctly interpreted relative to a project origin. It adds utility functions for finding common path ancestors and resolving source patterns, including support for negations and escaped characters. Review feedback focused on optimizing the common_ancestor function by using AsRef to avoid unnecessary cloning and reducing memory allocations during path component comparisons.

Comment thread src/cli/watch.rs Outdated
Comment thread src/cli/watch.rs Outdated
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 23, 2026

Greptile Summary

This PR fixes watch mode so that source globs belonging to dependency tasks are resolved relative to each task's own working directory before being passed to watchexec, rather than being handed to watchexec unchanged (and thus interpreted relative to the wrong cwd). It introduces parse_source/normalize_path/relativize_source helpers plus a common_ancestor utility to compute a --project-origin anchor that covers all task cwds and their resolved sources.

  • Source patterns from all watched tasks (including transitive deps) are now absolutized, re-expressed relative to a shared anchor, and passed with --project-origin so watchexec interprets them correctly.
  • Each task's cwd is added as an explicit --watch directory, and an early-exit path skips the new logic entirely when no tasks declare any sources.

Confidence Score: 4/5

The change is a meaningful correctness fix for watch mode; safe to merge with the two edge cases noted.

The new helpers are well-exercised by unit tests. Two narrow edge cases remain: relativize_source does not guard Plain kind against a relative path starting with !, silently converting an include into an exclusion; and the (None, None) anchor fallback produces an empty PathBuf.

src/cli/watch.rs — relativize_source and the (None, None) anchor fallback.

Important Files Changed

Filename Overview
src/cli/watch.rs Core watch logic rewritten to resolve source globs to anchor-relative paths. New helpers parse_source, normalize_path, relativize_source, and common_ancestor are well-tested. Minor edge cases: a plain source whose relative path starts with ! is silently mis-treated as a negation, and the (None, None) fallback anchor is an empty PathBuf.

Reviews (4): Last reviewed commit: "feat: handle empy sets of sources" | Re-trigger Greptile

Comment thread src/cli/watch.rs
Comment thread src/cli/watch.rs Outdated
Comment thread src/cli/watch.rs
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.

1 participant