Skip to content

Commit

Permalink
chore: migrate from execa to tinyexec (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji authored Oct 11, 2024
1 parent 7aea762 commit de7631c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
Empty file modified bin/index.js
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@
"@inquirer/prompts": "^6.0.1",
"commander": "^11.1.0",
"conventional-changelog": "^5.1.0",
"execa": "^8.0.1",
"fs-extra": "^11.1.1",
"glob": "^10.3.10",
"nanospinner": "^1.1.0",
"picocolors": "^1.0.0",
"semver": "^7.5.4"
"semver": "^7.5.4",
"tinyexec": "^0.3.0"
}
}
21 changes: 12 additions & 9 deletions pnpm-lock.yaml

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

28 changes: 14 additions & 14 deletions src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fse from 'fs-extra'
import logger from './logger'
import semver, { type ReleaseType } from 'semver'
import { confirm, select } from '@inquirer/prompts'
import { execa } from 'execa'
import { x } from 'tinyexec'
import { createSpinner } from 'nanospinner'
import { glob } from 'glob'
import { resolve } from 'path'
Expand All @@ -16,7 +16,7 @@ const releaseTypes = ['premajor', 'preminor', 'prepatch', 'major', 'minor', 'pat
const BACK_HINT = 'Back to previous step' as const

async function isWorktreeEmpty() {
const ret = await execa('git', ['status', '--porcelain'])
const ret = await x('git', ['status', '--porcelain'])
return !ret.stdout
}

Expand All @@ -28,7 +28,7 @@ export async function isSameVersion(version?: string) {
if (packageJson) {
const { config } = packageJson
try {
await execa('npm', ['view', `${config.name}@${version ?? config.version}`, 'version'])
await x('npm', ['view', `${config.name}@${version ?? config.version}`, 'version'])

s.warn({
text: `The npm package has a same remote version ${config.version}.`,
Expand Down Expand Up @@ -62,7 +62,7 @@ export async function publish({ preRelease, checkRemoteVersion, npmTag }: Publis
args.push('--tag', npmTag)
}

const ret = await execa('pnpm', args)
const ret = await x('pnpm', args)
if (ret.stderr && ret.stderr.includes('npm ERR!')) {
throw new Error('\n' + ret.stderr)
} else {
Expand All @@ -73,15 +73,15 @@ export async function publish({ preRelease, checkRemoteVersion, npmTag }: Publis

async function pushGit(version: string, remote = 'origin', skipGitTag = false) {
const s = createSpinner('Pushing to remote git repository').start()
await execa('git', ['add', '.'])
await execa('git', ['commit', '-m', `v${version}`])
await x('git', ['add', '.'])
await x('git', ['commit', '-m', `v${version}`])

if (!skipGitTag) {
await execa('git', ['tag', `v${version}`])
await execa('git', ['push', remote, `v${version}`])
await x('git', ['tag', `v${version}`])
await x('git', ['push', remote, `v${version}`])
}

const ret = await execa('git', ['push'])
const ret = await x('git', ['push'])
s.success({ text: 'Push remote repository successfully' })
ret.stdout && logger.info(ret.stdout)
}
Expand Down Expand Up @@ -112,7 +112,7 @@ export function updateVersion(version: string) {
}

async function confirmRegistry() {
const registry = (await execa('npm', ['config', 'get', 'registry'])).stdout
const registry = (await x('npm', ['config', 'get', 'registry'])).stdout
const ret = await confirm({
message: `Current registry is: ${registry}`,
})
Expand All @@ -133,10 +133,10 @@ async function confirmVersion(currentVersion: string, expectVersion: string) {
}

async function confirmRefs(remote = 'origin') {
const { stdout } = await execa('git', ['remote', '-v'])
const { stdout } = await x('git', ['remote', '-v'])
const reg = new RegExp(`${remote}\t(.*) \\(push`)
const repo = stdout.match(reg)?.[1]
const { stdout: branch } = await execa('git', ['branch', '--show-current'])
const { stdout: branch } = await x('git', ['branch', '--show-current'])

const ret = await confirm({
message: `Current refs ${repo}:refs/for/${branch}`,
Expand Down Expand Up @@ -229,13 +229,13 @@ export async function release(options: ReleaseCommandOptions) {

if (isPreRelease) {
try {
await execa('git', ['restore', '**/package.json'])
await x('git', ['restore', '**/package.json'])
} catch {
/* empty */
}

try {
await execa('git', ['restore', 'package.json'])
await x('git', ['restore', 'package.json'])
} catch {
/* empty */
}
Expand Down

0 comments on commit de7631c

Please sign in to comment.