From 75cd6b7894cab77d6b424f44f5c52075aad523a3 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 25 May 2023 16:38:34 -0500 Subject: [PATCH] fix(nuxt): normalize windows paths in granular watcher (#21066) --- packages/nuxt/src/core/builder.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/nuxt/src/core/builder.ts b/packages/nuxt/src/core/builder.ts index b17daf7141..3638c84263 100644 --- a/packages/nuxt/src/core/builder.ts +++ b/packages/nuxt/src/core/builder.ts @@ -5,7 +5,7 @@ import chokidar from 'chokidar' import { isIgnored, tryResolveModule, useNuxt } from '@nuxt/kit' import { interopDefault } from 'mlly' import { debounce } from 'perfect-debounce' -import { normalize } from 'pathe' +import { normalize, resolve } from 'pathe' import type { Nuxt } from 'nuxt/schema' import { generateApp as _generateApp, createApp } from './app' @@ -96,8 +96,9 @@ function createGranularWatcher () { const ignoredDirs = new Set([...nuxt.options.modulesDir, nuxt.options.buildDir]) const pathsToWatch = nuxt.options._layers.map(layer => layer.config.srcDir).filter(d => d && !isIgnored(d)) - for (const path of nuxt.options.watch) { - if (typeof path !== 'string') { continue } + for (const pattern of nuxt.options.watch) { + if (typeof pattern !== 'string') { continue } + const path = resolve(nuxt.options.srcDir, pattern) if (pathsToWatch.some(w => path.startsWith(w.replace(/[^/]$/, '$&/')))) { continue } pathsToWatch.push(path) } @@ -107,8 +108,9 @@ function createGranularWatcher () { const watchers: Record = {} watcher.on('all', (event, path) => { + path = normalize(path) if (!pending) { - nuxt.callHook('builder:watch', event, normalize(path)) + nuxt.callHook('builder:watch', event, path) } if (event === 'unlinkDir' && path in watchers) { watchers[path].close()