|
1 |
| -"use strict"; |
2 |
| - |
3 | 1 | /* eslint-env node*/
|
4 | 2 |
|
5 |
| -exports.unsafeFromNullable = function unsafeFromNullable(msg) { |
6 |
| - return function (x) { |
| 3 | +import { spawn, exec, execFile, execSync, execFileSync, fork as cp_fork } from "child_process"; |
| 4 | + |
| 5 | +export function unsafeFromNullable(msg) { |
| 6 | + return x => { |
7 | 7 | if (x === null) throw new Error(msg);
|
8 | 8 | return x;
|
9 | 9 | };
|
10 |
| -}; |
| 10 | +} |
11 | 11 |
|
12 |
| -exports.spawnImpl = function spawnImpl(command) { |
13 |
| - return function (args) { |
14 |
| - return function (opts) { |
15 |
| - return function () { |
16 |
| - return require("child_process").spawn(command, args, opts); |
17 |
| - }; |
18 |
| - }; |
19 |
| - }; |
20 |
| -}; |
| 12 | +export function spawnImpl(command) { |
| 13 | + return args => opts => () => spawn(command, args, opts); |
| 14 | +} |
21 | 15 |
|
22 |
| -exports.execImpl = function execImpl(command) { |
23 |
| - return function (opts) { |
24 |
| - return function (callback) { |
25 |
| - return function () { |
26 |
| - return require("child_process").exec( |
27 |
| - command, |
28 |
| - opts, |
29 |
| - function (err, stdout, stderr) { |
30 |
| - callback(err)(stdout)(stderr)(); |
31 |
| - } |
32 |
| - ); |
33 |
| - }; |
34 |
| - }; |
35 |
| - }; |
36 |
| -}; |
| 16 | +export function execImpl(command) { |
| 17 | + return opts => callback => () => exec( |
| 18 | + command, |
| 19 | + opts, |
| 20 | + (err, stdout, stderr) => { |
| 21 | + callback(err)(stdout)(stderr)(); |
| 22 | + } |
| 23 | + ); |
| 24 | +} |
37 | 25 |
|
38 |
| -exports.execFileImpl = function execImpl(command) { |
39 |
| - return function (args) { |
40 |
| - return function (opts) { |
41 |
| - return function (callback) { |
42 |
| - return function () { |
43 |
| - return require("child_process").execFile( |
44 |
| - command, |
45 |
| - args, |
46 |
| - opts, |
47 |
| - function (err, stdout, stderr) { |
48 |
| - callback(err)(stdout)(stderr)(); |
49 |
| - } |
50 |
| - ); |
51 |
| - }; |
52 |
| - }; |
53 |
| - }; |
54 |
| - }; |
| 26 | +export const execFileImpl = function execImpl(command) { |
| 27 | + return args => opts => callback => () => execFile( |
| 28 | + command, |
| 29 | + args, |
| 30 | + opts, |
| 31 | + (err, stdout, stderr) => { |
| 32 | + callback(err)(stdout)(stderr)(); |
| 33 | + } |
| 34 | + ); |
55 | 35 | };
|
56 | 36 |
|
57 |
| -exports.execSyncImpl = function execSyncImpl(command) { |
58 |
| - return function (opts) { |
59 |
| - return function () { |
60 |
| - return require("child_process").execSync(command, opts); |
61 |
| - }; |
62 |
| - }; |
63 |
| -}; |
| 37 | +export function execSyncImpl(command) { |
| 38 | + return opts => () => execSync(command, opts); |
| 39 | +} |
64 | 40 |
|
65 |
| -exports.execFileSyncImpl = function execFileSyncImpl(command) { |
66 |
| - return function (args) { |
67 |
| - return function (opts) { |
68 |
| - return function () { |
69 |
| - return require("child_process").execFileSync(command, args, opts); |
70 |
| - }; |
71 |
| - }; |
72 |
| - }; |
73 |
| -}; |
| 41 | +export function execFileSyncImpl(command) { |
| 42 | + return args => opts => () => execFileSync(command, args, opts); |
| 43 | +} |
74 | 44 |
|
75 |
| -exports.fork = function fork(cmd) { |
76 |
| - return function (args) { |
77 |
| - return function () { |
78 |
| - return require("child_process").fork(cmd, args); |
79 |
| - }; |
80 |
| - }; |
81 |
| -}; |
| 45 | +export function fork(cmd) { |
| 46 | + return args => () => cp_fork(cmd, args); |
| 47 | +} |
82 | 48 |
|
83 |
| -exports.mkOnExit = function mkOnExit(mkChildExit) { |
| 49 | +export function mkOnExit(mkChildExit) { |
84 | 50 | return function onExit(cp) {
|
85 |
| - return function (cb) { |
86 |
| - return function () { |
87 |
| - cp.on("exit", function (code, signal) { |
88 |
| - cb(mkChildExit(code)(signal))(); |
89 |
| - }); |
90 |
| - }; |
| 51 | + return cb => () => { |
| 52 | + cp.on("exit", (code, signal) => { |
| 53 | + cb(mkChildExit(code)(signal))(); |
| 54 | + }); |
91 | 55 | };
|
92 | 56 | };
|
93 |
| -}; |
| 57 | +} |
94 | 58 |
|
95 |
| -exports.mkOnClose = function mkOnClose(mkChildExit) { |
| 59 | +export function mkOnClose(mkChildExit) { |
96 | 60 | return function onClose(cp) {
|
97 |
| - return function (cb) { |
98 |
| - return function () { |
99 |
| - cp.on("close", function (code, signal) { |
100 |
| - cb(mkChildExit(code)(signal))(); |
101 |
| - }); |
102 |
| - }; |
103 |
| - }; |
104 |
| - }; |
105 |
| -}; |
106 |
| - |
107 |
| -exports.onDisconnect = function onDisconnect(cp) { |
108 |
| - return function (cb) { |
109 |
| - return function () { |
110 |
| - cp.on("disconnect", cb); |
| 61 | + return cb => () => { |
| 62 | + cp.on("close", (code, signal) => { |
| 63 | + cb(mkChildExit(code)(signal))(); |
| 64 | + }); |
111 | 65 | };
|
112 | 66 | };
|
113 |
| -}; |
| 67 | +} |
114 | 68 |
|
115 |
| -exports.mkOnMessage = function mkOnMessage(nothing) { |
116 |
| - return function (just) { |
117 |
| - return function onMessage(cp) { |
118 |
| - return function (cb) { |
119 |
| - return function () { |
120 |
| - cp.on("message", function (mess, sendHandle) { |
121 |
| - cb(mess, sendHandle ? just(sendHandle) : nothing)(); |
122 |
| - }); |
123 |
| - }; |
124 |
| - }; |
125 |
| - }; |
| 69 | +export function onDisconnect(cp) { |
| 70 | + return cb => () => { |
| 71 | + cp.on("disconnect", cb); |
126 | 72 | };
|
127 |
| -}; |
| 73 | +} |
128 | 74 |
|
129 |
| -exports.onError = function onError(cp) { |
130 |
| - return function (cb) { |
131 |
| - return function () { |
132 |
| - cp.on("error", function (err) { |
133 |
| - cb(err)(); |
| 75 | +export function mkOnMessage(nothing) { |
| 76 | + return just => (function onMessage(cp) { |
| 77 | + return cb => () => { |
| 78 | + cp.on("message", (mess, sendHandle) => { |
| 79 | + cb(mess, sendHandle ? just(sendHandle) : nothing)(); |
134 | 80 | });
|
135 | 81 | };
|
| 82 | + }); |
| 83 | +} |
| 84 | + |
| 85 | +export function onError(cp) { |
| 86 | + return cb => () => { |
| 87 | + cp.on("error", err => { |
| 88 | + cb(err)(); |
| 89 | + }); |
136 | 90 | };
|
137 |
| -}; |
| 91 | +} |
138 | 92 |
|
139 |
| -exports.undefined = undefined; |
140 |
| -exports.process = process; |
| 93 | +const _undefined = undefined; |
| 94 | +export { _undefined as undefined }; |
| 95 | +import process from "process"; |
| 96 | +export { process }; |
0 commit comments