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

Configurable watch root #9424

Merged
merged 12 commits into from
Dec 19, 2023

Conversation

jondlm
Copy link
Contributor

@jondlm jondlm commented Dec 7, 2023

related to: #4332

↪️ Pull Request

Adds a new --watch-dir CLI flag that allows users to specify a directory higher up than the project root. This allows Parcel in watch mode to detect changes to symlinked dependencies.

This is especially useful for monorepos that have lockfiles for each of the projects and where all projects can't share the same project root for various reasons.

💻 Examples

Suppose we have a project shaped like this:

.
├── package.json
└── packages
    ├── app
    │   ├── index.js              <- imports lib via the symlink in node_modules
    │   ├── node_modules
    │   │   └── lib -> ../../lib
    │   ├── package.json
    │   └── yarn.lock
    └── lib
        ├── index.js
        ├── package.json
        └── yarn.lock

We can run parcel server --watchDir ../.. from within packages/app and changes to packages/lib/index.js will trigger HMR updates, etc.

🚨 Test instructions

I have included an integration test that exercises this new behavior. I confirmed that without the watchDir option Parcel won't detect changes but it does with the proper watch directory set.

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@jondlm jondlm changed the title Configurable project root Configurable watch root Dec 7, 2023
packages/core/parcel/src/cli.js Show resolved Hide resolved
@@ -389,7 +389,7 @@ export default class Parcel {
let resolvedOptions = nullthrows(this.#resolvedOptions);
let opts = getWatcherOptions(resolvedOptions);
let sub = await resolvedOptions.inputFS.watch(
resolvedOptions.projectRoot,
resolvedOptions.watchDir,
(err, events) => {
if (err) {
Copy link
Member

Choose a reason for hiding this comment

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

we should probably also update this so it works for one-shot builds

let events = await options.inputFS.getEventsSince(

idk if watchRoot is the most obvious name in that case but not sure about another one. projectRoot is a different thing and affects more stuff so would need to be something different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Yeah the name because less intuitive when used in this context :|

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.

4 participants