这是indexloc提供的服务,不要输入任何密码
Skip to content

cleanup: replace execa with tinyexec #1215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ playground
.idea
.DS_Store
.eslintcache
.pnpm-store
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@
"consola": "^3.2.3",
"debug": "^4.3.7",
"esbuild": "^0.23.1",
"execa": "^5.1.1",
"joycon": "^3.1.1",
"picocolors": "^1.1.0",
"postcss-load-config": "^6.0.1",
"resolve-from": "^5.0.0",
"rollup": "^4.21.3",
"source-map": "0.8.0-beta.0",
"sucrase": "^3.35.0",
"tinyexec": "^0.3.0",
"tinyglobby": "^0.2.6",
"tree-kill": "^1.2.2"
},
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

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

14 changes: 8 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'node:path'
import fs from 'node:fs'
import { Worker } from 'node:worker_threads'
import { loadTsConfig } from 'bundle-require'
import execa from 'execa'
import { x } from 'tinyexec'
import { glob } from 'tinyglobby'
import kill from 'tree-kill'
import { version } from '../package.json'
Expand Down Expand Up @@ -365,11 +365,13 @@ export async function build(_options: Options) {
if (typeof options.onSuccess === 'function') {
onSuccessCleanup = await options.onSuccess()
} else {
onSuccessProcess = execa(options.onSuccess, {
shell: true,
stdio: 'inherit',
})
onSuccessProcess.on('exit', (code) => {
onSuccessProcess = x(options.onSuccess, [], {
nodeOptions: {
shell: true,
stdio: 'inherit',
},
}).process
onSuccessProcess?.on('exit', (code) => {
if (code && code !== 0) {
process.exitCode = code
}
Expand Down
16 changes: 6 additions & 10 deletions test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { expect } from 'vitest'
import execa from 'execa'
import fs from 'fs-extra'
import { x } from 'tinyexec'
import { glob } from 'tinyglobby'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
Expand Down Expand Up @@ -43,16 +43,12 @@ export async function run(
const entry = options.entry || ['input.ts']

// Run tsup cli
const { exitCode, stdout, stderr } = await execa(
bin,
[...entry, ...(options.flags || [])],
{
cwd: testDir,
env: { ...process.env, ...options.env },
},
)
const result = x(bin, [...entry, ...(options.flags || [])], {
nodeOptions: { cwd: testDir, env: { ...process.env, ...options.env } },
})
const { stdout, stderr } = await result
const logs = stdout + stderr
if (exitCode !== 0) {
if (result.exitCode !== 0) {
throw new Error(logs)
}

Expand Down
4 changes: 2 additions & 2 deletions vitest-global.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from 'node:path'
import fs from 'node:fs/promises'
import execa from 'execa'
import { x } from 'tinyexec'

export default async function setup() {
const testDir = path.resolve(__dirname, 'test')
const cacheDir = path.resolve(testDir, '.cache')
await fs.rm(cacheDir, { recursive: true, force: true })
console.log(`Installing dependencies in ./test folder`)
await execa('pnpm', ['i'], { cwd: testDir })
await x('pnpm', ['i'], { nodeOptions: { cwd: testDir } })
console.log(`Done... start testing..`)
}