diff --git a/package.json b/package.json index a199f2a..8d5c07f 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e887a0c..86b7394 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -69,6 +69,9 @@ importers: rimraf: specifier: ^6.0.1 version: 6.0.1 + shell-quote: + specifier: ^1.8.2 + version: 1.8.2 tsup: specifier: ^8.3.5 version: 8.3.5(jiti@2.4.1)(postcss@8.4.35)(tsx@4.19.1)(typescript@5.7.2) @@ -2872,6 +2875,10 @@ packages: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} + shell-quote@1.8.2: + resolution: {integrity: sha512-AzqKpGKjrj7EM6rKVQEPpB288oCfnrEIuyoT9cyF4nmGa7V8Zk6f7RRqYisX8X9m+Q7bd632aZW4ky7EhbQztA==} + engines: {node: '>= 0.4'} + siginfo@2.0.0: resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==} @@ -6298,6 +6305,8 @@ snapshots: shebang-regex@3.0.0: {} + shell-quote@1.8.2: {} + siginfo@2.0.0: {} signal-exit@3.0.6: {} diff --git a/src/version-bump.ts b/src/version-bump.ts index b1a7ad2..5300d93 100644 --- a/src/version-bump.ts +++ b/src/version-bump.ts @@ -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' @@ -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') diff --git a/test/exec.test.ts b/test/exec.test.ts new file mode 100644 index 0000000..5dddc95 --- /dev/null +++ b/test/exec.test.ts @@ -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() +}) diff --git a/test/fixture/package.json b/test/fixture/package.json new file mode 100644 index 0000000..2cb7d8f --- /dev/null +++ b/test/fixture/package.json @@ -0,0 +1,6 @@ +{ + "version": "0.0.1", + "scripts": { + "clean": "rimraf dist" + } +}