spawn-term 1.0.1 → 1.0.2

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.
Files changed (44) hide show
  1. package/dist/cjs/components/App.js +8 -16
  2. package/dist/cjs/components/App.js.map +1 -1
  3. package/dist/cjs/createApp.d.cts +3 -1
  4. package/dist/cjs/createApp.d.ts +3 -1
  5. package/dist/cjs/createApp.js +23 -78
  6. package/dist/cjs/createApp.js.map +1 -1
  7. package/dist/cjs/{contexts/Store.d.cts → store/Context.d.cts} +1 -1
  8. package/dist/cjs/{contexts/Store.d.ts → store/Context.d.ts} +1 -1
  9. package/dist/cjs/store/Context.js.map +1 -0
  10. package/dist/cjs/store/Store.d.cts +9 -0
  11. package/dist/cjs/store/Store.d.ts +9 -0
  12. package/dist/cjs/store/Store.js +37 -0
  13. package/dist/cjs/store/Store.js.map +1 -0
  14. package/dist/cjs/store/index.d.cts +2 -0
  15. package/dist/cjs/store/index.d.ts +2 -0
  16. package/dist/cjs/store/index.js +26 -0
  17. package/dist/cjs/store/index.js.map +1 -0
  18. package/dist/cjs/types.d.cts +0 -11
  19. package/dist/cjs/types.d.ts +0 -11
  20. package/dist/cjs/types.js.map +1 -1
  21. package/dist/cjs/worker.js +7 -7
  22. package/dist/cjs/worker.js.map +1 -1
  23. package/dist/esm/components/App.js +8 -16
  24. package/dist/esm/components/App.js.map +1 -1
  25. package/dist/esm/createApp.d.ts +3 -1
  26. package/dist/esm/createApp.js +20 -45
  27. package/dist/esm/createApp.js.map +1 -1
  28. package/dist/esm/{contexts/Store.d.ts → store/Context.d.ts} +1 -1
  29. package/dist/esm/store/Context.js.map +1 -0
  30. package/dist/esm/store/Store.d.ts +9 -0
  31. package/dist/esm/store/Store.js +16 -0
  32. package/dist/esm/store/Store.js.map +1 -0
  33. package/dist/esm/store/index.d.ts +2 -0
  34. package/dist/esm/store/index.js +2 -0
  35. package/dist/esm/store/index.js.map +1 -0
  36. package/dist/esm/types.d.ts +0 -11
  37. package/dist/esm/types.js.map +1 -1
  38. package/dist/esm/worker.js +7 -7
  39. package/dist/esm/worker.js.map +1 -1
  40. package/package.json +3 -3
  41. package/dist/cjs/contexts/Store.js.map +0 -1
  42. package/dist/esm/contexts/Store.js.map +0 -1
  43. /package/dist/cjs/{contexts/Store.js → store/Context.js} +0 -0
  44. /package/dist/esm/{contexts/Store.js → store/Context.js} +0 -0
@@ -11,8 +11,7 @@ Object.defineProperty(exports, "default", {
11
11
  var _jsxruntime = require("react/jsx-runtime");
12
12
  var _ink = require("ink");
13
13
  var _react = require("react");
14
- var _zustand = require("zustand");
15
- var _Store = /*#__PURE__*/ _interop_require_default(require("../contexts/Store.js"));
14
+ var _index = require("../store/index.js");
16
15
  var _ChildProcess = /*#__PURE__*/ _interop_require_default(require("./ChildProcess.js"));
17
16
  function _interop_require_default(obj) {
18
17
  return obj && obj.__esModule ? obj : {
@@ -20,20 +19,13 @@ function _interop_require_default(obj) {
20
19
  };
21
20
  }
22
21
  function App() {
23
- var store = (0, _react.useContext)(_Store.default);
24
- var appState = (0, _zustand.useStore)(store);
25
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_react.Profiler, {
26
- id: "App",
27
- onRender: function(_id, phase) {
28
- if (phase === 'update') store === null || store === void 0 ? void 0 : store.onRender();
29
- },
30
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_ink.Box, {
31
- flexDirection: "column",
32
- children: appState.processes.map(function(item) {
33
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_ChildProcess.default, {
34
- item: item
35
- }, item.id);
36
- })
22
+ var store = (0, _react.useContext)(_index.Context);
23
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_ink.Box, {
24
+ flexDirection: "column",
25
+ children: store.processes.map(function(item) {
26
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_ChildProcess.default, {
27
+ item: item
28
+ }, item.id);
37
29
  })
38
30
  });
39
31
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import { Box } from 'ink';\nimport { Profiler, useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store.js';\nimport type { AppState, ChildProcess as ChildProcessT, Store } from '../types.js';\nimport ChildProcess from './ChildProcess.js';\n\nexport default function App() {\n const store = useContext<Store>(StoreContext);\n const appState = useStore(store) as AppState;\n\n return (\n <Profiler\n id=\"App\"\n onRender={(_id, phase) => {\n if (phase === 'update') store?.onRender();\n }}\n >\n <Box flexDirection=\"column\">\n {appState.processes.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} item={item} />\n ))}\n </Box>\n </Profiler>\n );\n}\n"],"names":["App","store","useContext","StoreContext","appState","useStore","Profiler","id","onRender","_id","phase","Box","flexDirection","processes","map","item","ChildProcess"],"mappings":";;;;+BAOA;;;eAAwBA;;;;mBAPJ;qBACiB;uBACZ;4DACA;mEAEA;;;;;;AAEV,SAASA;IACtB,IAAMC,QAAQC,IAAAA,iBAAU,EAAQC,cAAY;IAC5C,IAAMC,WAAWC,IAAAA,iBAAQ,EAACJ;IAE1B,qBACE,qBAACK,eAAQ;QACPC,IAAG;QACHC,UAAU,SAACC,KAAKC;YACd,IAAIA,UAAU,UAAUT,kBAAAA,4BAAAA,MAAOO,QAAQ;QACzC;kBAEA,cAAA,qBAACG,QAAG;YAACC,eAAc;sBAChBR,SAASS,SAAS,CAACC,GAAG,CAAC,SAACC;qCACvB,qBAACC,qBAAY;oBAAeD,MAAMA;mBAAfA,KAAKR,EAAE;;;;AAKpC"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import { Box } from 'ink';\nimport { useContext } from 'react';\nimport { Context, type Store } from '../store/index.js';\nimport type { ChildProcess as ChildProcessT } from '../types.js';\nimport ChildProcess from './ChildProcess.js';\n\nexport default function App() {\n const store = useContext<Store>(Context);\n\n return (\n <Box flexDirection=\"column\">\n {store.processes.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} item={item} />\n ))}\n </Box>\n );\n}\n"],"names":["App","store","useContext","Context","Box","flexDirection","processes","map","item","ChildProcess","id"],"mappings":";;;;+BAMA;;;eAAwBA;;;;mBANJ;qBACO;qBACS;mEAEX;;;;;;AAEV,SAASA;IACtB,IAAMC,QAAQC,IAAAA,iBAAU,EAAQC,cAAO;IAEvC,qBACE,qBAACC,QAAG;QAACC,eAAc;kBAChBJ,MAAMK,SAAS,CAACC,GAAG,CAAC,SAACC;iCACpB,qBAACC,qBAAY;gBAAeD,MAAMA;eAAfA,KAAKE,EAAE;;;AAIlC"}
@@ -1,4 +1,6 @@
1
- import type { ReleaseCallback, RetainCallback } from './types.js';
1
+ import { Store } from './store/index.js';
2
+ export type RetainCallback = (app: Store) => undefined;
3
+ export type ReleaseCallback = () => undefined;
2
4
  export default function createApp(): {
3
5
  retain(fn: RetainCallback): undefined;
4
6
  release(cb: ReleaseCallback): undefined;
@@ -1,4 +1,6 @@
1
- import type { ReleaseCallback, RetainCallback } from './types.js';
1
+ import { Store } from './store/index.js';
2
+ export type RetainCallback = (app: Store) => undefined;
3
+ export type ReleaseCallback = () => undefined;
2
4
  export default function createApp(): {
3
5
  retain(fn: RetainCallback): undefined;
4
6
  release(cb: ReleaseCallback): undefined;
@@ -1,4 +1,3 @@
1
- // @ts-ignore
2
1
  "use strict";
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: true
@@ -11,105 +10,51 @@ Object.defineProperty(exports, "default", {
11
10
  });
12
11
  var _jsxruntime = require("react/jsx-runtime");
13
12
  var _ink = require("ink");
14
- var _zustand = require("zustand");
13
+ var _lodashthrottle = /*#__PURE__*/ _interop_require_default(require("lodash.throttle"));
15
14
  var _App = /*#__PURE__*/ _interop_require_default(require("./components/App.js"));
16
- var _Store = /*#__PURE__*/ _interop_require_default(require("./contexts/Store.js"));
17
- function _array_like_to_array(arr, len) {
18
- if (len == null || len > arr.length) len = arr.length;
19
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
20
- return arr2;
21
- }
22
- function _array_without_holes(arr) {
23
- if (Array.isArray(arr)) return _array_like_to_array(arr);
24
- }
15
+ var _Context = /*#__PURE__*/ _interop_require_default(require("./store/Context.js"));
16
+ var _index = require("./store/index.js");
25
17
  function _interop_require_default(obj) {
26
18
  return obj && obj.__esModule ? obj : {
27
19
  default: obj
28
20
  };
29
21
  }
30
- function _iterable_to_array(iter) {
31
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
32
- }
33
- function _non_iterable_spread() {
34
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
- }
36
- function _to_consumable_array(arr) {
37
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
38
- }
39
- function _unsupported_iterable_to_array(o, minLen) {
40
- if (!o) return;
41
- if (typeof o === "string") return _array_like_to_array(o, minLen);
42
- var n = Object.prototype.toString.call(o).slice(8, -1);
43
- if (n === "Object" && o.constructor) n = o.constructor.name;
44
- if (n === "Map" || n === "Set") return Array.from(n);
45
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
46
- }
22
+ var THROTTLE = 50;
47
23
  function createApp() {
48
24
  var refCount = 0;
49
25
  var store = null;
50
26
  var inkApp = null;
27
+ var rerender = function() {
28
+ inkApp === null || inkApp === void 0 ? void 0 : inkApp.rerender(/*#__PURE__*/ (0, _jsxruntime.jsx)(_Context.default.Provider, {
29
+ value: store,
30
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_App.default, {})
31
+ }));
32
+ };
33
+ var rerenderThrottled = (0, _lodashthrottle.default)(rerender, THROTTLE);
51
34
  return {
52
35
  retain: function retain(fn) {
53
36
  if (++refCount > 1) return fn(store);
54
37
  if (store) throw new Error('Not expecting store');
55
- store = (0, _zustand.createStore)()(function(set) {
56
- return {
57
- processes: [],
58
- addProcess: function(process1) {
59
- store.nextRenders = store.renders + 1;
60
- set(function(state) {
61
- return {
62
- processes: _to_consumable_array(state.processes).concat([
63
- process1
64
- ])
65
- };
66
- });
67
- },
68
- updateProcess: function(process1) {
69
- store.nextRenders = store.renders + 1;
70
- set(function(state) {
71
- return {
72
- processes: state.processes.map(function(x) {
73
- return x.id === process1.id ? process1 : x;
74
- })
75
- };
76
- });
77
- }
78
- };
79
- });
80
- store.nextRenders = 0;
81
- store.renders = 0;
82
- store.waiting = [];
83
- store.onRender = function() {
84
- store.renders++;
85
- if (store.renders === store.nextRenders) {
86
- while(store === null || store === void 0 ? void 0 : store.waiting.length)store.waiting.pop()();
87
- }
88
- };
89
- inkApp = (0, _ink.render)(/*#__PURE__*/ (0, _jsxruntime.jsx)(_Store.default.Provider, {
38
+ store = new _index.Store(rerenderThrottled);
39
+ inkApp = (0, _ink.render)(/*#__PURE__*/ (0, _jsxruntime.jsx)(_Context.default.Provider, {
90
40
  value: store,
91
41
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_App.default, {})
92
42
  }), {
93
43
  patchConsole: false
94
44
  });
95
- return fn(store);
45
+ fn(store);
96
46
  },
97
47
  release: function release(cb) {
98
- if (--refCount > 0) {
99
- if (store.renders === store.nextRenders) cb();
100
- else store.waiting.push(cb);
101
- return;
102
- }
48
+ if (--refCount > 0) return cb();
103
49
  if (!store) throw new Error('Expecting store');
104
- function done() {
105
- inkApp.unmount();
106
- inkApp = null;
107
- store = null;
108
- process.stdout.write('\x1b[?25h'); // show cursor
109
- cb();
110
- }
111
- if (store.renders === store.nextRenders) done();
112
- else store.waiting.push(done);
50
+ rerender();
51
+ inkApp.waitUntilExit().then(function() {
52
+ return cb();
53
+ }).catch(cb);
54
+ inkApp.unmount();
55
+ inkApp = null;
56
+ store = null;
57
+ process.stdout.write('\x1b[?25h'); // show cursor
113
58
  }
114
59
  };
115
60
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["// @ts-ignore\nimport { type Instance, render } from 'ink';\nimport { createStore } from 'zustand';\nimport App from './components/App.js';\nimport StoreContext from './contexts/Store.js';\nimport type { AppState, ReleaseCallback, RetainCallback } from './types.js';\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n\n return {\n retain(fn: RetainCallback): undefined {\n if (++refCount > 1) return fn(store);\n if (store) throw new Error('Not expecting store');\n store = createStore<AppState>()((set) => ({\n processes: [],\n addProcess: (process) => {\n store.nextRenders = store.renders + 1;\n set((state) => ({ processes: [...state.processes, process] }));\n },\n updateProcess: (process) => {\n store.nextRenders = store.renders + 1;\n set((state) => ({ processes: state.processes.map((x) => (x.id === process.id ? process : x)) }));\n },\n }));\n store.nextRenders = 0;\n store.renders = 0;\n store.waiting = [];\n store.onRender = () => {\n store.renders++;\n if (store.renders === store.nextRenders) {\n while (store?.waiting.length) store.waiting.pop()();\n }\n };\n inkApp = render(\n <StoreContext.Provider value={store}>\n <App />\n </StoreContext.Provider>,\n { patchConsole: false }\n );\n return fn(store);\n },\n release(cb: ReleaseCallback): undefined {\n if (--refCount > 0) {\n if (store.renders === store.nextRenders) cb();\n else store.waiting.push(cb);\n return;\n }\n if (!store) throw new Error('Expecting store');\n\n function done() {\n inkApp.unmount();\n inkApp = null;\n store = null;\n process.stdout.write('\\x1b[?25h'); // show cursor\n cb();\n }\n if (store.renders === store.nextRenders) done();\n else store.waiting.push(done);\n },\n };\n}\n"],"names":["createApp","refCount","store","inkApp","retain","fn","Error","createStore","set","processes","addProcess","process","nextRenders","renders","state","updateProcess","map","x","id","waiting","onRender","length","pop","render","StoreContext","Provider","value","App","patchConsole","release","cb","push","done","unmount","stdout","write"],"mappings":"AAAA,aAAa;;;;;+BAOb;;;eAAwBA;;;;mBANc;uBACV;0DACZ;4DACS;;;;;;;;;;;;;;;;;;;;;;;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W,OAAO,KAAKX,MAAMU,WAAW,EAAEkB;qBACpC5B,MAAMiB,OAAO,CAACY,IAAI,CAACD;gBACxB;YACF;YACA,IAAI,CAAC5B,OAAO,MAAM,IAAII,MAAM;YAE5B,SAAS0B;gBACP7B,OAAO8B,OAAO;gBACd9B,SAAS;gBACTD,QAAQ;gBACRS,QAAQuB,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;gBACjDL;YACF;YACA,IAAI5B,MAAMW,OAAO,KAAKX,MAAMU,WAAW,EAAEoB;iBACpC9B,MAAMiB,OAAO,CAACY,IAAI,CAACC;QAC1B;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import { type Instance, render } from 'ink';\nimport throttle from 'lodash.throttle';\nimport App from './components/App.js';\nimport StoreContext from './store/Context.js';\nimport { Store } from './store/index.js';\n\nexport type RetainCallback = (app: Store) => undefined;\nexport type ReleaseCallback = () => undefined;\n\nconst THROTTLE = 50;\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n\n const rerender = () => {\n inkApp?.rerender(\n <StoreContext.Provider value={store}>\n <App />\n </StoreContext.Provider>\n );\n };\n const rerenderThrottled = throttle(rerender, THROTTLE);\n\n return {\n retain(fn: RetainCallback): undefined {\n if (++refCount > 1) return fn(store);\n if (store) throw new Error('Not expecting store');\n\n store = new Store(rerenderThrottled);\n inkApp = render(\n <StoreContext.Provider value={store}>\n <App />\n </StoreContext.Provider>,\n { patchConsole: false }\n );\n fn(store);\n },\n release(cb: ReleaseCallback): undefined {\n if (--refCount > 0) return cb();\n if (!store) throw new Error('Expecting store');\n\n rerender();\n inkApp\n .waitUntilExit()\n .then(() => cb())\n .catch(cb);\n inkApp.unmount();\n inkApp = null;\n store = null;\n process.stdout.write('\\x1b[?25h'); // show cursor\n },\n };\n}\n"],"names":["createApp","THROTTLE","refCount","store","inkApp","rerender","StoreContext","Provider","value","App","rerenderThrottled","throttle","retain","fn","Error","Store","render","patchConsole","release","cb","waitUntilExit","then","catch","unmount","process","stdout","write"],"mappings":";;;;+BAWA;;;eAAwBA;;;;mBAXc;qEACjB;0DACL;8DACS;qBACH;;;;;;AAKtB,IAAMC,WAAW;AAEF,SAASD;IACtB,IAAIE,WAAW;IACf,IAAIC,QAAQ;IACZ,IAAIC,SAA0B;IAE9B,IAAMC,WAAW;QACfD,mBAAAA,6BAAAA,OAAQC,QAAQ,eACd,qBAACC,gBAAY,CAACC,QAAQ;YAACC,OAAOL;sBAC5B,cAAA,qBAACM,YAAG;;IAGV;IACA,IAAMC,oBAAoBC,IAAAA,uBAAQ,EAACN,UAAUJ;IAE7C,OAAO;QACLW,QAAAA,SAAAA,OAAOC,EAAkB;YACvB,IAAI,EAAEX,WAAW,GAAG,OAAOW,GAAGV;YAC9B,IAAIA,OAAO,MAAM,IAAIW,MAAM;YAE3BX,QAAQ,IAAIY,YAAK,CAACL;YAClBN,SAASY,IAAAA,WAAM,gBACb,qBAACV,gBAAY,CAACC,QAAQ;gBAACC,OAAOL;0BAC5B,cAAA,qBAACM,YAAG;gBAEN;gBAAEQ,cAAc;YAAM;YAExBJ,GAAGV;QACL;QACAe,SAAAA,SAAAA,QAAQC,EAAmB;YACzB,IAAI,EAAEjB,WAAW,GAAG,OAAOiB;YAC3B,IAAI,CAAChB,OAAO,MAAM,IAAIW,MAAM;YAE5BT;YACAD,OACGgB,aAAa,GACbC,IAAI,CAAC;uBAAMF;eACXG,KAAK,CAACH;YACTf,OAAOmB,OAAO;YACdnB,SAAS;YACTD,QAAQ;YACRqB,QAAQC,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;QACnD;IACF;AACF"}
@@ -1,3 +1,3 @@
1
- import type { Store } from '../types.js';
1
+ import type Store from './Store.js';
2
2
  declare const _default: import("react").Context<Store>;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
- import type { Store } from '../types.js';
1
+ import type Store from './Store.js';
2
2
  declare const _default: import("react").Context<Store>;
3
3
  export default _default;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/store/Context.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport type Store from './Store.js';\n\nexport default createContext<Store>(undefined);\n"],"names":["createContext","undefined"],"mappings":";;;;+BAGA;;;eAAA;;;qBAH8B;IAG9B,yBAAeA,IAAAA,oBAAa,EAAQC"}
@@ -0,0 +1,9 @@
1
+ import type { ChildProcess } from '../types.js';
2
+ export type RenderFunction = () => void;
3
+ export default class Store {
4
+ processes: ChildProcess[];
5
+ onRender: RenderFunction;
6
+ constructor(onRender: RenderFunction);
7
+ addProcess(process: ChildProcess): void;
8
+ updateProcess(process: ChildProcess): void;
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { ChildProcess } from '../types.js';
2
+ export type RenderFunction = () => void;
3
+ export default class Store {
4
+ processes: ChildProcess[];
5
+ onRender: RenderFunction;
6
+ constructor(onRender: RenderFunction);
7
+ addProcess(process: ChildProcess): void;
8
+ updateProcess(process: ChildProcess): void;
9
+ }
@@ -0,0 +1,37 @@
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.addProcess = function addProcess(process) {
26
+ this.processes.push(process);
27
+ this.onRender();
28
+ };
29
+ _proto.updateProcess = function updateProcess(process) {
30
+ this.processes = this.processes.map(function(x) {
31
+ return x.id === process.id ? process : x;
32
+ });
33
+ this.onRender();
34
+ };
35
+ return Store;
36
+ }();
37
+ /* 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/store/Store.ts"],"sourcesContent":["import type { ChildProcess } from '../types.js';\n\nexport type RenderFunction = () => void;\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 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","addProcess","process","push","updateProcess","map","x","id"],"mappings":";;;;;;;eAIqBA;;;;;;;;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,UAGC,GAHDA,SAAAA,WAAWC,OAAqB;QAC9B,IAAI,CAACF,SAAS,CAACG,IAAI,CAACD;QACpB,IAAI,CAACJ,QAAQ;IACf;IAEAM,OAAAA,aAGC,GAHDA,SAAAA,cAAcF,OAAqB;QACjC,IAAI,CAACF,SAAS,GAAG,IAAI,CAACA,SAAS,CAACK,GAAG,CAAC,SAACC;mBAAOA,EAAEC,EAAE,KAAKL,QAAQK,EAAE,GAAGL,UAAUI;;QAC5E,IAAI,CAACR,QAAQ;IACf;WAlBmBD"}
@@ -0,0 +1,2 @@
1
+ export { default as Context } from './Context.js';
2
+ export { default as Store } from './Store.js';
@@ -0,0 +1,2 @@
1
+ export { default as Context } from './Context.js';
2
+ export { default as Store } from './Store.js';
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get Context () {
13
+ return _Context.default;
14
+ },
15
+ get Store () {
16
+ return _Store.default;
17
+ }
18
+ });
19
+ var _Context = /*#__PURE__*/ _interop_require_default(require("./Context.js"));
20
+ var _Store = /*#__PURE__*/ _interop_require_default(require("./Store.js"));
21
+ function _interop_require_default(obj) {
22
+ return obj && obj.__esModule ? obj : {
23
+ default: obj
24
+ };
25
+ }
26
+ /* 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/store/index.ts"],"sourcesContent":["export { default as Context } from './Context.js';\nexport { default as Store } from './Store.js';\n"],"names":["Context","Store"],"mappings":";;;;;;;;;;;QAAoBA;eAAAA,gBAAO;;QACPC;eAAAA,cAAK;;;8DADU;4DACF"}
@@ -1,4 +1,3 @@
1
- import type { StoreApi } from 'zustand';
2
1
  export type { SpawnCallback, SpawnError, SpawnOptions, SpawnResult } from 'cross-spawn-cb';
3
2
  import type { SpawnError, SpawnResult } from 'cross-spawn-cb';
4
3
  export type TerminalOptions = {
@@ -23,13 +22,3 @@ export type ChildProcess = {
23
22
  lines: Line[];
24
23
  expanded?: boolean;
25
24
  };
26
- export interface AppState {
27
- processes: ChildProcess[];
28
- addProcess: (process: ChildProcess) => void;
29
- updateProcess: (process: ChildProcess) => void;
30
- }
31
- export interface Store extends StoreApi<AppState> {
32
- onRender: () => undefined;
33
- }
34
- export type RetainCallback = (app: Store) => undefined;
35
- export type ReleaseCallback = () => undefined;
@@ -1,4 +1,3 @@
1
- import type { StoreApi } from 'zustand';
2
1
  export type { SpawnCallback, SpawnError, SpawnOptions, SpawnResult } from 'cross-spawn-cb';
3
2
  import type { SpawnError, SpawnResult } from 'cross-spawn-cb';
4
3
  export type TerminalOptions = {
@@ -23,13 +22,3 @@ export type ChildProcess = {
23
22
  lines: Line[];
24
23
  expanded?: boolean;
25
24
  };
26
- export interface AppState {
27
- processes: ChildProcess[];
28
- addProcess: (process: ChildProcess) => void;
29
- updateProcess: (process: ChildProcess) => void;
30
- }
31
- export interface Store extends StoreApi<AppState> {
32
- onRender: () => undefined;
33
- }
34
- export type RetainCallback = (app: Store) => undefined;
35
- export type ReleaseCallback = () => undefined;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/types.ts"],"sourcesContent":["import type { StoreApi } from 'zustand';\n\nexport type { SpawnCallback, SpawnError, SpawnOptions, SpawnResult } from 'cross-spawn-cb';\n\nimport type { SpawnError, SpawnResult } from 'cross-spawn-cb';\n\nexport type TerminalOptions = {\n group?: string;\n expanded?: boolean;\n};\n\nexport type TerminalCallback = (error?: SpawnError, result?: SpawnResult) => undefined;\n\nexport const LineType = {\n stdout: 1,\n stderr: 2,\n} as const;\n\nexport type Line = {\n type: (typeof LineType)[keyof typeof LineType];\n text: string;\n};\n\nexport type State = 'running' | 'error' | 'success';\nexport type ChildProcess = {\n id: string;\n group?: string;\n title: string;\n state: State;\n lines: Line[];\n expanded?: boolean;\n};\n\nexport interface AppState {\n processes: ChildProcess[];\n addProcess: (process: ChildProcess) => void;\n updateProcess: (process: ChildProcess) => void;\n}\n\nexport interface Store extends StoreApi<AppState> {\n onRender: () => undefined;\n}\nexport type RetainCallback = (app: Store) => undefined;\nexport type ReleaseCallback = () => undefined;\n"],"names":["LineType","stdout","stderr"],"mappings":";;;;+BAaaA;;;eAAAA;;;AAAN,IAAMA,WAAW;IACtBC,QAAQ;IACRC,QAAQ;AACV"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/types.ts"],"sourcesContent":["export type { SpawnCallback, SpawnError, SpawnOptions, SpawnResult } from 'cross-spawn-cb';\n\nimport type { SpawnError, SpawnResult } from 'cross-spawn-cb';\n\nexport type TerminalOptions = {\n group?: string;\n expanded?: boolean;\n};\n\nexport type TerminalCallback = (error?: SpawnError, result?: SpawnResult) => undefined;\n\nexport const LineType = {\n stdout: 1,\n stderr: 2,\n} as const;\n\nexport type Line = {\n type: (typeof LineType)[keyof typeof LineType];\n text: string;\n};\n\nexport type State = 'running' | 'error' | 'success';\nexport type ChildProcess = {\n id: string;\n group?: string;\n title: string;\n state: State;\n lines: Line[];\n expanded?: boolean;\n};\n"],"names":["LineType","stdout","stderr"],"mappings":";;;;+BAWaA;;;eAAAA;;;AAAN,IAAMA,WAAW;IACtBC,QAAQ;IACRC,QAAQ;AACV"}
@@ -151,7 +151,7 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
151
151
  if (stdio === 'inherit') {
152
152
  terminal.retain(function(store) {
153
153
  var id = _crypto.default.randomUUID();
154
- store.getState().addProcess(_object_spread({
154
+ store.addProcess(_object_spread({
155
155
  id: id,
156
156
  title: [
157
157
  command
@@ -167,10 +167,10 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
167
167
  var queue = new _queuecb.default();
168
168
  if (cp.stdout) {
169
169
  outputs.stdout = (0, _addLines.default)(function(lines) {
170
- var item = store.getState().processes.find(function(x) {
170
+ var item = store.processes.find(function(x) {
171
171
  return x.id === id;
172
172
  });
173
- store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
173
+ store.updateProcess(_object_spread_props(_object_spread({}, item), {
174
174
  lines: item.lines.concat(lines.map(function(text) {
175
175
  return {
176
176
  type: _types.LineType.stdout,
@@ -188,10 +188,10 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
188
188
  }
189
189
  if (cp.stderr) {
190
190
  outputs.stderr = (0, _addLines.default)(function(lines) {
191
- var item = store.getState().processes.find(function(x) {
191
+ var item = store.processes.find(function(x) {
192
192
  return x.id === id;
193
193
  });
194
- store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
194
+ store.updateProcess(_object_spread_props(_object_spread({}, item), {
195
195
  lines: item.lines.concat(lines.map(function(text) {
196
196
  return {
197
197
  type: _types.LineType.stderr,
@@ -219,10 +219,10 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
219
219
  res.stderr,
220
220
  null
221
221
  ];
222
- var item = store.getState().processes.find(function(x) {
222
+ var item = store.processes.find(function(x) {
223
223
  return x.id === id;
224
224
  });
225
- store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
225
+ store.updateProcess(_object_spread_props(_object_spread({}, item), {
226
226
  state: err ? 'error' : 'success'
227
227
  }));
228
228
  // ensure rendering completes
@@ -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.js';\nimport addLines from './lib/addLines.js';\nimport concatWritable from './lib/concatWritable.js';\nimport formatArguments from './lib/formatArguments.js';\n\nimport type { SpawnError, SpawnOptions, TerminalCallback, TerminalOptions } from './types.js';\nimport { LineType } from './types.js';\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((store) => {\n const id = crypto.randomUUID();\n store.getState().addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = addLines((lines) => {\n const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, lines: item.lines.concat(lines.map((text) => ({ type: LineType.stdout, text }))) });\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 const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, lines: item.lines.concat(lines.map((text) => ({ type: LineType.stderr, text }))) });\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: 'utf8' }));\n queue.await((err?: 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 const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, state: err ? 'error' : 'success' });\n\n // ensure rendering completes\n terminal.release(() => {\n err ? callback(err) : callback(null, res);\n });\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: encoding || 'utf8' }));\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","retain","store","id","crypto","randomUUID","getState","addProcess","title","concat","formatArguments","join","state","lines","cp","crossSpawn","outputs","stdout","stderr","queue","Queue","addLines","item","processes","find","x","updateProcess","map","text","type","LineType","defer","oo","bind","pipe","spawn","worker","await","err","res","output","release","concatWritable","toString"],"mappings":";;;;+BAeA;;;eAAwBA;;;oEAf4B;6DACjC;4DACJ;8DACG;gEAEI;+DACD;qEACM;sEACC;qBAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzB,IAAMC,WAAWC,IAAAA,kBAAS;AAEX,SAASF,cAAcG,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAA0B;IACrJ,IAAQC,WAAkCH,aAAlCG,UAAUC,QAAwBJ,aAAxBI,OAAUC,uCAAcL;QAAlCG;QAAUC;;IAElB,IAAIA,UAAU,WAAW;QACvBR,SAASU,MAAM,CAAC,SAACC;YACf,IAAMC,KAAKC,eAAM,CAACC,UAAU;YAC5BH,MAAMI,QAAQ,GAAGC,UAAU,CAAC;gBAAEJ,IAAAA;gBAAIK,OAAO;oBAACf;iBAAQ,CAACgB,MAAM,CAACC,IAAAA,wBAAe,EAAChB,OAAOiB,IAAI,CAAC;gBAAMC,OAAO;gBAAWC,OAAO,EAAE;eAAKjB;YAE5H,IAAMkB,KAAKC,IAAAA,wBAAU,EAACtB,SAASC,MAAMM;YACrC,IAAMgB,UAAU;gBAAEC,QAAQ;gBAAMC,QAAQ;YAAK;YAE7C,IAAMC,QAAQ,IAAIC,gBAAK;YACvB,IAAIN,GAAGG,MAAM,EAAE;gBACbD,QAAQ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,CAACC,IAAI,CAAC,MAAMnB,GAAGI,MAAM,CAACgB,IAAI,CAAClB,QAAQE,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACAC,MAAMY,KAAK,CAACI,qBAAK,CAACC,MAAM,CAACH,IAAI,CAAC,MAAMnB,IAAI,wCAAKd;YAAWF,UAAUA,YAAY;;QAC9EqB,MAAMkB,KAAK,CAAC,SAACC;YACX,IAAMC,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAItB,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACuB,MAAM,GAAG;YACtDD,IAAIrB,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACsB,MAAM,GAAG;YACtDD,IAAIC,MAAM,GAAG;gBAACD,IAAItB,MAAM;gBAAEsB,IAAIrB,MAAM;gBAAE;aAAK;YAC3CoB,MAAMzC,SAASyC,OAAOzC,SAAS,MAAM0C;QACvC;IACF;AACF"}
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.js';\nimport addLines from './lib/addLines.js';\nimport concatWritable from './lib/concatWritable.js';\nimport formatArguments from './lib/formatArguments.js';\n\nimport type { SpawnError, SpawnOptions, TerminalCallback, TerminalOptions } from './types.js';\nimport { LineType } from './types.js';\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((store) => {\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 const item = store.processes.find((x) => x.id === id);\n store.updateProcess({ ...item, lines: item.lines.concat(lines.map((text) => ({ type: LineType.stdout, text }))) });\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 const item = store.processes.find((x) => x.id === id);\n store.updateProcess({ ...item, lines: item.lines.concat(lines.map((text) => ({ type: LineType.stderr, text }))) });\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: 'utf8' }));\n queue.await((err?: 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 const item = store.processes.find((x) => x.id === id);\n store.updateProcess({ ...item, state: err ? 'error' : 'success' });\n\n // ensure rendering completes\n terminal.release(() => {\n err ? callback(err) : callback(null, res);\n });\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: encoding || 'utf8' }));\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","retain","store","id","crypto","randomUUID","addProcess","title","concat","formatArguments","join","state","lines","cp","crossSpawn","outputs","stdout","stderr","queue","Queue","addLines","item","processes","find","x","updateProcess","map","text","type","LineType","defer","oo","bind","pipe","spawn","worker","await","err","res","output","release","concatWritable","toString"],"mappings":";;;;+BAeA;;;eAAwBA;;;oEAf4B;6DACjC;4DACJ;8DACG;gEAEI;+DACD;qEACM;sEACC;qBAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzB,IAAMC,WAAWC,IAAAA,kBAAS;AAEX,SAASF,cAAcG,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAA0B;IACrJ,IAAQC,WAAkCH,aAAlCG,UAAUC,QAAwBJ,aAAxBI,OAAUC,uCAAcL;QAAlCG;QAAUC;;IAElB,IAAIA,UAAU,WAAW;QACvBR,SAASU,MAAM,CAAC,SAACC;YACf,IAAMC,KAAKC,eAAM,CAACC,UAAU;YAC5BH,MAAMI,UAAU,CAAC;gBAAEH,IAAAA;gBAAII,OAAO;oBAACd;iBAAQ,CAACe,MAAM,CAACC,IAAAA,wBAAe,EAACf,OAAOgB,IAAI,CAAC;gBAAMC,OAAO;gBAAWC,OAAO,EAAE;eAAKhB;YAEjH,IAAMiB,KAAKC,IAAAA,wBAAU,EAACrB,SAASC,MAAMM;YACrC,IAAMe,UAAU;gBAAEC,QAAQ;gBAAMC,QAAQ;YAAK;YAE7C,IAAMC,QAAQ,IAAIC,gBAAK;YACvB,IAAIN,GAAGG,MAAM,EAAE;gBACbD,QA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AAS;gBAAO;gBAAS;aAAS;QAC/F;QACAC,MAAMY,KAAK,CAACI,qBAAK,CAACC,MAAM,CAACH,IAAI,CAAC,MAAMnB,IAAI,wCAAKb;YAAWF,UAAUA,YAAY;;QAC9EoB,MAAMkB,KAAK,CAAC,SAACC;YACX,IAAMC,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAItB,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACuB,MAAM,GAAG;YACtDD,IAAIrB,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACsB,MAAM,GAAG;YACtDD,IAAIC,MAAM,GAAG;gBAACD,IAAItB,MAAM;gBAAEsB,IAAIrB,MAAM;gBAAE;aAAK;YAC3CoB,MAAMxC,SAASwC,OAAOxC,SAAS,MAAMyC;QACvC;IACF;AACF"}
@@ -1,22 +1,14 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Box } from 'ink';
3
- import { Profiler, useContext } from 'react';
4
- import { useStore } from 'zustand';
5
- import StoreContext from '../contexts/Store.js';
3
+ import { useContext } from 'react';
4
+ import { Context } from '../store/index.js';
6
5
  import ChildProcess from './ChildProcess.js';
7
6
  export default function App() {
8
- const store = useContext(StoreContext);
9
- const appState = useStore(store);
10
- return /*#__PURE__*/ _jsx(Profiler, {
11
- id: "App",
12
- onRender: (_id, phase)=>{
13
- if (phase === 'update') store === null || store === void 0 ? void 0 : store.onRender();
14
- },
15
- children: /*#__PURE__*/ _jsx(Box, {
16
- flexDirection: "column",
17
- children: appState.processes.map((item)=>/*#__PURE__*/ _jsx(ChildProcess, {
18
- item: item
19
- }, item.id))
20
- })
7
+ const store = useContext(Context);
8
+ return /*#__PURE__*/ _jsx(Box, {
9
+ flexDirection: "column",
10
+ children: store.processes.map((item)=>/*#__PURE__*/ _jsx(ChildProcess, {
11
+ item: item
12
+ }, item.id))
21
13
  });
22
14
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import { Box } from 'ink';\nimport { Profiler, useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store.js';\nimport type { AppState, ChildProcess as ChildProcessT, Store } from '../types.js';\nimport ChildProcess from './ChildProcess.js';\n\nexport default function App() {\n const store = useContext<Store>(StoreContext);\n const appState = useStore(store) as AppState;\n\n return (\n <Profiler\n id=\"App\"\n onRender={(_id, phase) => {\n if (phase === 'update') store?.onRender();\n }}\n >\n <Box flexDirection=\"column\">\n {appState.processes.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} item={item} />\n ))}\n </Box>\n </Profiler>\n );\n}\n"],"names":["Box","Profiler","useContext","useStore","StoreContext","ChildProcess","App","store","appState","id","onRender","_id","phase","flexDirection","processes","map","item"],"mappings":";AAAA,SAASA,GAAG,QAAQ,MAAM;AAC1B,SAASC,QAAQ,EAAEC,UAAU,QAAQ,QAAQ;AAC7C,SAASC,QAAQ,QAAQ,UAAU;AACnC,OAAOC,kBAAkB,uBAAuB;AAEhD,OAAOC,kBAAkB,oBAAoB;AAE7C,eAAe,SAASC;IACtB,MAAMC,QAAQL,WAAkBE;IAChC,MAAMI,WAAWL,SAASI;IAE1B,qBACE,KAACN;QACCQ,IAAG;QACHC,UAAU,CAACC,KAAKC;YACd,IAAIA,UAAU,UAAUL,kBAAAA,4BAAAA,MAAOG,QAAQ;QACzC;kBAEA,cAAA,KAACV;YAAIa,eAAc;sBAChBL,SAASM,SAAS,CAACC,GAAG,CAAC,CAACC,qBACvB,KAACX;oBAA2BW,MAAMA;mBAAfA,KAAKP,EAAE;;;AAKpC"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import { Box } from 'ink';\nimport { useContext } from 'react';\nimport { Context, type Store } from '../store/index.js';\nimport type { ChildProcess as ChildProcessT } from '../types.js';\nimport ChildProcess from './ChildProcess.js';\n\nexport default function App() {\n const store = useContext<Store>(Context);\n\n return (\n <Box flexDirection=\"column\">\n {store.processes.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} item={item} />\n ))}\n </Box>\n );\n}\n"],"names":["Box","useContext","Context","ChildProcess","App","store","flexDirection","processes","map","item","id"],"mappings":";AAAA,SAASA,GAAG,QAAQ,MAAM;AAC1B,SAASC,UAAU,QAAQ,QAAQ;AACnC,SAASC,OAAO,QAAoB,oBAAoB;AAExD,OAAOC,kBAAkB,oBAAoB;AAE7C,eAAe,SAASC;IACtB,MAAMC,QAAQJ,WAAkBC;IAEhC,qBACE,KAACF;QAAIM,eAAc;kBAChBD,MAAME,SAAS,CAACC,GAAG,CAAC,CAACC,qBACpB,KAACN;gBAA2BM,MAAMA;eAAfA,KAAKC,EAAE;;AAIlC"}
@@ -1,4 +1,6 @@
1
- import type { ReleaseCallback, RetainCallback } from './types.js';
1
+ import { Store } from './store/index.js';
2
+ export type RetainCallback = (app: Store) => undefined;
3
+ export type ReleaseCallback = () => undefined;
2
4
  export default function createApp(): {
3
5
  retain(fn: RetainCallback): undefined;
4
6
  release(cb: ReleaseCallback): undefined;
@@ -1,68 +1,43 @@
1
- // @ts-ignore
2
1
  import { jsx as _jsx } from "react/jsx-runtime";
3
2
  import { render } from 'ink';
4
- import { createStore } from 'zustand';
3
+ import throttle from 'lodash.throttle';
5
4
  import App from './components/App.js';
6
- import StoreContext from './contexts/Store.js';
5
+ import StoreContext from './store/Context.js';
6
+ import { Store } from './store/index.js';
7
+ const THROTTLE = 50;
7
8
  export default function createApp() {
8
9
  let refCount = 0;
9
10
  let store = null;
10
11
  let inkApp = null;
12
+ const rerender = ()=>{
13
+ inkApp === null || inkApp === void 0 ? void 0 : inkApp.rerender(/*#__PURE__*/ _jsx(StoreContext.Provider, {
14
+ value: store,
15
+ children: /*#__PURE__*/ _jsx(App, {})
16
+ }));
17
+ };
18
+ const rerenderThrottled = throttle(rerender, THROTTLE);
11
19
  return {
12
20
  retain (fn) {
13
21
  if (++refCount > 1) return fn(store);
14
22
  if (store) throw new Error('Not expecting store');
15
- store = createStore()((set)=>({
16
- processes: [],
17
- addProcess: (process1)=>{
18
- store.nextRenders = store.renders + 1;
19
- set((state)=>({
20
- processes: [
21
- ...state.processes,
22
- process1
23
- ]
24
- }));
25
- },
26
- updateProcess: (process1)=>{
27
- store.nextRenders = store.renders + 1;
28
- set((state)=>({
29
- processes: state.processes.map((x)=>x.id === process1.id ? process1 : x)
30
- }));
31
- }
32
- }));
33
- store.nextRenders = 0;
34
- store.renders = 0;
35
- store.waiting = [];
36
- store.onRender = ()=>{
37
- store.renders++;
38
- if (store.renders === store.nextRenders) {
39
- while(store === null || store === void 0 ? void 0 : store.waiting.length)store.waiting.pop()();
40
- }
41
- };
23
+ store = new Store(rerenderThrottled);
42
24
  inkApp = render(/*#__PURE__*/ _jsx(StoreContext.Provider, {
43
25
  value: store,
44
26
  children: /*#__PURE__*/ _jsx(App, {})
45
27
  }), {
46
28
  patchConsole: false
47
29
  });
48
- return fn(store);
30
+ fn(store);
49
31
  },
50
32
  release (cb) {
51
- if (--refCount > 0) {
52
- if (store.renders === store.nextRenders) cb();
53
- else store.waiting.push(cb);
54
- return;
55
- }
33
+ if (--refCount > 0) return cb();
56
34
  if (!store) throw new Error('Expecting store');
57
- function done() {
58
- inkApp.unmount();
59
- inkApp = null;
60
- store = null;
61
- process.stdout.write('\x1b[?25h'); // show cursor
62
- cb();
63
- }
64
- if (store.renders === store.nextRenders) done();
65
- else store.waiting.push(done);
35
+ rerender();
36
+ inkApp.waitUntilExit().then(()=>cb()).catch(cb);
37
+ inkApp.unmount();
38
+ inkApp = null;
39
+ store = null;
40
+ process.stdout.write('\x1b[?25h'); // show cursor
66
41
  }
67
42
  };
68
43
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["// @ts-ignore\nimport { type Instance, render } from 'ink';\nimport { createStore } from 'zustand';\nimport App from './components/App.js';\nimport StoreContext from './contexts/Store.js';\nimport type { AppState, ReleaseCallback, RetainCallback } from './types.js';\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n\n return {\n retain(fn: RetainCallback): undefined {\n if (++refCount > 1) return fn(store);\n if (store) throw new Error('Not expecting store');\n store = createStore<AppState>()((set) => ({\n processes: [],\n addProcess: (process) => {\n store.nextRenders = store.renders + 1;\n set((state) => ({ processes: [...state.processes, process] }));\n },\n updateProcess: (process) => {\n store.nextRenders = store.renders + 1;\n set((state) => ({ processes: state.processes.map((x) => (x.id === process.id ? process : x)) }));\n },\n }));\n store.nextRenders = 0;\n store.renders = 0;\n store.waiting = [];\n store.onRender = () => {\n store.renders++;\n if (store.renders === store.nextRenders) {\n while (store?.waiting.length) store.waiting.pop()();\n }\n };\n inkApp = render(\n <StoreContext.Provider value={store}>\n <App />\n </StoreContext.Provider>,\n { patchConsole: false }\n );\n return fn(store);\n },\n release(cb: ReleaseCallback): undefined {\n if (--refCount > 0) {\n if (store.renders === store.nextRenders) cb();\n else store.waiting.push(cb);\n return;\n }\n if (!store) throw new Error('Expecting store');\n\n function done() {\n inkApp.unmount();\n inkApp = null;\n store = null;\n process.stdout.write('\\x1b[?25h'); // show cursor\n cb();\n }\n if (store.renders === store.nextRenders) done();\n else store.waiting.push(done);\n },\n };\n}\n"],"names":["render","createStore","App","StoreContext","createApp","refCount","store","inkApp","retain","fn","Error","set","processes","addProcess","process","nextRenders","renders","state","updateProcess","map","x","id","waiting","onRender","length","pop","Provider","value","patchConsole","release","cb","push","done","unmount","stdout","write"],"mappings":"AAAA,aAAa;;AACb,SAAwBA,MAAM,QAAQ,MAAM;AAC5C,SAASC,WAAW,QAAQ,UAAU;AACtC,OAAOC,SAAS,sBAAsB;AACtC,OAAOC,kBAAkB,sBAAsB;AAG/C,eAAe,SAASC;IACtB,IAAIC,WAAW;IACf,IAAIC,QAAQ;IACZ,IAAIC,SAA0B;IAE9B,OAAO;QACLC,QAAOC,EA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AO;gBACd1B,SAAS;gBACTD,QAAQ;gBACRQ,QAAQoB,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;gBACjDL;YACF;YACA,IAAIxB,MAAMU,OAAO,KAAKV,MAAMS,WAAW,EAAEiB;iBACpC1B,MAAMgB,OAAO,CAACS,IAAI,CAACC;QAC1B;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import { type Instance, render } from 'ink';\nimport throttle from 'lodash.throttle';\nimport App from './components/App.js';\nimport StoreContext from './store/Context.js';\nimport { Store } from './store/index.js';\n\nexport type RetainCallback = (app: Store) => undefined;\nexport type ReleaseCallback = () => undefined;\n\nconst THROTTLE = 50;\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n\n const rerender = () => {\n inkApp?.rerender(\n <StoreContext.Provider value={store}>\n <App />\n </StoreContext.Provider>\n );\n };\n const rerenderThrottled = throttle(rerender, THROTTLE);\n\n return {\n retain(fn: RetainCallback): undefined {\n if (++refCount > 1) return fn(store);\n if (store) throw new Error('Not expecting store');\n\n store = new Store(rerenderThrottled);\n inkApp = render(\n <StoreContext.Provider value={store}>\n <App />\n </StoreContext.Provider>,\n { patchConsole: false }\n );\n fn(store);\n },\n release(cb: ReleaseCallback): undefined {\n if (--refCount > 0) return cb();\n if (!store) throw new Error('Expecting store');\n\n rerender();\n inkApp\n .waitUntilExit()\n .then(() => cb())\n .catch(cb);\n inkApp.unmount();\n inkApp = null;\n store = null;\n process.stdout.write('\\x1b[?25h'); // show cursor\n },\n };\n}\n"],"names":["render","throttle","App","StoreContext","Store","THROTTLE","createApp","refCount","store","inkApp","rerender","Provider","value","rerenderThrottled","retain","fn","Error","patchConsole","release","cb","waitUntilExit","then","catch","unmount","process","stdout","write"],"mappings":";AAAA,SAAwBA,MAAM,QAAQ,MAAM;AAC5C,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,SAAS,sBAAsB;AACtC,OAAOC,kBAAkB,qBAAqB;AAC9C,SAASC,KAAK,QAAQ,mBAAmB;AAKzC,MAAMC,WAAW;AAEjB,eAAe,SAASC;IACtB,IAAIC,WAAW;IACf,IAAIC,QAAQ;IACZ,IAAIC,SAA0B;IAE9B,MAAMC,WAAW;QACfD,mBAAAA,6BAAAA,OAAQC,QAAQ,eACd,KAACP,aAAaQ,QAAQ;YAACC,OAAOJ;sBAC5B,cAAA,KAACN;;IAGP;IACA,MAAMW,oBAAoBZ,SAASS,UAAUL;IAE7C,OAAO;QACLS,QAAOC,EAAkB;YACvB,IAAI,EAAER,WAAW,GAAG,OAAOQ,GAAGP;YAC9B,IAAIA,OAAO,MAAM,IAAIQ,MAAM;YAE3BR,QAAQ,IAAIJ,MAAMS;YAClBJ,SAAST,qBACP,KAACG,aAAaQ,QAAQ;gBAACC,OAAOJ;0BAC5B,cAAA,KAACN;gBAEH;gBAAEe,cAAc;YAAM;YAExBF,GAAGP;QACL;QACAU,SAAQC,EAAmB;YACzB,IAAI,EAAEZ,WAAW,GAAG,OAAOY;YAC3B,IAAI,CAACX,OAAO,MAAM,IAAIQ,MAAM;YAE5BN;YACAD,OACGW,aAAa,GACbC,IAAI,CAAC,IAAMF,MACXG,KAAK,CAACH;YACTV,OAAOc,OAAO;YACdd,SAAS;YACTD,QAAQ;YACRgB,QAAQC,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;QACnD;IACF;AACF"}
@@ -1,3 +1,3 @@
1
- import type { Store } from '../types.js';
1
+ import type Store from './Store.js';
2
2
  declare const _default: import("react").Context<Store>;
3
3
  export default _default;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/store/Context.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport type Store from './Store.js';\n\nexport default createContext<Store>(undefined);\n"],"names":["createContext","undefined"],"mappings":"AAAA,SAASA,aAAa,QAAQ,QAAQ;AAGtC,6BAAeA,cAAqBC,WAAW"}
@@ -0,0 +1,9 @@
1
+ import type { ChildProcess } from '../types.js';
2
+ export type RenderFunction = () => void;
3
+ export default class Store {
4
+ processes: ChildProcess[];
5
+ onRender: RenderFunction;
6
+ constructor(onRender: RenderFunction);
7
+ addProcess(process: ChildProcess): void;
8
+ updateProcess(process: ChildProcess): void;
9
+ }
@@ -0,0 +1,16 @@
1
+ class Store {
2
+ addProcess(process) {
3
+ this.processes.push(process);
4
+ this.onRender();
5
+ }
6
+ updateProcess(process) {
7
+ this.processes = this.processes.map((x)=>x.id === process.id ? process : x);
8
+ this.onRender();
9
+ }
10
+ constructor(onRender){
11
+ if (!onRender) throw new Error('missing on render');
12
+ this.processes = [];
13
+ this.onRender = onRender;
14
+ }
15
+ }
16
+ export { Store as default };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/store/Store.ts"],"sourcesContent":["import type { ChildProcess } from '../types.js';\n\nexport type RenderFunction = () => void;\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 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","addProcess","process","processes","push","onRender","updateProcess","map","x","id","Error"],"mappings":"AAIe,MAAMA;IAUnBC,WAAWC,OAAqB,EAAQ;QACtC,IAAI,CAACC,SAAS,CAACC,IAAI,CAACF;QACpB,IAAI,CAACG,QAAQ;IACf;IAEAC,cAAcJ,OAAqB,EAAQ;QACzC,IAAI,CAACC,SAAS,GAAG,IAAI,CAACA,SAAS,CAACI,GAAG,CAAC,CAACC,IAAOA,EAAEC,EAAE,KAAKP,QAAQO,EAAE,GAAGP,UAAUM;QAC5E,IAAI,CAACH,QAAQ;IACf;IAdA,YAAYA,QAAwB,CAAE;QACpC,IAAI,CAACA,UAAU,MAAM,IAAIK,MAAM;QAC/B,IAAI,CAACP,SAAS,GAAG,EAAE;QACnB,IAAI,CAACE,QAAQ,GAAGA;IAClB;AAWF;AAnBA,SAAqBL,mBAmBpB"}
@@ -0,0 +1,2 @@
1
+ export { default as Context } from './Context.js';
2
+ export { default as Store } from './Store.js';
@@ -0,0 +1,2 @@
1
+ export { default as Context } from './Context.js';
2
+ export { default as Store } from './Store.js';
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/store/index.ts"],"sourcesContent":["export { default as Context } from './Context.js';\nexport { default as Store } from './Store.js';\n"],"names":["default","Context","Store"],"mappings":"AAAA,SAASA,WAAWC,OAAO,QAAQ,eAAe;AAClD,SAASD,WAAWE,KAAK,QAAQ,aAAa"}
@@ -1,4 +1,3 @@
1
- import type { StoreApi } from 'zustand';
2
1
  export type { SpawnCallback, SpawnError, SpawnOptions, SpawnResult } from 'cross-spawn-cb';
3
2
  import type { SpawnError, SpawnResult } from 'cross-spawn-cb';
4
3
  export type TerminalOptions = {
@@ -23,13 +22,3 @@ export type ChildProcess = {
23
22
  lines: Line[];
24
23
  expanded?: boolean;
25
24
  };
26
- export interface AppState {
27
- processes: ChildProcess[];
28
- addProcess: (process: ChildProcess) => void;
29
- updateProcess: (process: ChildProcess) => void;
30
- }
31
- export interface Store extends StoreApi<AppState> {
32
- onRender: () => undefined;
33
- }
34
- export type RetainCallback = (app: Store) => undefined;
35
- export type ReleaseCallback = () => undefined;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/types.ts"],"sourcesContent":["import type { StoreApi } from 'zustand';\n\nexport type { SpawnCallback, SpawnError, SpawnOptions, SpawnResult } from 'cross-spawn-cb';\n\nimport type { SpawnError, SpawnResult } from 'cross-spawn-cb';\n\nexport type TerminalOptions = {\n group?: string;\n expanded?: boolean;\n};\n\nexport type TerminalCallback = (error?: SpawnError, result?: SpawnResult) => undefined;\n\nexport const LineType = {\n stdout: 1,\n stderr: 2,\n} as const;\n\nexport type Line = {\n type: (typeof LineType)[keyof typeof LineType];\n text: string;\n};\n\nexport type State = 'running' | 'error' | 'success';\nexport type ChildProcess = {\n id: string;\n group?: string;\n title: string;\n state: State;\n lines: Line[];\n expanded?: boolean;\n};\n\nexport interface AppState {\n processes: ChildProcess[];\n addProcess: (process: ChildProcess) => void;\n updateProcess: (process: ChildProcess) => void;\n}\n\nexport interface Store extends StoreApi<AppState> {\n onRender: () => undefined;\n}\nexport type RetainCallback = (app: Store) => undefined;\nexport type ReleaseCallback = () => undefined;\n"],"names":["LineType","stdout","stderr"],"mappings":"AAaA,OAAO,MAAMA,WAAW;IACtBC,QAAQ;IACRC,QAAQ;AACV,EAAW"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/types.ts"],"sourcesContent":["export type { SpawnCallback, SpawnError, SpawnOptions, SpawnResult } from 'cross-spawn-cb';\n\nimport type { SpawnError, SpawnResult } from 'cross-spawn-cb';\n\nexport type TerminalOptions = {\n group?: string;\n expanded?: boolean;\n};\n\nexport type TerminalCallback = (error?: SpawnError, result?: SpawnResult) => undefined;\n\nexport const LineType = {\n stdout: 1,\n stderr: 2,\n} as const;\n\nexport type Line = {\n type: (typeof LineType)[keyof typeof LineType];\n text: string;\n};\n\nexport type State = 'running' | 'error' | 'success';\nexport type ChildProcess = {\n id: string;\n group?: string;\n title: string;\n state: State;\n lines: Line[];\n expanded?: boolean;\n};\n"],"names":["LineType","stdout","stderr"],"mappings":"AAWA,OAAO,MAAMA,WAAW;IACtBC,QAAQ;IACRC,QAAQ;AACV,EAAW"}
@@ -95,7 +95,7 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
95
95
  if (stdio === 'inherit') {
96
96
  terminal.retain((store)=>{
97
97
  const id = crypto.randomUUID();
98
- store.getState().addProcess(_object_spread({
98
+ store.addProcess(_object_spread({
99
99
  id,
100
100
  title: [
101
101
  command
@@ -111,8 +111,8 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
111
111
  const queue = new Queue();
112
112
  if (cp.stdout) {
113
113
  outputs.stdout = addLines((lines)=>{
114
- const item = store.getState().processes.find((x)=>x.id === id);
115
- store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
114
+ const item = store.processes.find((x)=>x.id === id);
115
+ store.updateProcess(_object_spread_props(_object_spread({}, item), {
116
116
  lines: item.lines.concat(lines.map((text)=>({
117
117
  type: LineType.stdout,
118
118
  text
@@ -128,8 +128,8 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
128
128
  }
129
129
  if (cp.stderr) {
130
130
  outputs.stderr = addLines((lines)=>{
131
- const item = store.getState().processes.find((x)=>x.id === id);
132
- store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
131
+ const item = store.processes.find((x)=>x.id === id);
132
+ store.updateProcess(_object_spread_props(_object_spread({}, item), {
133
133
  lines: item.lines.concat(lines.map((text)=>({
134
134
  type: LineType.stderr,
135
135
  text
@@ -155,8 +155,8 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
155
155
  res.stderr,
156
156
  null
157
157
  ];
158
- const item = store.getState().processes.find((x)=>x.id === id);
159
- store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
158
+ const item = store.processes.find((x)=>x.id === id);
159
+ store.updateProcess(_object_spread_props(_object_spread({}, item), {
160
160
  state: err ? 'error' : 'success'
161
161
  }));
162
162
  // ensure rendering completes
@@ -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.js';\nimport addLines from './lib/addLines.js';\nimport concatWritable from './lib/concatWritable.js';\nimport formatArguments from './lib/formatArguments.js';\n\nimport type { SpawnError, SpawnOptions, TerminalCallback, TerminalOptions } from './types.js';\nimport { LineType } from './types.js';\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((store) => {\n const id = crypto.randomUUID();\n store.getState().addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = addLines((lines) => {\n const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, lines: item.lines.concat(lines.map((text) => ({ type: LineType.stdout, text }))) });\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 const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, lines: item.lines.concat(lines.map((text) => ({ type: LineType.stderr, text }))) });\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: 'utf8' }));\n queue.await((err?: 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 const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, state: err ? 'error' : 'success' });\n\n // ensure rendering completes\n terminal.release(() => {\n err ? callback(err) : callback(null, res);\n });\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: encoding || 'utf8' }));\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","retain","store","id","randomUUID","getState","addProcess","title","concat","join","state","lines","cp","outputs","stdout","stderr","queue","item","processes","find","x","updateProcess","map","text","type","defer","bind","pipe","worker","await","err","res","output","release","toString"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,SAASC,UAAU,QAA0B,iBAAiB;AACrE,OAAOC,YAAY,SAAS;AAC5B,OAAOC,QAAQ,SAAS;AACxB,OAAOC,WAAW,WAAW;AAE7B,OAAOC,eAAe,iBAAiB;AACvC,OAAOC,cAAc,oBAAoB;AACzC,OAAOC,oBAAoB,0BAA0B;AACrD,OAAOC,qBAAqB,2BAA2B;AAGvD,SAASC,QAAQ,QAAQ,aAAa;AAEtC,MAAMC,WAAWL;AAEjB,eAAe,SAASM,cAAcC,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAA0B;IACrJ,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAgB,GAAGJ,cAAdK,uCAAcL;QAAlCG;QAAUC;;IAEl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MS,KAAK,CAACzC,GAAG0C,IAAI,CAAC,MAAMd,GAAGE,MAAM,CAACa,IAAI,CAACd,QAAQC,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACA,IAAIF,GAAGG,MAAM,EAAE;YACbF,QAAQE,MAAM,GAAG3B,eAAe,CAAC4C;gBAC/BnB,QAAQE,MAAM,CAACiB,MAAM,GAAGA,OAAOE,QAAQ,CAACpC,YAAY;YACtD;YACAkB,MAAMS,KAAK,CAACzC,GAAG0C,IAAI,CAAC,MAAMd,GAAGG,MAAM,CAACY,IAAI,CAACd,QAAQE,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACAC,MAAMS,KAAK,CAAC5C,MAAM+C,MAAM,CAACF,IAAI,CAAC,MAAMd,IAAI,wCAAKZ;YAAWF,UAAUA,YAAY;;QAC9EkB,MAAMa,KAAK,CAAC,CAACC;YACX,MAAMC,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAIjB,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACkB,MAAM,GAAG;YACtDD,IAAIhB,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACiB,MAAM,GAAG;YACtDD,IAAIC,MAAM,GAAG;gBAACD,IAAIjB,MAAM;gBAAEiB,IAAIhB,MAAM;gBAAE;aAAK;YAC3Ce,MAAMjC,SAASiC,OAAOjC,SAAS,MAAMkC;QACvC;IACF;AACF"}
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.js';\nimport addLines from './lib/addLines.js';\nimport concatWritable from './lib/concatWritable.js';\nimport formatArguments from './lib/formatArguments.js';\n\nimport type { SpawnError, SpawnOptions, TerminalCallback, TerminalOptions } from './types.js';\nimport { LineType } from './types.js';\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((store) => {\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 const item = store.processes.find((x) => x.id === id);\n store.updateProcess({ ...item, lines: item.lines.concat(lines.map((text) => ({ type: LineType.stdout, text }))) });\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 const item = store.processes.find((x) => x.id === id);\n store.updateProcess({ ...item, lines: item.lines.concat(lines.map((text) => ({ type: LineType.stderr, text }))) });\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: 'utf8' }));\n queue.await((err?: 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 const item = store.processes.find((x) => x.id === id);\n store.updateProcess({ ...item, state: err ? 'error' : 'success' });\n\n // ensure rendering completes\n terminal.release(() => {\n err ? callback(err) : callback(null, res);\n });\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: encoding || 'utf8' }));\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","retain","store","id","randomUUID","addProcess","title","concat","join","state","lines","cp","outputs","stdout","stderr","queue","item","processes","find","x","updateProcess","map","text","type","defer","bind","pipe","worker","await","err","res","output","release","toString"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,SAASC,UAAU,QAA0B,iBAAiB;AACrE,OAAOC,YAAY,SAAS;AAC5B,OAAOC,QAAQ,SAAS;AACxB,OAAOC,WAAW,WAAW;AAE7B,OAAOC,eAAe,iBAAiB;AACvC,OAAOC,cAAc,oBAAoB;AACzC,OAAOC,oBAAoB,0BAA0B;AACrD,OAAOC,qBAAqB,2BAA2B;AAGvD,SAASC,QAAQ,QAAQ,aAAa;AAEtC,MAAMC,WAAWL;AAEjB,eAAe,SAASM,cAAcC,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAA0B;IACrJ,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAgB,GAAGJ,cAAdK,uCAAcL;QAAlCG;QAAUC;;IAElB,IAAIA,UAAU,WAAW;QAC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;QAC/F;QACA,IAAIF,GAAGG,MAAM,EAAE;YACbF,QAAQE,MAAM,GAAG1B,eAAe,CAAC2C;gBAC/BnB,QAAQE,MAAM,CAACiB,MAAM,GAAGA,OAAOE,QAAQ,CAACnC,YAAY;YACtD;YACAiB,MAAMS,KAAK,CAACxC,GAAGyC,IAAI,CAAC,MAAMd,GAAGG,MAAM,CAACY,IAAI,CAACd,QAAQE,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACAC,MAAMS,KAAK,CAAC3C,MAAM8C,MAAM,CAACF,IAAI,CAAC,MAAMd,IAAI,wCAAKX;YAAWF,UAAUA,YAAY;;QAC9EiB,MAAMa,KAAK,CAAC,CAACC;YACX,MAAMC,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAIjB,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACkB,MAAM,GAAG;YACtDD,IAAIhB,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACiB,MAAM,GAAG;YACtDD,IAAIC,MAAM,GAAG;gBAACD,IAAIjB,MAAM;gBAAEiB,IAAIhB,MAAM;gBAAE;aAAK;YAC3Ce,MAAMhC,SAASgC,OAAOhC,SAAS,MAAMiC;QACvC;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spawn-term",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Formats spawn with for terminal grouping",
5
5
  "keywords": [
6
6
  "spawn",
@@ -43,10 +43,10 @@
43
43
  "ansi-colors": "^4.1.3",
44
44
  "cross-spawn-cb": "^2.2.9",
45
45
  "ink": "^6.0.0",
46
+ "lodash.throttle": "^4.1.1",
46
47
  "on-one": "^0.1.8",
47
48
  "queue-cb": "^1.5.3",
48
- "react": "^19.1.0",
49
- "zustand": "^5.0.5"
49
+ "react": "^19.1.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/mocha": "*",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/contexts/Store.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport type { Store } from '../types.js';\n\nexport default createContext<Store>(undefined);\n"],"names":["createContext","undefined"],"mappings":";;;;+BAGA;;;eAAA;;;qBAH8B;IAG9B,yBAAeA,IAAAA,oBAAa,EAAQC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/contexts/Store.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport type { Store } from '../types.js';\n\nexport default createContext<Store>(undefined);\n"],"names":["createContext","undefined"],"mappings":"AAAA,SAASA,aAAa,QAAQ,QAAQ;AAGtC,6BAAeA,cAAqBC,WAAW"}