spawn-term 1.1.6 → 1.1.8
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/components/App.js +17 -3
- package/dist/cjs/components/App.js.map +1 -1
- package/dist/cjs/createApp.js +25 -33
- package/dist/cjs/createApp.js.map +1 -1
- package/dist/cjs/index-esm.js +1 -1
- package/dist/cjs/index-esm.js.map +1 -1
- package/dist/cjs/lib/figures.js +1 -1
- package/dist/cjs/lib/figures.js.map +1 -1
- package/dist/cjs/spawnTerminal.js +3 -0
- package/dist/cjs/spawnTerminal.js.map +1 -1
- package/dist/cjs/src/components/App.d.ts +1 -5
- package/dist/cjs/src/createApp.d.ts +4 -5
- package/dist/cjs/src/state/processStore.d.ts +21 -0
- package/dist/cjs/state/processStore.js +143 -0
- package/dist/cjs/state/processStore.js.map +1 -0
- package/dist/cjs/worker.js +70 -113
- package/dist/cjs/worker.js.map +1 -1
- package/dist/esm/components/App.js +18 -3
- package/dist/esm/components/App.js.map +1 -1
- package/dist/esm/createApp.js +26 -32
- package/dist/esm/createApp.js.map +1 -1
- package/dist/esm/index-esm.js +1 -1
- package/dist/esm/index-esm.js.map +1 -1
- package/dist/esm/spawnTerminal.js +3 -0
- package/dist/esm/spawnTerminal.js.map +1 -1
- package/dist/esm/src/components/App.d.ts +1 -5
- package/dist/esm/src/createApp.d.ts +4 -5
- package/dist/esm/src/state/processStore.d.ts +21 -0
- package/dist/esm/state/processStore.js +84 -0
- package/dist/esm/state/processStore.js.map +1 -0
- package/dist/esm/worker.js +59 -96
- package/dist/esm/worker.js.map +1 -1
- package/package.json +2 -2
- package/dist/cjs/src/state/Store.d.ts +0 -11
- package/dist/cjs/state/Store.js +0 -40
- package/dist/cjs/state/Store.js.map +0 -1
- package/dist/esm/src/state/Store.d.ts +0 -11
- package/dist/esm/state/Store.js +0 -19
- package/dist/esm/state/Store.js.map +0 -1
|
@@ -10,17 +10,31 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
var _jsxruntime = require("react/jsx-runtime");
|
|
12
12
|
var _ink = require("ink");
|
|
13
|
+
var _react = require("react");
|
|
14
|
+
var _processStorets = require("../state/processStore.js");
|
|
13
15
|
var _ChildProcessts = /*#__PURE__*/ _interop_require_default(require("./ChildProcess.js"));
|
|
14
16
|
function _interop_require_default(obj) {
|
|
15
17
|
return obj && obj.__esModule ? obj : {
|
|
16
18
|
default: obj
|
|
17
19
|
};
|
|
18
20
|
}
|
|
19
|
-
function App(
|
|
20
|
-
var
|
|
21
|
+
function App() {
|
|
22
|
+
var exit = (0, _ink.useApp)().exit;
|
|
23
|
+
// Subscribe to process state
|
|
24
|
+
var processes = (0, _react.useSyncExternalStore)(_processStorets.processStore.subscribe, _processStorets.processStore.getSnapshot);
|
|
25
|
+
// Handle exit signal
|
|
26
|
+
var shouldExit = (0, _react.useSyncExternalStore)(_processStorets.processStore.subscribe, _processStorets.processStore.getShouldExit);
|
|
27
|
+
(0, _react.useEffect)(function() {
|
|
28
|
+
if (shouldExit) {
|
|
29
|
+
exit();
|
|
30
|
+
}
|
|
31
|
+
}, [
|
|
32
|
+
shouldExit,
|
|
33
|
+
exit
|
|
34
|
+
]);
|
|
21
35
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_ink.Box, {
|
|
22
36
|
flexDirection: "column",
|
|
23
|
-
children:
|
|
37
|
+
children: processes.map(function(item) {
|
|
24
38
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_ChildProcessts.default, {
|
|
25
39
|
item: item
|
|
26
40
|
}, item.id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import { Box } from 'ink';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import { Box, useApp } from 'ink';\nimport { useEffect, useSyncExternalStore } from 'react';\nimport { processStore } from '../state/processStore.ts';\nimport type { ChildProcess as ChildProcessT } from '../types.ts';\nimport ChildProcess from './ChildProcess.ts';\n\nexport default function App(): React.JSX.Element {\n const { exit } = useApp();\n\n // Subscribe to process state\n const processes = useSyncExternalStore(processStore.subscribe, processStore.getSnapshot);\n\n // Handle exit signal\n const shouldExit = useSyncExternalStore(processStore.subscribe, processStore.getShouldExit);\n\n useEffect(() => {\n if (shouldExit) {\n exit();\n }\n }, [shouldExit, exit]);\n\n return (\n <Box flexDirection=\"column\">\n {processes.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} item={item} />\n ))}\n </Box>\n );\n}\n"],"names":["App","exit","useApp","processes","useSyncExternalStore","processStore","subscribe","getSnapshot","shouldExit","getShouldExit","useEffect","Box","flexDirection","map","item","ChildProcess","id"],"mappings":";;;;+BAMA;;;eAAwBA;;;;mBANI;qBACoB;8BACnB;qEAEJ;;;;;;AAEV,SAASA;IACtB,IAAM,AAAEC,OAASC,IAAAA,WAAM,IAAfD;IAER,6BAA6B;IAC7B,IAAME,YAAYC,IAAAA,2BAAoB,EAACC,4BAAY,CAACC,SAAS,EAAED,4BAAY,CAACE,WAAW;IAEvF,qBAAqB;IACrB,IAAMC,aAAaJ,IAAAA,2BAAoB,EAACC,4BAAY,CAACC,SAAS,EAAED,4BAAY,CAACI,aAAa;IAE1FC,IAAAA,gBAAS,EAAC;QACR,IAAIF,YAAY;YACdP;QACF;IACF,GAAG;QAACO;QAAYP;KAAK;IAErB,qBACE,qBAACU,QAAG;QAACC,eAAc;kBAChBT,UAAUU,GAAG,CAAC,SAACC;iCACd,qBAACC,uBAAY;gBAAeD,MAAMA;eAAfA,KAAKE,EAAE;;;AAIlC"}
|
package/dist/cjs/createApp.js
CHANGED
|
@@ -10,52 +10,44 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
var _jsxruntime = require("react/jsx-runtime");
|
|
12
12
|
var _ink = require("ink");
|
|
13
|
-
var _lodashthrottle = /*#__PURE__*/ _interop_require_default(require("lodash.throttle"));
|
|
14
13
|
var _Appts = /*#__PURE__*/ _interop_require_default(require("./components/App.js"));
|
|
15
|
-
var
|
|
14
|
+
var _processStorets = require("./state/processStore.js");
|
|
16
15
|
function _interop_require_default(obj) {
|
|
17
16
|
return obj && obj.__esModule ? obj : {
|
|
18
17
|
default: obj
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
|
-
var THROTTLE = 100;
|
|
22
20
|
function createApp() {
|
|
23
21
|
var refCount = 0;
|
|
24
|
-
var store = null;
|
|
25
22
|
var inkApp = null;
|
|
26
|
-
var previousData = null;
|
|
27
|
-
var rerender = (0, _lodashthrottle.default)(function() {
|
|
28
|
-
if (!inkApp || !store) return;
|
|
29
|
-
if (store.data() === previousData) return;
|
|
30
|
-
previousData = store.data();
|
|
31
|
-
inkApp.rerender(/*#__PURE__*/ (0, _jsxruntime.jsx)(_Appts.default, {
|
|
32
|
-
store: store
|
|
33
|
-
}));
|
|
34
|
-
}, THROTTLE, {
|
|
35
|
-
leading: false
|
|
36
|
-
});
|
|
37
23
|
return {
|
|
38
|
-
retain: function retain(
|
|
39
|
-
if (++refCount > 1) return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
store: store
|
|
44
|
-
}));
|
|
45
|
-
fn(store);
|
|
24
|
+
retain: function retain() {
|
|
25
|
+
if (++refCount > 1) return _processStorets.processStore;
|
|
26
|
+
// Render once - React handles all subsequent updates via useSyncExternalStore
|
|
27
|
+
inkApp = (0, _ink.render)(/*#__PURE__*/ (0, _jsxruntime.jsx)(_Appts.default, {}));
|
|
28
|
+
return _processStorets.processStore;
|
|
46
29
|
},
|
|
47
|
-
release: function release(
|
|
48
|
-
if (--refCount > 0)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
30
|
+
release: function release(callback) {
|
|
31
|
+
if (--refCount > 0) {
|
|
32
|
+
callback();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!inkApp) throw new Error('Expecting inkApp');
|
|
36
|
+
// Signal exit to React component, provide callback for after cleanup
|
|
37
|
+
_processStorets.processStore.signalExit(function() {
|
|
38
|
+
_processStorets.processStore.reset();
|
|
39
|
+
process.stdout.write('\x1b[?25h'); // show cursor
|
|
40
|
+
callback();
|
|
41
|
+
});
|
|
42
|
+
// Wait for Ink to finish, then call the callback
|
|
52
43
|
inkApp.waitUntilExit().then(function() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
var cb = _processStorets.processStore.getExitCallback();
|
|
45
|
+
cb === null || cb === void 0 ? void 0 : cb();
|
|
46
|
+
}).catch(function() {
|
|
47
|
+
var cb = _processStorets.processStore.getExitCallback();
|
|
48
|
+
cb === null || cb === void 0 ? void 0 : cb();
|
|
49
|
+
});
|
|
56
50
|
inkApp = null;
|
|
57
|
-
store = null;
|
|
58
|
-
process.stdout.write('\x1b[?25h'); // show cursor
|
|
59
51
|
}
|
|
60
52
|
};
|
|
61
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import { render } from 'ink';\nimport App from './components/App.ts';\nimport { type ProcessStore, processStore } from './state/processStore.ts';\n\nexport type ReleaseCallback = () => void;\n\nexport default function createApp() {\n let refCount = 0;\n let inkApp: ReturnType<typeof render> | null = null;\n\n return {\n retain(): ProcessStore {\n if (++refCount > 1) return processStore;\n\n // Render once - React handles all subsequent updates via useSyncExternalStore\n inkApp = render(<App />);\n return processStore;\n },\n\n release(callback: ReleaseCallback): void {\n if (--refCount > 0) {\n callback();\n return;\n }\n if (!inkApp) throw new Error('Expecting inkApp');\n\n // Signal exit to React component, provide callback for after cleanup\n processStore.signalExit(() => {\n processStore.reset();\n process.stdout.write('\\x1b[?25h'); // show cursor\n callback();\n });\n\n // Wait for Ink to finish, then call the callback\n inkApp\n .waitUntilExit()\n .then(() => {\n const cb = processStore.getExitCallback();\n cb?.();\n })\n .catch(() => {\n const cb = processStore.getExitCallback();\n cb?.();\n });\n\n inkApp = null;\n },\n };\n}\n"],"names":["createApp","refCount","inkApp","retain","processStore","render","App","release","callback","Error","signalExit","reset","process","stdout","write","waitUntilExit","then","cb","getExitCallback","catch"],"mappings":";;;;+BAMA;;;eAAwBA;;;;mBAND;4DACP;8BACgC;;;;;;AAIjC,SAASA;IACtB,IAAIC,WAAW;IACf,IAAIC,SAA2C;IAE/C,OAAO;QACLC,QAAAA,SAAAA;YACE,IAAI,EAAEF,WAAW,GAAG,OAAOG,4BAAY;YAEvC,8EAA8E;YAC9EF,SAASG,IAAAA,WAAM,gBAAC,qBAACC,cAAG;YACpB,OAAOF,4BAAY;QACrB;QAEAG,SAAAA,SAAAA,QAAQC,QAAyB;YAC/B,IAAI,EAAEP,WAAW,GAAG;gBAClBO;gBACA;YACF;YACA,IAAI,CAACN,QAAQ,MAAM,IAAIO,MAAM;YAE7B,qEAAqE;YACrEL,4BAAY,CAACM,UAAU,CAAC;gBACtBN,4BAAY,CAACO,KAAK;gBAClBC,QAAQC,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;gBACjDN;YACF;YAEA,iDAAiD;YACjDN,OACGa,aAAa,GACbC,IAAI,CAAC;gBACJ,IAAMC,KAAKb,4BAAY,CAACc,eAAe;gBACvCD,eAAAA,yBAAAA;YACF,GACCE,KAAK,CAAC;gBACL,IAAMF,KAAKb,4BAAY,CAACc,eAAe;gBACvCD,eAAAA,yBAAAA;YACF;YAEFf,SAAS;QACX;IACF;AACF"}
|
package/dist/cjs/index-esm.js
CHANGED
|
@@ -42,5 +42,5 @@ function _interop_require_default(obj) {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
var major = +process.versions.node.split('.')[0];
|
|
45
|
-
var _default = major >
|
|
45
|
+
var _default = major > 18 ? _spawnTerminalts.default : undefined;
|
|
46
46
|
/* 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; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/index-esm.ts"],"sourcesContent":["export { default as figures } from './lib/figures.ts';\nexport { default as formatArguments } from './lib/formatArguments.ts';\nexport * from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\n\nimport { default as spawnTerminal } from './spawnTerminal.ts';\nexport default major >
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/index-esm.ts"],"sourcesContent":["export { default as figures } from './lib/figures.ts';\nexport { default as formatArguments } from './lib/formatArguments.ts';\nexport * from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\n\nimport { default as spawnTerminal } from './spawnTerminal.ts';\nexport default major > 18 ? spawnTerminal : (undefined as typeof spawnTerminal);\n"],"names":["figures","formatArguments","major","process","versions","node","split","spawnTerminal","undefined"],"mappings":";;;;;;;;;;;QAOA;eAAA;;QAPoBA;eAAAA,kBAAO;;QACPC;eAAAA,0BAAe;;;gEADA;wEACQ;qBAC7B;sEAI2B;;;;;;;;;;;;;;;;;;;AAFzC,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;IAGlD,WAAeJ,QAAQ,KAAKK,wBAAa,GAAIC"}
|
package/dist/cjs/lib/figures.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// From: https://github.com/sindresorhus/is-unicode-supported
|
|
2
1
|
"use strict";
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
3
|
value: true
|
|
@@ -9,6 +8,7 @@ Object.defineProperty(exports, "default", {
|
|
|
9
8
|
return _default;
|
|
10
9
|
}
|
|
11
10
|
});
|
|
11
|
+
// From: https://github.com/sindresorhus/is-unicode-supported
|
|
12
12
|
function isUnicodeSupported() {
|
|
13
13
|
var env = process.env;
|
|
14
14
|
var TERM = env.TERM, TERM_PROGRAM = env.TERM_PROGRAM;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/figures.ts"],"sourcesContent":["// From: https://github.com/sindresorhus/is-unicode-supported\nfunction isUnicodeSupported() {\n const { env } = process;\n const { TERM, TERM_PROGRAM } = env;\n\n if (process.platform !== 'win32') {\n return TERM !== 'linux'; // Linux console (kernel)\n }\n\n return (\n Boolean(env.WT_SESSION) || // Windows Terminal\n Boolean(env.TERMINUS_SUBLIME) || // Terminus (<0.2.27)\n env.ConEmuTask === '{cmd::Cmder}' || // ConEmu and cmder\n TERM_PROGRAM === 'Terminus-Sublime' ||\n TERM_PROGRAM === 'vscode' ||\n TERM === 'xterm-256color' ||\n TERM === 'alacritty' ||\n TERM === 'rxvt-unicode' ||\n TERM === 'rxvt-unicode-256color' ||\n env.TERMINAL_EMULATOR === 'JetBrains-JediTerm'\n );\n}\n\n// From https://github.com/sindresorhus/figures\nconst symbols = {\n arrowRight: '→',\n tick: '✔',\n info: 'ℹ',\n warning: '⚠',\n cross: '✖',\n squareSmallFilled: '◼',\n pointer: '❯',\n};\n\nconst fallbackSymbols = {\n arrowRight: '→',\n tick: '√',\n info: 'i',\n warning: '‼',\n cross: '×',\n squareSmallFilled: '■',\n pointer: '>',\n};\n\nexport default isUnicodeSupported() ? symbols : fallbackSymbols;\n"],"names":["isUnicodeSupported","env","process","TERM","TERM_PROGRAM","platform","Boolean","WT_SESSION","TERMINUS_SUBLIME","ConEmuTask","TERMINAL_EMULATOR","symbols","arrowRight","tick","info","warning","cross","squareSmallFilled","pointer","fallbackSymbols"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/figures.ts"],"sourcesContent":["// From: https://github.com/sindresorhus/is-unicode-supported\nfunction isUnicodeSupported() {\n const { env } = process;\n const { TERM, TERM_PROGRAM } = env;\n\n if (process.platform !== 'win32') {\n return TERM !== 'linux'; // Linux console (kernel)\n }\n\n return (\n Boolean(env.WT_SESSION) || // Windows Terminal\n Boolean(env.TERMINUS_SUBLIME) || // Terminus (<0.2.27)\n env.ConEmuTask === '{cmd::Cmder}' || // ConEmu and cmder\n TERM_PROGRAM === 'Terminus-Sublime' ||\n TERM_PROGRAM === 'vscode' ||\n TERM === 'xterm-256color' ||\n TERM === 'alacritty' ||\n TERM === 'rxvt-unicode' ||\n TERM === 'rxvt-unicode-256color' ||\n env.TERMINAL_EMULATOR === 'JetBrains-JediTerm'\n );\n}\n\n// From https://github.com/sindresorhus/figures\nconst symbols = {\n arrowRight: '→',\n tick: '✔',\n info: 'ℹ',\n warning: '⚠',\n cross: '✖',\n squareSmallFilled: '◼',\n pointer: '❯',\n};\n\nconst fallbackSymbols = {\n arrowRight: '→',\n tick: '√',\n info: 'i',\n warning: '‼',\n cross: '×',\n squareSmallFilled: '■',\n pointer: '>',\n};\n\nexport default isUnicodeSupported() ? symbols : fallbackSymbols;\n"],"names":["isUnicodeSupported","env","process","TERM","TERM_PROGRAM","platform","Boolean","WT_SESSION","TERMINUS_SUBLIME","ConEmuTask","TERMINAL_EMULATOR","symbols","arrowRight","tick","info","warning","cross","squareSmallFilled","pointer","fallbackSymbols"],"mappings":";;;;+BA4CA;;;eAAA;;;AA5CA,6DAA6D;AAC7D,SAASA;IACP,IAAM,AAAEC,MAAQC,QAARD;IACR,IAAQE,OAAuBF,IAAvBE,MAAMC,eAAiBH,IAAjBG;IAEd,IAAIF,QAAQG,QAAQ,KAAK,SAAS;QAChC,OAAOF,SAAS,SAAS,yBAAyB;IACpD;IAEA,OACEG,QAAQL,IAAIM,UAAU,KAAK,mBAAmB;IAC9CD,QAAQL,IAAIO,gBAAgB,KAAK,qBAAqB;IACtDP,IAAIQ,UAAU,KAAK,kBAAkB,mBAAmB;IACxDL,iBAAiB,sBACjBA,iBAAiB,YACjBD,SAAS,oBACTA,SAAS,eACTA,SAAS,kBACTA,SAAS,2BACTF,IAAIS,iBAAiB,KAAK;AAE9B;AAEA,+CAA+C;AAC/C,IAAMC,UAAU;IACdC,YAAY;IACZC,MAAM;IACNC,MAAM;IACNC,SAAS;IACTC,OAAO;IACPC,mBAAmB;IACnBC,SAAS;AACX;AAEA,IAAMC,kBAAkB;IACtBP,YAAY;IACZC,MAAM;IACNC,MAAM;IACNC,SAAS;IACTC,OAAO;IACPC,mBAAmB;IACnBC,SAAS;AACX;IAEA,WAAelB,uBAAuBW,UAAUQ"}
|
|
@@ -57,6 +57,9 @@ function worker(command, args, spawnOptions, options, callback) {
|
|
|
57
57
|
}).catch(callback);
|
|
58
58
|
}
|
|
59
59
|
function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
60
|
+
if (spawnOptions.stdio === 'inherit' && spawnOptions.encoding) {
|
|
61
|
+
throw new Error("Options 'stdio: inherit' and 'encoding' are mutually exclusive. Use 'stdio: inherit' to display output, or 'encoding' to collect output.");
|
|
62
|
+
}
|
|
60
63
|
if (typeof options === 'function') {
|
|
61
64
|
callback = options;
|
|
62
65
|
options = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/spawnTerminal.ts"],"sourcesContent":["import type { SpawnOptions, SpawnResult, TerminalCallback, TerminalOptions } from './types.ts';\n\nfunction worker(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n import('./worker.js')\n .then((fn) => {\n fn.default(command, args, spawnOptions, options, callback);\n })\n .catch(callback);\n}\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options?: TerminalOptions | TerminalCallback, callback?: TerminalCallback): undefined | Promise<SpawnResult> {\n if (typeof options === 'function') {\n callback = options as TerminalCallback;\n options = {};\n }\n options = options || {};\n\n if (typeof callback === 'function') return worker(command, args, spawnOptions, options, callback as TerminalCallback);\n return new Promise((resolve, reject) =>\n worker(command, args, spawnOptions, options, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n}\n"],"names":["spawnTerminal","worker","command","args","spawnOptions","options","callback","then","fn","default","catch","Promise","resolve","reject","err","result"],"mappings":";;;;+BAUA;;;eAAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AARxB,SAASC,OAAOC,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAA0B;IAC/H;uDAAA,QAAO;OACJC,IAAI,CAAC,SAACC;QACLA,GAAGC,OAAO,CAACP,SAASC,MAAMC,cAAcC,SAASC;IACnD,GACCI,KAAK,CAACJ;AACX;AAEe,SAASN,cAAcE,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAA4C,EAAEC,QAA2B;IAC1K,IAAI,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/spawnTerminal.ts"],"sourcesContent":["import type { SpawnOptions, SpawnResult, TerminalCallback, TerminalOptions } from './types.ts';\n\nfunction worker(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n import('./worker.js')\n .then((fn) => {\n fn.default(command, args, spawnOptions, options, callback);\n })\n .catch(callback);\n}\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options?: TerminalOptions | TerminalCallback, callback?: TerminalCallback): undefined | Promise<SpawnResult> {\n if (spawnOptions.stdio === 'inherit' && spawnOptions.encoding) {\n throw new Error(\"Options 'stdio: inherit' and 'encoding' are mutually exclusive. Use 'stdio: inherit' to display output, or 'encoding' to collect output.\");\n }\n\n if (typeof options === 'function') {\n callback = options as TerminalCallback;\n options = {};\n }\n options = options || {};\n\n if (typeof callback === 'function') return worker(command, args, spawnOptions, options, callback as TerminalCallback);\n return new Promise((resolve, reject) =>\n worker(command, args, spawnOptions, options, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n}\n"],"names":["spawnTerminal","worker","command","args","spawnOptions","options","callback","then","fn","default","catch","stdio","encoding","Error","Promise","resolve","reject","err","result"],"mappings":";;;;+BAUA;;;eAAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AARxB,SAASC,OAAOC,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAA0B;IAC/H;uDAAA,QAAO;OACJC,IAAI,CAAC,SAACC;QACLA,GAAGC,OAAO,CAACP,SAASC,MAAMC,cAAcC,SAASC;IACnD,GACCI,KAAK,CAACJ;AACX;AAEe,SAASN,cAAcE,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAA4C,EAAEC,QAA2B;IAC1K,IAAIF,aAAaO,KAAK,KAAK,aAAaP,aAAaQ,QAAQ,EAAE;QAC7D,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAI,OAAOR,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOL,OAAOC,SAASC,MAAMC,cAAcC,SAASC;IACxF,OAAO,IAAIQ,QAAQ,SAACC,SAASC;eAC3Bf,OAAOC,SAASC,MAAMC,cAAcC,SAAS,SAACY,KAAKC;YACjDD,MAAMD,OAAOC,OAAOF,QAAQG;QAC9B;;AAEJ"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type
|
|
3
|
-
export type ReleaseCallback = () => undefined;
|
|
1
|
+
import { type ProcessStore } from './state/processStore.js';
|
|
2
|
+
export type ReleaseCallback = () => void;
|
|
4
3
|
export default function createApp(): {
|
|
5
|
-
retain(
|
|
6
|
-
release(
|
|
4
|
+
retain(): ProcessStore;
|
|
5
|
+
release(callback: ReleaseCallback): void;
|
|
7
6
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ChildProcess, Line } from '../types.js';
|
|
2
|
+
type Listener = () => void;
|
|
3
|
+
declare class ProcessStore {
|
|
4
|
+
private processes;
|
|
5
|
+
private listeners;
|
|
6
|
+
private shouldExit;
|
|
7
|
+
private exitCallback;
|
|
8
|
+
subscribe: (listener: Listener) => (() => void);
|
|
9
|
+
getSnapshot: () => ChildProcess[];
|
|
10
|
+
addProcess(process: ChildProcess): void;
|
|
11
|
+
updateProcess(id: string, update: Partial<ChildProcess>): void;
|
|
12
|
+
appendLines(id: string, newLines: Line[]): void;
|
|
13
|
+
getProcess(id: string): ChildProcess | undefined;
|
|
14
|
+
signalExit(callback: () => void): void;
|
|
15
|
+
getShouldExit: () => boolean;
|
|
16
|
+
getExitCallback: () => (() => void) | null;
|
|
17
|
+
reset(): void;
|
|
18
|
+
private notify;
|
|
19
|
+
}
|
|
20
|
+
export declare const processStore: ProcessStore;
|
|
21
|
+
export type { ProcessStore };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "processStore", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return processStore;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function _array_like_to_array(arr, len) {
|
|
12
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
13
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
14
|
+
return arr2;
|
|
15
|
+
}
|
|
16
|
+
function _array_without_holes(arr) {
|
|
17
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
18
|
+
}
|
|
19
|
+
function _class_call_check(instance, Constructor) {
|
|
20
|
+
if (!(instance instanceof Constructor)) {
|
|
21
|
+
throw new TypeError("Cannot call a class as a function");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function _define_property(obj, key, value) {
|
|
25
|
+
if (key in obj) {
|
|
26
|
+
Object.defineProperty(obj, key, {
|
|
27
|
+
value: value,
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
obj[key] = value;
|
|
34
|
+
}
|
|
35
|
+
return obj;
|
|
36
|
+
}
|
|
37
|
+
function _iterable_to_array(iter) {
|
|
38
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
39
|
+
}
|
|
40
|
+
function _non_iterable_spread() {
|
|
41
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
42
|
+
}
|
|
43
|
+
function _object_spread(target) {
|
|
44
|
+
for(var i = 1; i < arguments.length; i++){
|
|
45
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
46
|
+
var ownKeys = Object.keys(source);
|
|
47
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
48
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
49
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
ownKeys.forEach(function(key) {
|
|
53
|
+
_define_property(target, key, source[key]);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
58
|
+
function _to_consumable_array(arr) {
|
|
59
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
60
|
+
}
|
|
61
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
62
|
+
if (!o) return;
|
|
63
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
64
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
65
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
66
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
67
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
68
|
+
}
|
|
69
|
+
var ProcessStore = /*#__PURE__*/ function() {
|
|
70
|
+
"use strict";
|
|
71
|
+
function ProcessStore() {
|
|
72
|
+
var _this = this;
|
|
73
|
+
_class_call_check(this, ProcessStore);
|
|
74
|
+
this.processes = [];
|
|
75
|
+
this.listeners = new Set();
|
|
76
|
+
this.shouldExit = false;
|
|
77
|
+
this.exitCallback = null;
|
|
78
|
+
// useSyncExternalStore API
|
|
79
|
+
this.subscribe = function(listener) {
|
|
80
|
+
_this.listeners.add(listener);
|
|
81
|
+
return function() {
|
|
82
|
+
return _this.listeners.delete(listener);
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
this.getSnapshot = function() {
|
|
86
|
+
return _this.processes;
|
|
87
|
+
};
|
|
88
|
+
this.getShouldExit = function() {
|
|
89
|
+
return _this.shouldExit;
|
|
90
|
+
};
|
|
91
|
+
this.getExitCallback = function() {
|
|
92
|
+
return _this.exitCallback;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
var _proto = ProcessStore.prototype;
|
|
96
|
+
// Mutations - Ink handles render throttling at 30 FPS
|
|
97
|
+
_proto.addProcess = function addProcess(process) {
|
|
98
|
+
this.processes = _to_consumable_array(this.processes).concat([
|
|
99
|
+
process
|
|
100
|
+
]);
|
|
101
|
+
this.notify();
|
|
102
|
+
};
|
|
103
|
+
_proto.updateProcess = function updateProcess(id, update) {
|
|
104
|
+
this.processes = this.processes.map(function(p) {
|
|
105
|
+
return p.id === id ? _object_spread({}, p, update) : p;
|
|
106
|
+
});
|
|
107
|
+
this.notify();
|
|
108
|
+
};
|
|
109
|
+
_proto.appendLines = function appendLines(id, newLines) {
|
|
110
|
+
var process = this.processes.find(function(p) {
|
|
111
|
+
return p.id === id;
|
|
112
|
+
});
|
|
113
|
+
if (process) {
|
|
114
|
+
this.updateProcess(id, {
|
|
115
|
+
lines: process.lines.concat(newLines)
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
_proto.getProcess = function getProcess(id) {
|
|
120
|
+
return this.processes.find(function(p) {
|
|
121
|
+
return p.id === id;
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
// Exit signaling
|
|
125
|
+
_proto.signalExit = function signalExit(callback) {
|
|
126
|
+
this.shouldExit = true;
|
|
127
|
+
this.exitCallback = callback;
|
|
128
|
+
this.notify();
|
|
129
|
+
};
|
|
130
|
+
_proto.reset = function reset() {
|
|
131
|
+
this.processes = [];
|
|
132
|
+
this.shouldExit = false;
|
|
133
|
+
this.exitCallback = null;
|
|
134
|
+
};
|
|
135
|
+
_proto.notify = function notify() {
|
|
136
|
+
this.listeners.forEach(function(l) {
|
|
137
|
+
l();
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
return ProcessStore;
|
|
141
|
+
}();
|
|
142
|
+
var processStore = new ProcessStore();
|
|
143
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/state/processStore.ts"],"sourcesContent":["import type { ChildProcess, Line } from '../types.ts';\n\ntype Listener = () => void;\n\nclass ProcessStore {\n private processes: ChildProcess[] = [];\n private listeners = new Set<Listener>();\n private shouldExit = false;\n private exitCallback: (() => void) | null = null;\n\n // useSyncExternalStore API\n subscribe = (listener: Listener): (() => void) => {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n };\n\n getSnapshot = (): ChildProcess[] => this.processes;\n\n // Mutations - Ink handles render throttling at 30 FPS\n addProcess(process: ChildProcess): void {\n this.processes = [...this.processes, process];\n this.notify();\n }\n\n updateProcess(id: string, update: Partial<ChildProcess>): void {\n this.processes = this.processes.map((p) => (p.id === id ? { ...p, ...update } : p));\n this.notify();\n }\n\n appendLines(id: string, newLines: Line[]): void {\n const process = this.processes.find((p) => p.id === id);\n if (process) {\n this.updateProcess(id, { lines: process.lines.concat(newLines) });\n }\n }\n\n getProcess(id: string): ChildProcess | undefined {\n return this.processes.find((p) => p.id === id);\n }\n\n // Exit signaling\n signalExit(callback: () => void): void {\n this.shouldExit = true;\n this.exitCallback = callback;\n this.notify();\n }\n\n getShouldExit = (): boolean => this.shouldExit;\n getExitCallback = (): (() => void) | null => this.exitCallback;\n\n reset(): void {\n this.processes = [];\n this.shouldExit = false;\n this.exitCallback = null;\n }\n\n private notify(): void {\n this.listeners.forEach((l) => {\n l();\n });\n }\n}\n\nexport const processStore = new ProcessStore();\nexport type { ProcessStore };\n"],"names":["processStore","ProcessStore","processes","listeners","Set","shouldExit","exitCallback","subscribe","listener","add","delete","getSnapshot","getShouldExit","getExitCallback","addProcess","process","notify","updateProcess","id","update","map","p","appendLines","newLines","find","lines","concat","getProcess","signalExit","callback","reset","forEach","l"],"mappings":";;;;+BA+DaA;;;eAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA3Db,IAAA,AAAMC,6BAAN;;aAAMA;;gCAAAA;aACIC,YAA4B,EAAE;aAC9BC,YAAY,IAAIC;aAChBC,aAAa;aACbC,eAAoC;QAE5C,2BAA2B;aAC3BC,YAAY,SAACC;YACX,MAAKL,SAAS,CAACM,GAAG,CAACD;YACnB,OAAO;uBAAM,MAAKL,SAAS,CAACO,MAAM,CAACF;;QACrC;aAEAG,cAAc;mBAAsB,MAAKT,SAAS;;aA+BlDU,gBAAgB;mBAAe,MAAKP,UAAU;;aAC9CQ,kBAAkB;mBAA2B,MAAKP,YAAY;;;iBA5C1DL;IAcJ,sDAAsD;IACtDa,OAAAA,UAGC,GAHDA,SAAAA,WAAWC,OAAqB;QAC9B,IAAI,CAACb,SAAS,GAAG,AAAC,qBAAG,IAAI,CAACA,SAAS,SAAlB;YAAoBa;SAAQ;QAC7C,IAAI,CAACC,MAAM;IACb;IAEAC,OAAAA,aAGC,GAHDA,SAAAA,cAAcC,EAAU,EAAEC,MAA6B;QACrD,IAAI,CAACjB,SAAS,GAAG,IAAI,CAACA,SAAS,CAACkB,GAAG,CAAC,SAACC;mBAAOA,EAAEH,EAAE,KAAKA,KAAK,mBAAKG,GAAMF,UAAWE;;QAChF,IAAI,CAACL,MAAM;IACb;IAEAM,OAAAA,WAKC,GALDA,SAAAA,YAAYJ,EAAU,EAAEK,QAAgB;QACtC,IAAMR,UAAU,IAAI,CAACb,SAAS,CAACsB,IAAI,CAAC,SAACH;mBAAMA,EAAEH,EAAE,KAAKA;;QACpD,IAAIH,SAAS;YACX,IAAI,CAACE,aAAa,CAACC,IAAI;gBAAEO,OAAOV,QAAQU,KAAK,CAACC,MAAM,CAACH;YAAU;QACjE;IACF;IAEAI,OAAAA,UAEC,GAFDA,SAAAA,WAAWT,EAAU;QACnB,OAAO,IAAI,CAAChB,SAAS,CAACsB,IAAI,CAAC,SAACH;mBAAMA,EAAEH,EAAE,KAAKA;;IAC7C;IAEA,iBAAiB;IACjBU,OAAAA,UAIC,GAJDA,SAAAA,WAAWC,QAAoB;QAC7B,IAAI,CAACxB,UAAU,GAAG;QAClB,IAAI,CAACC,YAAY,GAAGuB;QACpB,IAAI,CAACb,MAAM;IACb;IAKAc,OAAAA,KAIC,GAJDA,SAAAA;QACE,IAAI,CAAC5B,SAAS,GAAG,EAAE;QACnB,IAAI,CAACG,UAAU,GAAG;QAClB,IAAI,CAACC,YAAY,GAAG;IACtB;IAEA,OAAQU,MAIP,GAJD,SAAQA;QACN,IAAI,CAACb,SAAS,CAAC4B,OAAO,CAAC,SAACC;YACtBA;QACF;IACF;WAxDI/B;;AA2DC,IAAMD,eAAe,IAAIC"}
|
package/dist/cjs/worker.js
CHANGED
|
@@ -91,30 +91,6 @@ function _object_spread(target) {
|
|
|
91
91
|
}
|
|
92
92
|
return target;
|
|
93
93
|
}
|
|
94
|
-
function ownKeys(object, enumerableOnly) {
|
|
95
|
-
var keys = Object.keys(object);
|
|
96
|
-
if (Object.getOwnPropertySymbols) {
|
|
97
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
98
|
-
if (enumerableOnly) {
|
|
99
|
-
symbols = symbols.filter(function(sym) {
|
|
100
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
keys.push.apply(keys, symbols);
|
|
104
|
-
}
|
|
105
|
-
return keys;
|
|
106
|
-
}
|
|
107
|
-
function _object_spread_props(target, source) {
|
|
108
|
-
source = source != null ? source : {};
|
|
109
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
110
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
111
|
-
} else {
|
|
112
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
113
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
return target;
|
|
117
|
-
}
|
|
118
94
|
function _object_without_properties(source, excluded) {
|
|
119
95
|
if (source == null) return {};
|
|
120
96
|
var target = _object_without_properties_loose(source, excluded);
|
|
@@ -149,89 +125,16 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
149
125
|
"stdio"
|
|
150
126
|
]);
|
|
151
127
|
if (stdio === 'inherit') {
|
|
152
|
-
terminal.retain(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
var cp = (0, _crossspawncb.crossSpawn)(command, args, csOptions);
|
|
163
|
-
var outputs = {
|
|
164
|
-
stdout: null,
|
|
165
|
-
stderr: null
|
|
166
|
-
};
|
|
167
|
-
var queue = new _queuecb.default();
|
|
168
|
-
if (cp.stdout) {
|
|
169
|
-
outputs.stdout = (0, _addLinests.default)(function(lines) {
|
|
170
|
-
var item = store.processes.find(function(x) {
|
|
171
|
-
return x.id === id;
|
|
172
|
-
});
|
|
173
|
-
store.updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
174
|
-
lines: item.lines.concat(lines.map(function(text) {
|
|
175
|
-
return {
|
|
176
|
-
type: _typests.LineType.stdout,
|
|
177
|
-
text: text
|
|
178
|
-
};
|
|
179
|
-
}))
|
|
180
|
-
}));
|
|
181
|
-
});
|
|
182
|
-
queue.defer(_onone.default.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
183
|
-
'error',
|
|
184
|
-
'end',
|
|
185
|
-
'close',
|
|
186
|
-
'finish'
|
|
187
|
-
]));
|
|
188
|
-
}
|
|
189
|
-
if (cp.stderr) {
|
|
190
|
-
outputs.stderr = (0, _addLinests.default)(function(lines) {
|
|
191
|
-
var item = store.processes.find(function(x) {
|
|
192
|
-
return x.id === id;
|
|
193
|
-
});
|
|
194
|
-
store.updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
195
|
-
lines: item.lines.concat(lines.map(function(text) {
|
|
196
|
-
return {
|
|
197
|
-
type: _typests.LineType.stderr,
|
|
198
|
-
text: text
|
|
199
|
-
};
|
|
200
|
-
}))
|
|
201
|
-
}));
|
|
202
|
-
});
|
|
203
|
-
queue.defer(_onone.default.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
204
|
-
'error',
|
|
205
|
-
'end',
|
|
206
|
-
'close',
|
|
207
|
-
'finish'
|
|
208
|
-
]));
|
|
209
|
-
}
|
|
210
|
-
// FIX: Don't buffer output when pipes are already consuming streams
|
|
211
|
-
// Adding data listeners to already-piped streams prevents 'close' event from firing
|
|
212
|
-
queue.defer(_crossspawncb.default.worker.bind(null, cp, csOptions));
|
|
213
|
-
queue.await(function(err) {
|
|
214
|
-
var res = err ? err : {};
|
|
215
|
-
res.stdout = outputs.stdout ? outputs.stdout.output : null;
|
|
216
|
-
res.stderr = outputs.stderr ? outputs.stderr.output : null;
|
|
217
|
-
res.output = [
|
|
218
|
-
res.stdout,
|
|
219
|
-
res.stderr,
|
|
220
|
-
null
|
|
221
|
-
];
|
|
222
|
-
var item = store.processes.find(function(x) {
|
|
223
|
-
return x.id === id;
|
|
224
|
-
});
|
|
225
|
-
store.updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
226
|
-
state: err ? 'error' : 'success'
|
|
227
|
-
}));
|
|
228
|
-
// ensure rendering completes
|
|
229
|
-
terminal.release(function() {
|
|
230
|
-
err ? callback(err) : callback(null, res);
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
} else {
|
|
128
|
+
var store = terminal.retain();
|
|
129
|
+
var id = _crypto.default.randomUUID();
|
|
130
|
+
store.addProcess(_object_spread({
|
|
131
|
+
id: id,
|
|
132
|
+
title: [
|
|
133
|
+
command
|
|
134
|
+
].concat((0, _formatArgumentsts.default)(args)).join(' '),
|
|
135
|
+
state: 'running',
|
|
136
|
+
lines: []
|
|
137
|
+
}, options));
|
|
235
138
|
var cp = (0, _crossspawncb.crossSpawn)(command, args, csOptions);
|
|
236
139
|
var outputs = {
|
|
237
140
|
stdout: null,
|
|
@@ -239,8 +142,13 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
239
142
|
};
|
|
240
143
|
var queue = new _queuecb.default();
|
|
241
144
|
if (cp.stdout) {
|
|
242
|
-
outputs.stdout = (0,
|
|
243
|
-
|
|
145
|
+
outputs.stdout = (0, _addLinests.default)(function(lines) {
|
|
146
|
+
store.appendLines(id, lines.map(function(text) {
|
|
147
|
+
return {
|
|
148
|
+
type: _typests.LineType.stdout,
|
|
149
|
+
text: text
|
|
150
|
+
};
|
|
151
|
+
}));
|
|
244
152
|
});
|
|
245
153
|
queue.defer(_onone.default.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
246
154
|
'error',
|
|
@@ -250,8 +158,13 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
250
158
|
]));
|
|
251
159
|
}
|
|
252
160
|
if (cp.stderr) {
|
|
253
|
-
outputs.stderr = (0,
|
|
254
|
-
|
|
161
|
+
outputs.stderr = (0, _addLinests.default)(function(lines) {
|
|
162
|
+
store.appendLines(id, lines.map(function(text) {
|
|
163
|
+
return {
|
|
164
|
+
type: _typests.LineType.stderr,
|
|
165
|
+
text: text
|
|
166
|
+
};
|
|
167
|
+
}));
|
|
255
168
|
});
|
|
256
169
|
queue.defer(_onone.default.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
257
170
|
'error',
|
|
@@ -260,8 +173,6 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
260
173
|
'finish'
|
|
261
174
|
]));
|
|
262
175
|
}
|
|
263
|
-
// FIX: Don't buffer output when pipes are already consuming streams
|
|
264
|
-
// Adding data listeners to already-piped streams prevents 'close' event from firing
|
|
265
176
|
queue.defer(_crossspawncb.default.worker.bind(null, cp, csOptions));
|
|
266
177
|
queue.await(function(err) {
|
|
267
178
|
var res = err ? err : {};
|
|
@@ -272,6 +183,52 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
272
183
|
res.stderr,
|
|
273
184
|
null
|
|
274
185
|
];
|
|
186
|
+
store.updateProcess(id, {
|
|
187
|
+
state: err ? 'error' : 'success'
|
|
188
|
+
});
|
|
189
|
+
terminal.release(function() {
|
|
190
|
+
err ? callback(err) : callback(null, res);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
} else {
|
|
194
|
+
var cp1 = (0, _crossspawncb.crossSpawn)(command, args, csOptions);
|
|
195
|
+
var outputs1 = {
|
|
196
|
+
stdout: null,
|
|
197
|
+
stderr: null
|
|
198
|
+
};
|
|
199
|
+
var queue1 = new _queuecb.default();
|
|
200
|
+
if (cp1.stdout) {
|
|
201
|
+
outputs1.stdout = (0, _concatWritablets.default)(function(output) {
|
|
202
|
+
outputs1.stdout.output = output.toString(encoding || 'utf8');
|
|
203
|
+
});
|
|
204
|
+
queue1.defer(_onone.default.bind(null, cp1.stdout.pipe(outputs1.stdout), [
|
|
205
|
+
'error',
|
|
206
|
+
'end',
|
|
207
|
+
'close',
|
|
208
|
+
'finish'
|
|
209
|
+
]));
|
|
210
|
+
}
|
|
211
|
+
if (cp1.stderr) {
|
|
212
|
+
outputs1.stderr = (0, _concatWritablets.default)(function(output) {
|
|
213
|
+
outputs1.stderr.output = output.toString(encoding || 'utf8');
|
|
214
|
+
});
|
|
215
|
+
queue1.defer(_onone.default.bind(null, cp1.stderr.pipe(outputs1.stderr), [
|
|
216
|
+
'error',
|
|
217
|
+
'end',
|
|
218
|
+
'close',
|
|
219
|
+
'finish'
|
|
220
|
+
]));
|
|
221
|
+
}
|
|
222
|
+
queue1.defer(_crossspawncb.default.worker.bind(null, cp1, csOptions));
|
|
223
|
+
queue1.await(function(err) {
|
|
224
|
+
var res = err ? err : {};
|
|
225
|
+
res.stdout = outputs1.stdout ? outputs1.stdout.output : null;
|
|
226
|
+
res.stderr = outputs1.stderr ? outputs1.stderr.output : null;
|
|
227
|
+
res.output = [
|
|
228
|
+
res.stdout,
|
|
229
|
+
res.stderr,
|
|
230
|
+
null
|
|
231
|
+
];
|
|
275
232
|
err ? callback(err) : callback(null, res);
|
|
276
233
|
});
|
|
277
234
|
}
|