fix(nuxt)!: emit absolute paths in builder:watch hook (#27709)

This commit is contained in:
Daniel Roe 2024-06-19 17:06:46 +01:00 committed by GitHub
parent de06660e08
commit bbad9bf534
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 20 deletions

View File

@ -86,8 +86,7 @@ function createWatcher () {
], ],
}) })
// TODO: consider moving to emit absolute path in 3.8 or 4.0 watcher.on('all', (event, path) => nuxt.callHook('builder:watch', event, normalize(path)))
watcher.on('all', (event, path) => nuxt.callHook('builder:watch', event, nuxt.options.experimental.relativeWatchPaths ? normalize(relative(nuxt.options.srcDir, path)) : normalize(path)))
nuxt.hook('close', () => watcher?.close()) nuxt.hook('close', () => watcher?.close())
} }
@ -117,8 +116,7 @@ function createGranularWatcher () {
watcher.on('all', (event, path) => { watcher.on('all', (event, path) => {
path = normalize(path) path = normalize(path)
if (!pending) { if (!pending) {
// TODO: consider moving to emit absolute path in 3.8 or 4.0 nuxt.callHook('builder:watch', event, path)
nuxt.callHook('builder:watch', event, nuxt.options.experimental.relativeWatchPaths ? relative(nuxt.options.srcDir, path) : path)
} }
if (event === 'unlinkDir' && path in watchers) { if (event === 'unlinkDir' && path in watchers) {
watchers[path]?.close() watchers[path]?.close()
@ -126,8 +124,7 @@ function createGranularWatcher () {
} }
if (event === 'addDir' && path !== dir && !ignoredDirs.has(path) && !pathsToWatch.includes(path) && !(path in watchers) && !isIgnored(path)) { if (event === 'addDir' && path !== dir && !ignoredDirs.has(path) && !pathsToWatch.includes(path) && !(path in watchers) && !isIgnored(path)) {
watchers[path] = chokidar.watch(path, { ...nuxt.options.watchers.chokidar, ignored: [isIgnored] }) watchers[path] = chokidar.watch(path, { ...nuxt.options.watchers.chokidar, ignored: [isIgnored] })
// TODO: consider moving to emit absolute path in 3.8 or 4.0 watchers[path].on('all', (event, p) => nuxt.callHook('builder:watch', event, normalize(p)))
watchers[path].on('all', (event, p) => nuxt.callHook('builder:watch', event, nuxt.options.experimental.relativeWatchPaths ? normalize(relative(nuxt.options.srcDir, p)) : normalize(p)))
nuxt.hook('close', () => watchers[path]?.close()) nuxt.hook('close', () => watchers[path]?.close())
} }
}) })
@ -161,8 +158,7 @@ async function createParcelWatcher () {
if (err) { return } if (err) { return }
for (const event of events) { for (const event of events) {
if (isIgnored(event.path)) { continue } if (isIgnored(event.path)) { continue }
// TODO: consider moving to emit absolute path in 3.8 or 4.0 nuxt.callHook('builder:watch', watchEvents[event.type], normalize(event.path))
nuxt.callHook('builder:watch', watchEvents[event.type], nuxt.options.experimental.relativeWatchPaths ? normalize(relative(nuxt.options.srcDir, event.path)) : normalize(event.path))
} }
}, { }, {
ignore: [ ignore: [

View File

@ -434,18 +434,6 @@ export default defineUntypedSchema({
*/ */
clientNodeCompat: false, clientNodeCompat: false,
/**
* Whether to provide relative paths in the `builder:watch` hook.
*
* This flag will be removed with the release of v4 and exists only for
* advance testing within Nuxt v3.12+ or in [the nightly release channel](/docs/guide/going-further/nightly-release-channel).
*/
relativeWatchPaths: {
async $resolve (val, get) {
return val ?? ((await get('future') as Record<string, unknown>).compatibilityVersion !== 4)
},
},
/** /**
* Whether `clear` and `clearNuxtData` should reset async data to its _default_ value or update * Whether `clear` and `clearNuxtData` should reset async data to its _default_ value or update
* it to `null`/`undefined`. * it to `null`/`undefined`.