1- import path from 'node:path' ;
2-
31import { isHtmlWiki } from '@/constants/fileNames' ;
42import type { IWikiWorkspace , IWorkspace } from './interface' ;
53import { WorkspaceType } from './workspaceType' ;
64
5+ function normalizePathSeparators ( filePath : string ) : string {
6+ return filePath . replace ( / \\ / g, '/' ) ;
7+ }
8+
9+ function dirname ( filePath : string ) : string {
10+ const normalized = normalizePathSeparators ( filePath ) . replace ( / \/ + $ / , '' ) ;
11+ const separatorIndex = normalized . lastIndexOf ( '/' ) ;
12+ if ( separatorIndex <= 0 ) {
13+ return normalized ;
14+ }
15+ return normalized . slice ( 0 , separatorIndex ) ;
16+ }
17+
18+ function basename ( filePath : string ) : string {
19+ const normalized = normalizePathSeparators ( filePath ) . replace ( / \/ + $ / , '' ) ;
20+ return normalized . slice ( normalized . lastIndexOf ( '/' ) + 1 ) ;
21+ }
22+
723/** Local guard to avoid runtime circular import with interface.ts */
824function isWikiWorkspace ( workspace : IWorkspace ) : workspace is IWikiWorkspace {
925 return 'wikiFolderLocation' in workspace ;
@@ -61,7 +77,7 @@ export function getHtmlFileLocation(workspace: IWikiWorkspace): string | undefin
6177 */
6278export function getWorkspaceContainerPath ( workspace : IWikiWorkspace ) : string {
6379 if ( isHtmlWikiWorkspace ( workspace ) ) {
64- return path . dirname ( workspace . htmlFileLocation ) ;
80+ return dirname ( workspace . htmlFileLocation ) ;
6581 }
6682 return workspace . wikiFolderLocation ;
6783}
@@ -81,9 +97,9 @@ export function getWorkspaceGitScope(workspace: IWorkspace): IWorkspaceGitScope
8197 return undefined ;
8298 }
8399 if ( isHtmlWikiWorkspace ( workspace ) ) {
84- const managedAbsolutePath = path . resolve ( workspace . htmlFileLocation ) ;
85- const repoPath = path . dirname ( managedAbsolutePath ) ;
86- const managedRelativePath = path . basename ( managedAbsolutePath ) ;
100+ const managedAbsolutePath = normalizePathSeparators ( workspace . htmlFileLocation ) ;
101+ const repoPath = dirname ( managedAbsolutePath ) ;
102+ const managedRelativePath = basename ( managedAbsolutePath ) ;
87103 return {
88104 repoPath,
89105 managedRelativePath,
@@ -92,19 +108,19 @@ export function getWorkspaceGitScope(workspace: IWorkspace): IWorkspaceGitScope
92108 } ;
93109 }
94110 return {
95- repoPath : path . resolve ( workspace . wikiFolderLocation ) ,
96- managedAbsolutePath : path . resolve ( workspace . wikiFolderLocation ) ,
97- managedDisplayName : path . basename ( workspace . wikiFolderLocation ) ,
111+ repoPath : normalizePathSeparators ( workspace . wikiFolderLocation ) ,
112+ managedAbsolutePath : normalizePathSeparators ( workspace . wikiFolderLocation ) ,
113+ managedDisplayName : basename ( workspace . wikiFolderLocation ) ,
98114 } ;
99115}
100116
101117export function normalizeHtmlWorkspacePaths ( htmlFileLocation : string ) : Pick < IHtmlWikiWorkspace , 'htmlFileLocation' | 'wikiFolderLocation' > {
102- const resolvedHtml = path . resolve ( htmlFileLocation ) ;
118+ const resolvedHtml = normalizePathSeparators ( htmlFileLocation ) ;
103119 if ( ! isHtmlWiki ( resolvedHtml ) ) {
104120 throw new Error ( `Not a valid HTML wiki file: ${ resolvedHtml } ` ) ;
105121 }
106122 return {
107123 htmlFileLocation : resolvedHtml ,
108- wikiFolderLocation : path . dirname ( resolvedHtml ) ,
124+ wikiFolderLocation : dirname ( resolvedHtml ) ,
109125 } ;
110126}
0 commit comments