Skip to content

Commit c84b76d

Browse files
authored
refactor: replace execa with execSync (#222)
1 parent 3cfbe27 commit c84b76d

File tree

7 files changed

+37
-33
lines changed

7 files changed

+37
-33
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"colorette": "^2.0.20",
3838
"consola": "^3.2.3",
3939
"convert-gitmoji": "^0.1.5",
40-
"execa": "^8.0.1",
4140
"mri": "^1.2.0",
4241
"node-fetch-native": "^1.6.4",
4342
"ofetch": "^1.3.4",

pnpm-lock.yaml

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

src/commands/default.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { existsSync, promises as fsp } from "node:fs";
22
import type { Argv } from "mri";
33
import { resolve } from "pathe";
44
import consola from "consola";
5-
import { execa } from "execa";
65
import {
76
loadChangelogConfig,
87
getGitDiff,
@@ -14,6 +13,7 @@ import {
1413
} from "..";
1514
import { npmPublish, renamePackage } from "../package";
1615
import { githubRelease } from "./github";
16+
import { execCommand } from "../exec";
1717

1818
export default async function defaultMain(args: Argv) {
1919
const cwd = resolve(args._[0] /* bw compat */ || args.dir || "");
@@ -117,12 +117,12 @@ export default async function defaultMain(args: Argv) {
117117
const filesToAdd = [config.output, "package.json"].filter(
118118
(f) => f && typeof f === "string"
119119
) as string[];
120-
await execa("git", ["add", ...filesToAdd], { cwd });
120+
execCommand("git", ["add", ...filesToAdd], { cwd });
121121
const msg = config.templates.commitMessage.replaceAll(
122122
"{{newVersion}}",
123123
config.newVersion
124124
);
125-
await execa("git", ["commit", "-m", msg], { cwd });
125+
execCommand("git", ["commit", "-m", msg], { cwd });
126126
}
127127
if (args.tag !== false) {
128128
const msg = config.templates.tagMessage.replaceAll(
@@ -133,14 +133,14 @@ export default async function defaultMain(args: Argv) {
133133
"{{newVersion}}",
134134
config.newVersion
135135
);
136-
await execa(
136+
execCommand(
137137
"git",
138138
["tag", ...(config.signTags ? ["-s"] : []), "-am", msg, body],
139139
{ cwd }
140140
);
141141
}
142142
if (args.push === true) {
143-
await execa("git", ["push", "--follow-tags"], { cwd });
143+
execCommand("git", ["push", "--follow-tags"], { cwd });
144144
}
145145
if (args.github !== false && config.repo?.provider === "github") {
146146
await githubRelease(config, {

src/exec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import type { Options } from "execa";
1+
import {
2+
execSync,
3+
type ExecOptionsWithStringEncoding,
4+
} from "node:child_process";
25

3-
export async function execCommand(
6+
export function execCommand(
47
cmd: string,
58
args: string[],
6-
options?: Options<string>
9+
opts?: Omit<ExecOptionsWithStringEncoding, "encoding">
710
) {
8-
const { execa } = await import("execa");
9-
const res = await execa(cmd, args, options);
10-
return res.stdout;
11+
return execSync(`${cmd} ${args.join(" ")}`, { encoding: "utf8", ...opts });
1112
}

src/git.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,29 @@ export interface GitCommit extends RawGitCommit {
2828
}
2929

3030
export async function getLastGitTag() {
31-
const r = await execCommand("git", ["describe", "--tags", "--abbrev=0"])
32-
.then((r) => r.split("\n"))
33-
.catch(() => []);
34-
return r.at(-1);
31+
try {
32+
return execCommand("git", ["describe", "--tags", "--abbrev=0"])
33+
?.split("\n")
34+
.at(-1);
35+
} catch {
36+
// Ignore
37+
}
3538
}
3639

37-
export async function getCurrentGitBranch() {
38-
return await execCommand("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
40+
export function getCurrentGitBranch() {
41+
return execCommand("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
3942
}
4043

41-
export async function getCurrentGitTag() {
42-
return await execCommand("git", ["tag", "--points-at", "HEAD"]);
44+
export function getCurrentGitTag() {
45+
return execCommand("git", ["tag", "--points-at", "HEAD"]);
4346
}
4447

45-
export async function getCurrentGitRef() {
46-
return (await getCurrentGitTag()) || (await getCurrentGitBranch());
48+
export function getCurrentGitRef() {
49+
return getCurrentGitTag() || getCurrentGitBranch();
4750
}
4851

49-
export async function getGitRemoteURL(cwd: string, remote = "origin") {
50-
return await execCommand("git", [
52+
export function getGitRemoteURL(cwd: string, remote = "origin") {
53+
return execCommand("git", [
5154
`--work-tree=${cwd}`,
5255
"remote",
5356
"get-url",
@@ -56,15 +59,15 @@ export async function getGitRemoteURL(cwd: string, remote = "origin") {
5659
}
5760

5861
export async function getCurrentGitStatus() {
59-
return await execCommand("git", ["status", "--porcelain"]);
62+
return execCommand("git", ["status", "--porcelain"]);
6063
}
6164

6265
export async function getGitDiff(
6366
from: string | undefined,
6467
to = "HEAD"
6568
): Promise<RawGitCommit[]> {
6669
// https://git-scm.com/docs/pretty-formats
67-
const r = await execCommand("git", [
70+
const r = execCommand("git", [
6871
"--no-pager",
6972
"log",
7073
`${from ? `${from}...` : ""}${to}`,

src/package.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ export async function npmPublish(config: ChangelogConfig) {
5454
args.push("--provenance");
5555
}
5656

57-
return await execCommand("npm", ["publish", ...args]);
57+
return execCommand("npm", ["publish", ...args]);
5858
}

src/repo.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ export async function resolveRepoConfig(cwd: string) {
7575
return getRepoConfig(url);
7676
}
7777

78-
const gitRemote = await getGitRemoteURL(cwd).catch(() => {});
79-
if (gitRemote) {
80-
return getRepoConfig(gitRemote);
78+
try {
79+
const gitRemote = getGitRemoteURL(cwd);
80+
if (gitRemote) {
81+
return getRepoConfig(gitRemote);
82+
}
83+
} catch {
84+
// Ignore
8185
}
8286
}
8387

0 commit comments

Comments
 (0)