Skip to content

Commit d61c22b

Browse files
committed
fix: replace execa with tinyexec
1 parent 60d8cf7 commit d61c22b

File tree

4 files changed

+43
-23
lines changed

4 files changed

+43
-23
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"debug": "^4.1.1",
5454
"eslint": "^9.14.0",
5555
"eslint-config-prettier": "^9.1.0",
56-
"execa": "^5.1.1",
5756
"get-port-please": "^3.1.2",
5857
"jiti": "^2.4.0",
5958
"jsdom": "^25.0.1",
@@ -70,6 +69,7 @@
7069
"serve": "^11.3.2",
7170
"source-map": "0.6.1",
7271
"tiny-glob": "^0.2.9",
72+
"tinyexec": "^0.3.2",
7373
"typescript": "^5.6.3",
7474
"typescript-eslint": "^8.13.0",
7575
"vite": "^5.4.10",

pnpm-lock.yaml

+19-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/release.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
run,
1919
writeChangelog
2020
} from './utils'
21+
import { NonZeroExitError } from 'tinyexec'
2122

2223
import type { Logger, PackageJson } from './utils'
2324

@@ -26,8 +27,8 @@ const isDryRun = args.dry
2627
const skipBuild = args.skipBuild
2728
const skipChangelog = args.skipChangelog
2829

29-
const dryRun = (bin, args, opts = {}) =>
30-
console.log(chalk.yellow(`[dryrun] ${bin} ${args.join(' ')}`), opts)
30+
const dryRun = (command: string, args: string[] = [], opts = {}) =>
31+
console.log(chalk.yellow(`[dryrun] ${command} ${args.join(' ')}`), opts)
3132
const runIfNotDry = isDryRun ? dryRun : run
3233

3334
async function releasePackage(log: Logger) {
@@ -84,7 +85,7 @@ async function releasePackage(log: Logger) {
8485
}
8586

8687
log('Generating changelog...')
87-
let changelog: string | null = null
88+
let changelog: string | undefined
8889
if (!skipChangelog) {
8990
changelog = await renderChangelog(fromTag, releaseVersion, pkgName)
9091
if (!isDryRun) {
@@ -106,7 +107,7 @@ async function releasePackage(log: Logger) {
106107
}
107108

108109
log('Publishing package...')
109-
await publishPackage(targetVersion, pkgName, runIfNotDry)
110+
await publishPackage(targetVersion, pkgName)
110111

111112
log('Pushing tag to GitHub...')
112113
await runIfNotDry('git', ['tag', tag])
@@ -120,7 +121,7 @@ async function releasePackage(log: Logger) {
120121
tag,
121122
releaseVersion,
122123
changelog,
123-
isPrelease(targetVersion)
124+
isPrerelease(targetVersion)
124125
)
125126
} else {
126127
console.log(`(skipped)`)
@@ -152,7 +153,7 @@ async function updateVersion(
152153
return await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
153154
}
154155

155-
async function publishPackage(version: string, pkgName: string, runIfNotDry) {
156+
async function publishPackage(version: string, pkgName: string) {
156157
const publicArgs = ['publish', '--access', 'public', '--no-git-checks']
157158
if (args.tag) {
158159
publicArgs.push(`--tag`, args.tag)
@@ -162,15 +163,18 @@ async function publishPackage(version: string, pkgName: string, runIfNotDry) {
162163
console.log(chalk.green(`Successfully published ${pkgName}@${version}`))
163164
} catch (e) {
164165
console.error(e)
165-
if (e.stderr.match(/previously published/)) {
166+
if (
167+
e instanceof NonZeroExitError &&
168+
e.output?.stderr.match(/previously published/)
169+
) {
166170
console.log(chalk.red(`Skipping already published: ${pkgName}`))
167171
} else {
168172
throw e
169173
}
170174
}
171175
}
172176

173-
function isPrelease(version: string) {
177+
function isPrerelease(version: string) {
174178
return (
175179
version.includes('beta') ||
176180
version.includes('alpha') ||

scripts/utils.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'path'
22
import fs from 'fs/promises'
33
import semver from 'semver'
44
import prompts from 'prompts'
5-
import execa from 'execa'
5+
import { exec, Options } from 'tinyexec'
66
import { loadConfig, Changelog } from '@kazupon/lerna-changelog'
77

88
export type PackageJson = {
@@ -14,7 +14,7 @@ export type PackageJson = {
1414

1515
export type Mode = 'single' | 'batch'
1616
export type Logger = (...args: any[]) => void
17-
export type Incrementer = (i: any) => string
17+
export type Incrementer = (i: any) => string | null
1818

1919
const VersionIncrements = [
2020
'patch',
@@ -26,8 +26,15 @@ const VersionIncrements = [
2626
'prerelease'
2727
] as const
2828

29-
export const run = (bin, args, opts = {}) =>
30-
execa(bin, args, { stdio: 'inherit', ...opts })
29+
export const run = (
30+
command: string,
31+
args?: string[],
32+
opts: Partial<Options['nodeOptions']> = {}
33+
) =>
34+
exec(command, args, {
35+
nodeOptions: { stdio: 'inherit', ...opts },
36+
throwOnError: true
37+
})
3138

3239
export async function getRootPath() {
3340
const { stdout: rootPath } = await run(

0 commit comments

Comments
 (0)