diff --git a/.changeset/wild-nails-itch.md b/.changeset/wild-nails-itch.md new file mode 100644 index 0000000000..ceebcd6b3d --- /dev/null +++ b/.changeset/wild-nails-itch.md @@ -0,0 +1,5 @@ +--- +"dts-gen": patch +--- + +Use git binary instead of parse-git-config diff --git a/packages/dts-gen/package.json b/packages/dts-gen/package.json index f1bd422966..d484eb6e3c 100644 --- a/packages/dts-gen/package.json +++ b/packages/dts-gen/package.json @@ -25,13 +25,13 @@ }, "dependencies": { "dts-dom": "^3.7.0", - "parse-git-config": "^3.0.0", "typescript": "^5.9.3", + "which": "^6.0.0", "yargs": "^17.7.2" }, "devDependencies": { "@types/node": "^25.1.0", - "@types/parse-git-config": "^3.0.4", + "@types/which": "^3.0.4", "@types/yargs": "^17.0.35", "ecurve": "1.0.6", "jquery": "3.7.1", diff --git a/packages/dts-gen/src/definitely-typed.ts b/packages/dts-gen/src/definitely-typed.ts index e5e9f3b77b..970ea8da82 100644 --- a/packages/dts-gen/src/definitely-typed.ts +++ b/packages/dts-gen/src/definitely-typed.ts @@ -1,10 +1,9 @@ +import { execFileSync } from "child_process"; import { existsSync, mkdirSync, writeFileSync } from "fs"; import { STATUS_CODES } from "http"; import { get } from "https"; -import { homedir } from "os"; -import parseGitConfig = require("parse-git-config"); import { join as joinPaths } from "path"; -import { parse as parseUrl } from "url"; +import which = require("which"); import { getDTName } from "./names"; export default function writeDefinitelyTypedPackage( @@ -83,25 +82,22 @@ async function getPackageJson(dtName: string, packageName: string): Promise<{}> let authorName = "My Self"; try { - const globalGitConfig = parseGitConfig.sync({ cwd: homedir(), path: ".gitconfig" }); - if (globalGitConfig.user && globalGitConfig.user.name) { - authorName = globalGitConfig.user.name; - } + authorName = + execFileSync(which.sync("git"), ["config", "--global", "user.name"], { encoding: "utf-8" }).trim() || authorName; } catch (e: any) { console.warn(`Warning: Could not retrieve author name: ${e.message}`); } let authorUserName = "me"; try { - const repoGitConfig = parseGitConfig.sync({ path: joinPaths(".git", "config") }); - if (repoGitConfig['remote "origin"'] && repoGitConfig['remote "origin"'].url) { - const url = parseUrl(repoGitConfig['remote "origin"'].url); - if (url.hostname === "github.com" && url.pathname) { - authorUserName = url.pathname.split("/")[1] || authorUserName; - } else if (url.pathname?.startsWith("git@github.com")) { - authorUserName = url.pathname.split(":")?.[1].split("/")?.[0] || authorUserName; - } - } + const remoteUrl = execFileSync(which.sync("git"), ["config", "--get", "remote.origin.url"], { + encoding: "utf-8", + }).trim(); + // Handle HTTPS URLs like https://github.com/user/repo.git + const httpsMatch = remoteUrl.match(/github\.com\/([^/]+)/); + // Handle SSH URLs like git@github.com:user/repo.git + const sshMatch = remoteUrl.match(/github\.com:([^/]+)/); + authorUserName = httpsMatch?.[1] || sshMatch?.[1] || authorUserName; } catch (e: any) { console.warn(`Warning: Could not retrieve author's user name: ${e.message}`); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ec1d5ee36a..cf37badc63 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,12 +105,12 @@ importers: dts-dom: specifier: ^3.7.0 version: 3.7.0 - parse-git-config: - specifier: ^3.0.0 - version: 3.0.0 typescript: specifier: ^5.9.3 version: 5.9.3 + which: + specifier: ^6.0.0 + version: 6.0.0 yargs: specifier: ^17.7.2 version: 17.7.2 @@ -118,7 +118,7 @@ importers: '@types/node': specifier: ^25.1.0 version: 25.1.0 - '@types/parse-git-config': + '@types/which': specifier: ^3.0.4 version: 3.0.4 '@types/yargs': @@ -2020,9 +2020,6 @@ packages: '@types/pacote@11.1.8': resolution: {integrity: sha512-/XLR0VoTh2JEO0jJg1q/e6Rh9bxjBq9vorJuQmtT7rRrXSiWz7e7NsvXVYJQ0i8JxMlBMPPYDTnrRe7MZRFA8Q==} - '@types/parse-git-config@3.0.4': - resolution: {integrity: sha512-jz5eGdk9lBgAd4rMbXTP7MRG7AsGQ8DrXsRumDcXDLClHcpKluislylPVMP/qp90J/LlIrrPZRZIQUflHfrDnQ==} - '@types/parsimmon@1.10.9': resolution: {integrity: sha512-O2M2x1w+m7gWLen8i5DOy6tWRnbRcsW6Pke3j3HAsJUrPb4g0MgjksIUm2aqUtCYxy7Qjr3CzjjwQBzhiGn46A==} @@ -3237,10 +3234,6 @@ packages: getpass@0.1.7: resolution: {integrity: sha512-0fzj9JxOLfJ+XGLhR8ze3unN0KZCgZwiSSDz168VERjK8Wl8kVSdcu2kspd4s4wtAa1y/qrVRiAA0WclVsu0ng==} - git-config-path@2.0.0: - resolution: {integrity: sha512-qc8h1KIQbJpp+241id3GuAtkdyJ+IK+LIVtkiFTRKRrmddDzs3SI9CvP1QYmWBFvm1I/PWRwj//of8bgAc0ltA==} - engines: {node: '>=4'} - glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} @@ -3449,9 +3442,6 @@ packages: inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} - ini@1.3.8: - resolution: {integrity: sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==} - ini@6.0.0: resolution: {integrity: sha512-IBTdIkzZNOpqm7q3dRqJvMaldXjDHWkEDfrwGEQTs5eaQMWV+djAhR+wahyNNMAa+qpbDUhBMVt4ZKNwpPm7xQ==} engines: {node: ^20.17.0 || >=22.9.0} @@ -4341,10 +4331,6 @@ packages: resolution: {integrity: sha512-FwdRXKCohSVeXqwtYonZTXtbGJKrn+HNyWDYVcp5yuJlesTwNH4rsmRZ+GrKAPJ5bLpRxESMeS+Rl0VCHRvB2Q==} engines: {node: '>=0.8'} - parse-git-config@3.0.0: - resolution: {integrity: sha512-wXoQGL1D+2COYWCD35/xbiKma1Z15xvZL8cI25wvxzled58V51SJM04Urt/uznS900iQor7QO04SgdfT/XlbuA==} - engines: {node: '>=8'} - parse-imports@2.2.1: resolution: {integrity: sha512-OL/zLggRp8mFhKL0rNORUTR4yBYujK/uU+xZL+/0Rgm2QE4nLO9v8PzEweSJEbMGKmDRjJE4R3IMJlL2di4JeQ==} engines: {node: '>= 18'} @@ -7240,8 +7226,6 @@ snapshots: '@types/npmlog': 7.0.0 '@types/ssri': 7.1.5 - '@types/parse-git-config@3.0.4': {} - '@types/parsimmon@1.10.9': {} '@types/prettyjson@0.0.33': {} @@ -8611,8 +8595,6 @@ snapshots: dependencies: assert-plus: 1.0.0 - git-config-path@2.0.0: {} - glob-parent@5.1.2: dependencies: is-glob: 4.0.3 @@ -8827,8 +8809,6 @@ snapshots: inherits@2.0.4: {} - ini@1.3.8: {} - ini@6.0.0: {} internal-slot@1.1.0: @@ -9968,11 +9948,6 @@ snapshots: map-cache: 0.2.2 path-root: 0.1.1 - parse-git-config@3.0.0: - dependencies: - git-config-path: 2.0.0 - ini: 1.3.8 - parse-imports@2.2.1: dependencies: es-module-lexer: 1.7.0