diff --git a/extension/src/cli/git/executor.test.ts b/extension/src/cli/git/executor.test.ts index 7e1b129e70..cb419fc697 100644 --- a/extension/src/cli/git/executor.test.ts +++ b/extension/src/cli/git/executor.test.ts @@ -39,7 +39,7 @@ describe('GitExecutor', () => { } as unknown as EventEmitter }) - const cwd = standardizePath(__dirname) as string + const cwd = standardizePath(__dirname) describe('pushBranch', () => { it('should call createProcess with the correct parameters to push a branch', async () => { diff --git a/extension/src/cli/git/index.ts b/extension/src/cli/git/index.ts index d8be852428..efcc07adea 100644 --- a/extension/src/cli/git/index.ts +++ b/extension/src/cli/git/index.ts @@ -7,6 +7,6 @@ export class GitCli extends Cli { public async getGitRepositoryRoot(cwd: string) { const options = getOptions(cwd, Command.REV_PARSE, Flag.SHOW_TOPLEVEL) - return standardizePath(await this.executeProcess(options)) as string + return standardizePath(await this.executeProcess(options)) } } diff --git a/extension/src/experiments/columns/collect/index.ts b/extension/src/experiments/columns/collect/index.ts index 182430bb28..2faa836df5 100644 --- a/extension/src/experiments/columns/collect/index.ts +++ b/extension/src/experiments/columns/collect/index.ts @@ -77,6 +77,6 @@ export const collectParamsFiles = ( ): Set => { const files = Object.keys(data.workspace.baseline.data?.params || {}) .filter(Boolean) - .map(file => standardizePath(join(dvcRoot, file))) as string[] + .map(file => standardizePath(join(dvcRoot, file))) return new Set(files) } diff --git a/extension/src/experiments/context.ts b/extension/src/experiments/context.ts index 0245c5b57b..20a78776d8 100644 --- a/extension/src/experiments/context.ts +++ b/extension/src/experiments/context.ts @@ -1,7 +1,7 @@ import { Event, EventEmitter, window } from 'vscode' import { Disposable, Disposer } from '@hediet/std/disposable' import { setContextValue } from '../vscode/context' -import { standardizePath } from '../fileSystem/path' +import { standardizePossiblePath } from '../fileSystem/path' const setContextOnDidChangeParamsFiles = ( setActiveEditorContext: (paramsFileActive: boolean) => void, @@ -9,7 +9,9 @@ const setContextOnDidChangeParamsFiles = ( getParamsFiles: () => Set ): Disposable => onDidChangeColumns(() => { - const path = standardizePath(window.activeTextEditor?.document.fileName) + const path = standardizePossiblePath( + window.activeTextEditor?.document.fileName + ) if (!path) { return } @@ -26,7 +28,7 @@ const setContextOnDidChangeActiveEditor = ( getParamsFiles: () => Set ): Disposable => window.onDidChangeActiveTextEditor(event => { - const path = standardizePath(event?.document.fileName) + const path = standardizePossiblePath(event?.document.fileName) if (!path) { setActiveEditorContext(false) return diff --git a/extension/src/fileSystem/index.ts b/extension/src/fileSystem/index.ts index efbb3e4da1..0be02af222 100644 --- a/extension/src/fileSystem/index.ts +++ b/extension/src/fileSystem/index.ts @@ -38,7 +38,7 @@ export const findDvcSubRootPaths = async ( return children .filter(child => isDirectory(join(cwd, child, '.dvc'))) - .map(child => standardizePath(join(cwd, child)) as string) + .map(child => standardizePath(join(cwd, child))) } export const findDvcRootPaths = async (cwd: string): Promise => { @@ -59,7 +59,7 @@ export const findAbsoluteDvcRootPath = async ( return [] } - const absoluteRoot = standardizePath(resolve(cwd, relativePath)) as string + const absoluteRoot = standardizePath(resolve(cwd, relativePath)) return [absoluteRoot] } diff --git a/extension/src/fileSystem/path.ts b/extension/src/fileSystem/path.ts index 71111a339a..adaeac0e5c 100644 --- a/extension/src/fileSystem/path.ts +++ b/extension/src/fileSystem/path.ts @@ -1,8 +1,10 @@ import { Uri } from 'vscode' -export const standardizePath = (path?: string): string | undefined => { +export const standardizePath = (path: string): string => Uri.file(path).fsPath + +export const standardizePossiblePath = (path?: string): string | undefined => { if (!path) { return } - return Uri.file(path).fsPath + return standardizePath(path) } diff --git a/extension/src/repository/sourceControlManagement/decorationProvider.test.ts b/extension/src/repository/sourceControlManagement/decorationProvider.test.ts index 55c03e7f38..8df714446a 100644 --- a/extension/src/repository/sourceControlManagement/decorationProvider.test.ts +++ b/extension/src/repository/sourceControlManagement/decorationProvider.test.ts @@ -25,15 +25,15 @@ beforeEach(() => { describe('DecorationProvider', () => { const dvcRoot = __dirname - const model = standardizePath(join(dvcRoot, 'model.pt')) as string - const dataDir = standardizePath(join(dvcRoot, 'data')) as string - const features = standardizePath(join(dataDir, 'features')) as string - const logDir = standardizePath(join(dvcRoot, 'logs')) as string - const logAcc = standardizePath(join(logDir, 'acc.tsv')) as string - const logLoss = standardizePath(join(logDir, 'loss.tsv')) as string - const dataXml = standardizePath(join(dataDir, 'data.xml')) as string - const dataCsv = standardizePath(join(dataDir, 'data.csv')) as string - const prepared = standardizePath(join(dataDir, 'prepared')) as string + const model = standardizePath(join(dvcRoot, 'model.pt')) + const dataDir = standardizePath(join(dvcRoot, 'data')) + const features = standardizePath(join(dataDir, 'features')) + const logDir = standardizePath(join(dvcRoot, 'logs')) + const logAcc = standardizePath(join(logDir, 'acc.tsv')) + const logLoss = standardizePath(join(logDir, 'loss.tsv')) + const dataXml = standardizePath(join(dataDir, 'data.xml')) + const dataCsv = standardizePath(join(dataDir, 'data.csv')) + const prepared = standardizePath(join(dataDir, 'prepared')) const emptySet = new Set() diff --git a/extension/src/test/suite/fileSystem/index.test.ts b/extension/src/test/suite/fileSystem/index.test.ts index 3bba05f86e..7688f8def0 100644 --- a/extension/src/test/suite/fileSystem/index.test.ts +++ b/extension/src/test/suite/fileSystem/index.test.ts @@ -27,7 +27,7 @@ suite('File System Watcher Test Suite', () => { const root = await reader.getGitRepositoryRoot(__dirname) const submoduleDotGit = standardizePath( resolve(root, gitPath.DOT_GIT, 'modules', 'demo') - ) as string + ) const dotGitPath = getGitPath(dvcDemoPath, gitPath.DOT_GIT) expect(dotGitPath).to.equal(submoduleDotGit) @@ -39,9 +39,7 @@ suite('File System Watcher Test Suite', () => { it('should get the expected paths for this project', async () => { const reader = disposable.track(new GitReader()) const root = await reader.getGitRepositoryRoot(__dirname) - const rootDotGit = standardizePath( - resolve(root, gitPath.DOT_GIT) - ) as string + const rootDotGit = standardizePath(resolve(root, gitPath.DOT_GIT)) const dotGitPath = getGitPath(root, gitPath.DOT_GIT) expect(dotGitPath).to.equal(rootDotGit)