diff --git a/src/annotations/fileAnnotationController.ts b/src/annotations/fileAnnotationController.ts index 8fbdea4..e5fd34f 100644 --- a/src/annotations/fileAnnotationController.ts +++ b/src/annotations/fileAnnotationController.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { basename } from 'path'; import { ConfigurationChangeEvent, DecorationRangeBehavior, @@ -534,7 +534,7 @@ export class FileAnnotationController implements Disposable { } progress.report({ - message: `Computing ${annotationsLabel} for ${paths.basename(editor.document.fileName)}`, + message: `Computing ${annotationsLabel} for ${basename(editor.document.fileName)}`, }); } diff --git a/src/commands/browseRepoAtRevision.ts b/src/commands/browseRepoAtRevision.ts index d11bd97..41b440b 100644 --- a/src/commands/browseRepoAtRevision.ts +++ b/src/commands/browseRepoAtRevision.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { basename } from 'path'; import { commands, TextEditor, Uri } from 'vscode'; import { BuiltInCommands } from '../constants'; import { Container } from '../container'; @@ -73,7 +73,7 @@ export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand { openWorkspace(uri, { location: args.openInNewWindow ? OpenWorkspaceLocation.NewWindow : OpenWorkspaceLocation.AddToWorkspace, - name: `${paths.basename(gitUri.repoPath!)} @ ${gitUri.shortSha}`, + name: `${basename(gitUri.repoPath!)} @ ${gitUri.shortSha}`, }); if (!args.openInNewWindow) { diff --git a/src/commands/common.ts b/src/commands/common.ts index 7709423..001e72b 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { extname } from 'path'; import { commands, Disposable, @@ -715,7 +715,7 @@ export async function openEditor( uri = uri.documentUri(); } - if (uri.scheme === DocumentSchemes.GitLens && ImageMimetypes[paths.extname(uri.fsPath)]) { + if (uri.scheme === DocumentSchemes.GitLens && ImageMimetypes[extname(uri.fsPath)]) { await commands.executeCommand(BuiltInCommands.Open, uri); return undefined; diff --git a/src/commands/diffWith.ts b/src/commands/diffWith.ts index 905e740..7dd7ebf 100644 --- a/src/commands/diffWith.ts +++ b/src/commands/diffWith.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { basename } from 'path'; import { commands, Range, TextDocumentShowOptions, Uri, ViewColumn } from 'vscode'; import { BuiltInCommands, GlyphChars } from '../constants'; import { Container } from '../container'; @@ -147,10 +147,10 @@ export class DiffWithCommand extends Command { } if (args.lhs.title == null && (lhs != null || lhsSuffix.length !== 0)) { - args.lhs.title = `${paths.basename(args.lhs.uri.fsPath)}${lhsSuffix ? ` (${lhsSuffix})` : ''}`; + args.lhs.title = `${basename(args.lhs.uri.fsPath)}${lhsSuffix ? ` (${lhsSuffix})` : ''}`; } if (args.rhs.title == null) { - args.rhs.title = `${paths.basename(args.rhs.uri.fsPath)}${rhsSuffix ? ` (${rhsSuffix})` : ''}`; + args.rhs.title = `${basename(args.rhs.uri.fsPath)}${rhsSuffix ? ` (${rhsSuffix})` : ''}`; } const title = diff --git a/src/commands/diffWithRevisionFrom.ts b/src/commands/diffWithRevisionFrom.ts index ce437ed..9bda508 100644 --- a/src/commands/diffWithRevisionFrom.ts +++ b/src/commands/diffWithRevisionFrom.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { basename, relative } from 'path'; import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode'; import { GlyphChars, quickPickTitleMaxChars } from '../constants'; import { Container } from '../container'; @@ -42,7 +42,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand { let ref; let sha; if (args?.stash) { - const fileName = Strings.normalizePath(paths.relative(gitUri.repoPath, gitUri.fsPath)); + const fileName = Strings.normalizePath(relative(gitUri.repoPath, gitUri.fsPath)); const title = `Open Changes with Stash${Strings.pad(GlyphChars.Dot, 2, 2)}`; const pick = await StashPicker.show( @@ -83,11 +83,11 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand { // Check to see if this file has been renamed const files = await Container.instance.git.getDiffStatus(gitUri.repoPath, 'HEAD', ref, { filters: ['R', 'C'] }); if (files != null) { - const fileName = Strings.normalizePath(paths.relative(gitUri.repoPath, gitUri.fsPath)); + const fileName = Strings.normalizePath(relative(gitUri.repoPath, gitUri.fsPath)); const rename = files.find(s => s.fileName === fileName); if (rename?.originalFileName != null) { renamedUri = GitUri.resolveToUri(rename.originalFileName, gitUri.repoPath); - renamedTitle = `${paths.basename(rename.originalFileName)} (${GitRevision.shorten(ref)})`; + renamedTitle = `${basename(rename.originalFileName)} (${GitRevision.shorten(ref)})`; } } @@ -96,7 +96,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand { lhs: { sha: sha, uri: renamedUri ?? gitUri, - title: renamedTitle ?? `${paths.basename(gitUri.fsPath)} (${GitRevision.shorten(ref)})`, + title: renamedTitle ?? `${basename(gitUri.fsPath)} (${GitRevision.shorten(ref)})`, }, rhs: { sha: '', diff --git a/src/commands/openFileAtRevisionFrom.ts b/src/commands/openFileAtRevisionFrom.ts index dc06857..1fc26cc 100644 --- a/src/commands/openFileAtRevisionFrom.ts +++ b/src/commands/openFileAtRevisionFrom.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { relative } from 'path'; import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode'; import { FileAnnotationType } from '../configuration'; import { GlyphChars, quickPickTitleMaxChars } from '../constants'; @@ -44,7 +44,7 @@ export class OpenFileAtRevisionFromCommand extends ActiveEditorCommand { if (args.reference == null) { if (args?.stash) { - const fileName = Strings.normalizePath(paths.relative(gitUri.repoPath, gitUri.fsPath)); + const fileName = Strings.normalizePath(relative(gitUri.repoPath, gitUri.fsPath)); const title = `Open Changes with Stash${Strings.pad(GlyphChars.Dot, 2, 2)}`; const pick = await StashPicker.show( diff --git a/src/env/node/git/git.ts b/src/env/node/git/git.ts index 8814fae..3c29f04 100644 --- a/src/env/node/git/git.ts +++ b/src/env/node/git/git.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ 'use strict'; -import * as paths from 'path'; +import { dirname, isAbsolute, join as joinPaths } from 'path'; import { Uri, window, workspace } from 'vscode'; import { hrtime } from '@env/hrtime'; import { GlyphChars } from '../../../constants'; @@ -250,8 +250,8 @@ export namespace Git { let supported = await Git.isAtLeastVersion('2.23'); if (supported) { let ignoreRevsFile = params[index + 1]; - if (!paths.isAbsolute(ignoreRevsFile)) { - ignoreRevsFile = paths.join(repoPath ?? emptyStr, ignoreRevsFile); + if (!isAbsolute(ignoreRevsFile)) { + ignoreRevsFile = joinPaths(repoPath ?? emptyStr, ignoreRevsFile); } const exists = ignoreRevsFileMap.get(ignoreRevsFile); @@ -852,7 +852,7 @@ export namespace Git { if (format !== 'refs') { if (startLine == null) { // If this is the log of a folder, use `--name-status` to match non-file logs (for parsing) - if (format === 'simple' || isFolderGlob(file)) { + if (format === 'simple' || Paths.isFolderGlob(file)) { params.push('--name-status'); } else { params.push('--numstat', '--summary'); @@ -1258,7 +1258,7 @@ export namespace Git { let exists = inDotGit ? false : await fsExists(cwd); if (!exists) { do { - const parent = paths.dirname(cwd); + const parent = dirname(cwd); if (parent === cwd || parent.length === 0) return undefined; cwd = parent; @@ -1521,7 +1521,7 @@ export namespace Git { options?: { numeric?: boolean; throw?: boolean; trim?: boolean }, ): Promise { try { - const bytes = await workspace.fs.readFile(Uri.file(paths.join(...[repoPath, '.git', ...pathParts]))); + const bytes = await workspace.fs.readFile(Uri.file(joinPaths(...[repoPath, '.git', ...pathParts]))); let contents = textDecoder.decode(bytes); contents = options?.trim ?? true ? contents.trim() : contents; @@ -1538,7 +1538,3 @@ export namespace Git { } } } - -export function isFolderGlob(path: string) { - return paths.basename(path) === '*'; -} diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 98b67a8..09079dc 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -1,7 +1,7 @@ 'use strict'; -import * as fs from 'fs'; -import * as os from 'os'; -import * as paths from 'path'; +import { readdir, realpath, stat, Stats } from 'fs'; +import { hostname, userInfo } from 'os'; +import { dirname, relative, resolve as resolvePath } from 'path'; import { Disposable, env, @@ -100,7 +100,7 @@ import { GitDocumentState, TrackedDocument, } from '../../../trackers/gitDocumentTracker'; -import { Git, GitErrors, isFolderGlob, maxGitCliLength } from './git'; +import { Git, GitErrors, maxGitCliLength } from './git'; import { findGitPath, GitLocation, InvalidGitConfigError, UnableToFindGitError } from './locator'; import { fsExists, RunError } from './shell'; @@ -393,7 +393,7 @@ export class LocalGitProvider implements GitProvider, Disposable { } for (let p of repoPaths) { - p = paths.dirname(p); + p = dirname(p); // If we are the same as the root, skip it if (Strings.normalizePath(p) === rootPath) continue; @@ -420,7 +420,7 @@ export class LocalGitProvider implements GitProvider, Disposable { const cc = Logger.getCorrelationContext(); return new Promise((resolve, reject) => { - fs.readdir(root, { withFileTypes: true }, async (err, files) => { + readdir(root, { withFileTypes: true }, async (err, files) => { if (err != null) { reject(err); return; @@ -438,10 +438,10 @@ export class LocalGitProvider implements GitProvider, Disposable { if (!f.isDirectory()) continue; if (f.name === '.git') { - repositories.push(paths.resolve(root, f.name)); + repositories.push(resolvePath(root, f.name)); } else if (depth >= 0 && excludes[f.name] !== true) { try { - await this.repositorySearchCore(paths.resolve(root, f.name), depth, excludes, repositories); + await this.repositorySearchCore(resolvePath(root, f.name), depth, excludes, repositories); } catch (ex) { Logger.error(ex, cc, 'FAILED'); } @@ -1299,7 +1299,7 @@ export class LocalGitProvider implements GitProvider, Disposable { } while (true); } else { user.name = - process.env.GIT_AUTHOR_NAME || process.env.GIT_COMMITTER_NAME || os.userInfo()?.username || undefined; + process.env.GIT_AUTHOR_NAME || process.env.GIT_COMMITTER_NAME || userInfo()?.username || undefined; if (!user.name) { // If we found no user data, mark it so we won't bother trying again this._userMapCache.set(repoPath, null); @@ -1310,7 +1310,7 @@ export class LocalGitProvider implements GitProvider, Disposable { process.env.GIT_AUTHOR_EMAIL || process.env.GIT_COMMITTER_EMAIL || process.env.EMAIL || - `${user.name}@${os.hostname()}`; + `${user.name}@${hostname()}`; } const author = `${user.name} <${user.email}>`; @@ -2130,7 +2130,7 @@ export class LocalGitProvider implements GitProvider, Disposable { const log = GitLogParser.parse( data, // If this is the log of a folder, parse it as a normal log rather than a file log - isFolderGlob(file) ? GitCommitType.Log : GitCommitType.LogFile, + Paths.isFolderGlob(file) ? GitCommitType.Log : GitCommitType.LogFile, root, file, ref, @@ -3056,10 +3056,10 @@ export class LocalGitProvider implements GitProvider, Disposable { if (isDirectory) { path = filePath; } else { - const stat = await new Promise(resolve => - fs.stat(filePath, (err, stat) => resolve(err == null ? stat : undefined)), + const stats = await new Promise(resolve => + stat(filePath, (err, stats) => resolve(err == null ? stats : undefined)), ); - path = stat?.isDirectory() ? filePath : paths.dirname(filePath); + path = stats?.isDirectory() ? filePath : dirname(filePath); } repoPath = await Git.rev_parse__show_toplevel(path); @@ -3078,7 +3078,7 @@ export class LocalGitProvider implements GitProvider, Disposable { try { const networkPath = await new Promise(resolve => - fs.realpath.native(`${letter}:\\`, { encoding: 'utf8' }, (err, resolvedPath) => + realpath.native(`${letter}:\\`, { encoding: 'utf8' }, (err, resolvedPath) => resolve(err != null ? undefined : resolvedPath), ), ); @@ -3103,7 +3103,7 @@ export class LocalGitProvider implements GitProvider, Disposable { // If we are not on Windows (symlinks don't seem to have the same issue on Windows), check if we are a symlink and if so, use the symlink path (not its resolved path) // This is because VS Code will provide document Uris using the symlinked path repoPath = await new Promise(resolve => { - fs.realpath(path, { encoding: 'utf8' }, (err, resolvedPath) => { + realpath(path, { encoding: 'utf8' }, (err, resolvedPath) => { if (err != null) { Logger.debug(cc, `fs.realpath failed; repoPath=${repoPath}`); resolve(repoPath); @@ -3616,7 +3616,7 @@ export class LocalGitProvider implements GitProvider, Disposable { const fileName = typeof fileNameOrUri === 'string' ? fileNameOrUri - : Strings.normalizePath(paths.relative(repoPath, fileNameOrUri.fsPath)); + : Strings.normalizePath(relative(repoPath, fileNameOrUri.fsPath)); const blob = await Git.rev_parse__verify(repoPath, ref, fileName); if (blob == null) return GitRevision.deletedOrMissing; diff --git a/src/env/node/git/locator.ts b/src/env/node/git/locator.ts index b471f63..909be21 100644 --- a/src/env/node/git/locator.ts +++ b/src/env/node/git/locator.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { join as joinPaths } from 'path'; import { GlyphChars } from '../../../constants'; import { LogLevel } from '../../../logger'; import { Stopwatch } from '../../../system'; @@ -93,7 +93,7 @@ async function findGitDarwin(): Promise { function findSystemGitWin32(basePath: string | null | undefined): Promise { if (basePath == null || basePath.length === 0) return Promise.reject(new UnableToFindGitError()); - return findSpecificGit(paths.join(basePath, 'Git', 'cmd', 'git.exe')); + return findSpecificGit(joinPaths(basePath, 'Git', 'cmd', 'git.exe')); } function findGitWin32(): Promise { diff --git a/src/env/node/git/shell.ts b/src/env/node/git/shell.ts index 7687503..5667b7d 100644 --- a/src/env/node/git/shell.ts +++ b/src/env/node/git/shell.ts @@ -1,8 +1,8 @@ 'use strict'; import { ExecException, execFile } from 'child_process'; -import * as fs from 'fs'; -import * as paths from 'path'; -import * as iconv from 'iconv-lite'; +import { exists, existsSync, Stats, statSync } from 'fs'; +import { join as joinPaths } from 'path'; +import { decode } from 'iconv-lite'; import { Logger } from '../../../logger'; export const isWindows = process.platform === 'win32'; @@ -28,9 +28,9 @@ function runDownPath(exe: string): string { // Files with any directory path don't get this applied if (slashesRegex.test(exe)) return exe; - const target = paths.join('.', exe); + const target = joinPaths('.', exe); try { - const stats = fs.statSync(target); + const stats = statSync(target); if (stats?.isFile() && isExecutable(stats)) return target; } catch {} @@ -39,9 +39,9 @@ function runDownPath(exe: string): string { const haystack = path.split(isWindows ? ';' : ':'); let stats; for (const p of haystack) { - const needle = paths.join(p, exe); + const needle = joinPaths(p, exe); try { - stats = fs.statSync(needle); + stats = statSync(needle); if (stats?.isFile() && isExecutable(stats)) return needle; } catch {} } @@ -50,7 +50,7 @@ function runDownPath(exe: string): string { return exe; } -function isExecutable(stats: fs.Stats) { +function isExecutable(stats: Stats) { if (isWindows) return true; const isGroup = stats.gid ? process.getgid != null && stats.gid === process.getgid() : true; @@ -72,7 +72,7 @@ export function findExecutable(exe: string, args: string[]): { cmd: string; args // POSIX can just execute scripts directly, no need for silly goosery if (!isWindows) return { cmd: runDownPath(exe), args: args }; - if (!fs.existsSync(exe)) { + if (!existsSync(exe)) { // NB: When you write something like `surf-client ... -- surf-build` on Windows, // a shell would normally convert that to surf-build.cmd, but since it's passed // in as an argument, it doesn't happen @@ -80,12 +80,12 @@ export function findExecutable(exe: string, args: string[]): { cmd: string; args for (const ext of possibleExts) { const possibleFullPath = runDownPath(`${exe}${ext}`); - if (fs.existsSync(possibleFullPath)) return findExecutable(possibleFullPath, args); + if (existsSync(possibleFullPath)) return findExecutable(possibleFullPath, args); } } if (ps1Regex.test(exe)) { - const cmd = paths.join( + const cmd = joinPaths( process.env.SYSTEMROOT ?? 'C:\\WINDOWS', 'System32', 'WindowsPowerShell', @@ -98,7 +98,7 @@ export function findExecutable(exe: string, args: string[]): { cmd: string; args } if (batOrCmdRegex.test(exe)) { - const cmd = paths.join(process.env.SYSTEMROOT ?? 'C:\\WINDOWS', 'System32', 'cmd.exe'); + const cmd = joinPaths(process.env.SYSTEMROOT ?? 'C:\\WINDOWS', 'System32', 'cmd.exe'); const cmdArgs = ['/C', exe, ...args]; return { cmd: cmd, args: cmdArgs }; @@ -191,10 +191,10 @@ export function run( error, encoding === 'utf8' || encoding === 'binary' || encoding === 'buffer' ? stdout - : iconv.decode(Buffer.from(stdout, 'binary'), encoding), + : decode(Buffer.from(stdout, 'binary'), encoding), encoding === 'utf8' || encoding === 'binary' || encoding === 'buffer' ? stderr - : iconv.decode(Buffer.from(stderr, 'binary'), encoding), + : decode(Buffer.from(stderr, 'binary'), encoding), ), ); @@ -208,7 +208,7 @@ export function run( resolve( encoding === 'utf8' || encoding === 'binary' || encoding === 'buffer' ? (stdout as TOut) - : (iconv.decode(Buffer.from(stdout, 'binary'), encoding) as TOut), + : (decode(Buffer.from(stdout, 'binary'), encoding) as TOut), ); }); @@ -219,5 +219,5 @@ export function run( } export function fsExists(path: string) { - return new Promise(resolve => fs.exists(path, exists => resolve(exists))); + return new Promise(resolve => exists(path, exists => resolve(exists))); } diff --git a/src/git/formatters/statusFormatter.ts b/src/git/formatters/statusFormatter.ts index f3958e3..d360713 100644 --- a/src/git/formatters/statusFormatter.ts +++ b/src/git/formatters/statusFormatter.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { basename } from 'path'; import { GlyphChars } from '../../constants'; import { Strings } from '../../system'; import { GitFile, GitFileWithCommit } from '../models/file'; @@ -26,7 +26,7 @@ export class StatusFileFormatter extends Formatter } get file() { - const file = paths.basename(this._item.fileName); + const file = basename(this._item.fileName); return this._padOrTruncate(file, this._options.tokenOptions.file); } diff --git a/src/git/fsProvider.ts b/src/git/fsProvider.ts index e8763ae..7adf540 100644 --- a/src/git/fsProvider.ts +++ b/src/git/fsProvider.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { relative } from 'path'; import { Disposable, Event, @@ -70,7 +70,7 @@ export class GitFileSystemProvider implements FileSystemProvider, Disposable { const items = [ ...Iterables.map(tree, t => [ - path != null && path.length !== 0 ? Strings.normalizePath(paths.relative(path, t.path)) : t.path, + path != null && path.length !== 0 ? Strings.normalizePath(relative(path, t.path)) : t.path, typeToFileType(t.type), ]), ]; diff --git a/src/git/gitUri.ts b/src/git/gitUri.ts index f4e1708..7394d33 100644 --- a/src/git/gitUri.ts +++ b/src/git/gitUri.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { basename, dirname, isAbsolute, join as joinPaths, relative } from 'path'; import { Uri } from 'vscode'; import { UriComparer } from '../comparers'; import { DocumentSchemes } from '../constants'; @@ -140,7 +140,7 @@ export class GitUri extends (Uri as any as UriEx) { @memoize() get fileName(): string { - return paths.basename(this.relativeFsPath); + return basename(this.relativeFsPath); } @memoize() @@ -155,9 +155,7 @@ export class GitUri extends (Uri as any as UriEx) { @memoize() private get relativeFsPath() { - return this.repoPath == null || this.repoPath.length === 0 - ? this.fsPath - : paths.relative(this.repoPath, this.fsPath); + return this.repoPath == null || this.repoPath.length === 0 ? this.fsPath : relative(this.repoPath, this.fsPath); } @memoize() @@ -325,7 +323,7 @@ export class GitUri extends (Uri as any as UriEx) { } static getDirectory(fileName: string, relativeTo?: string): string { - let directory: string | undefined = paths.dirname(fileName); + let directory: string | undefined = dirname(fileName); directory = relativeTo != null ? GitUri.relativeTo(directory, relativeTo) : Strings.normalizePath(directory); return directory == null || directory.length === 0 || directory === '.' ? emptyStr : directory; } @@ -346,7 +344,7 @@ export class GitUri extends (Uri as any as UriEx) { fileName = fileNameOrUri; } - let file = paths.basename(fileName); + let file = basename(fileName); if (truncateTo != null && file.length >= truncateTo) { return Strings.truncateMiddle(file, truncateTo); } @@ -379,7 +377,7 @@ export class GitUri extends (Uri as any as UriEx) { fileName = fileNameOrUri; } - let file = paths.basename(fileName); + let file = basename(fileName); if (truncateTo != null && file.length >= truncateTo) { return Strings.truncateMiddle(file, truncateTo); } @@ -407,9 +405,9 @@ export class GitUri extends (Uri as any as UriEx) { static relativeTo(fileNameOrUri: string | Uri, relativeTo: string | undefined): string { const fileName = fileNameOrUri instanceof Uri ? fileNameOrUri.fsPath : fileNameOrUri; const relativePath = - relativeTo == null || relativeTo.length === 0 || !paths.isAbsolute(fileName) + relativeTo == null || relativeTo.length === 0 || !isAbsolute(fileName) ? fileName - : paths.relative(relativeTo, fileName); + : relative(relativeTo, fileName); return Strings.normalizePath(relativePath); } @@ -436,7 +434,7 @@ export class GitUri extends (Uri as any as UriEx) { if (normalizedFileName.startsWith(normalizedRepoPath)) return normalizedFileName; - return Strings.normalizePath(paths.join(normalizedRepoPath, normalizedFileName)); + return Strings.normalizePath(joinPaths(normalizedRepoPath, normalizedFileName)); } static resolveToUri(fileName: string, repoPath?: string) { diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index 2a29ea7..64bee62 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { basename, join as joinPaths, relative } from 'path'; import { commands, ConfigurationChangeEvent, @@ -217,14 +217,14 @@ export class Repository implements Disposable { suspended: boolean, closed: boolean = false, ) { - const relativePath = paths.relative(folder.uri.fsPath, path); + const relativePath = relative(folder.uri.fsPath, path); if (root) { // Check if the repository is not contained by a workspace folder const repoFolder = workspace.getWorkspaceFolder(GitUri.fromRepoPath(path)); if (repoFolder == null) { // If it isn't within a workspace folder we can't get change events, see: https://github.com/Microsoft/vscode/issues/3025 this._supportsChangeEvents = false; - this.formattedName = this.name = paths.basename(path); + this.formattedName = this.name = basename(path); } else { this.formattedName = this.name = folder.name; } @@ -582,7 +582,7 @@ export class Repository implements Disposable { } try { - const stat = await workspace.fs.stat(Uri.file(paths.join(this.path, '.git/FETCH_HEAD'))); + const stat = await workspace.fs.stat(Uri.file(joinPaths(this.path, '.git/FETCH_HEAD'))); // If the file is empty, assume the fetch failed, and don't update the timestamp if (stat.size > 0) { this._lastFetched = stat.mtime; diff --git a/src/git/parsers/blameParser.ts b/src/git/parsers/blameParser.ts index ac7d1d4..36572ee 100644 --- a/src/git/parsers/blameParser.ts +++ b/src/git/parsers/blameParser.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { relative } from 'path'; import { debug, Strings } from '../../system'; import { GitAuthor, GitBlame, GitBlameCommit, GitCommitLine, GitRevision, GitUser } from '../models'; @@ -131,7 +131,7 @@ export class GitBlameParser { emptyStr, ), ); - relativeFileName = Strings.normalizePath(paths.relative(repoPath, fileName)); + relativeFileName = Strings.normalizePath(relative(repoPath, fileName)); } else { relativeFileName = entry.fileName; } diff --git a/src/git/parsers/logParser.ts b/src/git/parsers/logParser.ts index 4fd9f3a..9f1c3c1 100644 --- a/src/git/parsers/logParser.ts +++ b/src/git/parsers/logParser.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { relative } from 'path'; import { Range } from 'vscode'; import { Arrays, debug, Strings } from '../../system'; import { @@ -346,7 +346,7 @@ export class GitLogParser { emptyStr, ), ); - relativeFileName = Strings.normalizePath(paths.relative(repoPath, fileName)); + relativeFileName = Strings.normalizePath(relative(repoPath, fileName)); } else { relativeFileName = entry.fileName!; } diff --git a/src/quickpicks/commitQuickPickItems.ts b/src/quickpicks/commitQuickPickItems.ts index 89a455a..c785a20 100644 --- a/src/quickpicks/commitQuickPickItems.ts +++ b/src/quickpicks/commitQuickPickItems.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { basename } from 'path'; import { QuickPickItem, window } from 'vscode'; import { Commands, GitActions, OpenChangedFilesCommandArgs } from '../commands'; import { GlyphChars } from '../constants'; @@ -37,7 +37,7 @@ export class CommitFilesQuickPickItem extends CommandQuickPickItem { export class CommitFileQuickPickItem extends CommandQuickPickItem { constructor(readonly commit: GitLogCommit, readonly file: GitFile, picked?: boolean) { super({ - label: `${Strings.pad(GitFile.getStatusCodicon(file.status), 0, 2)}${paths.basename(file.fileName)}`, + label: `${Strings.pad(GitFile.getStatusCodicon(file.status), 0, 2)}${basename(file.fileName)}`, description: GitFile.getFormattedDirectory(file, true), picked: picked, }); diff --git a/src/system/path.ts b/src/system/path.ts index d87b2a0..e2602aa 100644 --- a/src/system/path.ts +++ b/src/system/path.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { basename, dirname } from 'path'; import { Uri } from 'vscode'; import { Strings } from '../system'; import { normalizePath } from './string'; @@ -74,6 +74,10 @@ export function isDescendent(uriOrPath: Uri | string, baseUriOrPath: Uri | strin ); } +export function isFolderGlob(path: string) { + return basename(path) === '*'; +} + export function splitPath(filePath: string, repoPath: string | undefined, extract: boolean = true): [string, string] { if (repoPath) { filePath = normalizePath(filePath); @@ -84,8 +88,8 @@ export function splitPath(filePath: string, repoPath: string | undefined, extrac filePath = filePath.substring(normalizedRepoPath.length); } } else { - repoPath = normalizePath(extract ? paths.dirname(filePath) : repoPath!); - filePath = normalizePath(extract ? paths.basename(filePath) : filePath); + repoPath = normalizePath(extract ? dirname(filePath) : repoPath!); + filePath = normalizePath(extract ? basename(filePath) : filePath); } return [filePath, repoPath]; diff --git a/src/views/nodes/branchTrackingStatusFilesNode.ts b/src/views/nodes/branchTrackingStatusFilesNode.ts index 30a0744..812571d 100644 --- a/src/views/nodes/branchTrackingStatusFilesNode.ts +++ b/src/views/nodes/branchTrackingStatusFilesNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { join as joinPaths } from 'path'; import { TreeItem, TreeItemCollapsibleState } from 'vscode'; import { ViewFilesLayout } from '../../configuration'; import { GitUri } from '../../git/gitUri'; @@ -84,7 +84,7 @@ export class BranchTrackingStatusFilesNode extends ViewNode { const hierarchy = Arrays.makeHierarchical( children, n => n.uri.relativePath.split('/'), - (...parts: string[]) => Strings.normalizePath(paths.join(...parts)), + (...parts: string[]) => Strings.normalizePath(joinPaths(...parts)), this.view.config.files.compact, ); diff --git a/src/views/nodes/commitFileNode.ts b/src/views/nodes/commitFileNode.ts index 7f16b9a..b911442 100644 --- a/src/views/nodes/commitFileNode.ts +++ b/src/views/nodes/commitFileNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { dirname, join as joinPaths } from 'path'; import { Command, Selection, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode'; import { Commands, DiffWithPreviousCommandArgs } from '../../commands'; import { StatusFileFormatter } from '../../git/formatters'; @@ -69,8 +69,8 @@ export class CommitFileNode n.uri.relativePath.split('/'), - (...parts: string[]) => Strings.normalizePath(paths.join(...parts)), + (...parts: string[]) => Strings.normalizePath(joinPaths(...parts)), this.view.config.files.compact, ); diff --git a/src/views/nodes/fileHistoryNode.ts b/src/views/nodes/fileHistoryNode.ts index 6d9d261..6d5c67e 100644 --- a/src/views/nodes/fileHistoryNode.ts +++ b/src/views/nodes/fileHistoryNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { basename, join as joinPaths } from 'path'; import { Disposable, TreeItem, TreeItemCollapsibleState, window } from 'vscode'; import { configuration } from '../../configuration'; import { GitUri } from '../../git/gitUri'; @@ -151,7 +151,7 @@ export class FileHistoryNode extends SubscribeableViewNode impl get label() { // Check if this is a base folder if (this.folder && this.uri.fileName === '') { - return `${paths.basename(this.uri.fsPath)}${ + return `${basename(this.uri.fsPath)}${ this.uri.sha ? ` ${this.uri.sha === GitRevision.deletedOrMissing ? this.uri.shortSha : `(${this.uri.shortSha})`}` : '' @@ -242,7 +242,7 @@ export class FileHistoryNode extends SubscribeableViewNode impl @memoize() private getPathOrGlob() { - return this.folder ? paths.join(this.uri.fsPath, '*') : this.uri.fsPath; + return this.folder ? joinPaths(this.uri.fsPath, '*') : this.uri.fsPath; } get hasMore() { diff --git a/src/views/nodes/fileRevisionAsCommitNode.ts b/src/views/nodes/fileRevisionAsCommitNode.ts index afd49c9..b4d5264 100644 --- a/src/views/nodes/fileRevisionAsCommitNode.ts +++ b/src/views/nodes/fileRevisionAsCommitNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { join as joinPaths } from 'path'; import { Command, MarkdownString, @@ -120,8 +120,8 @@ export class FileRevisionAsCommitNode extends ViewRefFileNode implements private _folderName: string | undefined; get folderName() { if (this._folderName == null) { - this._folderName = paths.dirname(this.uri.relativePath); + this._folderName = dirname(this.uri.relativePath); } return this._folderName; } diff --git a/src/views/nodes/mergeStatusNode.ts b/src/views/nodes/mergeStatusNode.ts index f67dbf4..003bc8c 100644 --- a/src/views/nodes/mergeStatusNode.ts +++ b/src/views/nodes/mergeStatusNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { join as joinPaths } from 'path'; import { MarkdownString, ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { ViewFilesLayout } from '../../configuration'; import { GitUri } from '../../git/gitUri'; @@ -48,7 +48,7 @@ export class MergeStatusNode extends ViewNode { const hierarchy = Arrays.makeHierarchical( children, n => n.uri.relativePath.split('/'), - (...parts: string[]) => Strings.normalizePath(paths.join(...parts)), + (...parts: string[]) => Strings.normalizePath(joinPaths(...parts)), this.view.config.files.compact, ); diff --git a/src/views/nodes/rebaseStatusNode.ts b/src/views/nodes/rebaseStatusNode.ts index b550109..bb132dd 100644 --- a/src/views/nodes/rebaseStatusNode.ts +++ b/src/views/nodes/rebaseStatusNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { join as joinPaths } from 'path'; import { Command, commands, @@ -65,7 +65,7 @@ export class RebaseStatusNode extends ViewNode { const hierarchy = Arrays.makeHierarchical( children, n => n.uri.relativePath.split('/'), - (...parts: string[]) => Strings.normalizePath(paths.join(...parts)), + (...parts: string[]) => Strings.normalizePath(joinPaths(...parts)), this.view.config.files.compact, ); @@ -182,7 +182,7 @@ export class RebaseCommitNode extends ViewRefNode n.uri.relativePath.split('/'), - (...parts: string[]) => Strings.normalizePath(paths.join(...parts)), + (...parts: string[]) => Strings.normalizePath(joinPaths(...parts)), this.view.config.files.compact, ); diff --git a/src/views/nodes/resultsFileNode.ts b/src/views/nodes/resultsFileNode.ts index afc486f..c618793 100644 --- a/src/views/nodes/resultsFileNode.ts +++ b/src/views/nodes/resultsFileNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { dirname, join as joinPaths } from 'path'; import { Command, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { Commands, DiffWithCommandArgs } from '../../commands'; import { StatusFileFormatter } from '../../git/formatters'; @@ -49,8 +49,8 @@ export class ResultsFileNode extends ViewRefFileNode implements FileNode { const statusIcon = GitFile.getStatusIcon(this.file.status); item.iconPath = { - dark: this.view.container.context.asAbsolutePath(paths.join('images', 'dark', statusIcon)), - light: this.view.container.context.asAbsolutePath(paths.join('images', 'light', statusIcon)), + dark: this.view.container.context.asAbsolutePath(joinPaths('images', 'dark', statusIcon)), + light: this.view.container.context.asAbsolutePath(joinPaths('images', 'light', statusIcon)), }; item.command = this.getCommand(); @@ -74,7 +74,7 @@ export class ResultsFileNode extends ViewRefFileNode implements FileNode { private _folderName: string | undefined; get folderName() { if (this._folderName === undefined) { - this._folderName = paths.dirname(this.uri.relativePath); + this._folderName = dirname(this.uri.relativePath); } return this._folderName; } diff --git a/src/views/nodes/resultsFilesNode.ts b/src/views/nodes/resultsFilesNode.ts index b5dc38b..9f82f6d 100644 --- a/src/views/nodes/resultsFilesNode.ts +++ b/src/views/nodes/resultsFilesNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { join as joinPaths } from 'path'; import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { ViewFilesLayout } from '../../configuration'; import { GitUri } from '../../git/gitUri'; @@ -78,7 +78,7 @@ export class ResultsFilesNode extends ViewNode { const hierarchy = Arrays.makeHierarchical( children, n => n.uri.relativePath.split('/'), - (...parts: string[]) => Strings.normalizePath(paths.join(...parts)), + (...parts: string[]) => Strings.normalizePath(joinPaths(...parts)), this.view.config.files.compact, ); diff --git a/src/views/nodes/stashNode.ts b/src/views/nodes/stashNode.ts index fcf761a..d071ffc 100644 --- a/src/views/nodes/stashNode.ts +++ b/src/views/nodes/stashNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { join as joinPaths } from 'path'; import { TreeItem, TreeItemCollapsibleState } from 'vscode'; import { ViewFilesLayout } from '../../config'; import { CommitFormatter } from '../../git/formatters'; @@ -43,7 +43,7 @@ export class StashNode extends ViewRefNode n.uri.relativePath.split('/'), - (...parts: string[]) => Strings.normalizePath(paths.join(...parts)), + (...parts: string[]) => Strings.normalizePath(joinPaths(...parts)), this.view.config.files.compact, ); diff --git a/src/views/nodes/statusFileNode.ts b/src/views/nodes/statusFileNode.ts index 9646ecd..b3e2fb4 100644 --- a/src/views/nodes/statusFileNode.ts +++ b/src/views/nodes/statusFileNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { dirname, join as joinPaths } from 'path'; import { Command, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { Commands, DiffWithCommandArgs, DiffWithPreviousCommandArgs } from '../../commands'; import { StatusFileFormatter } from '../../git/formatters/statusFormatter'; @@ -111,8 +111,8 @@ export class StatusFileNode extends ViewNode implements FileNo const icon = GitFile.getStatusIcon(this.file.status); item.iconPath = { - dark: this.view.container.context.asAbsolutePath(paths.join('images', 'dark', icon)), - light: this.view.container.context.asAbsolutePath(paths.join('images', 'light', icon)), + dark: this.view.container.context.asAbsolutePath(joinPaths('images', 'dark', icon)), + light: this.view.container.context.asAbsolutePath(joinPaths('images', 'light', icon)), }; } @@ -151,7 +151,7 @@ export class StatusFileNode extends ViewNode implements FileNo private _folderName: string | undefined; get folderName() { if (this._folderName == null) { - this._folderName = paths.dirname(this.uri.relativePath); + this._folderName = dirname(this.uri.relativePath); } return this._folderName; } diff --git a/src/views/nodes/statusFilesNode.ts b/src/views/nodes/statusFilesNode.ts index e1f98c5..6d39d66 100644 --- a/src/views/nodes/statusFilesNode.ts +++ b/src/views/nodes/statusFilesNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import * as paths from 'path'; +import { join as joinPaths } from 'path'; import { TreeItem, TreeItemCollapsibleState } from 'vscode'; import { ViewFilesLayout } from '../../configuration'; import { GitUri } from '../../git/gitUri'; @@ -111,7 +111,7 @@ export class StatusFilesNode extends ViewNode { const hierarchy = Arrays.makeHierarchical( children, n => n.uri.relativePath.split('/'), - (...parts: string[]) => Strings.normalizePath(paths.join(...parts)), + (...parts: string[]) => Strings.normalizePath(joinPaths(...parts)), this.view.config.files.compact, );