refactor(cli): remove execa and migrate to nano-spawn (#593)

This commit is contained in:
pengzhanbo 2025-05-12 11:18:28 +08:00 committed by GitHub
parent c4da089745
commit 1f8a9ce251
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 20 additions and 119 deletions

View File

@ -33,8 +33,8 @@
"@clack/prompts": "catalog:prod",
"@pengzhanbo/utils": "catalog:prod",
"cac": "catalog:prod",
"execa": "catalog:prod",
"handlebars": "catalog:prod",
"nano-spawn": "catalog:prod",
"os-locale": "catalog:prod",
"picocolors": "catalog:prod"
},

View File

@ -2,7 +2,7 @@ import type { File, ResolvedData } from './types.js'
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'
import { execaCommand } from 'execa'
import spawn from 'nano-spawn'
import { DeployType, Mode } from './constants.js'
import { createPackageJson } from './packageJson.js'
import { createRender } from './render.js'
@ -36,8 +36,8 @@ export async function generate(mode: Mode, data: ResolvedData, cwd = process.cwd
})
}
if (data.packageManager === 'yarn') {
const { stdout: yarnVersion } = await execaCommand('yarn --version')
if (yarnVersion.startsWith('2')) {
const { output } = await spawn('yarn', ['--version'])
if (output.startsWith('2')) {
fileList.push({
filepath: '.yarnrc.yml',
content: 'nodeLinker: \'node-modules\'\n',

View File

@ -1,6 +1,6 @@
import type { File, ResolvedData } from './types.js'
import { kebabCase } from '@pengzhanbo/utils'
import { execaCommand } from 'execa'
import spawn from 'nano-spawn'
import { Mode } from './constants.js'
import { readJsonFile, resolve } from './utils/index.js'
@ -96,8 +96,9 @@ export async function createPackageJson(
async function getUserInfo() {
try {
const { stdout: username } = await execaCommand('git config --global user.name')
const { stdout: email } = await execaCommand('git config --global user.email')
const { output: username } = await spawn('git', ['config', '--global', 'user.name'])
const { output: email } = await spawn('git', ['config', '--global', 'user.email'])
console.log('userInfo', username, email)
return { username, email }
}
catch {
@ -107,8 +108,8 @@ async function getUserInfo() {
async function getPackageManagerVersion(pkg: string) {
try {
const { stdout } = await execaCommand(`${pkg} -v`)
return stdout
const { output } = await spawn(pkg, ['--version'])
return output
}
catch {
return null

View File

@ -3,7 +3,7 @@ import path from 'node:path'
import process from 'node:process'
import { intro, outro, spinner } from '@clack/prompts'
import { sleep } from '@pengzhanbo/utils'
import { execaCommand } from 'execa'
import spawn from 'nano-spawn'
import colors from 'picocolors'
import { Mode } from './constants.js'
import { generate } from './generate.js'
@ -36,7 +36,7 @@ export async function run(mode: Mode, root?: string) {
if (data.git) {
progress.message(t('spinner.git'))
try {
await execaCommand('git init', { cwd })
await spawn('git', ['init'], { cwd })
}
catch (e) {
console.error(`${colors.red('git init error: ')}\n`, e)
@ -49,7 +49,7 @@ export async function run(mode: Mode, root?: string) {
if (data.install) {
progress.message(t('spinner.install'))
try {
await execaCommand(`${pm} install`, { cwd })
await spawn(pm, ['install'], { cwd })
}
catch (e) {
console.error(`${colors.red('install dependencies error: ')}\n`, e)

112
pnpm-lock.yaml generated
View File

@ -209,9 +209,6 @@ catalogs:
echarts:
specifier: ^5.6.0
version: 5.6.0
execa:
specifier: ^9.5.3
version: 9.5.3
fast-glob:
specifier: ^3.3.3
version: 3.3.3
@ -263,6 +260,9 @@ catalogs:
minisearch:
specifier: ^7.1.2
version: 7.1.2
nano-spawn:
specifier: ^1.0.1
version: 1.0.1
nanoid:
specifier: ^5.1.5
version: 5.1.5
@ -482,12 +482,12 @@ importers:
cac:
specifier: catalog:prod
version: 6.7.14
execa:
specifier: catalog:prod
version: 9.5.3
handlebars:
specifier: catalog:prod
version: 4.7.8
nano-spawn:
specifier: catalog:prod
version: 1.0.1
os-locale:
specifier: catalog:prod
version: 6.0.2
@ -2189,9 +2189,6 @@ packages:
cpu: [x64]
os: [win32]
'@sec-ant/readable-stream@0.4.1':
resolution: {integrity: sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==}
'@shikijs/core@3.3.0':
resolution: {integrity: sha512-CovkFL2WVaHk6PCrwv6ctlmD4SS1qtIfN8yEyDXDYWh4ONvomdM9MaFw20qHuqJOcb8/xrkqoWQRJ//X10phOQ==}
@ -2255,10 +2252,6 @@ packages:
resolution: {integrity: sha512-LtoMMhxAlorcGhmFYI+LhPgbPZCkgP6ra1YL604EeF6U98pLlQ3iWIGMdWSC+vWmPBWBNgmDBAhnAobLROJmwg==}
engines: {node: '>=18'}
'@sindresorhus/merge-streams@4.0.0':
resolution: {integrity: sha512-tlqY9xq5ukxTUZBmoOp+m61cqwQD5pHJtFY3Mn8CA8ps6yghLH/Hw8UPdqg4OLmFW3IFlcXnQNmo/dh8HzXYIQ==}
engines: {node: '>=18'}
'@stylelint-types/stylelint-order@7.0.0':
resolution: {integrity: sha512-bOdHx5HctF1zrMwpn6eniu+0B/EtFtxAXUtOpyAi4je937URLHSjm3yLoyXE2uuJV0hdUcNe2aUFsS3/AkuSwA==}
engines: {node: '>=18.0.0', npm: '>=9.0.0', pnpm: '>=8.6.0'}
@ -4253,10 +4246,6 @@ packages:
resolution: {integrity: sha512-l19WpE2m9hSuyP06+FbuUUf1G+R0SFLrtQfbRb9PRr+oimOfxQhgGCbVaXg5IvZyyTThJsxh6L/srkMiCeBPDA==}
engines: {node: '>=18.0.0'}
execa@9.5.3:
resolution: {integrity: sha512-QFNnTvU3UjgWFy8Ef9iDHvIdcgZ344ebkwYx4/KLbR+CKQA4xBaHzv+iRpp86QfMHP8faFQLh8iOc57215y4Rg==}
engines: {node: ^18.19.0 || >=20.5.0}
expand-tilde@2.0.2:
resolution: {integrity: sha512-A5EmesHW6rfnZ9ysHQjPdJRni0SRar0tjtG5MNtm9n5TUvsYU8oozprtRD4AqHxcZWWlVuAmQo2nWKfN9oyjTw==}
engines: {node: '>=0.10.0'}
@ -4330,10 +4319,6 @@ packages:
resolution: {integrity: sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==}
engines: {node: '>=8'}
figures@6.1.0:
resolution: {integrity: sha512-d+l3qxjSesT4V7v2fh+QnmFnUWv9lSpjarhShNTgBOfA0ttejbQUAlHLitbjkoRiDulW0OPoQPYIGhIC8ohejg==}
engines: {node: '>=18'}
file-entry-cache@10.0.8:
resolution: {integrity: sha512-FGXHpfmI4XyzbLd3HQ8cbUcsFGohJpZtmQRHr8z8FxxtCe2PcpgIlVLwIgunqjvRmXypBETvwhV4ptJizA+Y1Q==}
@ -4471,10 +4456,6 @@ packages:
resolution: {integrity: sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==}
engines: {node: '>= 0.4'}
get-stream@9.0.1:
resolution: {integrity: sha512-kVCxPF3vQM/N0B1PmoqVUqgHP+EeVjmZSQn+1oCRPxd2P21P2F19lIgbR3HBosbB1PUhOAoctJnfEn2GbN2eZA==}
engines: {node: '>=18'}
get-tsconfig@4.10.0:
resolution: {integrity: sha512-kGzZ3LWWQcGIAmg6iWvXn0ei6WDtV26wzHRMwDSzmAbcXrTEXxHy6IehI6/4eT6VRKyMP1eF1VqwrVUmE/LR7A==}
@ -4699,10 +4680,6 @@ packages:
engines: {node: '>=12'}
hasBin: true
human-signals@8.0.0:
resolution: {integrity: sha512-/1/GPCpDUCCYwlERiYjxoczfP0zfvZMU/OWgQPMya9AbAE24vseigFdhAMObpc8Q4lc/kjutPfUddDYyAmejnA==}
engines: {node: '>=18.18.0'}
husky@9.1.7:
resolution: {integrity: sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==}
engines: {node: '>=18'}
@ -4881,10 +4858,6 @@ packages:
is-promise@4.0.0:
resolution: {integrity: sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==}
is-stream@4.0.1:
resolution: {integrity: sha512-Dnz92NInDqYckGEUJv689RbRiTSEHCQ7wOVeALbkOz999YpqT46yMRIGtSNl2iCL1waAZSx40+h59NV/EwzV/A==}
engines: {node: '>=18'}
is-text-path@2.0.0:
resolution: {integrity: sha512-+oDTluR6WEjdXEJMnC2z6A4FRwFoYuvShVVEGsS7ewc0UTi2QtAKMDJuL4BDEVt+5T7MjFo12RP8ghOM75oKJw==}
engines: {node: '>=8'}
@ -5604,10 +5577,6 @@ packages:
resolution: {integrity: sha512-bdok/XvKII3nUpklnV6P2hxtMNrCboOjAcyBuQnWEhO665FwrSNRxU+AqpsyvO6LgGYPspN+lu5CLtw4jPRKNA==}
engines: {node: '>=0.10.0'}
npm-run-path@6.0.0:
resolution: {integrity: sha512-9qny7Z9DsQU8Ou39ERsPU4OZQlSTP47ShQzuKZ6PRXpYLtIFgl/DEBYEXKlvcEa+9tHVcK8CF81Y2V72qaZhWA==}
engines: {node: '>=18'}
npm2url@0.2.4:
resolution: {integrity: sha512-arzGp/hQz0Ey+ZGhF64XVH7Xqwd+1Q/po5uGiBbzph8ebX6T0uvt3N7c1nBHQNsQVykQgHhqoRTX7JFcHecGuw==}
@ -5735,10 +5704,6 @@ packages:
resolution: {integrity: sha512-rum1bPifK5SSar35Z6EKZuYPJx85pkNaFrxBK3mwdfSJ1/WKbYrjoW/zTPSjRRamfmVX1ACBIdFAO0VRErW/EA==}
engines: {node: '>=18'}
parse-ms@4.0.0:
resolution: {integrity: sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==}
engines: {node: '>=18'}
parse-node-version@1.0.1:
resolution: {integrity: sha512-3YHlOa/JgH6Mnpr05jP9eDG254US9ek25LyIxZlDItp2iJtwyaXQb57lBYLdT3MowkUFYEV2XXNAYIPlESvJlA==}
engines: {node: '>= 0.10'}
@ -5785,10 +5750,6 @@ packages:
resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==}
engines: {node: '>=8'}
path-key@4.0.0:
resolution: {integrity: sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==}
engines: {node: '>=12'}
path-parse@1.0.7:
resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==}
@ -5953,10 +5914,6 @@ packages:
resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==}
engines: {node: '>= 0.8.0'}
pretty-ms@9.2.0:
resolution: {integrity: sha512-4yf0QO/sllf/1zbZWYnvWw3NxCQwLXKzIj0G849LSufP15BXKM0rbD2Z3wVnkMfjdn/CB0Dpp444gYAACdsplg==}
engines: {node: '>=18'}
prismjs@1.29.0:
resolution: {integrity: sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==}
engines: {node: '>=6'}
@ -6531,10 +6488,6 @@ packages:
resolution: {integrity: sha512-3xurFv5tEgii33Zi8Jtp55wEIILR9eh34FAW00PZf+JnSsTmV/ioewSgQl97JHvgjoRGwPShsWm+IdrxB35d0w==}
engines: {node: '>=8'}
strip-final-newline@4.0.0:
resolution: {integrity: sha512-aulFJcD6YK8V1G7iRB5tigAP4TsHBZZrOV8pjV++zdUwmeV8uzbY7yn6h9MswN62adStNZFuCIx4haBnRuMDaw==}
engines: {node: '>=18'}
strip-indent@4.0.0:
resolution: {integrity: sha512-mnVSV2l+Zv6BLpSD/8V87CW/y9EmmbYzGCIavsnsI6/nwn26DwffM/yztm30Z/I2DY9wdS3vXVCMnHDgZaVNoA==}
engines: {node: '>=12'}
@ -7294,10 +7247,6 @@ packages:
resolution: {integrity: sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g==}
engines: {node: '>=12.20'}
yoctocolors@2.1.1:
resolution: {integrity: sha512-GQHQqAopRhwU8Kt1DDM8NjibDXHC8eoh1erhGAJPEyveY9qqVeXvVikNKrDz69sHowPMorbPUrH/mx8c50eiBQ==}
engines: {node: '>=18'}
zod-to-json-schema@3.24.5:
resolution: {integrity: sha512-/AuWwMP+YqiPbsJx5D6TfgRTc4kTLjsh5SOcd4bLsfUg2RcEXrFMJl1DGgdHy2aCfsIA/cr/1JM0xcB2GZji8g==}
peerDependencies:
@ -8584,8 +8533,6 @@ snapshots:
'@rollup/rollup-win32-x64-msvc@4.40.0':
optional: true
'@sec-ant/readable-stream@0.4.1': {}
'@shikijs/core@3.3.0':
dependencies:
'@shikijs/types': 3.3.0
@ -8679,8 +8626,6 @@ snapshots:
'@sindresorhus/merge-streams@2.3.0': {}
'@sindresorhus/merge-streams@4.0.0': {}
'@stylelint-types/stylelint-order@7.0.0(stylelint-define-config@16.19.0(stylelint@16.19.1(typescript@5.8.3)))(stylelint@16.19.1(typescript@5.8.3))':
dependencies:
stylelint-define-config: 16.19.0(stylelint@16.19.1(typescript@5.8.3))
@ -11093,21 +11038,6 @@ snapshots:
dependencies:
eventsource-parser: 3.0.1
execa@9.5.3:
dependencies:
'@sindresorhus/merge-streams': 4.0.0
cross-spawn: 7.0.6
figures: 6.1.0
get-stream: 9.0.1
human-signals: 8.0.0
is-plain-obj: 4.1.0
is-stream: 4.0.1
npm-run-path: 6.0.0
pretty-ms: 9.2.0
signal-exit: 4.1.0
strip-final-newline: 4.0.0
yoctocolors: 2.1.1
expand-tilde@2.0.2:
dependencies:
homedir-polyfill: 1.0.3
@ -11200,10 +11130,6 @@ snapshots:
dependencies:
escape-string-regexp: 1.0.5
figures@6.1.0:
dependencies:
is-unicode-supported: 2.1.0
file-entry-cache@10.0.8:
dependencies:
flat-cache: 6.1.8
@ -11351,11 +11277,6 @@ snapshots:
dunder-proto: 1.0.1
es-object-atoms: 1.1.1
get-stream@9.0.1:
dependencies:
'@sec-ant/readable-stream': 0.4.1
is-stream: 4.0.1
get-tsconfig@4.10.0:
dependencies:
resolve-pkg-maps: 1.0.0
@ -11665,8 +11586,6 @@ snapshots:
- debug
- supports-color
human-signals@8.0.0: {}
husky@9.1.7: {}
hyperdyperid@1.2.0: {}
@ -11803,8 +11722,6 @@ snapshots:
is-promise@4.0.0: {}
is-stream@4.0.1: {}
is-text-path@2.0.0:
dependencies:
text-extensions: 2.4.0
@ -12718,11 +12635,6 @@ snapshots:
normalize-range@0.1.2: {}
npm-run-path@6.0.0:
dependencies:
path-key: 4.0.0
unicorn-magic: 0.3.0
npm2url@0.2.4: {}
nth-check@2.1.1:
@ -12871,8 +12783,6 @@ snapshots:
index-to-position: 0.1.2
type-fest: 4.36.0
parse-ms@4.0.0: {}
parse-node-version@1.0.1: {}
parse-passwd@1.0.0: {}
@ -12906,8 +12816,6 @@ snapshots:
path-key@3.1.1: {}
path-key@4.0.0: {}
path-parse@1.0.7: {}
path-scurry@1.11.1:
@ -13041,10 +12949,6 @@ snapshots:
prelude-ls@1.2.1: {}
pretty-ms@9.2.0:
dependencies:
parse-ms: 4.0.0
prismjs@1.29.0: {}
property-information@7.0.0: {}
@ -13640,8 +13544,6 @@ snapshots:
strip-bom@4.0.0: {}
strip-final-newline@4.0.0: {}
strip-indent@4.0.0:
dependencies:
min-indent: 1.0.1
@ -14432,8 +14334,6 @@ snapshots:
yocto-queue@1.1.1: {}
yoctocolors@2.1.1: {}
zod-to-json-schema@3.24.5(zod@3.24.4):
dependencies:
zod: 3.24.4

View File

@ -87,7 +87,6 @@ catalogs:
dayjs: ^1.11.13
echarts: ^5.6.0
esbuild: ^0.25.4
execa: ^9.5.3
fast-glob: ^3.3.3
flowchart.ts: ^3.0.1
focus-trap: ^7.6.4
@ -105,6 +104,7 @@ catalogs:
markmap-toolbar: ^0.18.10
markmap-view: ^0.18.10
minisearch: ^7.1.2
nano-spawn: ^1.0.1
nanoid: ^5.1.5
os-locale: ^6.0.2
p-map: ^7.0.3