1
1
package io .scalajs .nodejs
2
2
package child_process
3
3
4
- import io .scalajs .RawOptions
4
+ import io .scalajs .nodejs
5
5
import io .scalajs .nodejs .events .IEventEmitter
6
- import io .scalajs .nodejs .buffer .Buffer
7
6
8
7
import scala .scalajs .js
9
8
import scala .scalajs .js .annotation .JSImport
@@ -12,91 +11,56 @@ import scala.scalajs.js.|
12
11
/**
13
12
* The child_process module provides the ability to spawn child processes in a manner that is similar,
14
13
* but not identical, to popen(3). This capability is primarily provided by the child_process.spawn() function.
14
+ *
15
15
* @see https://nodejs.org/api/child_process.html
16
-
17
16
*/
18
17
@ js.native
19
18
trait ChildProcess extends IEventEmitter {
19
+ def kill (signal : js.UndefOr [Int | String ] = js.native): Unit = js.native
20
+ }
20
21
21
- /**
22
- * Spawns a shell then executes the command within that shell, buffering any generated output.
23
- * @param command <String> The command to run, with space-separated arguments
24
- * @param options the execution [[ExecOptions options ]]
25
- * @return the [[ChildProcess ]]
26
- * @example {{{ child_process.exec(command[, options][, callback]) }}}
27
- */
28
- def exec (command : String , options : ExecOptions | RawOptions ): this .type = js.native
22
+ /**
23
+ * @see https://nodejs.org/api/child_process.html
24
+ */
25
+ @ JSImport (" child_process" , JSImport .Namespace )
26
+ @ js.native
27
+ object ChildProcess extends scala.scalajs.js.Object {
28
+ def exec (
29
+ command : String ,
30
+ options : js.UndefOr [ExecOptions | io.scalajs.RawOptions ] = js.undefined,
31
+ callback : js.Function3 [
32
+ nodejs.Error ,
33
+ Output ,
34
+ Output ,
35
+ Any
36
+ ]
37
+ ): ChildProcess = js.native
29
38
30
- /**
31
- * Spawns a shell then executes the command within that shell, buffering any generated output.
32
- * @param command <String> The command to run, with space-separated arguments
33
- * @param callback called with the output when process terminates
34
- * @return the [[ChildProcess ]]
35
- * @example {{{ child_process.exec(command[, options][, callback]) }}}
36
- */
37
- def exec (command : String , callback : js.Function3 [Error , Buffer | String , Buffer | String , Any ]): this .type =
38
- js.native
39
+ def execSync (
40
+ command : String ,
41
+ options : ExecOptions | io.scalajs.RawOptions = js.native
42
+ ): Output = js.native
39
43
40
- /**
41
- * Spawns a shell then executes the command within that shell, buffering any generated output.
42
- * @param command <String> The command to run, with space-separated arguments
43
- * @param options the execution [[ExecOptions options ]]
44
- * @param callback called with the output when process terminates
45
- * @return the [[ChildProcess ]]
46
- * @example {{{ child_process.exec(command[, options][, callback]) }}}
47
- */
48
- def exec (command : String ,
49
- options : ExecOptions | RawOptions ,
50
- callback : js.Function3 [Error , Buffer | String , Buffer | String , Any ]): this .type = js.native
44
+ def fork (
45
+ modulePath : String ,
46
+ args : js.Array [String ] = js.native,
47
+ options : ForkOptions | io.scalajs.RawOptions = js.native
48
+ ): ChildProcess = js.native
51
49
52
- /**
53
- * The child_process.fork() method is a special case of child_process.spawn() used specifically to spawn new
54
- * Node.js processes. Like child_process.spawn(), a ChildProcess object is returned. The returned ChildProcess
55
- * will have an additional communication channel built-in that allows messages to be passed back and forth between
56
- * the parent and child. See child.send() for details.
57
- *
58
- * It is important to keep in mind that spawned Node.js child processes are independent of the parent with exception
59
- * of the IPC communication channel that is established between the two. Each process has its own memory, with their
60
- * own V8 instances. Because of the additional resource allocations required, spawning a large number of child Node.js
61
- * processes is not recommended.
62
- *
63
- * By default, child_process.fork() will spawn new Node.js instances using the process.execPath of the parent process.
64
- * The execPath property in the options object allows for an alternative execution path to be used.
65
- *
66
- * Node.js processes launched with a custom execPath will communicate with the parent process using the
67
- * file descriptor (fd) identified using the environment variable NODE_CHANNEL_FD on the child process.
68
- * The input and output on this fd is expected to be line delimited JSON objects.
69
- *
70
- * Note: Unlike the fork(2) POSIX system call, child_process.fork() does not clone the current process.
71
- * @param modulePath <String> The module to run in the child
72
- * @param args <Array> List of string arguments
73
- * @param options the fork [[ForkOptions options ]]
74
- * @return the [[ChildProcess ]]
75
- * @example {{{ child_process.fork(modulePath[, args][, options]) }}}
76
- */
77
- def fork (modulePath : String ,
78
- args : js.Array [String ] = js.native,
79
- options : ForkOptions | RawOptions = js.native): this .type = js.native
50
+ def spawn (
51
+ command : String ,
52
+ args : js.Array [String ] = js.native,
53
+ options : SpawnOptions | io.scalajs.RawOptions = js.native
54
+ ): ChildProcess = js.native
80
55
81
- /**
82
- * The child_process.spawn() method spawns a new process using the given command, with command line arguments
83
- * in args. If omitted, args defaults to an empty array.
84
- * @param command <String> The command to run
85
- * @param args <Array> List of string arguments
86
- * @param options the spawn [[SpawnOptions options ]]
87
- * @return the [[ChildProcess ]]
88
- * @example {{{ child_process.spawn(command[, args][, options]) }}}
89
- */
90
- def spawn (command : String ,
91
- args : js.Array [String ] = js.native,
92
- options : SpawnOptions | RawOptions = js.native): this .type = js.native
56
+ def spawnSync (
57
+ command : String ,
58
+ args : js.Array [String ] = js.native,
59
+ options : SpawnOptions | io.scalajs.RawOptions = js.native
60
+ ): SpawnResult = js.native
93
61
62
+ def spawnSync (
63
+ command : String ,
64
+ options : SpawnOptions | io.scalajs.RawOptions
65
+ ): SpawnResult = js.native
94
66
}
95
-
96
- /**
97
- * ChildProcess Singleton
98
-
99
- */
100
- @ js.native
101
- @ JSImport (" child_process" , JSImport .Namespace )
102
- object ChildProcess extends ChildProcess
0 commit comments