mirror of
https://github.com/egoist/tsup.git
synced 2025-12-08 20:35:58 +00:00
refactor: replace execa with tinyexec (#1127)
This commit is contained in:
parent
23f6bbb46d
commit
4dd5bfeb2f
@ -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"
|
||||
},
|
||||
|
||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@ -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
|
||||
|
||||
@ -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) {
|
||||
|
||||
23
src/index.ts
23
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<string> = 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import * as colors from 'picocolors'
|
||||
import colors from 'picocolors'
|
||||
import type { Logger } from '../log'
|
||||
|
||||
const prettyBytes = (bytes: number) => {
|
||||
|
||||
@ -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'
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
@ -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..`)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user