mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): test watch
paths against all layer srcDir
s (#22307)
This commit is contained in:
parent
9b09b4d112
commit
2df9a4b9db
@ -1,4 +1,4 @@
|
||||
import { join, normalize, resolve } from 'pathe'
|
||||
import { join, normalize, relative, resolve } from 'pathe'
|
||||
import { createDebugger, createHooks } from 'hookable'
|
||||
import type { LoadNuxtOptions } from '@nuxt/kit'
|
||||
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) {
|
||||
}
|
||||
|
||||
// User provided patterns
|
||||
const layerRelativePaths = nuxt.options._layers.map(l => relative(l.config.srcDir || l.cwd, path))
|
||||
for (const pattern of nuxt.options.watch) {
|
||||
if (typeof pattern === 'string') {
|
||||
if (pattern === path) { return nuxt.callHook('restart') }
|
||||
// Test (normalised) strings against absolute path and relative path to any layer `srcDir`
|
||||
if (pattern === path || layerRelativePaths.includes(pattern)) { return nuxt.callHook('restart') }
|
||||
continue
|
||||
}
|
||||
if (pattern.test(path)) { return nuxt.callHook('restart') }
|
||||
// Test regular expressions against path to _any_ layer `srcDir`
|
||||
if (layerRelativePaths.some(p => pattern.test(p))) {
|
||||
return nuxt.callHook('restart')
|
||||
}
|
||||
}
|
||||
|
||||
// Core Nuxt files: app.vue, error.vue and app.config.ts
|
||||
|
@ -365,8 +365,9 @@ export default defineUntypedSchema({
|
||||
/**
|
||||
* The watch property lets you define patterns that will restart the Nuxt dev server when changed.
|
||||
*
|
||||
* It is an array of strings or regular expressions, which will be matched against the file path
|
||||
* relative to the project `srcDir`.
|
||||
* It is an array of strings or regular expressions. Strings should be either absolute paths or
|
||||
* relative to the `srcDir` (and the `srcDir` of any layers). Regular expressions will be matched
|
||||
* against the path relative to the project `srcDir` (and the `srcDir` of any layers).
|
||||
*
|
||||
* @type {Array<string | RegExp>}
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user