sdnext 0.0.27 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils/runCommand.js +23 -2
- package/package.json +2 -2
- package/src/utils/runCommand.ts +31 -2
package/dist/utils/runCommand.js
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
|
-
function
|
|
2
|
+
function quotePosixArgument(arg) {
|
|
3
|
+
if (0 === arg.length) return "''";
|
|
4
|
+
return `'${arg.replaceAll("'", "'\"'\"'")}'`;
|
|
5
|
+
}
|
|
6
|
+
function quoteWindowsArgument(arg) {
|
|
7
|
+
if (0 === arg.length) return '""';
|
|
8
|
+
return `"${arg.replaceAll('"', '""')}"`;
|
|
9
|
+
}
|
|
10
|
+
function quoteWindowsCommand(command) {
|
|
11
|
+
if (/^[\w./:-]+$/.test(command)) return command;
|
|
12
|
+
return quoteWindowsArgument(command);
|
|
13
|
+
}
|
|
14
|
+
function formatShellCommand(args) {
|
|
3
15
|
const [command, ...commandArgs] = args;
|
|
4
|
-
|
|
16
|
+
const quoteArgument = "win32" === process.platform ? quoteWindowsArgument : quotePosixArgument;
|
|
17
|
+
if ("win32" === process.platform) return [
|
|
18
|
+
quoteWindowsCommand(command),
|
|
19
|
+
...commandArgs.map(quoteArgument)
|
|
20
|
+
].join(" ");
|
|
21
|
+
return args.map(quoteArgument).join(" ");
|
|
22
|
+
}
|
|
23
|
+
function spawnCommand({ args }) {
|
|
24
|
+
const command = formatShellCommand(args);
|
|
25
|
+
return spawn(command, {
|
|
5
26
|
shell: true,
|
|
6
27
|
stdio: "inherit"
|
|
7
28
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sdnext",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@inquirer/prompts": "^8.1.0",
|
|
42
42
|
"chokidar": "^5.0.0",
|
|
43
43
|
"commander": "^14.0.2",
|
|
44
|
-
"deepsea-tools": "5.47.
|
|
44
|
+
"deepsea-tools": "5.47.9"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "^24.10.14",
|
package/src/utils/runCommand.ts
CHANGED
|
@@ -4,10 +4,39 @@ export interface SpawnCommandParams {
|
|
|
4
4
|
args: string[]
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
function quotePosixArgument(arg: string) {
|
|
8
|
+
if (arg.length === 0) return "''"
|
|
9
|
+
|
|
10
|
+
return `'${arg.replaceAll("'", `'"'"'`)}'`
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function quoteWindowsArgument(arg: string) {
|
|
14
|
+
if (arg.length === 0) return '""'
|
|
15
|
+
|
|
16
|
+
return `"${arg.replaceAll('"', '""')}"`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function quoteWindowsCommand(command: string) {
|
|
20
|
+
if (/^[\w./:-]+$/.test(command)) return command
|
|
21
|
+
|
|
22
|
+
return quoteWindowsArgument(command)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function formatShellCommand(args: string[]) {
|
|
8
26
|
const [command, ...commandArgs] = args
|
|
27
|
+
const quoteArgument = process.platform === "win32" ? quoteWindowsArgument : quotePosixArgument
|
|
28
|
+
|
|
29
|
+
if (process.platform === "win32") {
|
|
30
|
+
return [quoteWindowsCommand(command), ...commandArgs.map(quoteArgument)].join(" ")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return args.map(quoteArgument).join(" ")
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function spawnCommand({ args }: SpawnCommandParams) {
|
|
37
|
+
const command = formatShellCommand(args)
|
|
9
38
|
|
|
10
|
-
return spawn(command,
|
|
39
|
+
return spawn(command, {
|
|
11
40
|
shell: true,
|
|
12
41
|
stdio: "inherit",
|
|
13
42
|
})
|