From de7631c14140132672d2c11fa946bb1438c1ffbc Mon Sep 17 00:00:00 2001 From: chouchouji <70570907+chouchouji@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:59:44 +0800 Subject: [PATCH] chore: migrate from execa to tinyexec (#11) --- bin/index.js | 0 package.json | 4 ++-- pnpm-lock.yaml | 21 ++++++++++++--------- src/release.ts | 28 ++++++++++++++-------------- 4 files changed, 28 insertions(+), 25 deletions(-) mode change 100644 => 100755 bin/index.js diff --git a/bin/index.js b/bin/index.js old mode 100644 new mode 100755 diff --git a/package.json b/package.json index 9dbae0d..9ea5111 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9756532..f2c7f45 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,9 +17,6 @@ importers: conventional-changelog: specifier: ^5.1.0 version: 5.1.0 - execa: - specifier: ^8.0.1 - version: 8.0.1 fs-extra: specifier: ^11.1.1 version: 11.1.1 @@ -35,6 +32,9 @@ importers: semver: specifier: ^7.5.4 version: 7.5.4 + tinyexec: + specifier: ^0.3.0 + version: 0.3.0 devDependencies: '@types/conventional-changelog': specifier: ^3.1.5 @@ -65,7 +65,7 @@ importers: version: 2.9.0 tsup: specifier: ^8.3.0 - version: 8.3.0(typescript@5.2.2)(yaml@2.3.4) + version: 8.3.0(typescript@5.2.2) typescript: specifier: ^5.2.2 version: 5.2.2 @@ -1937,6 +1937,9 @@ packages: through@2.3.8: resolution: {integrity: sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==} + tinyexec@0.3.0: + resolution: {integrity: sha512-tVGE0mVJPGb0chKhqmsoosjsS+qUnJVGJpZgsHYQcGoPlG3B51R3PouqTgEGH2Dc9jjFyOqOpix6ZHNMXp1FZg==} + tinyglobby@0.2.9: resolution: {integrity: sha512-8or1+BGEdk1Zkkw2ii16qSS7uVrQJPre5A9o/XkWPATkk23FZh/15BKFxPnlTy6vkljZxLqYCzzBMj30ZrSvjw==} engines: {node: '>=12.0.0'} @@ -3827,11 +3830,9 @@ snapshots: pirates@4.0.6: {} - postcss-load-config@6.0.1(yaml@2.3.4): + postcss-load-config@6.0.1: dependencies: lilconfig: 3.1.2 - optionalDependencies: - yaml: 2.3.4 postcss-selector-parser@6.0.13: dependencies: @@ -4092,6 +4093,8 @@ snapshots: through@2.3.8: {} + tinyexec@0.3.0: {} + tinyglobby@0.2.9: dependencies: fdir: 6.4.0(picomatch@4.0.2) @@ -4122,7 +4125,7 @@ snapshots: tslib@1.14.1: {} - tsup@8.3.0(typescript@5.2.2)(yaml@2.3.4): + tsup@8.3.0(typescript@5.2.2): dependencies: bundle-require: 5.0.0(esbuild@0.23.1) cac: 6.7.14 @@ -4133,7 +4136,7 @@ snapshots: execa: 5.1.1 joycon: 3.1.1 picocolors: 1.1.0 - postcss-load-config: 6.0.1(yaml@2.3.4) + postcss-load-config: 6.0.1 resolve-from: 5.0.0 rollup: 4.24.0 source-map: 0.8.0-beta.0 diff --git a/src/release.ts b/src/release.ts index 4e9a444..fa12d25 100644 --- a/src/release.ts +++ b/src/release.ts @@ -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' @@ -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 } @@ -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}.`, @@ -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 { @@ -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) } @@ -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}`, }) @@ -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}`, @@ -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 */ }