Skip to content

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

Merged
danielroe merged 5 commits intomainfrom
fix/watch-paths
Jul 26, 2023
Merged

fix(nuxt): pass (and handle) relative paths in builder:watch#22333
danielroe merged 5 commits intomainfrom
fix/watch-paths

Conversation

@danielroe
Copy link
Copy Markdown
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.

@bolt-new-by-stackblitz
Copy link
Copy Markdown

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

@TheAlexLichter
Copy link
Copy Markdown
Member

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

@TheAlexLichter
Copy link
Copy Markdown
Member

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

@danielroe
Copy link
Copy Markdown
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 TheAlexLichter July 26, 2023 06:41
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.

3 participants