Skip to content

Commit 1a8c2bd

Browse files
committed
fix(hmr): ignore sources without cwd
1 parent 75affdb commit 1a8c2bd

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/utils/dev.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ export async function watchContents(nuxt: Nuxt, options: ModuleOptions, manifest
9393
const collections = manifest.collections
9494

9595
const sourceMap = collections.flatMap((c) => {
96-
return c.source
97-
? c.source.filter(s => !s.repository).map(s => ({ collection: c, source: s, cwd: withTrailingSlash(s.cwd) }))
98-
: []
96+
if (c.source) {
97+
return c.source.filter(s => !s.repository).map(s => ({ collection: c, source: s, cwd: s.cwd && withTrailingSlash(s.cwd) }))
98+
}
99+
return []
99100
})
100101
const dirsToWatch = Array.from(new Set(sourceMap.map(({ source }) => source.cwd)))
101102
// Filter out empty cwd for custom collections
@@ -112,7 +113,13 @@ export async function watchContents(nuxt: Nuxt, options: ModuleOptions, manifest
112113
return
113114
}
114115
let path = pathOrError as string
115-
const match = sourceMap.find(({ source, cwd }) => path.startsWith(cwd) && micromatch.isMatch(path.substring(cwd.length), source!.include, { ignore: source!.exclude || [], dot: true }))
116+
const match = sourceMap.find(({ source, cwd }) => {
117+
if (cwd && path.startsWith(cwd)) {
118+
return micromatch.isMatch(path.substring(cwd.length), source!.include, { ignore: source!.exclude || [], dot: true })
119+
}
120+
121+
return false
122+
})
116123
if (match) {
117124
const { collection, source, cwd } = match
118125
// Remove the cwd prefix

0 commit comments

Comments
 (0)