8000 fix(nuxt): test `watch` paths against all layer `srcDir`s (#22307) · nuxt/nuxt@2df9a4b · GitHub
[go: up one dir, main page]

Skip to content

Commit 2df9a4b

Browse files
authored
fix(nuxt): test watch paths against all layer srcDirs (#22307)
1 parent 9b09b4d commit 2df9a4b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/nuxt/src/core/nuxt.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join, normalize, resolve } from 'pathe'
1+
import { join, normalize, relative, resolve } from 'pathe'
22
import { createDebugger, createHooks } from 'hookable'
33
import type { LoadNuxtOptions } from '@nuxt/kit'
44
import { addBuildPlugin, addComponent, addPlugin, addVitePlugin, addWebpackPlugin, installModule, loadNuxtConfig, logger, nuxtCtx, resolveAlias, resolveFiles, resolvePath, tryResolveModule, useNitro } from '@nuxt/kit'
@@ -349,12 +349,17 @@ async function initNuxt (nuxt: Nuxt) {
349349
}
350350

351351
// User provided patterns
352+
const layerRelativePaths = nuxt.options._layers.map(l => relative(l.config.srcDir || l.cwd, path))
352353
for (const pattern of nuxt.options.watch) {
353354
if (typeof pattern === 'string') {
354-
if (pattern === path) { return nuxt.callHook('restart') }
355+
// Test (normalised) strings against absolute path and relative path to any layer `srcDir`
356+
if (pattern === path || layerRelativePaths.includes(pattern)) { return nuxt.callHook('restart') }
355357
continue
356358
}
357-
if (pattern.test(path)) { return nuxt.callHook('restart') }
359+
// Test regular expressions against path to _any_ layer `srcDir`
360+
if (layerRelativePaths.some(p => pattern.test(p))) {
361+
return nuxt.callHook('restart')
362+
}
358363
}
359364

360365
// Core Nuxt files: app.vue, error.vue and app.config.ts

packages/schema/src/config/common.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,9 @@ export default defineUntypedSchema({
365365
/**
366366
* The watch property lets you define patterns that will restart the Nuxt dev server when changed.
367367
*
368-
* It is an array of strings or regular expressions, which will be matched against the file path
369-
* relative to the project `srcDir`.
368+
* It is an array of strings or regular expressions. Strings should be either absolute paths or
369+
* relative to the `srcDir` (and the `srcDir` of any layers). Regular expressions will be matched
370+
* against the path relative to the project `srcDir` (and the `srcDir` of any layers).
370371
*
371372
* @type {Array<string | RegExp>}
372373
*/

0 commit comments

Comments
 (0)
0