Skip to content

Configurable watch root#9424

Merged
devongovett merged 12 commits into
parcel-bundler:v2from
jondlm:jdlm-configurable-project-root
Dec 19, 2023
Merged

Configurable watch root#9424
devongovett merged 12 commits into
parcel-bundler:v2from
jondlm:jdlm-configurable-project-root

Conversation

@jondlm

@jondlm jondlm commented Dec 7, 2023

Copy link
Copy Markdown
Contributor

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
Comment thread packages/core/parcel/src/cli.js
Comment thread packages/core/parcel/src/cli.js
resolvedOptions.projectRoot,
resolvedOptions.watchDir,
(err, events) => {
if (err) {

Copy link
Copy Markdown
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
Copy Markdown
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