Skip to content

Commit

Permalink
fix(hmr): ignore sources without cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Jan 20, 2025
1 parent 75affdb commit 1a8c2bd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/utils/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1a8c2bd

Please sign in to comment.