spawn-term 0.1.3 → 0.1.4
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/createApp.cjs +42 -33
- package/dist/cjs/createApp.cjs.map +1 -1
- package/dist/cjs/worker.cjs +97 -101
- package/dist/cjs/worker.cjs.map +1 -1
- package/dist/esm/createApp.mjs +27 -22
- package/dist/esm/createApp.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/package.json +2 -1
package/dist/cjs/createApp.cjs
CHANGED
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
12
|
+
var _resolveoncecb = /*#__PURE__*/ _interop_require_default(require("resolve-once-cb"));
|
|
12
13
|
var _zustand = require("zustand");
|
|
13
14
|
var _App = /*#__PURE__*/ _interop_require_default(require("./components/App.cjs"));
|
|
14
15
|
var _Store = /*#__PURE__*/ _interop_require_default(require("./contexts/Store.cjs"));
|
|
@@ -43,50 +44,58 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
43
44
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
44
45
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
45
46
|
}
|
|
47
|
+
var initialize = (0, _resolveoncecb.default)(function(cb) {
|
|
48
|
+
return setTimeout(function() {
|
|
49
|
+
return cb();
|
|
50
|
+
}, 0);
|
|
51
|
+
});
|
|
46
52
|
function createApp() {
|
|
47
53
|
var refCount = 0;
|
|
48
54
|
var store = null;
|
|
49
55
|
var inkApp = null;
|
|
56
|
+
var _waiting = [];
|
|
50
57
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
58
|
+
retain: function retain(fn) {
|
|
59
|
+
initialize(function() {
|
|
60
|
+
if (++refCount > 1) return fn(store);
|
|
61
|
+
if (store) throw new Error('Not expecting store');
|
|
62
|
+
store = (0, _zustand.createStore)()(function(set) {
|
|
63
|
+
return {
|
|
64
|
+
processes: [],
|
|
65
|
+
addProcess: function(process1) {
|
|
66
|
+
return set(function(state) {
|
|
67
|
+
return {
|
|
68
|
+
processes: _to_consumable_array(state.processes).concat([
|
|
69
|
+
process1
|
|
70
|
+
])
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
updateProcess: function(process1) {
|
|
75
|
+
return set(function(state) {
|
|
76
|
+
return {
|
|
77
|
+
processes: state.processes.map(function(x) {
|
|
78
|
+
return x.id === process1.id ? process1 : x;
|
|
79
|
+
})
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
inkApp = (0, _ink.render)(/*#__PURE__*/ _react.default.createElement(_Store.default.Provider, {
|
|
86
|
+
value: store
|
|
87
|
+
}, /*#__PURE__*/ _react.default.createElement(_App.default, null)), {
|
|
88
|
+
patchConsole: false
|
|
89
|
+
});
|
|
90
|
+
return fn(store);
|
|
81
91
|
});
|
|
82
|
-
return store;
|
|
83
92
|
},
|
|
84
93
|
release: function release() {
|
|
85
94
|
if (--refCount > 0) return;
|
|
86
|
-
if (!
|
|
95
|
+
if (!store) throw new Error('Expecting store');
|
|
96
|
+
store = null;
|
|
87
97
|
inkApp.unmount();
|
|
88
98
|
inkApp = null;
|
|
89
|
-
store = null;
|
|
90
99
|
process.stdout.write('\x1b[?25h'); // show cursor
|
|
91
100
|
}
|
|
92
101
|
};
|
|
@@ -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 resolveOnce from 'resolve-once-cb';\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\nconst initialize = resolveOnce((cb) => setTimeout(() => cb(), 0));\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n const _waiting = [];\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","initialize","resolveOnce","cb","setTimeout","refCount","store","inkApp","_waiting","retain","fn","Error","createStore","set","processes","addProcess","process","state","updateProcess","map","x","id","render","StoreContext","Provider","value","App","patchConsole","release","unmount","stdout","write"],"mappings":";;;;+BAYA;;;eAAwBA;;;4DAZN;oEACM;uBACI;0DACZ;4DACS;mBAGa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtC,IAAMC,aAAaC,IAAAA,sBAAW,EAAC,SAACC;WAAOC,WAAW;eAAMD;OAAM;;AAE/C,SAASH;IACtB,IAAIK,WAAW;IACf,IAAIC,QAAQ;IACZ,IAAIC,SAA0B;IAC9B,IAAMC,WAAW,EAAE;IAEnB,OAAO;QACLC,QAAAA,SAAAA,OAAOC,EAAE;YACPT,WAAW;gBACT,IAAI,EAAEI,WAAW,GAAG,OAAOK,GAAGJ;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,OAAOjB,GAAGJ;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/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":"AAAA,aAAa;;;;;+BAeb;;;eAAwBA;;;oEAd4B;8DACnC;4DACF;8DACG;gEAEI;+DACD;qEACM;qBAGF;;;;;;;;;;;;;;;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,CAACH,IAAI,CAAC,MAAM1B,IAAI,wCAAKZ;YAAWF,UAAU;;QAClEsB,MAAMsB,KAAK,CAAC,SAACC;YACX,IAAI/B,GAAGG,MAAM,IAAIE,QAAQF,MAAM,CAACG,eAAe,EAAE;gBAC/CD,QAAQF,MAAM,CAACI,eAAe,CAACF,QAAQF,MAAM,CAACG,eAAe,KAAK;gBAClED,QAAQD,MAAM,CAACG,eAAe,CAACF,QAAQD,MAAM,CAACE,eAAe,KAAK;YACpE;YAEA,IAAM0B,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAI7B,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACmB,MAAM,GAAG;YACtDU,IAAI5B,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACkB,MAAM,GAAG;YACtDU,IAAIV,MAAM,GAAG;gBAACU,IAAI7B,MAAM;gBAAE6B,IAAI5B,MAAM;gBAAE;aAAK;YAC3C,IAAMQ,OAAOtB,MAAMG,QAAQ,GAAGoB,SAAS,CAACC,IAAI,CAAC,SAACC;uBAAMA,EAAExB,EAAE,KAAKA;;YAC7DD,MAAMG,QAAQ,GAAG2B,aAAa,CAAC,wCAAKR;gBAAMd,OAAOiC,MAAM,UAAU;;YACjEpD,SAASsD,OAAO;YAChBF,MAAM9C,SAAS8C,OAAO9C,SAAS,MAAM+C;QACvC;IACF;AACF"}
|
package/dist/esm/createApp.mjs
CHANGED
|
@@ -1,42 +1,47 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import resolveOnce from 'resolve-once-cb';
|
|
2
3
|
import { createStore } from 'zustand';
|
|
3
4
|
import App from './components/App.mjs';
|
|
4
5
|
import StoreContext from './contexts/Store.mjs';
|
|
5
6
|
// @ts-ignore
|
|
6
7
|
import { render } from './ink.mjs';
|
|
8
|
+
const initialize = resolveOnce((cb)=>setTimeout(()=>cb(), 0));
|
|
7
9
|
export default function createApp() {
|
|
8
10
|
let refCount = 0;
|
|
9
11
|
let store = null;
|
|
10
12
|
let inkApp = null;
|
|
13
|
+
const _waiting = [];
|
|
11
14
|
return {
|
|
12
|
-
retain () {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
retain (fn) {
|
|
16
|
+
initialize(()=>{
|
|
17
|
+
if (++refCount > 1) return fn(store);
|
|
18
|
+
if (store) throw new Error('Not expecting store');
|
|
19
|
+
store = createStore()((set)=>({
|
|
20
|
+
processes: [],
|
|
21
|
+
addProcess: (process1)=>set((state)=>({
|
|
22
|
+
processes: [
|
|
23
|
+
...state.processes,
|
|
24
|
+
process1
|
|
25
|
+
]
|
|
26
|
+
})),
|
|
27
|
+
updateProcess: (process1)=>set((state)=>({
|
|
28
|
+
processes: state.processes.map((x)=>x.id === process1.id ? process1 : x)
|
|
29
|
+
}))
|
|
30
|
+
}));
|
|
31
|
+
inkApp = render(/*#__PURE__*/ React.createElement(StoreContext.Provider, {
|
|
32
|
+
value: store
|
|
33
|
+
}, /*#__PURE__*/ React.createElement(App, null)), {
|
|
34
|
+
patchConsole: false
|
|
35
|
+
});
|
|
36
|
+
return fn(store);
|
|
31
37
|
});
|
|
32
|
-
return store;
|
|
33
38
|
},
|
|
34
39
|
release () {
|
|
35
40
|
if (--refCount > 0) return;
|
|
36
|
-
if (!
|
|
41
|
+
if (!store) throw new Error('Expecting store');
|
|
42
|
+
store = null;
|
|
37
43
|
inkApp.unmount();
|
|
38
44
|
inkApp = null;
|
|
39
|
-
store = null;
|
|
40
45
|
process.stdout.write('\x1b[?25h'); // show cursor
|
|
41
46
|
}
|
|
42
47
|
};
|
|
@@ -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 resolveOnce from 'resolve-once-cb';\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\nconst initialize = resolveOnce((cb) => setTimeout(() => cb(), 0));\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n const _waiting = [];\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","resolveOnce","createStore","App","StoreContext","render","initialize","cb","setTimeout","createApp","refCount","store","inkApp","_waiting","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,OAAOC,iBAAiB,kBAAkB;AAC1C,SAASC,WAAW,QAAQ,UAAU;AACtC,OAAOC,SAAS,mBAAmB;AACnC,OAAOC,kBAAkB,mBAAmB;AAE5C,aAAa;AACb,SAAwBC,MAAM,QAAQ,YAAY;AAGlD,MAAMC,aAAaL,YAAY,CAACM,KAAOC,WAAW,IAAMD,MAAM;AAE9D,eAAe,SAASE;IACtB,IAAIC,WAAW;IACf,IAAIC,QAAQ;IACZ,IAAIC,SAA0B;IAC9B,MAAMC,WAAW,EAAE;IAEnB,OAAO;QACLC,QAAOC,EAAE;YACPT,WAAW;gBACT,IAAI,EAAEI,WAAW,GAAG,OAAOK,GAAGJ;gBAC9B,IAAIA,OAAO,MAAM,IAAIK,MAAM;gBAC3BL,QAAQT,cAAwB,CAACe,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;gBACAZ,SAASP,qBACP,oBAACD,aAAasB,QAAQ;oBAACC,OAAOhB;iCAC5B,oBAACR,aAEH;oBAAEyB,cAAc;gBAAM;gBAExB,OAAOb,GAAGJ;YACZ;QACF;QACAkB;YACE,IAAI,EAAEnB,WAAW,GAAG;YACpB,IAAI,CAACC,OAAO,MAAM,IAAIK,MAAM;YAC5BL,QAAQ;YACRC,OAAOkB,OAAO;YACdlB,SAAS;YACTQ,QAAQW,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;QACnD;IACF;AACF"}
|
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":"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;AAGlD,SAASC,QAAQ,QAAQ,UAAU;AAEnC,MAAMC,WAAWJ;AAEjB,eAAe,SAASK,cAAcC,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,QAAyB,EAAEC,QAAQ;IACpI,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAgB,GAAGJ,cAAdK,uCAAcL;QAAlCG;QAAUC;;IAElBR,SAASU,MAAM,CAAC,CAACC;QACf,MAAMC,KAAKnB;QACXkB,MAAME,QAAQ,GAAGC,UAAU,CAAC;YAAEF;YAAIG,OAAO;gBAACb;aAAQ,CAACc,MAAM,CAACb,MAAMc,IAAI,CAAC;YAAMC,OAAO;YAAWC,OAAO,EAAE;QAAC;QAEvG,MAAMC,KAAK5B,WAAWU,SAASC,MAAMM;QACrC,MAAMY,UAAU;YAAEC,QAAQ;YAAMC,QAAQ;QAAK;QAE7C,IAAIH,GAAGE,MAAM,IAAIE,QAAQF,MAAM,CAACG,eAAe,EAAE;YAC/CD,QAAQF,MAAM,CAACI,eAAe,CAACF,QAAQF,MAAM,CAACG,eAAe,KAAK;YAClED,QAAQD,MAAM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
2
|
"name": "spawn-term",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Formats spawn with for terminal grouping",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"spawn",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"queue-cb": "^1.4.16",
|
|
47
47
|
"react": "^18.3.1",
|
|
48
48
|
"readable-stream": "^2.3.8",
|
|
49
|
+
"resolve-once-cb": "^0.1.14",
|
|
49
50
|
"yoga-wasm-web": "^0.3.3",
|
|
50
51
|
"zustand": "^5.0.3"
|
|
51
52
|
},
|