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

fix(nuxt): pass (and handle) relative paths in builder:watch #22333

Merged
merged 5 commits into from Jul 26, 2023

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Jul 26, 2023

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

For chokidar-granular and parcel watcher options, watch events emit the absolute path. For chokidar, the path was relative to srcDir. (This was an unintentionally breaking change when #20836 was merged and later made default.)

This PR:

  • Makes chokidar-granular and parcel watchers also emit relative paths. The reason I've chosen this rather than reverting to previous behaviour is that 3.7 is a minor release so we can make a more significant change to this behaviour. In addition, I think it makes more sense to have absolute path when handling things like watching layers in a monorepo, which may not be 'within' the source directory of the project. However, I would welcome thoughts on this. (We could instead emit all paths as relative in parcel/chokidar-granular for backwards compatibility.)
  • Adds support for treating layers as first class citizens with regard to restarting - changes to pages/layouts/middleware/composable/etc. will now be treated in the same way as changing the source project.
  • Other improvements include not restarting when directories that start with the same pattern are changed/updated (e.g. ~/composablestest

Related: #22307.

TODO:

  • consider emitting relative paths for backwards compatibility and moving to absolute paths in a future major release. How significant do we feel this change is?

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@stackblitz
Copy link

stackblitz bot commented Jul 26, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@manniL
Copy link
Member

manniL commented Jul 26, 2023

The reason I've chosen this rather than reverting to previous behaviour is that 3.7 is a minor release so we can make a more significant change to this behaviour.

Makes sense, especially because the majority of users won't rely on these paths directly.

In addition, I think it makes more sense to have absolute path when handling things like watching layers in a monorepo, which may not be 'within' the source directory of the project. However, I would welcome thoughts on this. (We could instead emit all paths as relative in parcel/chokidar-granular for backwards compatibility.)

To me this sounds reasonable, especially given no issues/feedback (known to me) to the absolute vs. relative path changes. And better monorepo layer support is another big benefit here πŸ‘πŸ»

@danielroe danielroe requested a review from pi0 July 26, 2023 05:37
@danielroe
Copy link
Member Author

Here are some examples of where people are already expecting fully resolved paths (likely in response to this unintentional change):

Here are some examples of where people are handling relative paths:

There are other examples too.

Either way will require updating. It's likely easier for apollo/devtools to get an absolute path by resolve(nuxt.options.srcDir, path) which will work either with abs/relative paths being passed to them, than it would be to normalise back to relative path for modules using it.

@manniL
Copy link
Member

manniL commented Jul 26, 2023

Either way will require updating. It's likely easier for apollo/devtools to get an absolute path by resolve(nuxt.options.srcDir, path) which will work either with abs/relative paths being passed to them, than it would be to normalise back to relative path for modules using it.

Good point. Then indeed relative paths make more sense. We should keep a TODO or similar though for making them absolute in the next major.

@Hebilicious
Copy link
Member

@danielroe
Copy link
Member Author

I've talked myself around. I'm thinking we should probably refactor this to emit relative paths again, even if we use absolute paths under-the-hood.

We can then change the behaviour in a major version.

Maintainers of modules who rely on absolute path can simply normalise paths with path = resolve(nuxt.options.srcDir, path) which will work with relative and absolute paths (if module is being used on a version of nuxt with this regression)....

@danielroe danielroe changed the title fix(nuxt): pass (and handle) fully resolved paths in builder:watch fix(nuxt): pass (and handle) relative paths in builder:watch Jul 26, 2023
@danielroe danielroe requested a review from manniL July 26, 2023 06:41
@danielroe danielroe merged commit e2c7edd into main Jul 26, 2023
29 checks passed
@danielroe danielroe deleted the fix/watch-paths branch July 26, 2023 09:16
@github-actions github-actions bot mentioned this pull request Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants