From e1b4834fee1d7aa90654b34b501405ec2855f544 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 1 May 2021 10:25:36 -0600 Subject: [PATCH] refactor: Remove ShellJS, colors --- package-lock.json | 67 +++++------------------ package.json | 3 - src/lib/converter/plugins/GitHubPlugin.ts | 50 ++++++----------- 3 files changed, 30 insertions(+), 90 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9f4fae14c..44d6d6700 100644 --- a/package-lock.json +++ b/package-lock.json @@ -429,16 +429,6 @@ "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, - "@types/glob": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==", - "dev": true, - "requires": { - "@types/minimatch": "*", - "@types/node": "*" - } - }, "@types/json-schema": { "version": "7.0.7", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.7.tgz", @@ -487,16 +477,6 @@ "integrity": "sha512-TMkXt0Ck1y0KKsGr9gJtWGjttxlZnnvDtphxUOSd0bfaR6Q1jle+sPvrzNR1urqYTWMinoKvjKfXUGsumaO1PA==", "dev": true }, - "@types/shelljs": { - "version": "0.8.8", - "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.8.tgz", - "integrity": "sha512-lD3LWdg6j8r0VRBFahJVaxoW0SIcswxKaFUrmKl33RJVeeoNYQAz4uqCJ5Z6v4oIBOsC5GozX+I5SorIKiTcQA==", - "dev": true, - "requires": { - "@types/glob": "*", - "@types/node": "*" - } - }, "@typescript-eslint/eslint-plugin": { "version": "4.22.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.22.0.tgz", @@ -816,11 +796,6 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, - "colors": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", - "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==" - }, "commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -1274,7 +1249,8 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true }, "fsevents": { "version": "2.3.2", @@ -1311,6 +1287,7 @@ "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -1441,6 +1418,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -1449,12 +1427,8 @@ "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" - }, - "interpret": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.2.0.tgz", - "integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true }, "is-binary-path": { "version": "2.1.0", @@ -2134,6 +2108,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, "requires": { "wrappy": "1" } @@ -2223,7 +2198,8 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true }, "path-key": { "version": "3.1.1", @@ -2234,7 +2210,8 @@ "path-parse": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==" + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true }, "path-type": { "version": "4.0.0", @@ -2313,14 +2290,6 @@ "picomatch": "^2.2.1" } }, - "rechoir": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", - "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", - "requires": { - "resolve": "^1.1.6" - } - }, "regexpp": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", @@ -2358,6 +2327,7 @@ "version": "1.15.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz", "integrity": "sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w==", + "dev": true, "requires": { "path-parse": "^1.0.6" } @@ -2454,16 +2424,6 @@ "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true }, - "shelljs": { - "version": "0.8.4", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.4.tgz", - "integrity": "sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==", - "requires": { - "glob": "^7.0.0", - "interpret": "^1.0.0", - "rechoir": "^0.6.2" - } - }, "shiki": { "version": "0.9.3", "resolved": "https://registry.npmjs.org/shiki/-/shiki-0.9.3.tgz", @@ -2859,7 +2819,8 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true }, "write-file-atomic": { "version": "3.0.3", diff --git a/package.json b/package.json index 89eb4ba06..5c2dac385 100644 --- a/package.json +++ b/package.json @@ -20,14 +20,12 @@ "node": ">= 10.8.0" }, "dependencies": { - "colors": "^1.4.0", "handlebars": "^4.7.7", "lodash": "^4.17.21", "lunr": "^2.3.9", "marked": "^2.0.3", "minimatch": "^3.0.0", "progress": "^2.0.3", - "shelljs": "^0.8.4", "shiki": "^0.9.3", "typedoc-default-themes": "^0.12.10" }, @@ -42,7 +40,6 @@ "@types/mocha": "^8.2.2", "@types/mockery": "^1.4.29", "@types/node": "^15.0.1", - "@types/shelljs": "^0.8.8", "@typescript-eslint/eslint-plugin": "^4.22.0", "@typescript-eslint/parser": "^4.22.0", "eslint": "^7.25.0", diff --git a/src/lib/converter/plugins/GitHubPlugin.ts b/src/lib/converter/plugins/GitHubPlugin.ts index 21a29afa7..d2d25c128 100644 --- a/src/lib/converter/plugins/GitHubPlugin.ts +++ b/src/lib/converter/plugins/GitHubPlugin.ts @@ -1,13 +1,17 @@ -import * as ShellJS from "shelljs"; import * as Path from "path"; +import { spawnSync } from "child_process"; -import { SourceReference } from "../../models/sources/file"; +import type { SourceReference } from "../../models/sources/file"; import { Component, ConverterComponent } from "../components"; import { BasePath } from "../utils/base-path"; import { Converter } from "../converter"; -import { Context } from "../context"; +import type { Context } from "../context"; import { BindOption } from "../../utils"; +function git(...args: string[]) { + return spawnSync("git", args, { encoding: "utf-8", windowsHide: true }); +} + /** * Stores data of a repository. */ @@ -55,7 +59,6 @@ export class Repository { constructor(path: string, gitRevision: string, repoLinks: string[]) { this.path = path; this.branch = gitRevision || "master"; - ShellJS.pushd(path); for (let i = 0, c = repoLinks.length; i < c; i++) { const url = /(github(?:\.[a-z]+)*\.[a-z]{2,})[:/]([^/]+)\/(.*)/.exec( @@ -76,10 +79,8 @@ export class Repository { } } - let out = ( - ShellJS.exec("git ls-files", { silent: true }) - ); - if (out.code === 0) { + let out = git("-C", path, "ls-files"); + if (out.status === 0) { out.stdout.split("\n").forEach((file) => { if (file !== "") { this.files.push(BasePath.normalize(path + "/" + file)); @@ -88,15 +89,11 @@ export class Repository { } if (!gitRevision) { - out = ( - ShellJS.exec("git rev-parse --short HEAD", { silent: true }) - ); - if (out.code === 0) { + out = git("-C", path, "rev-parse", "--short", "HEAD"); + if (out.status === 0) { this.branch = out.stdout.replace("\n", ""); } } - - ShellJS.popd(); } /** @@ -148,31 +145,17 @@ export class Repository { gitRevision: string, gitRemote: string ): Repository | undefined { - ShellJS.pushd(path); - const out = ( - ShellJS.exec("git rev-parse --show-toplevel", { silent: true }) - ); - const remotesOutput = ( - ShellJS.exec(`git remote get-url ${gitRemote}`, { silent: true }) - ); - ShellJS.popd(); + const out = git("-C", path, "rev-parse", "--show-toplevel"); + const remotesOutput = git("-C", path, "remote", "get-url", gitRemote); - if ( - !out || - out.code !== 0 || - !remotesOutput || - remotesOutput.code !== 0 - ) { + if (out.status !== 0 || remotesOutput.status !== 0) { return; } - const remotes: string[] = - remotesOutput.code === 0 ? remotesOutput.stdout.split("\n") : []; - return new Repository( BasePath.normalize(out.stdout.replace("\n", "")), gitRevision, - remotes + remotesOutput.stdout.split("\n") ); } } @@ -205,8 +188,7 @@ export class GitHubPlugin extends ConverterComponent { * @param converter The converter this plugin should be attached to. */ initialize() { - ShellJS.config.silent = true; - if (ShellJS.which("git")) { + if (git("--version").status === 0) { this.listenTo( this.owner, Converter.EVENT_RESOLVE_END,