diff --git a/package.json b/package.json index 1ce49b9f..46b94dca 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,6 @@ "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", @@ -66,6 +65,7 @@ "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" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 66a7fff7..1138e457 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,9 +26,6 @@ importers: esbuild: specifier: ^0.23.1 version: 0.23.1 - execa: - specifier: ^5.1.1 - version: 5.1.1 joycon: specifier: ^3.1.1 version: 3.1.1 @@ -50,6 +47,9 @@ importers: sucrase: specifier: ^3.35.0 version: 3.35.0 + tinyexec: + specifier: ^0.3.0 + version: 0.3.0 tinyglobby: specifier: ^0.2.6 version: 0.2.6 diff --git a/src/errors.ts b/src/errors.ts index d6b2dde6..7aa0906c 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,5 +1,5 @@ import { isMainThread, parentPort } from 'node:worker_threads' -import * as colors from 'picocolors' +import colors from 'picocolors' export class PrettyError extends Error { constructor(message: string) { diff --git a/src/index.ts b/src/index.ts index 2b694159..425832b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 { exec, type Result as ExecChild } from 'tinyexec' import { glob } from 'tinyglobby' import kill from 'tree-kill' import { version } from '../package.json' @@ -28,7 +28,6 @@ import { terserPlugin } from './plugins/terser' import { runTypeScriptCompiler } from './tsc' import { runDtsRollup } from './api-extractor' import { cjsInterop } from './plugins/cjs-interop' -import type { ChildProcess } from 'node:child_process' import type { Format, KILL_SIGNAL, NormalizedOptions, Options } from './options' export type { Format, Options, NormalizedOptions } @@ -272,7 +271,7 @@ export async function build(_options: Options) { const mainTasks = async () => { if (!options.dts?.only) { - let onSuccessProcess: ChildProcess | undefined + let onSuccessProcess: ExecChild | undefined let onSuccessCleanup: (() => any) | undefined | void /** Files imported by the entry */ const buildDependencies: Set = new Set() @@ -365,15 +364,17 @@ 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) => { - if (code && code !== 0) { - process.exitCode = code - } + onSuccessProcess = exec(options.onSuccess, [], { + nodeOptions: { shell: true, stdio: 'inherit' }, }) + + await onSuccessProcess + if ( + onSuccessProcess.exitCode && + onSuccessProcess.exitCode !== 0 + ) { + process.exitCode = onSuccessProcess.exitCode + } } } } diff --git a/src/lib/report-size.ts b/src/lib/report-size.ts index efd841e2..6603df7f 100644 --- a/src/lib/report-size.ts +++ b/src/lib/report-size.ts @@ -1,4 +1,4 @@ -import * as colors from 'picocolors' +import colors from 'picocolors' import type { Logger } from '../log' const prettyBytes = (bytes: number) => { diff --git a/src/log.ts b/src/log.ts index 0a8565e9..5a88191c 100644 --- a/src/log.ts +++ b/src/log.ts @@ -1,6 +1,6 @@ import util from 'node:util' import { isMainThread, parentPort } from 'node:worker_threads' -import * as colors from 'picocolors' +import colors from 'picocolors' type LOG_TYPE = 'info' | 'success' | 'error' | 'warn' diff --git a/test/utils.ts b/test/utils.ts index ca9e702c..1bce118f 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -3,7 +3,7 @@ import fsp from 'node:fs/promises' import path from 'node:path' import { fileURLToPath } from 'node:url' import { expect } from 'vitest' -import execa from 'execa' +import { exec } from 'tinyexec' import { glob } from 'tinyglobby' const __dirname = path.dirname(fileURLToPath(import.meta.url)) @@ -48,16 +48,16 @@ export async function run( const entry = options.entry || ['input.ts'] // Run tsup cli - const { exitCode, stdout, stderr } = await execa( - bin, - [...entry, ...(options.flags || [])], - { + const processPromise = exec(bin, [...entry, ...(options.flags || [])], { + nodeOptions: { cwd: testDir, env: { ...process.env, ...options.env }, }, - ) + }) + const { stdout, stderr } = await processPromise + const logs = stdout + stderr - if (exitCode !== 0) { + if (processPromise.exitCode !== 0) { throw new Error(logs) } diff --git a/vitest-global.ts b/vitest-global.ts index 90f7b3bd..5bda97a6 100644 --- a/vitest-global.ts +++ b/vitest-global.ts @@ -1,12 +1,12 @@ import path from 'node:path' import fs from 'node:fs/promises' -import execa from 'execa' +import { exec } 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 exec('pnpm', ['i'], { nodeOptions: { cwd: testDir } }) console.log(`Done... start testing..`) }