Skip to content

Commit 75e7cf0

Browse files
committed
Merge branch 'main' into remove-qiwi
2 parents 1f1ca89 + 589f363 commit 75e7cf0

4 files changed

Lines changed: 23 additions & 47 deletions

File tree

.changeset/wild-nails-itch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"dts-gen": patch
3+
---
4+
5+
Use git binary instead of parse-git-config

packages/dts-gen/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
},
2626
"dependencies": {
2727
"dts-dom": "^3.7.0",
28-
"parse-git-config": "^3.0.0",
2928
"typescript": "^5.9.3",
29+
"which": "^6.0.0",
3030
"yargs": "^17.7.2"
3131
},
3232
"devDependencies": {
3333
"@types/node": "^25.1.0",
34-
"@types/parse-git-config": "^3.0.4",
34+
"@types/which": "^3.0.4",
3535
"@types/yargs": "^17.0.35",
3636
"ecurve": "1.0.6",
3737
"jquery": "3.7.1",

packages/dts-gen/src/definitely-typed.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import { execFileSync } from "child_process";
12
import { existsSync, mkdirSync, writeFileSync } from "fs";
23
import { STATUS_CODES } from "http";
34
import { get } from "https";
4-
import { homedir } from "os";
5-
import parseGitConfig = require("parse-git-config");
65
import { join as joinPaths } from "path";
7-
import { parse as parseUrl } from "url";
6+
import which = require("which");
87
import { getDTName } from "./names";
98

109
export default function writeDefinitelyTypedPackage(
@@ -83,25 +82,22 @@ async function getPackageJson(dtName: string, packageName: string): Promise<{}>
8382

8483
let authorName = "My Self";
8584
try {
86-
const globalGitConfig = parseGitConfig.sync({ cwd: homedir(), path: ".gitconfig" });
87-
if (globalGitConfig.user && globalGitConfig.user.name) {
88-
authorName = globalGitConfig.user.name;
89-
}
85+
authorName =
86+
execFileSync(which.sync("git"), ["config", "--global", "user.name"], { encoding: "utf-8" }).trim() || authorName;
9087
} catch (e: any) {
9188
console.warn(`Warning: Could not retrieve author name: ${e.message}`);
9289
}
9390

9491
let authorUserName = "me";
9592
try {
96-
const repoGitConfig = parseGitConfig.sync({ path: joinPaths(".git", "config") });
97-
if (repoGitConfig['remote "origin"'] && repoGitConfig['remote "origin"'].url) {
98-
const url = parseUrl(repoGitConfig['remote "origin"'].url);
99-
if (url.hostname === "github.com" && url.pathname) {
100-
authorUserName = url.pathname.split("/")[1] || authorUserName;
101-
} else if (url.pathname?.startsWith("git@github.com")) {
102-
authorUserName = url.pathname.split(":")?.[1].split("/")?.[0] || authorUserName;
103-
}
104-
}
93+
const remoteUrl = execFileSync(which.sync("git"), ["config", "--get", "remote.origin.url"], {
94+
encoding: "utf-8",
95+
}).trim();
96+
// Handle HTTPS URLs like https://github.com/user/repo.git
97+
const httpsMatch = remoteUrl.match(/github\.com\/([^/]+)/);
98+
// Handle SSH URLs like git@github.com:user/repo.git
99+
const sshMatch = remoteUrl.match(/github\.com:([^/]+)/);
100+
authorUserName = httpsMatch?.[1] || sshMatch?.[1] || authorUserName;
105101
} catch (e: any) {
106102
console.warn(`Warning: Could not retrieve author's user name: ${e.message}`);
107103
}

pnpm-lock.yaml

Lines changed: 4 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)