From c948423407ccc4f8971f59fb10848c6424e42b04 Mon Sep 17 00:00:00 2001 From: markthree <1801982702@qq.com> Date: Wed, 10 Aug 2022 15:48:56 +0800 Subject: [PATCH 1/4] fix: slash some path for windows --- src/core/context.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/context.ts b/src/core/context.ts index 1254aac33..0894ad939 100644 --- a/src/core/context.ts +++ b/src/core/context.ts @@ -6,7 +6,7 @@ import { generateRouteNamedMap } from '../codegen/generateRouteMap' import { MODULE_ROUTES_PATH, MODULE_VUE_ROUTER } from './moduleConstants' import { generateRouteRecord } from '../codegen/generateRouteRecords' import fg from 'fast-glob' -import { resolve } from 'pathe' +import { resolve, normalize as slash } from 'pathe' import { ServerContext } from '../options' import { getRouteBlock } from './customBlock' import { RoutesFolderWatcher, HandlerContext } from './RoutesFolderWatcher' @@ -93,6 +93,7 @@ export function createRoutesContext(options: ResolvedOptions) { } async function addPage({ filePath: path, routePath }: HandlerContext) { + path = slash(path) const routeBlock = await getRouteBlock(path, options) log(`added "${routePath}" for "${path}"`) if (routeBlock) log(routeBlock) @@ -110,6 +111,7 @@ export function createRoutesContext(options: ResolvedOptions) { } async function updatePage({ filePath: path, routePath }: HandlerContext) { + path = slash(path) log(`updated "${routePath}" for "${path}"`) const node = routeMap.get(path) if (!node) { @@ -122,6 +124,7 @@ export function createRoutesContext(options: ResolvedOptions) { } function removePage({ filePath: path, routePath }: HandlerContext) { + path = slash(path) log(`remove "${routePath}" for "${path}"`) routeTree.remove(routePath) routeMap.delete(path) From fed607e934ee271d15c68e7acd716605c3a4fe98 Mon Sep 17 00:00:00 2001 From: markthree <1801982702@qq.com> Date: Thu, 11 Aug 2022 21:59:18 +0800 Subject: [PATCH 2/4] chore: slash path once --- src/core/RoutesFolderWatcher.ts | 3 ++- src/core/context.ts | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/RoutesFolderWatcher.ts b/src/core/RoutesFolderWatcher.ts index 51ac3c819..efb0f7f87 100644 --- a/src/core/RoutesFolderWatcher.ts +++ b/src/core/RoutesFolderWatcher.ts @@ -1,4 +1,5 @@ import chokidar from 'chokidar' +import { normalize } from 'pathe' import { ResolvedOptions, RoutesFolderOption } from '../options' export class RoutesFolderWatcher { @@ -41,7 +42,7 @@ export class RoutesFolderWatcher { return } handler({ - filePath, + filePath: normalize(filePath), routePath: this.asRoutePath(filePath), }) }) diff --git a/src/core/context.ts b/src/core/context.ts index 0894ad939..1254aac33 100644 --- a/src/core/context.ts +++ b/src/core/context.ts @@ -6,7 +6,7 @@ import { generateRouteNamedMap } from '../codegen/generateRouteMap' import { MODULE_ROUTES_PATH, MODULE_VUE_ROUTER } from './moduleConstants' import { generateRouteRecord } from '../codegen/generateRouteRecords' import fg from 'fast-glob' -import { resolve, normalize as slash } from 'pathe' +import { resolve } from 'pathe' import { ServerContext } from '../options' import { getRouteBlock } from './customBlock' import { RoutesFolderWatcher, HandlerContext } from './RoutesFolderWatcher' @@ -93,7 +93,6 @@ export function createRoutesContext(options: ResolvedOptions) { } async function addPage({ filePath: path, routePath }: HandlerContext) { - path = slash(path) const routeBlock = await getRouteBlock(path, options) log(`added "${routePath}" for "${path}"`) if (routeBlock) log(routeBlock) @@ -111,7 +110,6 @@ export function createRoutesContext(options: ResolvedOptions) { } async function updatePage({ filePath: path, routePath }: HandlerContext) { - path = slash(path) log(`updated "${routePath}" for "${path}"`) const node = routeMap.get(path) if (!node) { @@ -124,7 +122,6 @@ export function createRoutesContext(options: ResolvedOptions) { } function removePage({ filePath: path, routePath }: HandlerContext) { - path = slash(path) log(`remove "${routePath}" for "${path}"`) routeTree.remove(routePath) routeMap.delete(path) From 3db88920f86efe2eaedf9cfc426f296b5f0f3475 Mon Sep 17 00:00:00 2001 From: markthree <1801982702@qq.com> Date: Tue, 16 Aug 2022 22:31:43 +0800 Subject: [PATCH 3/4] chore: move the location of the normalized path --- src/core/RoutesFolderWatcher.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/RoutesFolderWatcher.ts b/src/core/RoutesFolderWatcher.ts index efb0f7f87..d3c8cc22b 100644 --- a/src/core/RoutesFolderWatcher.ts +++ b/src/core/RoutesFolderWatcher.ts @@ -33,6 +33,7 @@ export class RoutesFolderWatcher { handler: (context: HandlerContext) => void ) { this.watcher.on(event, (filePath) => { + filePath = normalize(filePath) // skip other extensions if ( this.options.extensions.every( @@ -42,7 +43,7 @@ export class RoutesFolderWatcher { return } handler({ - filePath: normalize(filePath), + filePath, routePath: this.asRoutePath(filePath), }) }) From 1fe38effe49a95365a6f911d9b9f156c6026378a Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 16 Aug 2022 16:49:31 +0200 Subject: [PATCH 4/4] Update src/core/RoutesFolderWatcher.ts [skip ci] --- src/core/RoutesFolderWatcher.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/RoutesFolderWatcher.ts b/src/core/RoutesFolderWatcher.ts index d3c8cc22b..2f629eb73 100644 --- a/src/core/RoutesFolderWatcher.ts +++ b/src/core/RoutesFolderWatcher.ts @@ -33,6 +33,7 @@ export class RoutesFolderWatcher { handler: (context: HandlerContext) => void ) { this.watcher.on(event, (filePath) => { + // ensure consistent path for Windows and Unix filePath = normalize(filePath) // skip other extensions if (