spawn-term 1.1.7 → 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/lib/figures.js +1 -1
- package/dist/cjs/lib/figures.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 -108
- 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/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 -91
- package/dist/esm/worker.js.map +1 -1
- package/package.json +1 -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/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"}
|
|
@@ -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,86 +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
|
-
queue.defer(_crossspawncb.default.worker.bind(null, cp, csOptions));
|
|
211
|
-
queue.await(function(err) {
|
|
212
|
-
var res = err ? err : {};
|
|
213
|
-
res.stdout = outputs.stdout ? outputs.stdout.output : null;
|
|
214
|
-
res.stderr = outputs.stderr ? outputs.stderr.output : null;
|
|
215
|
-
res.output = [
|
|
216
|
-
res.stdout,
|
|
217
|
-
res.stderr,
|
|
218
|
-
null
|
|
219
|
-
];
|
|
220
|
-
var item = store.processes.find(function(x) {
|
|
221
|
-
return x.id === id;
|
|
222
|
-
});
|
|
223
|
-
store.updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
224
|
-
state: err ? 'error' : 'success'
|
|
225
|
-
}));
|
|
226
|
-
terminal.release(function() {
|
|
227
|
-
err ? callback(err) : callback(null, res);
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
} 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));
|
|
232
138
|
var cp = (0, _crossspawncb.crossSpawn)(command, args, csOptions);
|
|
233
139
|
var outputs = {
|
|
234
140
|
stdout: null,
|
|
@@ -236,8 +142,13 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
236
142
|
};
|
|
237
143
|
var queue = new _queuecb.default();
|
|
238
144
|
if (cp.stdout) {
|
|
239
|
-
outputs.stdout = (0,
|
|
240
|
-
|
|
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
|
+
}));
|
|
241
152
|
});
|
|
242
153
|
queue.defer(_onone.default.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
243
154
|
'error',
|
|
@@ -247,8 +158,13 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
247
158
|
]));
|
|
248
159
|
}
|
|
249
160
|
if (cp.stderr) {
|
|
250
|
-
outputs.stderr = (0,
|
|
251
|
-
|
|
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
|
+
}));
|
|
252
168
|
});
|
|
253
169
|
queue.defer(_onone.default.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
254
170
|
'error',
|
|
@@ -267,6 +183,52 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
267
183
|
res.stderr,
|
|
268
184
|
null
|
|
269
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
|
+
];
|
|
270
232
|
err ? callback(err) : callback(null, res);
|
|
271
233
|
});
|
|
272
234
|
}
|
package/dist/cjs/worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["import spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport crypto from 'crypto';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp.ts';\nimport addLines from './lib/addLines.ts';\nimport concatWritable from './lib/concatWritable.ts';\nimport formatArguments from './lib/formatArguments.ts';\n\nimport type { SpawnError, SpawnOptions, TerminalCallback, TerminalOptions } from './types.ts';\nimport { LineType } from './types.ts';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n if (stdio === 'inherit') {\n terminal.retain(
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["import spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport crypto from 'crypto';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp.ts';\nimport addLines from './lib/addLines.ts';\nimport concatWritable from './lib/concatWritable.ts';\nimport formatArguments from './lib/formatArguments.ts';\n\nimport type { SpawnError, SpawnOptions, TerminalCallback, TerminalOptions } from './types.ts';\nimport { LineType } from './types.ts';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n if (stdio === 'inherit') {\n const store = terminal.retain();\n const id = crypto.randomUUID();\n store.addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = addLines((lines) => {\n store.appendLines(\n id,\n lines.map((text) => ({ type: LineType.stdout, text }))\n );\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = addLines((lines) => {\n store.appendLines(\n id,\n lines.map((text) => ({ type: LineType.stderr, text }))\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));\n queue.await((err?: SpawnError) => {\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 store.updateProcess(id, { state: err ? 'error' : 'success' });\n\n terminal.release(() => {\n err ? callback(err) : callback(null, res);\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, csOptions));\n queue.await((err?: SpawnError) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n err ? callback(err) : callback(null, res);\n });\n }\n}\n"],"names":["spawnTerminal","terminal","createApp","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","store","retain","id","crypto","randomUUID","addProcess","title","concat","formatArguments","join","state","lines","cp","crossSpawn","outputs","stdout","stderr","queue","Queue","addLines","appendLines","map","text","type","LineType","defer","oo","bind","pipe","spawn","worker","await","err","res","output","updateProcess","release","concatWritable","toString"],"mappings":"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"}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Box } from 'ink';
|
|
2
|
+
import { Box, useApp } from 'ink';
|
|
3
|
+
import { useEffect, useSyncExternalStore } from 'react';
|
|
4
|
+
import { processStore } from '../state/processStore.js';
|
|
3
5
|
import ChildProcess from './ChildProcess.js';
|
|
4
|
-
export default function App(
|
|
6
|
+
export default function App() {
|
|
7
|
+
const { exit } = useApp();
|
|
8
|
+
// Subscribe to process state
|
|
9
|
+
const processes = useSyncExternalStore(processStore.subscribe, processStore.getSnapshot);
|
|
10
|
+
// Handle exit signal
|
|
11
|
+
const shouldExit = useSyncExternalStore(processStore.subscribe, processStore.getShouldExit);
|
|
12
|
+
useEffect(()=>{
|
|
13
|
+
if (shouldExit) {
|
|
14
|
+
exit();
|
|
15
|
+
}
|
|
16
|
+
}, [
|
|
17
|
+
shouldExit,
|
|
18
|
+
exit
|
|
19
|
+
]);
|
|
5
20
|
return /*#__PURE__*/ _jsx(Box, {
|
|
6
21
|
flexDirection: "column",
|
|
7
|
-
children:
|
|
22
|
+
children: processes.map((item)=>/*#__PURE__*/ _jsx(ChildProcess, {
|
|
8
23
|
item: item
|
|
9
24
|
}, item.id))
|
|
10
25
|
});
|
|
@@ -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":["Box","useApp","useEffect","useSyncExternalStore","processStore","ChildProcess","App","exit","processes","subscribe","getSnapshot","shouldExit","getShouldExit","flexDirection","map","item","id"],"mappings":";AAAA,SAASA,GAAG,EAAEC,MAAM,QAAQ,MAAM;AAClC,SAASC,SAAS,EAAEC,oBAAoB,QAAQ,QAAQ;AACxD,SAASC,YAAY,QAAQ,2BAA2B;AAExD,OAAOC,kBAAkB,oBAAoB;AAE7C,eAAe,SAASC;IACtB,MAAM,EAAEC,IAAI,EAAE,GAAGN;IAEjB,6BAA6B;IAC7B,MAAMO,YAAYL,qBAAqBC,aAAaK,SAAS,EAAEL,aAAaM,WAAW;IAEvF,qBAAqB;IACrB,MAAMC,aAAaR,qBAAqBC,aAAaK,SAAS,EAAEL,aAAaQ,aAAa;IAE1FV,UAAU;QACR,IAAIS,YAAY;YACdJ;QACF;IACF,GAAG;QAACI;QAAYJ;KAAK;IAErB,qBACE,KAACP;QAAIa,eAAc;kBAChBL,UAAUM,GAAG,CAAC,CAACC,qBACd,KAACV;gBAA2BU,MAAMA;eAAfA,KAAKC,EAAE;;AAIlC"}
|
package/dist/esm/createApp.js
CHANGED
|
@@ -1,44 +1,38 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render } from 'ink';
|
|
3
|
-
import throttle from 'lodash.throttle';
|
|
4
3
|
import App from './components/App.js';
|
|
5
|
-
import {
|
|
6
|
-
const THROTTLE = 100;
|
|
4
|
+
import { processStore } from './state/processStore.js';
|
|
7
5
|
export default function createApp() {
|
|
8
6
|
let refCount = 0;
|
|
9
|
-
let store = null;
|
|
10
7
|
let inkApp = null;
|
|
11
|
-
let previousData = null;
|
|
12
|
-
const rerender = throttle(()=>{
|
|
13
|
-
if (!inkApp || !store) return;
|
|
14
|
-
if (store.data() === previousData) return;
|
|
15
|
-
previousData = store.data();
|
|
16
|
-
inkApp.rerender(/*#__PURE__*/ _jsx(App, {
|
|
17
|
-
store: store
|
|
18
|
-
}));
|
|
19
|
-
}, THROTTLE, {
|
|
20
|
-
leading: false
|
|
21
|
-
});
|
|
22
8
|
return {
|
|
23
|
-
retain (
|
|
24
|
-
if (++refCount > 1) return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
store: store
|
|
29
|
-
}));
|
|
30
|
-
fn(store);
|
|
9
|
+
retain () {
|
|
10
|
+
if (++refCount > 1) return processStore;
|
|
11
|
+
// Render once - React handles all subsequent updates via useSyncExternalStore
|
|
12
|
+
inkApp = render(/*#__PURE__*/ _jsx(App, {}));
|
|
13
|
+
return processStore;
|
|
31
14
|
},
|
|
32
|
-
release (
|
|
33
|
-
if (--refCount > 0)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
inkApp
|
|
38
|
-
|
|
15
|
+
release (callback) {
|
|
16
|
+
if (--refCount > 0) {
|
|
17
|
+
callback();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!inkApp) throw new Error('Expecting inkApp');
|
|
21
|
+
// Signal exit to React component, provide callback for after cleanup
|
|
22
|
+
processStore.signalExit(()=>{
|
|
23
|
+
processStore.reset();
|
|
24
|
+
process.stdout.write('\x1b[?25h'); // show cursor
|
|
25
|
+
callback();
|
|
26
|
+
});
|
|
27
|
+
// Wait for Ink to finish, then call the callback
|
|
28
|
+
inkApp.waitUntilExit().then(()=>{
|
|
29
|
+
const cb = processStore.getExitCallback();
|
|
30
|
+
cb === null || cb === void 0 ? void 0 : cb();
|
|
31
|
+
}).catch(()=>{
|
|
32
|
+
const cb = processStore.getExitCallback();
|
|
33
|
+
cb === null || cb === void 0 ? void 0 : cb();
|
|
34
|
+
});
|
|
39
35
|
inkApp = null;
|
|
40
|
-
store = null;
|
|
41
|
-
process.stdout.write('\x1b[?25h'); // show cursor
|
|
42
36
|
}
|
|
43
37
|
};
|
|
44
38
|
}
|
|
@@ -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":["render","App","processStore","createApp","refCount","inkApp","retain","release","callback","Error","signalExit","reset","process","stdout","write","waitUntilExit","then","cb","getExitCallback","catch"],"mappings":";AAAA,SAASA,MAAM,QAAQ,MAAM;AAC7B,OAAOC,SAAS,sBAAsB;AACtC,SAA4BC,YAAY,QAAQ,0BAA0B;AAI1E,eAAe,SAASC;IACtB,IAAIC,WAAW;IACf,IAAIC,SAA2C;IAE/C,OAAO;QACLC;YACE,IAAI,EAAEF,WAAW,GAAG,OAAOF;YAE3B,8EAA8E;YAC9EG,SAASL,qBAAO,KAACC;YACjB,OAAOC;QACT;QAEAK,SAAQC,QAAyB;YAC/B,IAAI,EAAEJ,WAAW,GAAG;gBAClBI;gBACA;YACF;YACA,IAAI,CAACH,QAAQ,MAAM,IAAII,MAAM;YAE7B,qEAAqE;YACrEP,aAAaQ,UAAU,CAAC;gBACtBR,aAAaS,KAAK;gBAClBC,QAAQC,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;gBACjDN;YACF;YAEA,iDAAiD;YACjDH,OACGU,aAAa,GACbC,IAAI,CAAC;gBACJ,MAAMC,KAAKf,aAAagB,eAAe;gBACvCD,eAAAA,yBAAAA;YACF,GACCE,KAAK,CAAC;gBACL,MAAMF,KAAKf,aAAagB,eAAe;gBACvCD,eAAAA,yBAAAA;YACF;YAEFZ,SAAS;QACX;IACF;AACF"}
|
|
@@ -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,84 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _object_spread(target) {
|
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_define_property(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
29
|
+
class ProcessStore {
|
|
30
|
+
// Mutations - Ink handles render throttling at 30 FPS
|
|
31
|
+
addProcess(process) {
|
|
32
|
+
this.processes = [
|
|
33
|
+
...this.processes,
|
|
34
|
+
process
|
|
35
|
+
];
|
|
36
|
+
this.notify();
|
|
37
|
+
}
|
|
38
|
+
updateProcess(id, update) {
|
|
39
|
+
this.processes = this.processes.map((p)=>p.id === id ? _object_spread({}, p, update) : p);
|
|
40
|
+
this.notify();
|
|
41
|
+
}
|
|
42
|
+
appendLines(id, newLines) {
|
|
43
|
+
const process = this.processes.find((p)=>p.id === id);
|
|
44
|
+
if (process) {
|
|
45
|
+
this.updateProcess(id, {
|
|
46
|
+
lines: process.lines.concat(newLines)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
getProcess(id) {
|
|
51
|
+
return this.processes.find((p)=>p.id === id);
|
|
52
|
+
}
|
|
53
|
+
// Exit signaling
|
|
54
|
+
signalExit(callback) {
|
|
55
|
+
this.shouldExit = true;
|
|
56
|
+
this.exitCallback = callback;
|
|
57
|
+
this.notify();
|
|
58
|
+
}
|
|
59
|
+
reset() {
|
|
60
|
+
this.processes = [];
|
|
61
|
+
this.shouldExit = false;
|
|
62
|
+
this.exitCallback = null;
|
|
63
|
+
}
|
|
64
|
+
notify() {
|
|
65
|
+
this.listeners.forEach((l)=>{
|
|
66
|
+
l();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
constructor(){
|
|
70
|
+
this.processes = [];
|
|
71
|
+
this.listeners = new Set();
|
|
72
|
+
this.shouldExit = false;
|
|
73
|
+
this.exitCallback = null;
|
|
74
|
+
// useSyncExternalStore API
|
|
75
|
+
this.subscribe = (listener)=>{
|
|
76
|
+
this.listeners.add(listener);
|
|
77
|
+
return ()=>this.listeners.delete(listener);
|
|
78
|
+
};
|
|
79
|
+
this.getSnapshot = ()=>this.processes;
|
|
80
|
+
this.getShouldExit = ()=>this.shouldExit;
|
|
81
|
+
this.getExitCallback = ()=>this.exitCallback;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export const processStore = new ProcessStore();
|
|
@@ -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","addProcess","process","processes","notify","updateProcess","id","update","map","p","appendLines","newLines","find","lines","concat","getProcess","signalExit","callback","shouldExit","exitCallback","reset","listeners","forEach","l","Set","subscribe","listener","add","delete","getSnapshot","getShouldExit","getExitCallback","processStore"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAMA;IAcJ,sDAAsD;IACtDC,WAAWC,OAAqB,EAAQ;QACtC,IAAI,CAACC,SAAS,GAAG;eAAI,IAAI,CAACA,SAAS;YAAED;SAAQ;QAC7C,IAAI,CAACE,MAAM;IACb;IAEAC,cAAcC,EAAU,EAAEC,MAA6B,EAAQ;QAC7D,IAAI,CAACJ,SAAS,GAAG,IAAI,CAACA,SAAS,CAACK,GAAG,CAAC,CAACC,IAAOA,EAAEH,EAAE,KAAKA,KAAK,mBAAKG,GAAMF,UAAWE;QAChF,IAAI,CAACL,MAAM;IACb;IAEAM,YAAYJ,EAAU,EAAEK,QAAgB,EAAQ;QAC9C,MAAMT,UAAU,IAAI,CAACC,SAAS,CAACS,IAAI,CAAC,CAACH,IAAMA,EAAEH,EAAE,KAAKA;QACpD,IAAIJ,SAAS;YACX,IAAI,CAACG,aAAa,CAACC,IAAI;gBAAEO,OAAOX,QAAQW,KAAK,CAACC,MAAM,CAACH;YAAU;QACjE;IACF;IAEAI,WAAWT,EAAU,EAA4B;QAC/C,OAAO,IAAI,CAACH,SAAS,CAACS,IAAI,CAAC,CAACH,IAAMA,EAAEH,EAAE,KAAKA;IAC7C;IAEA,iBAAiB;IACjBU,WAAWC,QAAoB,EAAQ;QACrC,IAAI,CAACC,UAAU,GAAG;QAClB,IAAI,CAACC,YAAY,GAAGF;QACpB,IAAI,CAACb,MAAM;IACb;IAKAgB,QAAc;QACZ,IAAI,CAACjB,SAAS,GAAG,EAAE;QACnB,IAAI,CAACe,UAAU,GAAG;QAClB,IAAI,CAACC,YAAY,GAAG;IACtB;IAEQf,SAAe;QACrB,IAAI,CAACiB,SAAS,CAACC,OAAO,CAAC,CAACC;YACtBA;QACF;IACF;;aAvDQpB,YAA4B,EAAE;aAC9BkB,YAAY,IAAIG;aAChBN,aAAa;aACbC,eAAoC;QAE5C,2BAA2B;aAC3BM,YAAY,CAACC;YACX,IAAI,CAACL,SAAS,CAACM,GAAG,CAACD;YACnB,OAAO,IAAM,IAAI,CAACL,SAAS,CAACO,MAAM,CAACF;QACrC;aAEAG,cAAc,IAAsB,IAAI,CAAC1B,SAAS;aA+BlD2B,gBAAgB,IAAe,IAAI,CAACZ,UAAU;aAC9Ca,kBAAkB,IAA2B,IAAI,CAACZ,YAAY;;AAahE;AAEA,OAAO,MAAMa,eAAe,IAAIhC,eAAe"}
|
package/dist/esm/worker.js
CHANGED
|
@@ -26,30 +26,6 @@ function _object_spread(target) {
|
|
|
26
26
|
}
|
|
27
27
|
return target;
|
|
28
28
|
}
|
|
29
|
-
function ownKeys(object, enumerableOnly) {
|
|
30
|
-
var keys = Object.keys(object);
|
|
31
|
-
if (Object.getOwnPropertySymbols) {
|
|
32
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
33
|
-
if (enumerableOnly) {
|
|
34
|
-
symbols = symbols.filter(function(sym) {
|
|
35
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
keys.push.apply(keys, symbols);
|
|
39
|
-
}
|
|
40
|
-
return keys;
|
|
41
|
-
}
|
|
42
|
-
function _object_spread_props(target, source) {
|
|
43
|
-
source = source != null ? source : {};
|
|
44
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
45
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
46
|
-
} else {
|
|
47
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
48
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return target;
|
|
52
|
-
}
|
|
53
29
|
function _object_without_properties(source, excluded) {
|
|
54
30
|
if (source == null) return {};
|
|
55
31
|
var target = _object_without_properties_loose(source, excluded);
|
|
@@ -93,73 +69,65 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
93
69
|
"stdio"
|
|
94
70
|
]);
|
|
95
71
|
if (stdio === 'inherit') {
|
|
96
|
-
terminal.retain(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
];
|
|
156
|
-
const item = store.processes.find((x)=>x.id === id);
|
|
157
|
-
store.updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
158
|
-
state: err ? 'error' : 'success'
|
|
159
|
-
}));
|
|
160
|
-
terminal.release(()=>{
|
|
161
|
-
err ? callback(err) : callback(null, res);
|
|
162
|
-
});
|
|
72
|
+
const store = terminal.retain();
|
|
73
|
+
const id = crypto.randomUUID();
|
|
74
|
+
store.addProcess(_object_spread({
|
|
75
|
+
id,
|
|
76
|
+
title: [
|
|
77
|
+
command
|
|
78
|
+
].concat(formatArguments(args)).join(' '),
|
|
79
|
+
state: 'running',
|
|
80
|
+
lines: []
|
|
81
|
+
}, options));
|
|
82
|
+
const cp = crossSpawn(command, args, csOptions);
|
|
83
|
+
const outputs = {
|
|
84
|
+
stdout: null,
|
|
85
|
+
stderr: null
|
|
86
|
+
};
|
|
87
|
+
const queue = new Queue();
|
|
88
|
+
if (cp.stdout) {
|
|
89
|
+
outputs.stdout = addLines((lines)=>{
|
|
90
|
+
store.appendLines(id, lines.map((text)=>({
|
|
91
|
+
type: LineType.stdout,
|
|
92
|
+
text
|
|
93
|
+
})));
|
|
94
|
+
});
|
|
95
|
+
queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
96
|
+
'error',
|
|
97
|
+
'end',
|
|
98
|
+
'close',
|
|
99
|
+
'finish'
|
|
100
|
+
]));
|
|
101
|
+
}
|
|
102
|
+
if (cp.stderr) {
|
|
103
|
+
outputs.stderr = addLines((lines)=>{
|
|
104
|
+
store.appendLines(id, lines.map((text)=>({
|
|
105
|
+
type: LineType.stderr,
|
|
106
|
+
text
|
|
107
|
+
})));
|
|
108
|
+
});
|
|
109
|
+
queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
110
|
+
'error',
|
|
111
|
+
'end',
|
|
112
|
+
'close',
|
|
113
|
+
'finish'
|
|
114
|
+
]));
|
|
115
|
+
}
|
|
116
|
+
queue.defer(spawn.worker.bind(null, cp, csOptions));
|
|
117
|
+
queue.await((err)=>{
|
|
118
|
+
const res = err ? err : {};
|
|
119
|
+
res.stdout = outputs.stdout ? outputs.stdout.output : null;
|
|
120
|
+
res.stderr = outputs.stderr ? outputs.stderr.output : null;
|
|
121
|
+
res.output = [
|
|
122
|
+
res.stdout,
|
|
123
|
+
res.stderr,
|
|
124
|
+
null
|
|
125
|
+
];
|
|
126
|
+
store.updateProcess(id, {
|
|
127
|
+
state: err ? 'error' : 'success'
|
|
128
|
+
});
|
|
129
|
+
terminal.release(()=>{
|
|
130
|
+
err ? callback(err) : callback(null, res);
|
|
163
131
|
});
|
|
164
132
|
});
|
|
165
133
|
} else {
|
package/dist/esm/worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["import spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport crypto from 'crypto';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp.ts';\nimport addLines from './lib/addLines.ts';\nimport concatWritable from './lib/concatWritable.ts';\nimport formatArguments from './lib/formatArguments.ts';\n\nimport type { SpawnError, SpawnOptions, TerminalCallback, TerminalOptions } from './types.ts';\nimport { LineType } from './types.ts';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n if (stdio === 'inherit') {\n terminal.retain(
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["import spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport crypto from 'crypto';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp.ts';\nimport addLines from './lib/addLines.ts';\nimport concatWritable from './lib/concatWritable.ts';\nimport formatArguments from './lib/formatArguments.ts';\n\nimport type { SpawnError, SpawnOptions, TerminalCallback, TerminalOptions } from './types.ts';\nimport { LineType } from './types.ts';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n if (stdio === 'inherit') {\n const store = terminal.retain();\n const id = crypto.randomUUID();\n store.addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = addLines((lines) => {\n store.appendLines(\n id,\n lines.map((text) => ({ type: LineType.stdout, text }))\n );\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = addLines((lines) => {\n store.appendLines(\n id,\n lines.map((text) => ({ type: LineType.stderr, text }))\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));\n queue.await((err?: SpawnError) => {\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 store.updateProcess(id, { state: err ? 'error' : 'success' });\n\n terminal.release(() => {\n err ? callback(err) : callback(null, res);\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, csOptions));\n queue.await((err?: SpawnError) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n err ? callback(err) : callback(null, res);\n });\n }\n}\n"],"names":["spawn","crossSpawn","crypto","oo","Queue","createApp","addLines","concatWritable","formatArguments","LineType","terminal","spawnTerminal","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","store","retain","id","randomUUID","addProcess","title","concat","join","state","lines","cp","outputs","stdout","stderr","queue","appendLines","map","text","type","defer","bind","pipe","worker","await","err","res","output","updateProcess","release","toString"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spawn-term",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "Formats spawn with for terminal grouping",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"spawn",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"cross-spawn-cb": "*",
|
|
45
45
|
"ink": "*",
|
|
46
|
-
"lodash.throttle": "*",
|
|
47
46
|
"on-one": "*",
|
|
48
47
|
"queue-cb": "*",
|
|
49
48
|
"react": "*"
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ChildProcess } from '../types.js';
|
|
2
|
-
export type RenderFunction = () => void;
|
|
3
|
-
export type StoreData = ChildProcess[];
|
|
4
|
-
export default class Store {
|
|
5
|
-
processes: ChildProcess[];
|
|
6
|
-
onRender: RenderFunction;
|
|
7
|
-
constructor(onRender: RenderFunction);
|
|
8
|
-
data(): StoreData;
|
|
9
|
-
addProcess(process: ChildProcess): void;
|
|
10
|
-
updateProcess(process: ChildProcess): void;
|
|
11
|
-
}
|
package/dist/cjs/state/Store.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "default", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return Store;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
function _class_call_check(instance, Constructor) {
|
|
12
|
-
if (!(instance instanceof Constructor)) {
|
|
13
|
-
throw new TypeError("Cannot call a class as a function");
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
var Store = /*#__PURE__*/ function() {
|
|
17
|
-
"use strict";
|
|
18
|
-
function Store(onRender) {
|
|
19
|
-
_class_call_check(this, Store);
|
|
20
|
-
if (!onRender) throw new Error('missing on render');
|
|
21
|
-
this.processes = [];
|
|
22
|
-
this.onRender = onRender;
|
|
23
|
-
}
|
|
24
|
-
var _proto = Store.prototype;
|
|
25
|
-
_proto.data = function data() {
|
|
26
|
-
return this.processes;
|
|
27
|
-
};
|
|
28
|
-
_proto.addProcess = function addProcess(process) {
|
|
29
|
-
this.processes.push(process);
|
|
30
|
-
this.onRender();
|
|
31
|
-
};
|
|
32
|
-
_proto.updateProcess = function updateProcess(process) {
|
|
33
|
-
this.processes = this.processes.map(function(x) {
|
|
34
|
-
return x.id === process.id ? process : x;
|
|
35
|
-
});
|
|
36
|
-
this.onRender();
|
|
37
|
-
};
|
|
38
|
-
return Store;
|
|
39
|
-
}();
|
|
40
|
-
/* 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 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/state/Store.ts"],"sourcesContent":["import type { ChildProcess } from '../types.ts';\n\nexport type RenderFunction = () => void;\nexport type StoreData = ChildProcess[];\n\nexport default class Store {\n processes: ChildProcess[];\n onRender: RenderFunction;\n\n constructor(onRender: RenderFunction) {\n if (!onRender) throw new Error('missing on render');\n this.processes = [];\n this.onRender = onRender;\n }\n\n data(): StoreData {\n return this.processes;\n }\n\n addProcess(process: ChildProcess): void {\n this.processes.push(process);\n this.onRender();\n }\n\n updateProcess(process: ChildProcess): void {\n this.processes = this.processes.map((x) => (x.id === process.id ? process : x));\n this.onRender();\n }\n}\n"],"names":["Store","onRender","Error","processes","data","addProcess","process","push","updateProcess","map","x","id"],"mappings":";;;;;;;eAKqBA;;;;;;;;AAAN,IAAA,AAAMA,sBAAN;;aAAMA,MAIPC,QAAwB;gCAJjBD;QAKjB,IAAI,CAACC,UAAU,MAAM,IAAIC,MAAM;QAC/B,IAAI,CAACC,SAAS,GAAG,EAAE;QACnB,IAAI,CAACF,QAAQ,GAAGA;;iBAPCD;IAUnBI,OAAAA,IAEC,GAFDA,SAAAA;QACE,OAAO,IAAI,CAACD,SAAS;IACvB;IAEAE,OAAAA,UAGC,GAHDA,SAAAA,WAAWC,OAAqB;QAC9B,IAAI,CAACH,SAAS,CAACI,IAAI,CAACD;QACpB,IAAI,CAACL,QAAQ;IACf;IAEAO,OAAAA,aAGC,GAHDA,SAAAA,cAAcF,OAAqB;QACjC,IAAI,CAACH,SAAS,GAAG,IAAI,CAACA,SAAS,CAACM,GAAG,CAAC,SAACC;mBAAOA,EAAEC,EAAE,KAAKL,QAAQK,EAAE,GAAGL,UAAUI;;QAC5E,IAAI,CAACT,QAAQ;IACf;WAtBmBD"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ChildProcess } from '../types.js';
|
|
2
|
-
export type RenderFunction = () => void;
|
|
3
|
-
export type StoreData = ChildProcess[];
|
|
4
|
-
export default class Store {
|
|
5
|
-
processes: ChildProcess[];
|
|
6
|
-
onRender: RenderFunction;
|
|
7
|
-
constructor(onRender: RenderFunction);
|
|
8
|
-
data(): StoreData;
|
|
9
|
-
addProcess(process: ChildProcess): void;
|
|
10
|
-
updateProcess(process: ChildProcess): void;
|
|
11
|
-
}
|
package/dist/esm/state/Store.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
class Store {
|
|
2
|
-
data() {
|
|
3
|
-
return this.processes;
|
|
4
|
-
}
|
|
5
|
-
addProcess(process) {
|
|
6
|
-
this.processes.push(process);
|
|
7
|
-
this.onRender();
|
|
8
|
-
}
|
|
9
|
-
updateProcess(process) {
|
|
10
|
-
this.processes = this.processes.map((x)=>x.id === process.id ? process : x);
|
|
11
|
-
this.onRender();
|
|
12
|
-
}
|
|
13
|
-
constructor(onRender){
|
|
14
|
-
if (!onRender) throw new Error('missing on render');
|
|
15
|
-
this.processes = [];
|
|
16
|
-
this.onRender = onRender;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export { Store as default };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/state/Store.ts"],"sourcesContent":["import type { ChildProcess } from '../types.ts';\n\nexport type RenderFunction = () => void;\nexport type StoreData = ChildProcess[];\n\nexport default class Store {\n processes: ChildProcess[];\n onRender: RenderFunction;\n\n constructor(onRender: RenderFunction) {\n if (!onRender) throw new Error('missing on render');\n this.processes = [];\n this.onRender = onRender;\n }\n\n data(): StoreData {\n return this.processes;\n }\n\n addProcess(process: ChildProcess): void {\n this.processes.push(process);\n this.onRender();\n }\n\n updateProcess(process: ChildProcess): void {\n this.processes = this.processes.map((x) => (x.id === process.id ? process : x));\n this.onRender();\n }\n}\n"],"names":["Store","data","processes","addProcess","process","push","onRender","updateProcess","map","x","id","Error"],"mappings":"AAKe,MAAMA;IAUnBC,OAAkB;QAChB,OAAO,IAAI,CAACC,SAAS;IACvB;IAEAC,WAAWC,OAAqB,EAAQ;QACtC,IAAI,CAACF,SAAS,CAACG,IAAI,CAACD;QACpB,IAAI,CAACE,QAAQ;IACf;IAEAC,cAAcH,OAAqB,EAAQ;QACzC,IAAI,CAACF,SAAS,GAAG,IAAI,CAACA,SAAS,CAACM,GAAG,CAAC,CAACC,IAAOA,EAAEC,EAAE,KAAKN,QAAQM,EAAE,GAAGN,UAAUK;QAC5E,IAAI,CAACH,QAAQ;IACf;IAlBA,YAAYA,QAAwB,CAAE;QACpC,IAAI,CAACA,UAAU,MAAM,IAAIK,MAAM;QAC/B,IAAI,CAACT,SAAS,GAAG,EAAE;QACnB,IAAI,CAACI,QAAQ,GAAGA;IAClB;AAeF;AAvBA,SAAqBN,mBAuBpB"}
|