Skip to content

Commit 27af6b6

Browse files
committed
refactor: replace shelljs with Node.js built-in child_process
Use execSync from child_process instead of shelljs for synchronous command execution. This removes the external shelljs dependency while maintaining sync behavior needed for exit hooks (pod cleanup).
1 parent 145dfbf commit 27af6b6

File tree

4 files changed

+13
-111
lines changed

4 files changed

+13
-111
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"fuse.js": "7.1.0",
4949
"lodash-es": "4.17.23",
5050
"memoizee": "0.4.17",
51-
"shelljs": "0.10.0",
5251
"update-notifier": "7.3.1"
5352
},
5453
"devDependencies": {
@@ -61,7 +60,6 @@
6160
"@types/lodash-es": "4.17.12",
6261
"@types/memoizee": "0.4.12",
6362
"@types/node": "24.10.6",
64-
"@types/shelljs": "0.10.0",
6563
"@types/update-notifier": "6.0.8",
6664
"@yao-pkg/pkg": "6.14.0",
6765
"eslint": "10.0.0",

pnpm-lock.yaml

Lines changed: 0 additions & 98 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/util/exec.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
import { exec } from 'child_process'
1+
import { exec, execSync } from 'child_process'
22
import { EOL } from 'os'
33
import { promisify } from 'util'
4-
import shell from 'shelljs'
54
import { CommandExecutionError } from './error.js'
65

76
const execPromise = promisify(exec)
87

98
export const execCommand = (command: string): string => {
10-
const { stdout, stderr, code } = shell.exec(command, { silent: true })
11-
12-
if (code !== 0) {
13-
throw new CommandExecutionError(command, stderr, stdout)
9+
try {
10+
return execSync(command, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim()
11+
}
12+
catch (error: unknown) {
13+
const err = error as { stderr?: Buffer | string, stdout?: Buffer | string }
14+
throw new CommandExecutionError(
15+
command,
16+
err.stderr?.toString() || '',
17+
err.stdout?.toString(),
18+
)
1419
}
15-
16-
return stdout.trim()
1720
}
1821

1922
export const execCommandMultiline = (command: string): string[] => {
2023
return execCommand(command).split(EOL)
2124
}
2225

23-
export const execCommandAttached = (command: string) => {
24-
shell.exec(command)
26+
export const execCommandAttached = (command: string): void => {
27+
execSync(command, { stdio: 'inherit' })
2528
}
2629

2730
export const execCommandAsync = async (command: string): Promise<string> => {

tsdown.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ export default defineConfig({
66
format: ['cjs'],
77
platform: 'node',
88
noExternal: /^.*$/,
9-
external: ['shelljs'],
109
failOnWarn: false,
1110
})

0 commit comments

Comments
 (0)