Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wild-nails-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"dts-gen": patch
---

Use git binary instead of parse-git-config
4 changes: 2 additions & 2 deletions packages/dts-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 12 additions & 16 deletions packages/dts-gen/src/definitely-typed.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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}`);
}
Expand Down
33 changes: 4 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading