Skip to content
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

chore(deps): replace execa with tinyexec #6454

Merged
merged 15 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
2 changes: 1 addition & 1 deletion packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@
"@vitest/utils": "workspace:*",
"chai": "^5.1.1",
"debug": "^4.3.6",
"execa": "^8.0.1",
"magic-string": "^0.30.11",
"pathe": "^1.1.2",
"std-env": "^3.7.0",
"tinybench": "^2.9.0",
"tinyexec": "^0.3.0",
"tinypool": "^1.0.0",
"tinyrainbow": "^1.2.0",
"vite": "^5.0.0",
Expand Down
9 changes: 5 additions & 4 deletions packages/vitest/src/create/browser/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import c from 'tinyrainbow'
import type { Agent } from '@antfu/install-pkg'
import { detectPackageManager, installPackage } from '@antfu/install-pkg'
import { findUp } from 'find-up'
import { execa } from 'execa'
import { x } from 'tinyexec'
import type { BrowserBuiltinProvider } from '../../node/types/browser'
import { configFiles } from '../../constants'
import { generateExampleFiles } from './examples'
Expand Down Expand Up @@ -499,9 +499,10 @@ export async function create() {
const allArgs = [...args, 'playwright', 'install', '--with-deps']
log(c.cyan('◼'), `Installing Playwright dependencies with \`${c.bold(command)} ${c.bold(allArgs.join(' '))}\`...`)
log()
await execa(command, allArgs, {
stdout: 'inherit',
stderr: 'inherit',
await x(command, allArgs, {
nodeOptions: {
stdio: ['pipe', 'inherit', 'inherit'],
},
Comment on lines -502 to +505
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tinyexec doesn't provide a wrapper that passes the options along to stdio, so we pass them directly. pipe is used for stdin (first item in the array) as it was the default in execa: https://github.com/sindresorhus/execa/blob/HEAD/docs/api.md#optionsstdin.

})
}

Expand Down
14 changes: 7 additions & 7 deletions packages/vitest/src/node/git.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'pathe'
import { execa } from 'execa'
import type { ExecaReturnValue } from 'execa'
import type { Output } from 'tinyexec'
import { x } from 'tinyexec'

export interface GitOptions {
changedSince?: string | boolean
Expand All @@ -12,10 +12,10 @@ export class VitestGit {
constructor(private cwd: string) {}

private async resolveFilesWithGitCommand(args: string[]): Promise<string[]> {
let result: ExecaReturnValue
let result: Output

try {
result = await execa('git', args, { cwd: this.root })
result = await x('git', args, { nodeOptions: { cwd: this.root } })
}
catch (e: any) {
e.message = e.stderr
Expand Down Expand Up @@ -75,12 +75,12 @@ export class VitestGit {
}

async getRoot(cwd: string) {
const options = ['rev-parse', '--show-cdup']
const args = ['rev-parse', '--show-cdup']

try {
const result = await execa('git', options, { cwd })
const result = await x('git', args, { nodeOptions: { cwd } })

return resolve(cwd, result.stdout)
return resolve(cwd, result.stdout.trim())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execa trims the leading newline by default, while tinyexec doesn't. Without trimming, we'd try to launch git with invalid cwd (due to the leading newline) which broke the functionality.

}
catch {
return null
Expand Down
20 changes: 11 additions & 9 deletions packages/vitest/src/typecheck/typechecker.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { rm } from 'node:fs/promises'
import { performance } from 'node:perf_hooks'
import type { ExecaChildProcess } from 'execa'
import { execa } from 'execa'
import type { ChildProcess } from 'node:child_process'
import { basename, extname, resolve } from 'pathe'
import { TraceMap, generatedPositionFor } from '@vitest/utils/source-map'
import type { RawSourceMap } from '@ampproject/remapping'
import type { ParsedStack } from '@vitest/utils'
import type { File, Task, TaskResultPack, TaskState } from '@vitest/runner'
import { x } from 'tinyexec'
import { getTasks } from '../utils'
import type { WorkspaceProject } from '../node/workspace'
import type { Awaitable } from '../types/general'
Expand Down Expand Up @@ -50,7 +50,7 @@ export class Typechecker {
private _tests: Record<string, FileInformation> | null = {}
private tempConfigPath?: string
private allowJs?: boolean
private process?: ExecaChildProcess
private process?: ChildProcess

protected files: string[] = []

Expand Down Expand Up @@ -310,15 +310,17 @@ export class Typechecker {
}
this._output = ''
this._startTime = performance.now()
const child = execa(typecheck.checker, args, {
cwd: root,
stdout: 'pipe',
reject: false,
const child = x(typecheck.checker, args, {
nodeOptions: {
cwd: root,
stdio: 'pipe',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdio: 'pipe' is equivalent to stdio: ['pipe', 'pipe', 'pipe'] which is the default in execa.

},
throwOnError: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've investigated in both execa and tinyexec, this should be roughly equivalent to reject: false. Relevant PR: tinylibs/tinyexec#34.

})
this.process = child
this.process = child.process
await this._onParseStart?.()
let rerunTriggered = false
child.stdout?.on('data', (chunk) => {
child.process?.stdout?.on('data', (chunk) => {
this._output += chunk
if (!watch) {
return
Expand Down
Loading
Loading