From 1a8c2bdf85621722251a097d09931b7483185eb5 Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Mon, 20 Jan 2025 15:00:14 +0100 Subject: [PATCH] fix(hmr): ignore sources without `cwd` --- src/utils/dev.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/utils/dev.ts b/src/utils/dev.ts index 2f776cf7d..ffecc9b53 100644 --- a/src/utils/dev.ts +++ b/src/utils/dev.ts @@ -93,9 +93,10 @@ export async function watchContents(nuxt: Nuxt, options: ModuleOptions, manifest const collections = manifest.collections const sourceMap = collections.flatMap((c) => { - return c.source - ? c.source.filter(s => !s.repository).map(s => ({ collection: c, source: s, cwd: withTrailingSlash(s.cwd) })) - : [] + if (c.source) { + return c.source.filter(s => !s.repository).map(s => ({ collection: c, source: s, cwd: s.cwd && withTrailingSlash(s.cwd) })) + } + return [] }) const dirsToWatch = Array.from(new Set(sourceMap.map(({ source }) => source.cwd))) // Filter out empty cwd for custom collections @@ -112,7 +113,13 @@ export async function watchContents(nuxt: Nuxt, options: ModuleOptions, manifest return } let path = pathOrError as string - const match = sourceMap.find(({ source, cwd }) => path.startsWith(cwd) && micromatch.isMatch(path.substring(cwd.length), source!.include, { ignore: source!.exclude || [], dot: true })) + const match = sourceMap.find(({ source, cwd }) => { + if (cwd && path.startsWith(cwd)) { + return micromatch.isMatch(path.substring(cwd.length), source!.include, { ignore: source!.exclude || [], dot: true }) + } + + return false + }) if (match) { const { collection, source, cwd } = match // Remove the cwd prefix