@magic/cli 0.0.51 → 0.0.53
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/README.md +9 -1
- package/package.json +1 -1
- package/src/exec.js +3 -1
- package/src/execFile.js +14 -5
- package/src/index.js +4 -0
- package/src/spawn.js +6 -4
- package/types/exec.d.ts +4 -6
- package/types/execFile.d.ts +4 -1
- package/types/index.d.ts +6 -8
- package/types/spawn.d.ts +2 -1
package/README.md
CHANGED
|
@@ -576,6 +576,14 @@ update dependencies
|
|
|
576
576
|
|
|
577
577
|
- exec and execFile options are correctly typed
|
|
578
578
|
|
|
579
|
-
##### 0.0.52
|
|
579
|
+
##### 0.0.52
|
|
580
|
+
|
|
581
|
+
- actually publish the types from 0.0.51.
|
|
582
|
+
|
|
583
|
+
##### 0.0.53
|
|
584
|
+
|
|
585
|
+
- export exec, execFile and spawn option types
|
|
586
|
+
|
|
587
|
+
##### 0.0.54 - unreleased
|
|
580
588
|
|
|
581
589
|
- ...
|
package/package.json
CHANGED
package/src/exec.js
CHANGED
|
@@ -4,10 +4,12 @@ import error from '@magic/error'
|
|
|
4
4
|
|
|
5
5
|
const libName = '@magic/cli.exec'
|
|
6
6
|
|
|
7
|
+
/** @typedef {child_process.ExecOptionsWithStringEncoding & { stderrToStdout?: boolean }} CLIExecOptions */
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Executes a shell command using child_process.exec
|
|
9
11
|
* @param {string} cmd - The shell command to execute.
|
|
10
|
-
* @param {
|
|
12
|
+
* @param {CLIExecOptions} [options = {}] - Execution options.
|
|
11
13
|
* @returns {Promise<string>} Resolves with stdout or stderr (if stderrToStdout = true), rejects with Error.
|
|
12
14
|
*/
|
|
13
15
|
export const exec = (cmd, options) =>
|
package/src/execFile.js
CHANGED
|
@@ -4,15 +4,18 @@ import error from '@magic/error'
|
|
|
4
4
|
|
|
5
5
|
const libName = '@magic/cli.execFile'
|
|
6
6
|
|
|
7
|
+
/** @typedef {child_process.ExecFileOptions & { stderrToStdout?: boolean }} CLIExecFileOptions */
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Executes a file using child_process.execFile
|
|
9
11
|
* @param {string} p - Path to the executable file.
|
|
10
12
|
* @param {string[]} [args=[]] - Arguments to pass to the executable.
|
|
11
|
-
* @param {
|
|
13
|
+
* @param {CLIExecFileOptions} [options={}] - Execution options.
|
|
12
14
|
* @returns {Promise<string | Buffer>} Resolves with stdout, rejects with Error.
|
|
13
15
|
*/
|
|
14
|
-
export const execFile = (p, args = [],
|
|
16
|
+
export const execFile = (p, args = [], options = {}) =>
|
|
15
17
|
new Promise((resolve, reject) => {
|
|
18
|
+
const { stderrToStdout = false, ...opts } = options
|
|
16
19
|
child_process.execFile(
|
|
17
20
|
p,
|
|
18
21
|
args.filter(a => a),
|
|
@@ -23,10 +26,16 @@ export const execFile = (p, args = [], opts = {}) =>
|
|
|
23
26
|
reject(err)
|
|
24
27
|
return
|
|
25
28
|
}
|
|
29
|
+
|
|
26
30
|
if (stderr) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
if (stderrToStdout) {
|
|
32
|
+
resolve(stderr)
|
|
33
|
+
return
|
|
34
|
+
} else {
|
|
35
|
+
const e = error(new Error(`${libName}: error: ${stderr}`), 'E_EXECFILE_STDERR')
|
|
36
|
+
reject(e)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
30
39
|
}
|
|
31
40
|
|
|
32
41
|
resolve(stdout)
|
package/src/index.js
CHANGED
|
@@ -73,4 +73,8 @@ cli.prompt = promptUser
|
|
|
73
73
|
export const execFile = executeFile
|
|
74
74
|
cli.execFile = executeFile
|
|
75
75
|
|
|
76
|
+
/** @typedef {import('./execFile.js').CLIExecFileOptions} CLIExecFileOptions */
|
|
77
|
+
/** @typedef {import('./exec.js').CLIExecOptions} CLIExecOptions */
|
|
78
|
+
/** @typedef {import('./spawn.js')} CLISpawnOptions*/
|
|
79
|
+
|
|
76
80
|
export default cli
|
package/src/spawn.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import child_process from 'child_process'
|
|
2
2
|
|
|
3
|
+
/** @typedef {import('child_process').SpawnOptions} CLISpawnOptions*/
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Spawns a new process.
|
|
5
7
|
* @param {string} cmd - Command to run.
|
|
6
8
|
* @param {string[]} [args=[]] - Arguments for the command.
|
|
7
|
-
* @param {
|
|
9
|
+
* @param {CLISpawnOptions} [options={}] - Spawn options.
|
|
8
10
|
* @returns {import('child_process').ChildProcess} The spawned process.
|
|
9
11
|
*/
|
|
10
|
-
export const spawn = (cmd, args = [],
|
|
11
|
-
/** @type {
|
|
12
|
+
export const spawn = (cmd, args = [], options = {}) => {
|
|
13
|
+
/** @type {CLISpawnOptions} */
|
|
12
14
|
const opts = {
|
|
13
15
|
cwd: process.cwd(),
|
|
14
16
|
env: process.env,
|
|
15
17
|
stdio: 'inherit',
|
|
16
|
-
...
|
|
18
|
+
...options,
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
return child_process.spawn(cmd, args, opts)
|
package/types/exec.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export function exec(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
},
|
|
6
|
-
): Promise<string>
|
|
1
|
+
export function exec(cmd: string, options?: CLIExecOptions): Promise<string>
|
|
2
|
+
export type CLIExecOptions = child_process.ExecOptionsWithStringEncoding & {
|
|
3
|
+
stderrToStdout?: boolean
|
|
4
|
+
}
|
|
7
5
|
import child_process from 'child_process'
|
package/types/execFile.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export function execFile(
|
|
2
2
|
p: string,
|
|
3
3
|
args?: string[],
|
|
4
|
-
|
|
4
|
+
options?: CLIExecFileOptions,
|
|
5
5
|
): Promise<string | Buffer>
|
|
6
|
+
export type CLIExecFileOptions = child_process.ExecFileOptions & {
|
|
7
|
+
stderrToStdout?: boolean
|
|
8
|
+
}
|
|
6
9
|
import child_process from 'child_process'
|
package/types/index.d.ts
CHANGED
|
@@ -8,14 +8,9 @@ export namespace cli {
|
|
|
8
8
|
export const spawn: (
|
|
9
9
|
cmd: string,
|
|
10
10
|
args?: string[],
|
|
11
|
-
|
|
11
|
+
options?: import('./spawn.js').CLISpawnOptions,
|
|
12
12
|
) => import('child_process').ChildProcess
|
|
13
|
-
export const exec: (
|
|
14
|
-
cmd: string,
|
|
15
|
-
options?: import('child_process').ExecOptionsWithStringEncoding & {
|
|
16
|
-
stderrToStdout: boolean
|
|
17
|
-
},
|
|
18
|
-
) => Promise<string>
|
|
13
|
+
export const exec: (cmd: string, options?: import('./exec.js').CLIExecOptions) => Promise<string>
|
|
19
14
|
export const prompt: (
|
|
20
15
|
msg?: string | string[],
|
|
21
16
|
options?: {
|
|
@@ -27,7 +22,7 @@ export const prompt: (
|
|
|
27
22
|
export const execFile: (
|
|
28
23
|
p: string,
|
|
29
24
|
args?: string[],
|
|
30
|
-
|
|
25
|
+
options?: import('./execFile.js').CLIExecFileOptions,
|
|
31
26
|
) => Promise<string | Buffer>
|
|
32
27
|
export default cli
|
|
33
28
|
export type ParseProps = {
|
|
@@ -52,6 +47,9 @@ export type ParsedCLI = {
|
|
|
52
47
|
commands: Record<string, boolean>
|
|
53
48
|
errors: Array<string | string[]>
|
|
54
49
|
}
|
|
50
|
+
export type CLIExecFileOptions = import('./execFile.js').CLIExecFileOptions
|
|
51
|
+
export type CLIExecOptions = import('./exec.js').CLIExecOptions
|
|
52
|
+
export type CLISpawnOptions = typeof import('./spawn.js')
|
|
55
53
|
import { spawn as spawner } from './spawn.js'
|
|
56
54
|
import { exec as execute } from './exec.js'
|
|
57
55
|
import { prompt as promptUser } from './prompt.js'
|
package/types/spawn.d.ts
CHANGED