Skip to content

Commit

Permalink
fix: --exec ENOENT tinyexec args, close #62 (#63)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
YunYouJun and antfu authored Dec 12, 2024
1 parent 1229cd7 commit 1eda378
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"npm-check": "^6.0.1",
"picocolors": "^1.1.1",
"rimraf": "^6.0.1",
"shell-quote": "^1.8.2",
"tsup": "^8.3.5",
"typescript": "^5.7.2",
"vitest": "^2.1.8"
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

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

8 changes: 6 additions & 2 deletions src/version-bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import process from 'node:process'
import symbols from 'log-symbols'
import c from 'picocolors'
import prompts from 'prompts'
// @ts-expect-error missing types
import parseCommand from 'shell-quote/parse'
import { x } from 'tinyexec'
import { getCurrentVersion } from './get-current-version'
import { getNewVersion } from './get-new-version'
Expand Down Expand Up @@ -76,10 +78,12 @@ export async function versionBump(arg: (VersionBumpOptions) | string = {}): Prom
await operation.options.execute(operation)
}
else {
console.log(symbols.info, 'Executing script', operation.options.execute)
await x(operation.options.execute, [], {
const [command, ...args] = parseCommand(operation.options.execute)
console.log(symbols.info, 'Executing script', command, ...args)
await x(command, args, {
nodeOptions: {
stdio: 'inherit',
cwd: operation.options.cwd,
},
})
console.log(symbols.success, 'Script finished')
Expand Down
23 changes: 23 additions & 0 deletions test/exec.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { existsSync } from 'node:fs'
import { mkdir } from 'node:fs/promises'
import { join } from 'node:path'
import { cwd } from 'node:process'
import { expect, it } from 'vitest'
import { versionBump } from '../src'

const distDir = join(cwd(), 'test', 'fixture', 'dist')

it('exec command to clean dist dir', async () => {
if (!existsSync(distDir)) {
await mkdir(distDir)
}

expect(existsSync(distDir)).toBeTruthy()
await versionBump({
cwd: join(cwd(), 'test', 'fixture'),
release: '0.0.1',
confirm: false,
execute: 'npm run clean',
})
expect(existsSync(distDir)).toBeFalsy()
})
6 changes: 6 additions & 0 deletions test/fixture/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "0.0.1",
"scripts": {
"clean": "rimraf dist"
}
}

0 comments on commit 1eda378

Please sign in to comment.