Skip to content

Commit

Permalink
fix: windows path normalize on update route from hmr
Browse files Browse the repository at this point in the history
  • Loading branch information
hannoeru committed May 12, 2021
1 parent 808afcd commit a59e5ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,27 @@ function pagesPlugin(userOptions: UserOptions = {}): Plugin {
}

watcher.on('add', (file) => {
if (isTarget(file, options)) {
debug.hmr('add', file)
const path = slash(file)
if (isTarget(path, options)) {
debug.hmr('add', path)
generatedRoutes = null
fullReload()
}
})
watcher.on('unlink', (file) => {
if (isTarget(file, options)) {
debug.hmr('remove', file)
const path = slash(file)
if (isTarget(path, options)) {
debug.hmr('remove', path)
generatedRoutes = null
fullReload()
}
})
watcher.on('change', (file) => {
if (isTarget(file, options) && generatedRoutes) {
const needReload = updateRouteFromHMR(file, generatedRoutes, options)
const path = slash(file)
if (isTarget(path, options) && generatedRoutes) {
const needReload = updateRouteFromHMR(path, generatedRoutes, options)
if (needReload) {
debug.hmr('change', file)
debug.hmr('change', path)
fullReload()
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ function isPagesDir(path: string, options: ResolvedOptions) {
return false
}

export function isTarget(filePath: string, options: ResolvedOptions) {
const path = slash(filePath)
export function isTarget(path: string, options: ResolvedOptions) {
return isPagesDir(path, options) && options.extensionsRE.test(path)
}

Expand Down

0 comments on commit a59e5ff

Please sign in to comment.