mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-12 11:48:17 +00:00
fix(nuxt): allow restarting nuxt on paths outside srcDir
(#30771)
This commit is contained in:
parent
6fafc85ea0
commit
5c8744a30d
@ -108,6 +108,18 @@ function createWatcher () {
|
|||||||
ignored: [isIgnored, /[\\/]node_modules[\\/]/],
|
ignored: [isIgnored, /[\\/]node_modules[\\/]/],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const restartPaths = new Set<string>()
|
||||||
|
const srcDir = nuxt.options.srcDir.replace(/\/?$/, '/')
|
||||||
|
for (const pattern of nuxt.options.watch) {
|
||||||
|
if (typeof pattern !== 'string') { continue }
|
||||||
|
const path = resolve(nuxt.options.srcDir, pattern)
|
||||||
|
if (!path.startsWith(srcDir)) {
|
||||||
|
restartPaths.add(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watcher.add([...restartPaths])
|
||||||
|
|
||||||
watcher.on('all', (event, path) => {
|
watcher.on('all', (event, path) => {
|
||||||
if (event === 'all' || event === 'ready' || event === 'error' || event === 'raw') {
|
if (event === 'all' || event === 'ready' || event === 'error' || event === 'raw') {
|
||||||
return
|
return
|
||||||
|
@ -413,7 +413,7 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
await nuxt.callHook('modules:before')
|
await nuxt.callHook('modules:before')
|
||||||
const modulesToInstall = new Map<string | NuxtModule, Record<string, any>>()
|
const modulesToInstall = new Map<string | NuxtModule, Record<string, any>>()
|
||||||
|
|
||||||
const watchedPaths = new Set<string>()
|
const modulePaths = new Set<string>()
|
||||||
const specifiedModules = new Set<string>()
|
const specifiedModules = new Set<string>()
|
||||||
|
|
||||||
for (const _mod of nuxt.options.modules) {
|
for (const _mod of nuxt.options.modules) {
|
||||||
@ -431,13 +431,15 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
`${modulesDir}/*/index{${nuxt.options.extensions.join(',')}}`,
|
`${modulesDir}/*/index{${nuxt.options.extensions.join(',')}}`,
|
||||||
])
|
])
|
||||||
for (const mod of layerModules) {
|
for (const mod of layerModules) {
|
||||||
watchedPaths.add(mod)
|
modulePaths.add(mod)
|
||||||
if (specifiedModules.has(mod)) { continue }
|
if (specifiedModules.has(mod)) { continue }
|
||||||
specifiedModules.add(mod)
|
specifiedModules.add(mod)
|
||||||
modulesToInstall.set(mod, {})
|
modulesToInstall.set(mod, {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nuxt.options.watch.push(...modulePaths)
|
||||||
|
|
||||||
// Register user and then ad-hoc modules
|
// Register user and then ad-hoc modules
|
||||||
for (const key of ['modules', '_modules'] as const) {
|
for (const key of ['modules', '_modules'] as const) {
|
||||||
for (const item of nuxt.options[key as 'modules']) {
|
for (const item of nuxt.options[key as 'modules']) {
|
||||||
@ -660,7 +662,7 @@ export default defineNuxtPlugin({
|
|||||||
nuxt.hooks.hook('builder:watch', (event, relativePath) => {
|
nuxt.hooks.hook('builder:watch', (event, relativePath) => {
|
||||||
const path = resolve(nuxt.options.srcDir, relativePath)
|
const path = resolve(nuxt.options.srcDir, relativePath)
|
||||||
// Local module patterns
|
// Local module patterns
|
||||||
if (watchedPaths.has(path)) {
|
if (modulePaths.has(path)) {
|
||||||
return nuxt.callHook('restart', { hard: true })
|
return nuxt.callHook('restart', { hard: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user