From 78d372f093197d4d0b0de8d32b521bae2e1ac2ed Mon Sep 17 00:00:00 2001 From: sf-v Date: Fri, 17 Feb 2023 11:39:48 -0800 Subject: [PATCH] fix: update `simple-git` to `v3` This change is done as part of updating or removing dependencies that have vulnerabilities. --- packages/@best/cli/package.json | 2 +- packages/@best/cli/src/run_compare.ts | 14 ++++++------- packages/@best/config/package.json | 2 +- packages/@best/config/src/utils/git.ts | 23 ++++++++------------- yarn.lock | 28 +++++++++++++++++++------- 5 files changed, 38 insertions(+), 31 deletions(-) diff --git a/packages/@best/cli/package.json b/packages/@best/cli/package.json index cf65d937..ab121d60 100644 --- a/packages/@best/cli/package.json +++ b/packages/@best/cli/package.json @@ -20,7 +20,7 @@ "fast-glob": "3.2.12", "micromatch": "~3.1.10", "rimraf": "3.0.2", - "simple-git": "~1.113.0", + "simple-git": "3.16.1", "simple-statistics": "^6.0.1", "yargs": "^16.1.0" }, diff --git a/packages/@best/cli/src/run_compare.ts b/packages/@best/cli/src/run_compare.ts index 4cc1d371..2bfb1915 100644 --- a/packages/@best/cli/src/run_compare.ts +++ b/packages/@best/cli/src/run_compare.ts @@ -13,15 +13,15 @@ import { updateLatestRelease, } from '@best/github-integration'; import { runBest } from './run_best'; -import git from 'simple-git/promise'; +import { simpleGit, SimpleGit } from 'simple-git'; import { FrozenProjectConfig, FrozenGlobalConfig, BenchmarkComparison } from '@best/types'; const STORAGE_FS = '@best/store-fs'; const isHex = (x: string) => /^[0-9a-fA-F]+$/.test(x); -const normalizeCommit = async (commit: string, gitCLI: any) => { +const normalizeCommit = async (commit: string, gitCLI: SimpleGit) => { if (commit === 'current') { const result = await gitCLI.log(); - commit = result.latest.hash; + commit = result.latest!.hash; } if (!isHex(commit)) { @@ -44,9 +44,9 @@ export async function runCompare( externalStorage, compareStats = [], } = globalConfig; - const gitCLI = git(rootDir); + const gitCLI = simpleGit(rootDir); const status = await gitCLI.status(); - const initialBranch = status.current; + const initialBranch: string = status.current as string; let baseCommit = compareStats[0] || 'main'; let compareCommit = compareStats[1] || (localChanges ? 'local' : 'current'); @@ -84,7 +84,7 @@ export async function runCompare( storageProvider = require(STORAGE_FS); storageProvider.initialize({ rootDir }); if (localChanges) { - await gitCLI.stash({ '--include-untracked': true }); + await gitCLI.stash(['--include-untracked']); stashedLocalChanges = true; } @@ -104,7 +104,7 @@ export async function runCompare( // Run local changes or compare commit. if (compareCommit === 'local') { - await gitCLI.checkout(initialBranch); + await gitCLI.checkout(initialBranch) if (stashedLocalChanges) { await gitCLI.stash(['pop']); } diff --git a/packages/@best/config/package.json b/packages/@best/config/package.json index 5a8ea56b..010eb23e 100644 --- a/packages/@best/config/package.json +++ b/packages/@best/config/package.json @@ -16,7 +16,7 @@ "@best/regex-util": "8.1.2", "@best/utils": "8.1.2", "chalk": "~2.4.2", - "simple-git": "~1.113.0" + "simple-git": "3.16.1" }, "files": [ "build/**/*.js" diff --git a/packages/@best/config/src/utils/git.ts b/packages/@best/config/src/utils/git.ts index b140038d..f7fd16f1 100644 --- a/packages/@best/config/src/utils/git.ts +++ b/packages/@best/config/src/utils/git.ts @@ -5,33 +5,26 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ -import SimpleGit from 'simple-git/promise'; +import { simpleGit, SimpleGit } from 'simple-git'; import { GitConfig } from '@best/types'; -// TODO: Remove this once the library fixes its types -declare module 'simple-git/promise' { - interface SimpleGit { - listRemote(options: string[]): Promise; - } -} - -async function getCurrentHashAndDate(git: SimpleGit.SimpleGit): Promise<{ hash: string; date: string }> { +async function getCurrentHashAndDate(git: SimpleGit): Promise<{ hash: string; date: string }> { const { latest } = await git.log(); - const date = latest.date; - const hash = latest.hash.slice(0, 7); + const date = latest!.date; + const hash = latest!.hash.slice(0, 7); return { hash, date }; } -async function hasLocalChanges(git: SimpleGit.SimpleGit): Promise { +async function hasLocalChanges(git: SimpleGit): Promise { const diff = await git.diffSummary(); return diff.files && diff.files.length > 0; } -function getBranch(git: SimpleGit.SimpleGit): Promise { +function getBranch(git: SimpleGit): Promise { return git.revparse(['--abbrev-ref', 'HEAD']); } -async function getRepository(git: SimpleGit.SimpleGit): Promise<{ owner: string; repo: string }> { +async function getRepository(git: SimpleGit): Promise<{ owner: string; repo: string }> { const url = await git.listRemote(['--get-url']); const matches = url.trim().match(/^.+[:/](.+)\/(.+)/); if (!matches) { @@ -43,7 +36,7 @@ async function getRepository(git: SimpleGit.SimpleGit): Promise<{ owner: string; } export async function getGitInfo(baseDir?: string): Promise { - const git = SimpleGit(baseDir); + const git = simpleGit(baseDir); const isRepo = await git.checkIsRepo(); if (isRepo) { diff --git a/yarn.lock b/yarn.lock index 53f41c13..84e4046a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2532,6 +2532,18 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" +"@kwsites/file-exists@^1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@kwsites/file-exists/-/file-exists-1.1.1.tgz#ad1efcac13e1987d8dbaf235ef3be5b0d96faa99" + integrity sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw== + dependencies: + debug "^4.1.1" + +"@kwsites/promise-deferred@^1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz#8ace5259254426ccef57f3175bc64ed7095ed919" + integrity sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw== + "@lerna/add@3.21.0": version "3.21.0" resolved "https://registry.yarnpkg.com/@lerna/add/-/add-3.21.0.tgz#27007bde71cc7b0a2969ab3c2f0ae41578b4577b" @@ -15963,6 +15975,15 @@ signal-exit@^3.0.7: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== +simple-git@3.16.1: + version "3.16.1" + resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-3.16.1.tgz#b67f18cbd3c68bbc4b9177ed49256afe51f12d47" + integrity sha512-xzRxMKiy1zEYeHGXgAzvuXffDS0xgsq07Oi4LWEEcVH29vLpcZ2tyQRWyK0NLLlCVaKysZeem5tC1qHEOxsKwA== + dependencies: + "@kwsites/file-exists" "^1.1.1" + "@kwsites/promise-deferred" "^1.1.1" + debug "^4.3.4" + simple-git@^1.85.0: version "1.121.0" resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-1.121.0.tgz#4bdf0828cd1b0bb3cb7ed9bead2771982ef5876a" @@ -15970,13 +15991,6 @@ simple-git@^1.85.0: dependencies: debug "^4.0.1" -simple-git@~1.113.0: - version "1.113.0" - resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-1.113.0.tgz#668989728a1e9cf4ec6c72b69ea2eecc93489bea" - integrity sha512-i9WVsrK2u0G/cASI9nh7voxOk9mhanWY9eGtWBDSYql6m49Yk5/Fan6uZsDr/xmzv8n+eQ8ahKCoEr8cvU3h+g== - dependencies: - debug "^4.0.1" - simple-statistics@^6.0.1: version "6.1.1" resolved "https://registry.yarnpkg.com/simple-statistics/-/simple-statistics-6.1.1.tgz#e3a0799ffc49914d6f421c5a4ac585f6a13e2bad"