@wyxos/zephyr 0.2.21 → 0.2.22

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.
@@ -1,92 +1,92 @@
1
- import { spawn } from 'node:child_process'
2
- import process from 'node:process'
3
-
4
- const DEFAULT_IS_WINDOWS = process.platform === 'win32'
5
-
6
- export function resolveCommandForPlatform(command, { isWindows = DEFAULT_IS_WINDOWS } = {}) {
7
- if (!isWindows) {
8
- return command
9
- }
10
-
11
- // On Windows, these are typically shimmed as *.cmd on PATH
12
- if (command === 'npm' || command === 'npx' || command === 'pnpm' || command === 'yarn') {
13
- return `${command}.cmd`
14
- }
15
-
16
- return command
17
- }
18
-
19
- function isWindowsShellShim(command) {
20
- return DEFAULT_IS_WINDOWS && typeof command === 'string' && /\.(cmd|bat)$/i.test(command)
21
- }
22
-
23
- function quoteForCmd(arg) {
24
- const value = arg == null ? '' : String(arg)
25
- if (value.length === 0) {
26
- return '""'
27
- }
28
- if (/[ \t"]/g.test(value)) {
29
- return `"${value.replace(/"/g, '\\"')}"`
30
- }
31
- return value
32
- }
33
-
34
- export async function runCommand(command, args, { cwd = process.cwd(), stdio = 'inherit' } = {}) {
35
- const resolvedCommand = resolveCommandForPlatform(command)
36
-
37
- return new Promise((resolve, reject) => {
38
- const child = isWindowsShellShim(resolvedCommand)
39
- ? spawn([resolvedCommand, ...(args ?? []).map(quoteForCmd)].join(' '), { cwd, stdio, shell: true })
40
- : spawn(resolvedCommand, args, { cwd, stdio })
41
-
42
- child.on('error', reject)
43
- child.on('close', (code) => {
44
- if (code === 0) {
45
- resolve()
46
- } else {
47
- const error = new Error(`${resolvedCommand} exited with code ${code}`)
48
- error.exitCode = code
49
- reject(error)
50
- }
51
- })
52
- })
53
- }
54
-
55
- export async function runCommandCapture(command, args, { cwd = process.cwd() } = {}) {
56
- const resolvedCommand = resolveCommandForPlatform(command)
57
-
58
- return new Promise((resolve, reject) => {
59
- let stdout = ''
60
- let stderr = ''
61
-
62
- const child = isWindowsShellShim(resolvedCommand)
63
- ? spawn([resolvedCommand, ...(args ?? []).map(quoteForCmd)].join(' '), {
64
- cwd,
65
- stdio: ['ignore', 'pipe', 'pipe'],
66
- shell: true
67
- })
68
- : spawn(resolvedCommand, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] })
69
-
70
- child.stdout.on('data', (chunk) => {
71
- stdout += chunk
72
- })
73
-
74
- child.stderr.on('data', (chunk) => {
75
- stderr += chunk
76
- })
77
-
78
- child.on('error', reject)
79
- child.on('close', (code) => {
80
- if (code === 0) {
81
- resolve({ stdout, stderr })
82
- } else {
83
- const error = new Error(`${resolvedCommand} exited with code ${code}: ${stderr.trim()}`)
84
- error.exitCode = code
85
- error.stdout = stdout
86
- error.stderr = stderr
87
- reject(error)
88
- }
89
- })
90
- })
91
- }
92
-
1
+ import { spawn } from 'node:child_process'
2
+ import process from 'node:process'
3
+
4
+ const DEFAULT_IS_WINDOWS = process.platform === 'win32'
5
+
6
+ export function resolveCommandForPlatform(command, { isWindows = DEFAULT_IS_WINDOWS } = {}) {
7
+ if (!isWindows) {
8
+ return command
9
+ }
10
+
11
+ // On Windows, these are typically shimmed as *.cmd on PATH
12
+ if (command === 'npm' || command === 'npx' || command === 'pnpm' || command === 'yarn') {
13
+ return `${command}.cmd`
14
+ }
15
+
16
+ return command
17
+ }
18
+
19
+ function isWindowsShellShim(command) {
20
+ return DEFAULT_IS_WINDOWS && typeof command === 'string' && /\.(cmd|bat)$/i.test(command)
21
+ }
22
+
23
+ function quoteForCmd(arg) {
24
+ const value = arg == null ? '' : String(arg)
25
+ if (value.length === 0) {
26
+ return '""'
27
+ }
28
+ if (/[ \t"]/g.test(value)) {
29
+ return `"${value.replace(/"/g, '\\"')}"`
30
+ }
31
+ return value
32
+ }
33
+
34
+ export async function runCommand(command, args, { cwd = process.cwd(), stdio = 'inherit' } = {}) {
35
+ const resolvedCommand = resolveCommandForPlatform(command)
36
+
37
+ return new Promise((resolve, reject) => {
38
+ const child = isWindowsShellShim(resolvedCommand)
39
+ ? spawn([resolvedCommand, ...(args ?? []).map(quoteForCmd)].join(' '), { cwd, stdio, shell: true })
40
+ : spawn(resolvedCommand, args, { cwd, stdio })
41
+
42
+ child.on('error', reject)
43
+ child.on('close', (code) => {
44
+ if (code === 0) {
45
+ resolve()
46
+ } else {
47
+ const error = new Error(`${resolvedCommand} exited with code ${code}`)
48
+ error.exitCode = code
49
+ reject(error)
50
+ }
51
+ })
52
+ })
53
+ }
54
+
55
+ export async function runCommandCapture(command, args, { cwd = process.cwd() } = {}) {
56
+ const resolvedCommand = resolveCommandForPlatform(command)
57
+
58
+ return new Promise((resolve, reject) => {
59
+ let stdout = ''
60
+ let stderr = ''
61
+
62
+ const child = isWindowsShellShim(resolvedCommand)
63
+ ? spawn([resolvedCommand, ...(args ?? []).map(quoteForCmd)].join(' '), {
64
+ cwd,
65
+ stdio: ['ignore', 'pipe', 'pipe'],
66
+ shell: true
67
+ })
68
+ : spawn(resolvedCommand, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] })
69
+
70
+ child.stdout.on('data', (chunk) => {
71
+ stdout += chunk
72
+ })
73
+
74
+ child.stderr.on('data', (chunk) => {
75
+ stderr += chunk
76
+ })
77
+
78
+ child.on('error', reject)
79
+ child.on('close', (code) => {
80
+ if (code === 0) {
81
+ resolve({ stdout, stderr })
82
+ } else {
83
+ const error = new Error(`${resolvedCommand} exited with code ${code}: ${stderr.trim()}`)
84
+ error.exitCode = code
85
+ error.stdout = stdout
86
+ error.stderr = stderr
87
+ reject(error)
88
+ }
89
+ })
90
+ })
91
+ }
92
+