spawn-term 0.1.3 → 0.1.5
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/assets/ink.cjs +12 -0
- package/dist/cjs/createApp.cjs +35 -33
- package/dist/cjs/createApp.cjs.map +1 -1
- package/dist/cjs/ink.cjs +4 -1
- package/dist/cjs/ink.cjs.map +1 -1
- package/dist/cjs/worker.cjs +97 -101
- package/dist/cjs/worker.cjs.map +1 -1
- package/dist/esm/createApp.mjs +25 -23
- package/dist/esm/createApp.mjs.map +1 -1
- package/dist/esm/ink.mjs +2 -2
- package/dist/esm/ink.mjs.map +1 -1
- package/dist/esm/worker.mjs +88 -92
- package/dist/esm/worker.mjs.map +1 -1
- package/dist/types/createApp.d.ts +1 -1
- package/dist/types/ink.d.mts +1 -0
- package/package.json +1 -1
package/assets/ink.cjs
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
var IntlSegmenter = typeof Intl === 'undefined' || !Intl.Segmenter ? require('./intl-adapter.cjs').Segmenter : Intl.Segmenter;
|
|
4
4
|
var globalThis = global;
|
|
5
|
+
|
|
6
|
+
var _waiting = [];
|
|
7
|
+
var _isReady = false;
|
|
8
|
+
function _notifyInitialized() {
|
|
9
|
+
_isReady = true;
|
|
10
|
+
_waiting.slice(0).forEach(function (fn) { fn(); })
|
|
11
|
+
}
|
|
12
|
+
exports.initialize = function _initialize(fn) {
|
|
13
|
+
_isReady ? fn() : _waiting.push(fn);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
5
16
|
"use strict";
|
|
6
17
|
Object.defineProperty(exports, "__esModule", {
|
|
7
18
|
value: true
|
|
@@ -2206,6 +2217,7 @@ function _initYoga() {
|
|
|
2206
2217
|
var Yoga = null;
|
|
2207
2218
|
initYoga(require('fs').readFileSync(require.resolve("yoga-wasm-web/dist/yoga.wasm"))).then(function(_Y) {
|
|
2208
2219
|
Yoga = _Y;
|
|
2220
|
+
_notifyInitialized();
|
|
2209
2221
|
});
|
|
2210
2222
|
var reactReconciler = {
|
|
2211
2223
|
exports: {}
|
package/dist/cjs/createApp.cjs
CHANGED
|
@@ -48,45 +48,47 @@ function createApp() {
|
|
|
48
48
|
var store = null;
|
|
49
49
|
var inkApp = null;
|
|
50
50
|
return {
|
|
51
|
-
retain: function retain() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
51
|
+
retain: function retain(fn) {
|
|
52
|
+
(0, _ink.initialize)(function() {
|
|
53
|
+
if (++refCount > 1) return fn(store);
|
|
54
|
+
if (store) throw new Error('Not expecting store');
|
|
55
|
+
store = (0, _zustand.createStore)()(function(set) {
|
|
56
|
+
return {
|
|
57
|
+
processes: [],
|
|
58
|
+
addProcess: function(process1) {
|
|
59
|
+
return set(function(state) {
|
|
60
|
+
return {
|
|
61
|
+
processes: _to_consumable_array(state.processes).concat([
|
|
62
|
+
process1
|
|
63
|
+
])
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
updateProcess: function(process1) {
|
|
68
|
+
return set(function(state) {
|
|
69
|
+
return {
|
|
70
|
+
processes: state.processes.map(function(x) {
|
|
71
|
+
return x.id === process1.id ? process1 : x;
|
|
72
|
+
})
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
inkApp = (0, _ink.render)(/*#__PURE__*/ _react.default.createElement(_Store.default.Provider, {
|
|
79
|
+
value: store
|
|
80
|
+
}, /*#__PURE__*/ _react.default.createElement(_App.default, null)), {
|
|
81
|
+
patchConsole: false
|
|
82
|
+
});
|
|
83
|
+
return fn(store);
|
|
76
84
|
});
|
|
77
|
-
inkApp = (0, _ink.render)(/*#__PURE__*/ _react.default.createElement(_Store.default.Provider, {
|
|
78
|
-
value: store
|
|
79
|
-
}, /*#__PURE__*/ _react.default.createElement(_App.default, null)), {
|
|
80
|
-
patchConsole: false
|
|
81
|
-
});
|
|
82
|
-
return store;
|
|
83
85
|
},
|
|
84
86
|
release: function release() {
|
|
85
87
|
if (--refCount > 0) return;
|
|
86
|
-
if (!
|
|
88
|
+
if (!store) throw new Error('Expecting store');
|
|
89
|
+
store = null;
|
|
87
90
|
inkApp.unmount();
|
|
88
91
|
inkApp = null;
|
|
89
|
-
store = null;
|
|
90
92
|
process.stdout.write('\x1b[?25h'); // show cursor
|
|
91
93
|
}
|
|
92
94
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import React from 'react';\nimport { createStore } from 'zustand';\nimport App from './components/App';\nimport StoreContext from './contexts/Store';\n\n// @ts-ignore\nimport { type Instance, render } from './ink.mjs';\nimport type { AppState } from './types';\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n\n return {\n retain() {\n if (++refCount > 1) return store;\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import React from 'react';\nimport { createStore } from 'zustand';\nimport App from './components/App';\nimport StoreContext from './contexts/Store';\n\n// @ts-ignore\nimport { type Instance, initialize, render } from './ink.mjs';\nimport type { AppState } from './types';\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n\n return {\n retain(fn) {\n initialize(() => {\n if (++refCount > 1) return fn(store);\n if (store) throw new Error('Not expecting store');\n store = createStore<AppState>()((set) => ({\n processes: [],\n addProcess: (process) => set((state) => ({ processes: [...state.processes, process] })),\n updateProcess: (process) => set((state) => ({ processes: state.processes.map((x) => (x.id === process.id ? process : x)) })),\n }));\n inkApp = render(\n <StoreContext.Provider value={store}>\n <App />\n </StoreContext.Provider>,\n { patchConsole: false }\n );\n return fn(store);\n });\n },\n release() {\n if (--refCount > 0) return;\n if (!store) throw new Error('Expecting store');\n store = null;\n inkApp.unmount();\n inkApp = null;\n process.stdout.write('\\x1b[?25h'); // show cursor\n },\n };\n}\n"],"names":["createApp","refCount","store","inkApp","retain","fn","initialize","Error","createStore","set","processes","addProcess","process","state","updateProcess","map","x","id","render","StoreContext","Provider","value","App","patchConsole","release","unmount","stdout","write"],"mappings":";;;;+BASA;;;eAAwBA;;;4DATN;uBACU;0DACZ;4DACS;mBAGyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGnC,SAASA;IACtB,IAAIC,WAAW;IACf,IAAIC,QAAQ;IACZ,IAAIC,SAA0B;IAE9B,OAAO;QACLC,QAAAA,SAAAA,OAAOC,EAAE;YACPC,IAAAA,eAAU,EAAC;gBACT,IAAI,EAAEL,WAAW,GAAG,OAAOI,GAAGH;gBAC9B,IAAIA,OAAO,MAAM,IAAIK,MAAM;gBAC3BL,QAAQM,IAAAA,oBAAW,IAAa,SAACC;2BAAS;wBACxCC,WAAW,EAAE;wBACbC,YAAY,SAACC;mCAAYH,IAAI,SAACI;uCAAW;oCAAEH,WAAW,AAAC,qBAAGG,MAAMH,SAAS,SAAnB;wCAAqBE;qCAAQ;gCAAC;;;wBACpFE,eAAe,SAACF;mCAAYH,IAAI,SAACI;uCAAW;oCAAEH,WAAWG,MAAMH,SAAS,CAACK,GAAG,CAAC,SAACC;+CAAOA,EAAEC,EAAE,KAAKL,SAAQK,EAAE,GAAGL,WAAUI;;gCAAI;;;oBAC3H;;gBACAb,SAASe,IAAAA,WAAM,gBACb,6BAACC,cAAY,CAACC,QAAQ;oBAACC,OAAOnB;iCAC5B,6BAACoB,YAAG,UAEN;oBAAEC,cAAc;gBAAM;gBAExB,OAAOlB,GAAGH;YACZ;QACF;QACAsB,SAAAA,SAAAA;YACE,IAAI,EAAEvB,WAAW,GAAG;YACpB,IAAI,CAACC,OAAO,MAAM,IAAIK,MAAM;YAC5BL,QAAQ;YACRC,OAAOsB,OAAO;YACdtB,SAAS;YACTS,QAAQc,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;QACnD;IACF;AACF"}
|
package/dist/cjs/ink.cjs
CHANGED
|
@@ -27,6 +27,9 @@ _export(exports, {
|
|
|
27
27
|
Transform: function() {
|
|
28
28
|
return Transform;
|
|
29
29
|
},
|
|
30
|
+
initialize: function() {
|
|
31
|
+
return initialize;
|
|
32
|
+
},
|
|
30
33
|
measureElement: function() {
|
|
31
34
|
return measureElement;
|
|
32
35
|
},
|
|
@@ -108,5 +111,5 @@ if (typeof process.stdout.off === 'undefined') process.stdout.off = function(nam
|
|
|
108
111
|
if (typeof process.stderr.off === 'undefined') process.stderr.off = function(name, fn) {
|
|
109
112
|
return process.stderr.removeListener(name, fn);
|
|
110
113
|
};
|
|
111
|
-
var _ref = _inkcjs.default || _inkcjs, Box = _ref.Box, Newline = _ref.Newline, Spacer = _ref.Spacer, Static = _ref.Static, Text = _ref.Text, Transform = _ref.Transform, measureElement = _ref.measureElement, render = _ref.render, useApp = _ref.useApp, useFocus = _ref.useFocus, useFocusManager = _ref.useFocusManager, useInput = _ref.useInput, useStderr = _ref.useStderr, useStdin = _ref.useStdin, useStdout = _ref.useStdout;
|
|
114
|
+
var _ref = _inkcjs.default || _inkcjs, Box = _ref.Box, Newline = _ref.Newline, Spacer = _ref.Spacer, Static = _ref.Static, Text = _ref.Text, Transform = _ref.Transform, measureElement = _ref.measureElement, render = _ref.render, useApp = _ref.useApp, useFocus = _ref.useFocus, useFocusManager = _ref.useFocusManager, useInput = _ref.useInput, useStderr = _ref.useStderr, useStdin = _ref.useStdin, useStdout = _ref.useStdout, initialize = _ref.initialize;
|
|
112
115
|
/* 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/ink.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/ink.mjs"],"sourcesContent":["import 'core-js/actual/array/at.js';\nimport 'core-js/actual/object/has-own.js';\nimport 'core-js/actual/object/values.js';\nimport 'core-js/actual/string/replace-all.js';\nimport 'core-js/actual/string/trim-end.js';\nif (typeof process.stdout.off === 'undefined') process.stdout.off = (name, fn) => process.stdout.removeListener(name, fn);\nif (typeof process.stderr.off === 'undefined') process.stderr.off = (name, fn) => process.stderr.removeListener(name, fn);\n\nimport * as ink from '../../assets/ink.cjs';\nconst { Box, Newline, Spacer, Static, Text, Transform, measureElement, render, useApp, useFocus, useFocusManager, useInput, useStderr, useStdin, useStdout } = ink.default || ink;\nexport { Box, Newline, Spacer, Static, Text, Transform, measureElement, render, useApp, useFocus, useFocusManager, useInput, useStderr, useStdin, useStdout };\n"],"names":["Box","Newline","Spacer","Static","Text","Transform","measureElement","render","useApp","useFocus","useFocusManager","useInput","useStderr","useStdin","useStdout","process","stdout","off","name","fn","removeListener","stderr","ink","default"],"mappings":";;;;;;;;;;;IAUSA,GAAG;eAAHA;;IAAKC,OAAO;eAAPA;;IAASC,MAAM;eAANA;;IAAQC,MAAM;eAANA;;IAAQC,IAAI;eAAJA;;IAAMC,SAAS;eAATA;;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/ink.mjs"],"sourcesContent":["import 'core-js/actual/array/at.js';\nimport 'core-js/actual/object/has-own.js';\nimport 'core-js/actual/object/values.js';\nimport 'core-js/actual/string/replace-all.js';\nimport 'core-js/actual/string/trim-end.js';\nif (typeof process.stdout.off === 'undefined') process.stdout.off = (name, fn) => process.stdout.removeListener(name, fn);\nif (typeof process.stderr.off === 'undefined') process.stderr.off = (name, fn) => process.stderr.removeListener(name, fn);\n\nimport * as ink from '../../assets/ink.cjs';\nconst { Box, Newline, Spacer, Static, Text, Transform, measureElement, render, useApp, useFocus, useFocusManager, useInput, useStderr, useStdin, useStdout, initialize } = ink.default || ink;\nexport { Box, Newline, Spacer, Static, Text, Transform, measureElement, render, useApp, useFocus, useFocusManager, useInput, useStderr, useStdin, useStdout, initialize };\n"],"names":["Box","Newline","Spacer","Static","Text","Transform","initialize","measureElement","render","useApp","useFocus","useFocusManager","useInput","useStderr","useStdin","useStdout","process","stdout","off","name","fn","removeListener","stderr","ink","default"],"mappings":";;;;;;;;;;;IAUSA,GAAG;eAAHA;;IAAKC,OAAO;eAAPA;;IAASC,MAAM;eAANA;;IAAQC,MAAM;eAANA;;IAAQC,IAAI;eAAJA;;IAAMC,SAAS;eAATA;;IAAgHC,UAAU;eAAVA;;IAArGC,cAAc;eAAdA;;IAAgBC,MAAM;eAANA;;IAAQC,MAAM;eAANA;;IAAQC,QAAQ;eAARA;;IAAUC,eAAe;eAAfA;;IAAiBC,QAAQ;eAARA;;IAAUC,SAAS;eAATA;;IAAWC,QAAQ;eAARA;;IAAUC,SAAS;eAATA;;;QAV3I;QACA;QACA;QACA;QACA;8DAIc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAHrB,IAAI,OAAOC,QAAQC,MAAM,CAACC,GAAG,KAAK,aAAaF,QAAQC,MAAM,CAACC,GAAG,GAAG,SAACC,MAAMC;WAAOJ,QAAQC,MAAM,CAACI,cAAc,CAACF,MAAMC;;AACtH,IAAI,OAAOJ,QAAQM,MAAM,CAACJ,GAAG,KAAK,aAAaF,QAAQM,MAAM,CAACJ,GAAG,GAAG,SAACC,MAAMC;WAAOJ,QAAQM,MAAM,CAACD,cAAc,CAACF,MAAMC;;AAGtH,IAA2KG,OAAAA,QAAIC,OAAO,IAAID,SAAlLvB,MAAmKuB,KAAnKvB,KAAKC,UAA8JsB,KAA9JtB,SAASC,SAAqJqB,KAArJrB,QAAQC,SAA6IoB,KAA7IpB,QAAQC,OAAqImB,KAArInB,MAAMC,YAA+HkB,KAA/HlB,WAAWE,iBAAoHgB,KAApHhB,gBAAgBC,SAAoGe,KAApGf,QAAQC,SAA4Fc,KAA5Fd,QAAQC,WAAoFa,KAApFb,UAAUC,kBAA0EY,KAA1EZ,iBAAiBC,WAAyDW,KAAzDX,UAAUC,YAA+CU,KAA/CV,WAAWC,WAAoCS,KAApCT,UAAUC,YAA0BQ,KAA1BR,WAAWT,aAAeiB,KAAfjB"}
|
package/dist/cjs/worker.cjs
CHANGED
|
@@ -3,12 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports,
|
|
7
|
-
// const THROTTLE = 100;
|
|
8
|
-
// const rerender = throttle(() => {
|
|
9
|
-
// terminal.rerender();
|
|
10
|
-
// }, THROTTLE);
|
|
11
|
-
"default", {
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
12
7
|
enumerable: true,
|
|
13
8
|
get: function() {
|
|
14
9
|
return spawnTerminal;
|
|
@@ -153,106 +148,107 @@ function spawnTerminal(command, args, spawnOptions, _options, callback) {
|
|
|
153
148
|
"encoding",
|
|
154
149
|
"stdio"
|
|
155
150
|
]);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
var queue = new _queuecb.default();
|
|
176
|
-
if (cp.stdout) {
|
|
177
|
-
if (stdio === 'inherit') {
|
|
178
|
-
outputs.stdout = (0, _addLines.default)(function(texts) {
|
|
179
|
-
var item = store.getState().processes.find(function(x) {
|
|
180
|
-
return x.id === id;
|
|
181
|
-
});
|
|
182
|
-
var lines = item.lines.concat(texts.map(function(text) {
|
|
183
|
-
return {
|
|
184
|
-
type: _types.LineType.stdout,
|
|
185
|
-
text: text
|
|
186
|
-
};
|
|
187
|
-
}));
|
|
188
|
-
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
189
|
-
lines: lines
|
|
190
|
-
}));
|
|
191
|
-
});
|
|
192
|
-
} else {
|
|
193
|
-
outputs.stdout = (0, _concatWritable.default)(function(output) {
|
|
194
|
-
outputs.stdout.output = output.toString(encoding || 'utf8');
|
|
195
|
-
});
|
|
151
|
+
terminal.retain(function(store) {
|
|
152
|
+
var id = (0, _liluuid.default)();
|
|
153
|
+
store.getState().addProcess({
|
|
154
|
+
id: id,
|
|
155
|
+
title: [
|
|
156
|
+
command
|
|
157
|
+
].concat(args).join(' '),
|
|
158
|
+
state: 'running',
|
|
159
|
+
lines: []
|
|
160
|
+
});
|
|
161
|
+
var cp = (0, _crossspawncb.crossSpawn)(command, args, csOptions);
|
|
162
|
+
var outputs = {
|
|
163
|
+
stdout: null,
|
|
164
|
+
stderr: null
|
|
165
|
+
};
|
|
166
|
+
if (cp.stdout && process.stdout.getMaxListeners) {
|
|
167
|
+
process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);
|
|
168
|
+
process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);
|
|
196
169
|
}
|
|
197
|
-
queue.
|
|
198
|
-
|
|
199
|
-
'
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
170
|
+
var queue = new _queuecb.default();
|
|
171
|
+
if (cp.stdout) {
|
|
172
|
+
if (stdio === 'inherit') {
|
|
173
|
+
outputs.stdout = (0, _addLines.default)(function(texts) {
|
|
174
|
+
var item = store.getState().processes.find(function(x) {
|
|
175
|
+
return x.id === id;
|
|
176
|
+
});
|
|
177
|
+
var lines = item.lines.concat(texts.map(function(text) {
|
|
178
|
+
return {
|
|
179
|
+
type: _types.LineType.stdout,
|
|
180
|
+
text: text
|
|
181
|
+
};
|
|
182
|
+
}));
|
|
183
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
184
|
+
lines: lines
|
|
185
|
+
}));
|
|
209
186
|
});
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
outputs.stderr = (0, _concatWritable.default)(function(output) {
|
|
222
|
-
outputs.stderr.output = output.toString(encoding || 'utf8');
|
|
223
|
-
});
|
|
187
|
+
} else {
|
|
188
|
+
outputs.stdout = (0, _concatWritable.default)(function(output) {
|
|
189
|
+
outputs.stdout.output = output.toString(encoding || 'utf8');
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
queue.defer(_onone.default.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
193
|
+
'error',
|
|
194
|
+
'end',
|
|
195
|
+
'close',
|
|
196
|
+
'finish'
|
|
197
|
+
]));
|
|
224
198
|
}
|
|
225
|
-
|
|
226
|
-
'
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
199
|
+
if (cp.stderr) {
|
|
200
|
+
if (stdio === 'inherit') {
|
|
201
|
+
outputs.stderr = (0, _addLines.default)(function(texts) {
|
|
202
|
+
var item = store.getState().processes.find(function(x) {
|
|
203
|
+
return x.id === id;
|
|
204
|
+
});
|
|
205
|
+
var lines = item.lines.concat(texts.map(function(text) {
|
|
206
|
+
return {
|
|
207
|
+
type: _types.LineType.stderr,
|
|
208
|
+
text: text
|
|
209
|
+
};
|
|
210
|
+
}));
|
|
211
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
212
|
+
lines: lines
|
|
213
|
+
}));
|
|
214
|
+
});
|
|
215
|
+
} else {
|
|
216
|
+
outputs.stderr = (0, _concatWritable.default)(function(output) {
|
|
217
|
+
outputs.stderr.output = output.toString(encoding || 'utf8');
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
queue.defer(_onone.default.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
221
|
+
'error',
|
|
222
|
+
'end',
|
|
223
|
+
'close',
|
|
224
|
+
'finish'
|
|
225
|
+
]));
|
|
239
226
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
227
|
+
queue.defer(_crossspawncb.default.worker.bind(null, cp, _object_spread_props(_object_spread({}, csOptions), {
|
|
228
|
+
encoding: 'utf8'
|
|
229
|
+
})));
|
|
230
|
+
queue.await(function(err) {
|
|
231
|
+
if (cp.stdout && process.stdout.getMaxListeners) {
|
|
232
|
+
process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);
|
|
233
|
+
process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);
|
|
234
|
+
}
|
|
235
|
+
var res = err ? err : {};
|
|
236
|
+
res.stdout = outputs.stdout ? outputs.stdout.output : null;
|
|
237
|
+
res.stderr = outputs.stderr ? outputs.stderr.output : null;
|
|
238
|
+
res.output = [
|
|
239
|
+
res.stdout,
|
|
240
|
+
res.stderr,
|
|
241
|
+
null
|
|
242
|
+
];
|
|
243
|
+
var item = store.getState().processes.find(function(x) {
|
|
244
|
+
return x.id === id;
|
|
245
|
+
});
|
|
246
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
247
|
+
state: err ? 'error' : 'success'
|
|
248
|
+
}));
|
|
249
|
+
terminal.release();
|
|
250
|
+
err ? callback(err) : callback(null, res);
|
|
250
251
|
});
|
|
251
|
-
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
252
|
-
state: err ? 'error' : 'success'
|
|
253
|
-
}));
|
|
254
|
-
terminal.release();
|
|
255
|
-
err ? callback(err) : callback(null, res);
|
|
256
252
|
});
|
|
257
253
|
}
|
|
258
254
|
/* 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';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst terminal = createApp();\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';\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 const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(args).join(' '), state: 'running', lines: [] });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);\n }\n\n const queue = new Queue();\n if (cp.stdout) {\n if (stdio === 'inherit') {\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 } else {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n }\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n if (stdio === 'inherit') {\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 } else {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\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 if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);\n }\n\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 terminal.release();\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","join","state","lines","cp","crossSpawn","outputs","stdout","stderr","process","getMaxListeners","setMaxListeners","queue","Queue","addLines","texts","item","processes","find","x","map","text","type","LineType","updateProcess","concatWritable","output","toString","defer","oo","bind","pipe","spawn","worker","await","err","res","release"],"mappings":"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"}
|
package/dist/esm/createApp.mjs
CHANGED
|
@@ -3,40 +3,42 @@ import { createStore } from 'zustand';
|
|
|
3
3
|
import App from './components/App.mjs';
|
|
4
4
|
import StoreContext from './contexts/Store.mjs';
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import { render } from './ink.mjs';
|
|
6
|
+
import { initialize, render } from './ink.mjs';
|
|
7
7
|
export default function createApp() {
|
|
8
8
|
let refCount = 0;
|
|
9
9
|
let store = null;
|
|
10
10
|
let inkApp = null;
|
|
11
11
|
return {
|
|
12
|
-
retain () {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
retain (fn) {
|
|
13
|
+
initialize(()=>{
|
|
14
|
+
if (++refCount > 1) return fn(store);
|
|
15
|
+
if (store) throw new Error('Not expecting store');
|
|
16
|
+
store = createStore()((set)=>({
|
|
17
|
+
processes: [],
|
|
18
|
+
addProcess: (process1)=>set((state)=>({
|
|
19
|
+
processes: [
|
|
20
|
+
...state.processes,
|
|
21
|
+
process1
|
|
22
|
+
]
|
|
23
|
+
})),
|
|
24
|
+
updateProcess: (process1)=>set((state)=>({
|
|
25
|
+
processes: state.processes.map((x)=>x.id === process1.id ? process1 : x)
|
|
26
|
+
}))
|
|
27
|
+
}));
|
|
28
|
+
inkApp = render(/*#__PURE__*/ React.createElement(StoreContext.Provider, {
|
|
29
|
+
value: store
|
|
30
|
+
}, /*#__PURE__*/ React.createElement(App, null)), {
|
|
31
|
+
patchConsole: false
|
|
32
|
+
});
|
|
33
|
+
return fn(store);
|
|
31
34
|
});
|
|
32
|
-
return store;
|
|
33
35
|
},
|
|
34
36
|
release () {
|
|
35
37
|
if (--refCount > 0) return;
|
|
36
|
-
if (!
|
|
38
|
+
if (!store) throw new Error('Expecting store');
|
|
39
|
+
store = null;
|
|
37
40
|
inkApp.unmount();
|
|
38
41
|
inkApp = null;
|
|
39
|
-
store = null;
|
|
40
42
|
process.stdout.write('\x1b[?25h'); // show cursor
|
|
41
43
|
}
|
|
42
44
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import React from 'react';\nimport { createStore } from 'zustand';\nimport App from './components/App';\nimport StoreContext from './contexts/Store';\n\n// @ts-ignore\nimport { type Instance, render } from './ink.mjs';\nimport type { AppState } from './types';\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n\n return {\n retain() {\n if (++refCount > 1) return store;\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import React from 'react';\nimport { createStore } from 'zustand';\nimport App from './components/App';\nimport StoreContext from './contexts/Store';\n\n// @ts-ignore\nimport { type Instance, initialize, render } from './ink.mjs';\nimport type { AppState } from './types';\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n\n return {\n retain(fn) {\n initialize(() => {\n if (++refCount > 1) return fn(store);\n if (store) throw new Error('Not expecting store');\n store = createStore<AppState>()((set) => ({\n processes: [],\n addProcess: (process) => set((state) => ({ processes: [...state.processes, process] })),\n updateProcess: (process) => set((state) => ({ processes: state.processes.map((x) => (x.id === process.id ? process : x)) })),\n }));\n inkApp = render(\n <StoreContext.Provider value={store}>\n <App />\n </StoreContext.Provider>,\n { patchConsole: false }\n );\n return fn(store);\n });\n },\n release() {\n if (--refCount > 0) return;\n if (!store) throw new Error('Expecting store');\n store = null;\n inkApp.unmount();\n inkApp = null;\n process.stdout.write('\\x1b[?25h'); // show cursor\n },\n };\n}\n"],"names":["React","createStore","App","StoreContext","initialize","render","createApp","refCount","store","inkApp","retain","fn","Error","set","processes","addProcess","process","state","updateProcess","map","x","id","Provider","value","patchConsole","release","unmount","stdout","write"],"mappings":"AAAA,OAAOA,WAAW,QAAQ;AAC1B,SAASC,WAAW,QAAQ,UAAU;AACtC,OAAOC,SAAS,mBAAmB;AACnC,OAAOC,kBAAkB,mBAAmB;AAE5C,aAAa;AACb,SAAwBC,UAAU,EAAEC,MAAM,QAAQ,YAAY;AAG9D,eAAe,SAASC;IACtB,IAAIC,WAAW;IACf,IAAIC,QAAQ;IACZ,IAAIC,SAA0B;IAE9B,OAAO;QACLC,QAAOC,EAAE;YACPP,WAAW;gBACT,IAAI,EAAEG,WAAW,GAAG,OAAOI,GAAGH;gBAC9B,IAAIA,OAAO,MAAM,IAAII,MAAM;gBAC3BJ,QAAQP,cAAwB,CAACY,MAAS,CAAA;wBACxCC,WAAW,EAAE;wBACbC,YAAY,CAACC,WAAYH,IAAI,CAACI,QAAW,CAAA;oCAAEH,WAAW;2CAAIG,MAAMH,SAAS;wCAAEE;qCAAQ;gCAAC,CAAA;wBACpFE,eAAe,CAACF,WAAYH,IAAI,CAACI,QAAW,CAAA;oCAAEH,WAAWG,MAAMH,SAAS,CAACK,GAAG,CAAC,CAACC,IAAOA,EAAEC,EAAE,KAAKL,SAAQK,EAAE,GAAGL,WAAUI;gCAAI,CAAA;oBAC3H,CAAA;gBACAX,SAASJ,qBACP,oBAACF,aAAamB,QAAQ;oBAACC,OAAOf;iCAC5B,oBAACN,aAEH;oBAAEsB,cAAc;gBAAM;gBAExB,OAAOb,GAAGH;YACZ;QACF;QACAiB;YACE,IAAI,EAAElB,WAAW,GAAG;YACpB,IAAI,CAACC,OAAO,MAAM,IAAII,MAAM;YAC5BJ,QAAQ;YACRC,OAAOiB,OAAO;YACdjB,SAAS;YACTO,QAAQW,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;QACnD;IACF;AACF"}
|
package/dist/esm/ink.mjs
CHANGED
|
@@ -6,5 +6,5 @@ import 'core-js/actual/string/trim-end.js';
|
|
|
6
6
|
if (typeof process.stdout.off === 'undefined') process.stdout.off = (name, fn)=>process.stdout.removeListener(name, fn);
|
|
7
7
|
if (typeof process.stderr.off === 'undefined') process.stderr.off = (name, fn)=>process.stderr.removeListener(name, fn);
|
|
8
8
|
import * as ink from '../../assets/ink.cjs';
|
|
9
|
-
const { Box, Newline, Spacer, Static, Text, Transform, measureElement, render, useApp, useFocus, useFocusManager, useInput, useStderr, useStdin, useStdout } = ink.default || ink;
|
|
10
|
-
export { Box, Newline, Spacer, Static, Text, Transform, measureElement, render, useApp, useFocus, useFocusManager, useInput, useStderr, useStdin, useStdout };
|
|
9
|
+
const { Box, Newline, Spacer, Static, Text, Transform, measureElement, render, useApp, useFocus, useFocusManager, useInput, useStderr, useStdin, useStdout, initialize } = ink.default || ink;
|
|
10
|
+
export { Box, Newline, Spacer, Static, Text, Transform, measureElement, render, useApp, useFocus, useFocusManager, useInput, useStderr, useStdin, useStdout, initialize };
|
package/dist/esm/ink.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/ink.mjs"],"sourcesContent":["import 'core-js/actual/array/at.js';\nimport 'core-js/actual/object/has-own.js';\nimport 'core-js/actual/object/values.js';\nimport 'core-js/actual/string/replace-all.js';\nimport 'core-js/actual/string/trim-end.js';\nif (typeof process.stdout.off === 'undefined') process.stdout.off = (name, fn) => process.stdout.removeListener(name, fn);\nif (typeof process.stderr.off === 'undefined') process.stderr.off = (name, fn) => process.stderr.removeListener(name, fn);\n\nimport * as ink from '../../assets/ink.cjs';\nconst { Box, Newline, Spacer, Static, Text, Transform, measureElement, render, useApp, useFocus, useFocusManager, useInput, useStderr, useStdin, useStdout } = ink.default || ink;\nexport { Box, Newline, Spacer, Static, Text, Transform, measureElement, render, useApp, useFocus, useFocusManager, useInput, useStderr, useStdin, useStdout };\n"],"names":["process","stdout","off","name","fn","removeListener","stderr","ink","Box","Newline","Spacer","Static","Text","Transform","measureElement","render","useApp","useFocus","useFocusManager","useInput","useStderr","useStdin","useStdout","default"],"mappings":"AAAA,OAAO,6BAA6B;AACpC,OAAO,mCAAmC;AAC1C,OAAO,kCAAkC;AACzC,OAAO,uCAAuC;AAC9C,OAAO,oCAAoC;AAC3C,IAAI,OAAOA,QAAQC,MAAM,CAACC,GAAG,KAAK,aAAaF,QAAQC,MAAM,CAACC,GAAG,GAAG,CAACC,MAAMC,KAAOJ,QAAQC,MAAM,CAACI,cAAc,CAACF,MAAMC;AACtH,IAAI,OAAOJ,QAAQM,MAAM,CAACJ,GAAG,KAAK,aAAaF,QAAQM,MAAM,CAACJ,GAAG,GAAG,CAACC,MAAMC,KAAOJ,QAAQM,MAAM,CAACD,cAAc,CAACF,MAAMC;AAEtH,YAAYG,SAAS,uBAAuB;AAC5C,MAAM,EAAEC,GAAG,EAAEC,OAAO,EAAEC,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,cAAc,EAAEC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,eAAe,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,SAAS,EAAE,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/ink.mjs"],"sourcesContent":["import 'core-js/actual/array/at.js';\nimport 'core-js/actual/object/has-own.js';\nimport 'core-js/actual/object/values.js';\nimport 'core-js/actual/string/replace-all.js';\nimport 'core-js/actual/string/trim-end.js';\nif (typeof process.stdout.off === 'undefined') process.stdout.off = (name, fn) => process.stdout.removeListener(name, fn);\nif (typeof process.stderr.off === 'undefined') process.stderr.off = (name, fn) => process.stderr.removeListener(name, fn);\n\nimport * as ink from '../../assets/ink.cjs';\nconst { Box, Newline, Spacer, Static, Text, Transform, measureElement, render, useApp, useFocus, useFocusManager, useInput, useStderr, useStdin, useStdout, initialize } = ink.default || ink;\nexport { Box, Newline, Spacer, Static, Text, Transform, measureElement, render, useApp, useFocus, useFocusManager, useInput, useStderr, useStdin, useStdout, initialize };\n"],"names":["process","stdout","off","name","fn","removeListener","stderr","ink","Box","Newline","Spacer","Static","Text","Transform","measureElement","render","useApp","useFocus","useFocusManager","useInput","useStderr","useStdin","useStdout","initialize","default"],"mappings":"AAAA,OAAO,6BAA6B;AACpC,OAAO,mCAAmC;AAC1C,OAAO,kCAAkC;AACzC,OAAO,uCAAuC;AAC9C,OAAO,oCAAoC;AAC3C,IAAI,OAAOA,QAAQC,MAAM,CAACC,GAAG,KAAK,aAAaF,QAAQC,MAAM,CAACC,GAAG,GAAG,CAACC,MAAMC,KAAOJ,QAAQC,MAAM,CAACI,cAAc,CAACF,MAAMC;AACtH,IAAI,OAAOJ,QAAQM,MAAM,CAACJ,GAAG,KAAK,aAAaF,QAAQM,MAAM,CAACJ,GAAG,GAAG,CAACC,MAAMC,KAAOJ,QAAQM,MAAM,CAACD,cAAc,CAACF,MAAMC;AAEtH,YAAYG,SAAS,uBAAuB;AAC5C,MAAM,EAAEC,GAAG,EAAEC,OAAO,EAAEC,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,cAAc,EAAEC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,eAAe,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,UAAU,EAAE,GAAGhB,IAAIiB,OAAO,IAAIjB;AAC1L,SAASC,GAAG,EAAEC,OAAO,EAAEC,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,cAAc,EAAEC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,eAAe,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,UAAU,GAAG"}
|
package/dist/esm/worker.mjs
CHANGED
|
@@ -87,105 +87,101 @@ import addLines from './lib/addLines.mjs';
|
|
|
87
87
|
import concatWritable from './lib/concatWritable.mjs';
|
|
88
88
|
import { LineType } from './types.mjs';
|
|
89
89
|
const terminal = createApp();
|
|
90
|
-
// import throttle from 'lodash.throttle';
|
|
91
|
-
// const THROTTLE = 100;
|
|
92
|
-
// const rerender = throttle(() => {
|
|
93
|
-
// terminal.rerender();
|
|
94
|
-
// }, THROTTLE);
|
|
95
90
|
export default function spawnTerminal(command, args, spawnOptions, _options, callback) {
|
|
96
91
|
const { encoding, stdio } = spawnOptions, csOptions = _object_without_properties(spawnOptions, [
|
|
97
92
|
"encoding",
|
|
98
93
|
"stdio"
|
|
99
94
|
]);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
const queue = new Queue();
|
|
120
|
-
if (cp.stdout) {
|
|
121
|
-
if (stdio === 'inherit') {
|
|
122
|
-
outputs.stdout = addLines((texts)=>{
|
|
123
|
-
const item = store.getState().processes.find((x)=>x.id === id);
|
|
124
|
-
const lines = item.lines.concat(texts.map((text)=>({
|
|
125
|
-
type: LineType.stdout,
|
|
126
|
-
text
|
|
127
|
-
})));
|
|
128
|
-
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
129
|
-
lines
|
|
130
|
-
}));
|
|
131
|
-
});
|
|
132
|
-
} else {
|
|
133
|
-
outputs.stdout = concatWritable((output)=>{
|
|
134
|
-
outputs.stdout.output = output.toString(encoding || 'utf8');
|
|
135
|
-
});
|
|
95
|
+
terminal.retain((store)=>{
|
|
96
|
+
const id = uuid();
|
|
97
|
+
store.getState().addProcess({
|
|
98
|
+
id,
|
|
99
|
+
title: [
|
|
100
|
+
command
|
|
101
|
+
].concat(args).join(' '),
|
|
102
|
+
state: 'running',
|
|
103
|
+
lines: []
|
|
104
|
+
});
|
|
105
|
+
const cp = crossSpawn(command, args, csOptions);
|
|
106
|
+
const outputs = {
|
|
107
|
+
stdout: null,
|
|
108
|
+
stderr: null
|
|
109
|
+
};
|
|
110
|
+
if (cp.stdout && process.stdout.getMaxListeners) {
|
|
111
|
+
process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);
|
|
112
|
+
process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);
|
|
136
113
|
}
|
|
137
|
-
queue
|
|
138
|
-
|
|
139
|
-
'
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
114
|
+
const queue = new Queue();
|
|
115
|
+
if (cp.stdout) {
|
|
116
|
+
if (stdio === 'inherit') {
|
|
117
|
+
outputs.stdout = addLines((texts)=>{
|
|
118
|
+
const item = store.getState().processes.find((x)=>x.id === id);
|
|
119
|
+
const lines = item.lines.concat(texts.map((text)=>({
|
|
120
|
+
type: LineType.stdout,
|
|
121
|
+
text
|
|
122
|
+
})));
|
|
123
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
124
|
+
lines
|
|
125
|
+
}));
|
|
126
|
+
});
|
|
127
|
+
} else {
|
|
128
|
+
outputs.stdout = concatWritable((output)=>{
|
|
129
|
+
outputs.stdout.output = output.toString(encoding || 'utf8');
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
133
|
+
'error',
|
|
134
|
+
'end',
|
|
135
|
+
'close',
|
|
136
|
+
'finish'
|
|
137
|
+
]));
|
|
160
138
|
}
|
|
161
|
-
|
|
162
|
-
'
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
139
|
+
if (cp.stderr) {
|
|
140
|
+
if (stdio === 'inherit') {
|
|
141
|
+
outputs.stderr = addLines((texts)=>{
|
|
142
|
+
const item = store.getState().processes.find((x)=>x.id === id);
|
|
143
|
+
const lines = item.lines.concat(texts.map((text)=>({
|
|
144
|
+
type: LineType.stderr,
|
|
145
|
+
text
|
|
146
|
+
})));
|
|
147
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
148
|
+
lines
|
|
149
|
+
}));
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
outputs.stderr = concatWritable((output)=>{
|
|
153
|
+
outputs.stderr.output = output.toString(encoding || 'utf8');
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
157
|
+
'error',
|
|
158
|
+
'end',
|
|
159
|
+
'close',
|
|
160
|
+
'finish'
|
|
161
|
+
]));
|
|
175
162
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
163
|
+
queue.defer(spawn.worker.bind(null, cp, _object_spread_props(_object_spread({}, csOptions), {
|
|
164
|
+
encoding: 'utf8'
|
|
165
|
+
})));
|
|
166
|
+
queue.await((err)=>{
|
|
167
|
+
if (cp.stdout && process.stdout.getMaxListeners) {
|
|
168
|
+
process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);
|
|
169
|
+
process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);
|
|
170
|
+
}
|
|
171
|
+
const res = err ? err : {};
|
|
172
|
+
res.stdout = outputs.stdout ? outputs.stdout.output : null;
|
|
173
|
+
res.stderr = outputs.stderr ? outputs.stderr.output : null;
|
|
174
|
+
res.output = [
|
|
175
|
+
res.stdout,
|
|
176
|
+
res.stderr,
|
|
177
|
+
null
|
|
178
|
+
];
|
|
179
|
+
const item = store.getState().processes.find((x)=>x.id === id);
|
|
180
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
181
|
+
state: err ? 'error' : 'success'
|
|
182
|
+
}));
|
|
183
|
+
terminal.release();
|
|
184
|
+
err ? callback(err) : callback(null, res);
|
|
185
|
+
});
|
|
190
186
|
});
|
|
191
187
|
}
|
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';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst terminal = createApp();\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';\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 const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(args).join(' '), state: 'running', lines: [] });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);\n }\n\n const queue = new Queue();\n if (cp.stdout) {\n if (stdio === 'inherit') {\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 } else {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n }\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n if (stdio === 'inherit') {\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 } else {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\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 if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);\n }\n\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 terminal.release();\n err ? callback(err) : callback(null, res);\n });\n });\n}\n"],"names":["spawn","crossSpawn","uuid","oo","Queue","createApp","addLines","concatWritable","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","process","getMaxListeners","setMaxListeners","queue","texts","item","processes","find","x","map","text","type","updateProcess","output","toString","defer","bind","pipe","worker","await","err","res","release"],"mappings":"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"}
|
package/dist/types/ink.d.mts
CHANGED