Skip to content

Commit

Permalink
fix: update simple-git to v3
Browse files Browse the repository at this point in the history
This change is done as part of updating or removing dependencies
that have vulnerabilities.
  • Loading branch information
sf-v committed Feb 17, 2023
1 parent 24c8c9a commit 78d372f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/@best/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
14 changes: 7 additions & 7 deletions packages/@best/cli/src/run_compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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');
Expand Down Expand Up @@ -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;
}

Expand All @@ -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']);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@best/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 8 additions & 15 deletions packages/@best/config/src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
}
}

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<boolean> {
async function hasLocalChanges(git: SimpleGit): Promise<boolean> {
const diff = await git.diffSummary();
return diff.files && diff.files.length > 0;
}

function getBranch(git: SimpleGit.SimpleGit): Promise<string> {
function getBranch(git: SimpleGit): Promise<string> {
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) {
Expand All @@ -43,7 +36,7 @@ async function getRepository(git: SimpleGit.SimpleGit): Promise<{ owner: string;
}

export async function getGitInfo(baseDir?: string): Promise<GitConfig | undefined> {
const git = SimpleGit(baseDir);
const git = simpleGit(baseDir);
const isRepo = await git.checkIsRepo();

if (isRepo) {
Expand Down
28 changes: 21 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -15963,20 +15975,22 @@ 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"
integrity sha512-LyYri/nuAX8+cx9nZw38mWO6oHNi//CmiPlkBL7aVjZIsdldve7eeDwXu9L4wP/74MpNHucXkXc/BOuIQShhPg==
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"
Expand Down

0 comments on commit 78d372f

Please sign in to comment.