Skip to content

Commit 3324bdc

Browse files
committed
chore: shell option
no wip here in case i need to search for it later again 😂
1 parent 1fd11a4 commit 3324bdc

File tree

8 files changed

+59
-28
lines changed

8 files changed

+59
-28
lines changed

.stacks/core/actions/src/build/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import { runCommands } from '@stacksjs/cli'
33

44
await runCommands([
55
'pnpm -r --filter "./core/*" --filter "!./core/x-ray" build', // build all packages except x-ray (which is a dev tool/app)
6-
], { verbose: true, cwd: frameworkPath(), shell: true })
6+
], { verbose: true, cwd: frameworkPath() })

.stacks/core/actions/src/bump.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { frameworkPath } from '@stacksjs/path'
33

44
await runCommand(
55
'bunx bumpp ./package.json ./core/**/package.json ./ide/vscode/package.json --execute "buddy changelog --quiet" --all',
6-
{ verbose: true, cwd: frameworkPath(), shell: true },
6+
{ verbose: true, cwd: frameworkPath() },
77
)

.stacks/core/actions/src/changelog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { projectPath } from '@stacksjs/path'
33

44
await runCommand(
55
'changelogen --output CHANGELOG.md --from $(git describe --abbrev=0 --tags HEAD^) --to $(git describe)',
6-
{ verbose: true, cwd: projectPath(), shell: true },
6+
{ verbose: true, cwd: projectPath() },
77
)

.stacks/core/actions/src/release.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ await runActions([
1010
Action.LintFix, // ensure there are no lint errors
1111
// Action.Test, // run the tests
1212
Action.Bump, // bump the versions, create the git tag, generate the changelog, commit & push the changes
13-
], { verbose: true, cwd: frameworkPath(), shell: true }) // debug mode needs to be enabled to see the output due to the interactive prompts
13+
], { verbose: true, cwd: frameworkPath() }) // debug mode needs to be enabled to see the output due to the interactive prompts
1414

1515
log.success(`Successfully released ${app.name}`)

.stacks/core/buddy/src/commands/upgrade.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function upgrade(buddy: CLI) {
5252
options = answers.reduce((a: any, v: any) => ({ ...a, [v]: true }), {})
5353
}
5454

55-
const result = await runAction(Action.Upgrade, { ...options, shell: true })
55+
const result = await runAction(Action.Upgrade, { ...options })
5656

5757
if (result.isErr()) {
5858
outro('While running the buddy:upgrade command, there was an issue', { startTime: perf, useSeconds: true, isError: true }, result.error as Error)

.stacks/core/cli/src/run.ts

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,37 @@ import { log } from './console'
1212
* @param options The options to pass to the command.
1313
* @param errorMsg The name of the error to throw if the command fails.
1414
* @returns The result of the command.
15+
* @example
16+
* ```ts
17+
* const result = await exec('ls')
18+
*
19+
* if (result.isErr())
20+
* console.error(result.error)
21+
* else
22+
* console.log(result)
23+
* ```
24+
* @example
25+
* ```ts
26+
* const result = await exec('ls', { cwd: '/home' })
27+
* ```
1528
*/
1629
export async function exec(command: string | string[], options?: CliOptions): Promise<ResultAsync<Subprocess, StacksError>> {
17-
const cmd = Array.isArray(command) ? command : command.split(' ')
30+
const cmd: string[] = Array.isArray(command) ? command : command.split(' ')
1831
const proc = spawn(cmd, {
1932
...options,
2033
stdout: options?.stdout || 'inherit',
2134
cwd: options?.cwd || import.meta.dir,
2235
onExit(subprocess, exitCode, signalCode, error) {
23-
if (exitCode !== ExitCode.Success && exitCode) {
36+
console.log('here')
37+
if (exitCode !== 0 && exitCode) {
2438
log.error(error)
2539
process.exit(exitCode)
2640
}
2741
},
2842
})
29-
const exited = await proc.exited
3043

31-
if (exited === ExitCode.Success)
44+
const exited = await proc.exited
45+
if (exited === 0)
3246
return okAsync(proc)
3347

3448
return errAsync(handleError(new Error(`Failed to execute command: ${cmd.join(' ')}`)))
@@ -39,6 +53,19 @@ export async function exec(command: string | string[], options?: CliOptions): Pr
3953
*
4054
* @param command The command to execute.
4155
* @returns The result of the command.
56+
* @example
57+
* ```ts
58+
* const result = execSync('ls')
59+
*
60+
* if (result.isErr())
61+
* console.error(result.error)
62+
* else
63+
* console.log(result)
64+
* ```
65+
* @example
66+
* ```ts
67+
* const result = execSync('ls', { cwd: '/home' })
68+
* ```
4269
*/
4370
export function execSync(command: string | string[], options?: CliOptions): Result<SyncSubprocess, Error> {
4471
const cmd = Array.isArray(command) ? command : command.split(' ')
@@ -64,9 +91,29 @@ export function execSync(command: string | string[], options?: CliOptions): Resu
6491
* @param command The command to run.
6592
* @param options The options to pass to the command.
6693
* @returns The result of the command.
94+
* @example
95+
* ```ts
96+
* const result = await runCommand('ls')
97+
*
98+
* if (result.isErr())
99+
* console.error(result.error)
100+
* else
101+
* console.log(result)
102+
* ```
103+
* @example
104+
* ```ts
105+
* const result = await runCommand('ls', { cwd: '/home' })
106+
*
107+
* if (result.isErr())
108+
* console.error(result.error)
109+
* else
110+
* console.log(result)
111+
* ```
67112
*/
68-
// export async function runCommand(command: string, options?: CliOptions): Promise<ResultAsync<Subprocess, StacksError>> {
69-
export async function runCommand(command: string, options?: any): Promise<ResultAsync<Subprocess, StacksError>> {
113+
export async function runCommand(command: string, options?: string | CliOptions): Promise<ResultAsync<Subprocess, StacksError>> {
114+
if (typeof options === 'string')
115+
return await exec(command, { cwd: options })
116+
70117
return await exec(command, options)
71118
}
72119

.stacks/core/types/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { log, runCommand } from '@stacksjs/cli'
22

3-
const result = await runCommand('bun build ./src/index.ts --outdir dist --format esm --target bun', {
3+
const result = await runCommand('bun build ./src/index.ts --outdir dist --format esm --target node', {
44
cwd: import.meta.dir,
55
})
66

.stacks/core/types/src/cli.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,6 @@ export interface CliOptions {
5656

5757
env?: Record<string, string>
5858

59-
/**
60-
* **Should the command be run inside a shell?**
61-
*
62-
* If `true`, runs `command` inside of a shell. Uses `/bin/sh` on UNIX and `cmd.exe`
63-
* on Windows. A different shell can be specified as a string. The shell should
64-
* understand the `-c` switch on UNIX or `/d /s /c` on Windows.
65-
*
66-
* We recommend against using this option since it is:
67-
* - not cross-platform, encouraging shell-specific syntax.
68-
* - slower, because of the additional shell interpretation.
69-
* - unsafe, potentially allowing command injection.
70-
*
71-
* @default false
72-
*/
73-
shell?: boolean
74-
7559
/**
7660
* **Encoding**
7761
*

0 commit comments

Comments
 (0)