spawn-term 0.1.16 → 0.1.17
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/cjs/worker.cjs +80 -55
- package/dist/cjs/worker.cjs.map +1 -1
- package/dist/esm/worker.mjs +78 -53
- package/dist/esm/worker.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cjs/worker.cjs
CHANGED
|
@@ -149,28 +149,24 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
149
149
|
"encoding",
|
|
150
150
|
"stdio"
|
|
151
151
|
]);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
var queue = new _queuecb.default();
|
|
172
|
-
if (cp.stdout) {
|
|
173
|
-
if (stdio === 'inherit') {
|
|
152
|
+
if (stdio === 'inherit') {
|
|
153
|
+
terminal.retain(function(store) {
|
|
154
|
+
var id = (0, _liluuid.default)();
|
|
155
|
+
store.getState().addProcess(_object_spread({
|
|
156
|
+
id: id,
|
|
157
|
+
title: [
|
|
158
|
+
command
|
|
159
|
+
].concat((0, _formatArguments.default)(args)).join(' '),
|
|
160
|
+
state: 'running',
|
|
161
|
+
lines: []
|
|
162
|
+
}, options));
|
|
163
|
+
var cp = (0, _crossspawncb.crossSpawn)(command, args, csOptions);
|
|
164
|
+
var outputs = {
|
|
165
|
+
stdout: null,
|
|
166
|
+
stderr: null
|
|
167
|
+
};
|
|
168
|
+
var queue = new _queuecb.default();
|
|
169
|
+
if (cp.stdout) {
|
|
174
170
|
outputs.stdout = (0, _addLines.default)(function(texts) {
|
|
175
171
|
var item = store.getState().processes.find(function(x) {
|
|
176
172
|
return x.id === id;
|
|
@@ -185,20 +181,14 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
185
181
|
lines: lines
|
|
186
182
|
}));
|
|
187
183
|
});
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
184
|
+
queue.defer(_onone.default.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
185
|
+
'error',
|
|
186
|
+
'end',
|
|
187
|
+
'close',
|
|
188
|
+
'finish'
|
|
189
|
+
]));
|
|
192
190
|
}
|
|
193
|
-
|
|
194
|
-
'error',
|
|
195
|
-
'end',
|
|
196
|
-
'close',
|
|
197
|
-
'finish'
|
|
198
|
-
]));
|
|
199
|
-
}
|
|
200
|
-
if (cp.stderr) {
|
|
201
|
-
if (stdio === 'inherit') {
|
|
191
|
+
if (cp.stderr) {
|
|
202
192
|
outputs.stderr = (0, _addLines.default)(function(texts) {
|
|
203
193
|
var item = store.getState().processes.find(function(x) {
|
|
204
194
|
return x.id === id;
|
|
@@ -213,11 +203,60 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
213
203
|
lines: lines
|
|
214
204
|
}));
|
|
215
205
|
});
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
206
|
+
queue.defer(_onone.default.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
207
|
+
'error',
|
|
208
|
+
'end',
|
|
209
|
+
'close',
|
|
210
|
+
'finish'
|
|
211
|
+
]));
|
|
220
212
|
}
|
|
213
|
+
queue.defer(_crossspawncb.default.worker.bind(null, cp, _object_spread_props(_object_spread({}, csOptions), {
|
|
214
|
+
encoding: 'utf8'
|
|
215
|
+
})));
|
|
216
|
+
queue.await(function(err) {
|
|
217
|
+
var res = err ? err : {};
|
|
218
|
+
res.stdout = outputs.stdout ? outputs.stdout.output : null;
|
|
219
|
+
res.stderr = outputs.stderr ? outputs.stderr.output : null;
|
|
220
|
+
res.output = [
|
|
221
|
+
res.stdout,
|
|
222
|
+
res.stderr,
|
|
223
|
+
null
|
|
224
|
+
];
|
|
225
|
+
var item = store.getState().processes.find(function(x) {
|
|
226
|
+
return x.id === id;
|
|
227
|
+
});
|
|
228
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
229
|
+
state: err ? 'error' : 'success'
|
|
230
|
+
}));
|
|
231
|
+
// let rendering complete
|
|
232
|
+
setTimeout(function() {
|
|
233
|
+
terminal.release();
|
|
234
|
+
err ? callback(err) : callback(null, res);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
} else {
|
|
239
|
+
var cp = (0, _crossspawncb.crossSpawn)(command, args, csOptions);
|
|
240
|
+
var outputs = {
|
|
241
|
+
stdout: null,
|
|
242
|
+
stderr: null
|
|
243
|
+
};
|
|
244
|
+
var queue = new _queuecb.default();
|
|
245
|
+
if (cp.stdout) {
|
|
246
|
+
outputs.stdout = (0, _concatWritable.default)(function(output) {
|
|
247
|
+
outputs.stdout.output = output.toString(encoding || 'utf8');
|
|
248
|
+
});
|
|
249
|
+
queue.defer(_onone.default.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
250
|
+
'error',
|
|
251
|
+
'end',
|
|
252
|
+
'close',
|
|
253
|
+
'finish'
|
|
254
|
+
]));
|
|
255
|
+
}
|
|
256
|
+
if (cp.stderr) {
|
|
257
|
+
outputs.stderr = (0, _concatWritable.default)(function(output) {
|
|
258
|
+
outputs.stderr.output = output.toString(encoding || 'utf8');
|
|
259
|
+
});
|
|
221
260
|
queue.defer(_onone.default.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
222
261
|
'error',
|
|
223
262
|
'end',
|
|
@@ -229,10 +268,6 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
229
268
|
encoding: 'utf8'
|
|
230
269
|
})));
|
|
231
270
|
queue.await(function(err) {
|
|
232
|
-
if (cp.stdout && process.stdout.getMaxListeners) {
|
|
233
|
-
process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);
|
|
234
|
-
process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);
|
|
235
|
-
}
|
|
236
271
|
var res = err ? err : {};
|
|
237
272
|
res.stdout = outputs.stdout ? outputs.stdout.output : null;
|
|
238
273
|
res.stderr = outputs.stderr ? outputs.stderr.output : null;
|
|
@@ -241,18 +276,8 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
241
276
|
res.stderr,
|
|
242
277
|
null
|
|
243
278
|
];
|
|
244
|
-
|
|
245
|
-
return x.id === id;
|
|
246
|
-
});
|
|
247
|
-
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
248
|
-
state: err ? 'error' : 'success'
|
|
249
|
-
}));
|
|
250
|
-
// let rendering complete
|
|
251
|
-
setTimeout(function() {
|
|
252
|
-
terminal.release();
|
|
253
|
-
err ? callback(err) : callback(null, res);
|
|
254
|
-
});
|
|
279
|
+
err ? callback(err) : callback(null, res);
|
|
255
280
|
});
|
|
256
|
-
}
|
|
281
|
+
}
|
|
257
282
|
}
|
|
258
283
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
package/dist/cjs/worker.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["// @ts-ignore\nimport spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport uuid from 'lil-uuid';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp';\nimport addLines from './lib/addLines';\nimport concatWritable from './lib/concatWritable';\nimport formatArguments from './lib/formatArguments';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback) {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n terminal.retain((store) => {\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["// @ts-ignore\nimport spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport uuid from 'lil-uuid';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp';\nimport addLines from './lib/addLines';\nimport concatWritable from './lib/concatWritable';\nimport formatArguments from './lib/formatArguments';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback) {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n if (stdio === 'inherit') {\n terminal.retain((store) => {\n const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = addLines((texts) => {\n const item = store.getState().processes.find((x) => x.id === id);\n const lines = item.lines.concat(texts.map((text) => ({ type: LineType.stdout, text })));\n store.getState().updateProcess({ ...item, lines });\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = addLines((texts) => {\n const item = store.getState().processes.find((x) => x.id === id);\n const lines = item.lines.concat(texts.map((text) => ({ type: LineType.stderr, text })));\n store.getState().updateProcess({ ...item, lines });\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: 'utf8' }));\n queue.await((err) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, state: err ? 'error' : 'success' });\n\n // let rendering complete\n setTimeout(() => {\n terminal.release();\n err ? callback(err) : callback(null, res);\n });\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: 'utf8' }));\n queue.await((err) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n err ? callback(err) : callback(null, res);\n });\n }\n}\n"],"names":["spawnTerminal","terminal","createApp","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","retain","store","id","uuid","getState","addProcess","title","concat","formatArguments","join","state","lines","cp","crossSpawn","outputs","stdout","stderr","queue","Queue","addLines","texts","item","processes","find","x","map","text","type","LineType","updateProcess","defer","oo","bind","pipe","spawn","worker","await","err","res","output","setTimeout","release","concatWritable","toString"],"mappings":"AAAA,aAAa;;;;;+BAgBb;;;eAAwBA;;;oEAf4B;8DACnC;4DACF;8DACG;gEAEI;+DACD;qEACM;sEACC;qBAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,MAAM;gBAAEuB,IAAItB,MAAM;gBAAE;aAAK;YAC3CqB,MAAMzC,SAASyC,OAAOzC,SAAS,MAAM0C;QACvC;IACF;AACF"}
|
package/dist/esm/worker.mjs
CHANGED
|
@@ -93,28 +93,24 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
93
93
|
"encoding",
|
|
94
94
|
"stdio"
|
|
95
95
|
]);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
const queue = new Queue();
|
|
116
|
-
if (cp.stdout) {
|
|
117
|
-
if (stdio === 'inherit') {
|
|
96
|
+
if (stdio === 'inherit') {
|
|
97
|
+
terminal.retain((store)=>{
|
|
98
|
+
const id = uuid();
|
|
99
|
+
store.getState().addProcess(_object_spread({
|
|
100
|
+
id,
|
|
101
|
+
title: [
|
|
102
|
+
command
|
|
103
|
+
].concat(formatArguments(args)).join(' '),
|
|
104
|
+
state: 'running',
|
|
105
|
+
lines: []
|
|
106
|
+
}, options));
|
|
107
|
+
const cp = crossSpawn(command, args, csOptions);
|
|
108
|
+
const outputs = {
|
|
109
|
+
stdout: null,
|
|
110
|
+
stderr: null
|
|
111
|
+
};
|
|
112
|
+
const queue = new Queue();
|
|
113
|
+
if (cp.stdout) {
|
|
118
114
|
outputs.stdout = addLines((texts)=>{
|
|
119
115
|
const item = store.getState().processes.find((x)=>x.id === id);
|
|
120
116
|
const lines = item.lines.concat(texts.map((text)=>({
|
|
@@ -125,20 +121,14 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
125
121
|
lines
|
|
126
122
|
}));
|
|
127
123
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
125
|
+
'error',
|
|
126
|
+
'end',
|
|
127
|
+
'close',
|
|
128
|
+
'finish'
|
|
129
|
+
]));
|
|
132
130
|
}
|
|
133
|
-
|
|
134
|
-
'error',
|
|
135
|
-
'end',
|
|
136
|
-
'close',
|
|
137
|
-
'finish'
|
|
138
|
-
]));
|
|
139
|
-
}
|
|
140
|
-
if (cp.stderr) {
|
|
141
|
-
if (stdio === 'inherit') {
|
|
131
|
+
if (cp.stderr) {
|
|
142
132
|
outputs.stderr = addLines((texts)=>{
|
|
143
133
|
const item = store.getState().processes.find((x)=>x.id === id);
|
|
144
134
|
const lines = item.lines.concat(texts.map((text)=>({
|
|
@@ -149,11 +139,58 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
149
139
|
lines
|
|
150
140
|
}));
|
|
151
141
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
142
|
+
queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
143
|
+
'error',
|
|
144
|
+
'end',
|
|
145
|
+
'close',
|
|
146
|
+
'finish'
|
|
147
|
+
]));
|
|
156
148
|
}
|
|
149
|
+
queue.defer(spawn.worker.bind(null, cp, _object_spread_props(_object_spread({}, csOptions), {
|
|
150
|
+
encoding: 'utf8'
|
|
151
|
+
})));
|
|
152
|
+
queue.await((err)=>{
|
|
153
|
+
const res = err ? err : {};
|
|
154
|
+
res.stdout = outputs.stdout ? outputs.stdout.output : null;
|
|
155
|
+
res.stderr = outputs.stderr ? outputs.stderr.output : null;
|
|
156
|
+
res.output = [
|
|
157
|
+
res.stdout,
|
|
158
|
+
res.stderr,
|
|
159
|
+
null
|
|
160
|
+
];
|
|
161
|
+
const item = store.getState().processes.find((x)=>x.id === id);
|
|
162
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
163
|
+
state: err ? 'error' : 'success'
|
|
164
|
+
}));
|
|
165
|
+
// let rendering complete
|
|
166
|
+
setTimeout(()=>{
|
|
167
|
+
terminal.release();
|
|
168
|
+
err ? callback(err) : callback(null, res);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
const cp = crossSpawn(command, args, csOptions);
|
|
174
|
+
const outputs = {
|
|
175
|
+
stdout: null,
|
|
176
|
+
stderr: null
|
|
177
|
+
};
|
|
178
|
+
const queue = new Queue();
|
|
179
|
+
if (cp.stdout) {
|
|
180
|
+
outputs.stdout = concatWritable((output)=>{
|
|
181
|
+
outputs.stdout.output = output.toString(encoding || 'utf8');
|
|
182
|
+
});
|
|
183
|
+
queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
184
|
+
'error',
|
|
185
|
+
'end',
|
|
186
|
+
'close',
|
|
187
|
+
'finish'
|
|
188
|
+
]));
|
|
189
|
+
}
|
|
190
|
+
if (cp.stderr) {
|
|
191
|
+
outputs.stderr = concatWritable((output)=>{
|
|
192
|
+
outputs.stderr.output = output.toString(encoding || 'utf8');
|
|
193
|
+
});
|
|
157
194
|
queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
158
195
|
'error',
|
|
159
196
|
'end',
|
|
@@ -165,10 +202,6 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
165
202
|
encoding: 'utf8'
|
|
166
203
|
})));
|
|
167
204
|
queue.await((err)=>{
|
|
168
|
-
if (cp.stdout && process.stdout.getMaxListeners) {
|
|
169
|
-
process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);
|
|
170
|
-
process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);
|
|
171
|
-
}
|
|
172
205
|
const res = err ? err : {};
|
|
173
206
|
res.stdout = outputs.stdout ? outputs.stdout.output : null;
|
|
174
207
|
res.stderr = outputs.stderr ? outputs.stderr.output : null;
|
|
@@ -177,15 +210,7 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
177
210
|
res.stderr,
|
|
178
211
|
null
|
|
179
212
|
];
|
|
180
|
-
|
|
181
|
-
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
182
|
-
state: err ? 'error' : 'success'
|
|
183
|
-
}));
|
|
184
|
-
// let rendering complete
|
|
185
|
-
setTimeout(()=>{
|
|
186
|
-
terminal.release();
|
|
187
|
-
err ? callback(err) : callback(null, res);
|
|
188
|
-
});
|
|
213
|
+
err ? callback(err) : callback(null, res);
|
|
189
214
|
});
|
|
190
|
-
}
|
|
215
|
+
}
|
|
191
216
|
}
|
package/dist/esm/worker.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["// @ts-ignore\nimport spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport uuid from 'lil-uuid';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp';\nimport addLines from './lib/addLines';\nimport concatWritable from './lib/concatWritable';\nimport formatArguments from './lib/formatArguments';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback) {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n terminal.retain((store) => {\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["// @ts-ignore\nimport spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport uuid from 'lil-uuid';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp';\nimport addLines from './lib/addLines';\nimport concatWritable from './lib/concatWritable';\nimport formatArguments from './lib/formatArguments';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback) {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n if (stdio === 'inherit') {\n terminal.retain((store) => {\n const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = addLines((texts) => {\n const item = store.getState().processes.find((x) => x.id === id);\n const lines = item.lines.concat(texts.map((text) => ({ type: LineType.stdout, text })));\n store.getState().updateProcess({ ...item, lines });\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = addLines((texts) => {\n const item = store.getState().processes.find((x) => x.id === id);\n const lines = item.lines.concat(texts.map((text) => ({ type: LineType.stderr, text })));\n store.getState().updateProcess({ ...item, lines });\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: 'utf8' }));\n queue.await((err) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, state: err ? 'error' : 'success' });\n\n // let rendering complete\n setTimeout(() => {\n terminal.release();\n err ? callback(err) : callback(null, res);\n });\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: 'utf8' }));\n queue.await((err) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n err ? callback(err) : callback(null, res);\n });\n }\n}\n"],"names":["spawn","crossSpawn","uuid","oo","Queue","createApp","addLines","concatWritable","formatArguments","LineType","terminal","spawnTerminal","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","retain","store","id","getState","addProcess","title","concat","join","state","lines","cp","outputs","stdout","stderr","queue","texts","item","processes","find","x","map","text","type","updateProcess","defer","bind","pipe","worker","await","err","res","output","setTimeout","release","toString"],"mappings":"AAAA,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,OAAOA,SAASC,UAAU,QAA0B,iBAAiB;AACrE,OAAOC,UAAU,WAAW;AAC5B,OAAOC,QAAQ,SAAS;AACxB,OAAOC,WAAW,WAAW;AAE7B,OAAOC,eAAe,cAAc;AACpC,OAAOC,cAAc,iBAAiB;AACtC,OAAOC,oBAAoB,uBAAuB;AAClD,OAAOC,qBAAqB,wBAAwB;AAGpD,SAASC,QAAQ,QAAQ,UAAU;AAEnC,MAAMC,WAAWL;AAEjB,eAAe,SAASM,cAAcC,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAAQ;IACnI,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAgB,GAAGJ,cAAdK,uCAAcL;QAAlCG;QAAUC;;IAElB,IAAIA,UAAU,WAAW;QACvBR,SAASU,MAAM,CAAC,CAACC;YACf,MAAMC,KAAKpB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