spawn-term 1.0.0 → 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 (63) 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/index-cjs.d.cts +3 -1
  8. package/dist/cjs/index-cjs.d.ts +3 -1
  9. package/dist/cjs/index-cjs.js.map +1 -1
  10. package/dist/cjs/index-esm.d.cts +1 -2
  11. package/dist/cjs/index-esm.d.ts +1 -2
  12. package/dist/cjs/index-esm.js +2 -62
  13. package/dist/cjs/index-esm.js.map +1 -1
  14. package/dist/cjs/spawnTerminal.d.cts +2 -0
  15. package/dist/cjs/spawnTerminal.d.ts +2 -0
  16. package/dist/cjs/spawnTerminal.js +72 -0
  17. package/dist/cjs/spawnTerminal.js.map +1 -0
  18. package/dist/cjs/{contexts/Store.d.cts → store/Context.d.cts} +1 -1
  19. package/dist/cjs/{contexts/Store.d.ts → store/Context.d.ts} +1 -1
  20. package/dist/cjs/store/Context.js.map +1 -0
  21. package/dist/cjs/store/Store.d.cts +9 -0
  22. package/dist/cjs/store/Store.d.ts +9 -0
  23. package/dist/cjs/store/Store.js +37 -0
  24. package/dist/cjs/store/Store.js.map +1 -0
  25. package/dist/cjs/store/index.d.cts +2 -0
  26. package/dist/cjs/store/index.d.ts +2 -0
  27. package/dist/cjs/store/index.js +26 -0
  28. package/dist/cjs/store/index.js.map +1 -0
  29. package/dist/cjs/types.d.cts +0 -11
  30. package/dist/cjs/types.d.ts +0 -11
  31. package/dist/cjs/types.js.map +1 -1
  32. package/dist/cjs/worker.js +7 -7
  33. package/dist/cjs/worker.js.map +1 -1
  34. package/dist/esm/components/App.js +8 -16
  35. package/dist/esm/components/App.js.map +1 -1
  36. package/dist/esm/createApp.d.ts +3 -1
  37. package/dist/esm/createApp.js +20 -45
  38. package/dist/esm/createApp.js.map +1 -1
  39. package/dist/esm/index-cjs.d.ts +3 -1
  40. package/dist/esm/index-cjs.js.map +1 -1
  41. package/dist/esm/index-esm.d.ts +1 -2
  42. package/dist/esm/index-esm.js +2 -17
  43. package/dist/esm/index-esm.js.map +1 -1
  44. package/dist/esm/spawnTerminal.d.ts +2 -0
  45. package/dist/esm/spawnTerminal.js +16 -0
  46. package/dist/esm/spawnTerminal.js.map +1 -0
  47. package/dist/esm/{contexts/Store.d.ts → store/Context.d.ts} +1 -1
  48. package/dist/esm/store/Context.js.map +1 -0
  49. package/dist/esm/store/Store.d.ts +9 -0
  50. package/dist/esm/store/Store.js +16 -0
  51. package/dist/esm/store/Store.js.map +1 -0
  52. package/dist/esm/store/index.d.ts +2 -0
  53. package/dist/esm/store/index.js +2 -0
  54. package/dist/esm/store/index.js.map +1 -0
  55. package/dist/esm/types.d.ts +0 -11
  56. package/dist/esm/types.js.map +1 -1
  57. package/dist/esm/worker.js +7 -7
  58. package/dist/esm/worker.js.map +1 -1
  59. package/package.json +3 -3
  60. package/dist/cjs/contexts/Store.js.map +0 -1
  61. package/dist/esm/contexts/Store.js.map +0 -1
  62. /package/dist/cjs/{contexts/Store.js → store/Context.js} +0 -0
  63. /package/dist/esm/{contexts/Store.js → store/Context.js} +0 -0
@@ -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,O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,QAAQC,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACA,IAAIH,GAAGI,MAAM,EAAE;YACbF,QAAQE,MAAM,GAAGwB,IAAAA,uBAAc,EAAC,SAACF;gBAC/BxB,QAAQE,MAAM,CAACsB,MAAM,GAAGA,OAAOG,QAAQ,CAAC7C,YAAY;YACtD;YACAqB,MAAMY,KAAK,CAACC,cAAE,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,EAAC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AE;YACbF,QAAQE,MAAM,GAAGwB,IAAAA,uBAAc,EAAC,SAACF;gBAC/BxB,QAAQE,MAAM,CAACsB,MAAM,GAAGA,OAAOG,QAAQ,CAAC5C,YAAY;YACtD;YACAoB,MAAMY,KAAK,CAACC,cAAE,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,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","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AOnB,GAAGH;QACZ;QACAuB,SAAQC,EAAmB;YACzB,IAAI,EAAEzB,WAAW,GAAG;gBAClB,IAAIC,MAAMU,OAAO,KAAKV,MAAMS,WAAW,EAAEe;qBACpCxB,MAAMgB,OAAO,CAACS,IAAI,CAACD;gBACxB;YACF;YACA,IAAI,CAACxB,OAAO,MAAM,IAAII,MAAM;YAE5B,SAASsB;gBACPzB,OAAO0B,OAAO;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,4 +1,6 @@
1
1
  export { default as figures } from './lib/figures.js';
2
2
  export { default as formatArguments } from './lib/formatArguments.js';
3
3
  export * from './types.js';
4
- export default undefined;
4
+ import type { default as spawnTerminal } from './spawnTerminal.js';
5
+ declare const _default: typeof spawnTerminal;
6
+ export default _default;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/index-cjs.ts"],"sourcesContent":["export { default as figures } from './lib/figures.js';\nexport { default as formatArguments } from './lib/formatArguments.js';\nexport * from './types.js';\nexport default undefined;\n"],"names":["default","figures","formatArguments","undefined"],"mappings":"AAAA,SAASA,WAAWC,OAAO,QAAQ,mBAAmB;AACtD,SAASD,WAAWE,eAAe,QAAQ,2BAA2B;AACtE,cAAc,aAAa;AAC3B,eAAeC,UAAU"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/index-cjs.ts"],"sourcesContent":["export { default as figures } from './lib/figures.js';\nexport { default as formatArguments } from './lib/formatArguments.js';\nexport * from './types.js';\n\nimport type { default as spawnTerminal } from './spawnTerminal.js';\nexport default undefined as typeof spawnTerminal;\n"],"names":["default","figures","formatArguments","undefined"],"mappings":"AAAA,SAASA,WAAWC,OAAO,QAAQ,mBAAmB;AACtD,SAASD,WAAWE,eAAe,QAAQ,2BAA2B;AACtE,cAAc,aAAa;AAG3B,eAAeC,UAAkC"}
@@ -1,7 +1,6 @@
1
- import type { SpawnOptions, SpawnResult, TerminalCallback, TerminalOptions } from './types.js';
2
- declare function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options?: TerminalOptions | TerminalCallback, callback?: TerminalCallback): undefined | Promise<SpawnResult>;
3
1
  export { default as figures } from './lib/figures.js';
4
2
  export { default as formatArguments } from './lib/formatArguments.js';
5
3
  export * from './types.js';
4
+ import { default as spawnTerminal } from './spawnTerminal.js';
6
5
  declare const _default: typeof spawnTerminal;
7
6
  export default _default;
@@ -1,21 +1,6 @@
1
- function worker(command, args, spawnOptions, options, callback) {
2
- import('./worker.js').then((fn)=>{
3
- fn.default(command, args, spawnOptions, options, callback);
4
- }).catch(callback);
5
- }
6
- function spawnTerminal(command, args, spawnOptions, options, callback) {
7
- if (typeof options === 'function') {
8
- callback = options;
9
- options = {};
10
- }
11
- options = options || {};
12
- if (typeof callback === 'function') return worker(command, args, spawnOptions, options, callback);
13
- return new Promise((resolve, reject)=>worker(command, args, spawnOptions, options, (err, result)=>{
14
- err ? reject(err) : resolve(result);
15
- }));
16
- }
17
- const major = +process.versions.node.split('.')[0];
18
1
  export { default as figures } from './lib/figures.js';
19
2
  export { default as formatArguments } from './lib/formatArguments.js';
20
3
  export * from './types.js';
4
+ const major = +process.versions.node.split('.')[0];
5
+ import { default as spawnTerminal } from './spawnTerminal.js';
21
6
  export default major > 14 ? spawnTerminal : undefined;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/index-esm.ts"],"sourcesContent":["import type { SpawnOptions, SpawnResult, TerminalCallback, TerminalOptions } from './types.js';\n\nfunction worker(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n import('./worker.js')\n .then((fn) => {\n fn.default(command, args, spawnOptions, options, callback);\n })\n .catch(callback);\n}\n\nfunction spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options?: TerminalOptions | TerminalCallback, callback?: TerminalCallback): undefined | Promise<SpawnResult> {\n if (typeof options === 'function') {\n callback = options as TerminalCallback;\n options = {};\n }\n options = options || {};\n\n if (typeof callback === 'function') return worker(command, args, spawnOptions, options, callback as TerminalCallback);\n return new Promise((resolve, reject) =>\n worker(command, args, spawnOptions, options, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n}\n\nconst major = +process.versions.node.split('.')[0];\n\nexport { default as figures } from './lib/figures.js';\nexport { default as formatArguments } from './lib/formatArguments.js';\nexport * from './types.js';\nexport default major > 14 ? spawnTerminal : undefined;\n"],"names":["worker","command","args","spawnOptions","options","callback","then","fn","default","catch","spawnTerminal","Promise","resolve","reject","err","result","major","process","versions","node","split","figures","formatArguments","undefined"],"mappings":"AAEA,SAASA,OAAOC,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAA0B;IAC/H,MAAM,CAAC,eACJC,IAAI,CAAC,CAACC;QACLA,GAAGC,OAAO,CAACP,SAASC,MAAMC,cAAcC,SAASC;IACnD,GACCI,KAAK,CAACJ;AACX;AAEA,SAASK,cAAcT,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAA4C,EAAEC,QAA2B;IAC3J,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOL,OAAOC,SAASC,MAAMC,cAAcC,SAASC;IACxF,OAAO,IAAIM,QAAQ,CAACC,SAASC,SAC3Bb,OAAOC,SAASC,MAAMC,cAAcC,SAAS,CAACU,KAAKC;YACjDD,MAAMD,OAAOC,OAAOF,QAAQG;QAC9B;AAEJ;AAEA,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAElD,SAASZ,WAAWa,OAAO,QAAQ,mBAAmB;AACtD,SAASb,WAAWc,eAAe,QAAQ,2BAA2B;AACtE,cAAc,aAAa;AAC3B,eAAeN,QAAQ,KAAKN,gBAAgBa,UAAU"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/index-esm.ts"],"sourcesContent":["export { default as figures } from './lib/figures.js';\nexport { default as formatArguments } from './lib/formatArguments.js';\nexport * from './types.js';\n\nconst major = +process.versions.node.split('.')[0];\n\nimport { default as spawnTerminal } from './spawnTerminal.js';\nexport default major > 14 ? spawnTerminal : (undefined as typeof spawnTerminal);\n"],"names":["default","figures","formatArguments","major","process","versions","node","split","spawnTerminal","undefined"],"mappings":"AAAA,SAASA,WAAWC,OAAO,QAAQ,mBAAmB;AACtD,SAASD,WAAWE,eAAe,QAAQ,2BAA2B;AACtE,cAAc,aAAa;AAE3B,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAElD,SAASP,WAAWQ,aAAa,QAAQ,qBAAqB;AAC9D,eAAeL,QAAQ,KAAKK,gBAAiBC,UAAmC"}
@@ -0,0 +1,2 @@
1
+ import type { SpawnOptions, SpawnResult, TerminalCallback, TerminalOptions } from './types.js';
2
+ export default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options?: TerminalOptions | TerminalCallback, callback?: TerminalCallback): undefined | Promise<SpawnResult>;
@@ -0,0 +1,16 @@
1
+ function worker(command, args, spawnOptions, options, callback) {
2
+ import('./worker.js').then((fn)=>{
3
+ fn.default(command, args, spawnOptions, options, callback);
4
+ }).catch(callback);
5
+ }
6
+ export default function spawnTerminal(command, args, spawnOptions, options, callback) {
7
+ if (typeof options === 'function') {
8
+ callback = options;
9
+ options = {};
10
+ }
11
+ options = options || {};
12
+ if (typeof callback === 'function') return worker(command, args, spawnOptions, options, callback);
13
+ return new Promise((resolve, reject)=>worker(command, args, spawnOptions, options, (err, result)=>{
14
+ err ? reject(err) : resolve(result);
15
+ }));
16
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/spawnTerminal.ts"],"sourcesContent":["import type { SpawnOptions, SpawnResult, TerminalCallback, TerminalOptions } from './types.js';\n\nfunction worker(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n import('./worker.js')\n .then((fn) => {\n fn.default(command, args, spawnOptions, options, callback);\n })\n .catch(callback);\n}\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options?: TerminalOptions | TerminalCallback, callback?: TerminalCallback): undefined | Promise<SpawnResult> {\n if (typeof options === 'function') {\n callback = options as TerminalCallback;\n options = {};\n }\n options = options || {};\n\n if (typeof callback === 'function') return worker(command, args, spawnOptions, options, callback as TerminalCallback);\n return new Promise((resolve, reject) =>\n worker(command, args, spawnOptions, options, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n}\n"],"names":["worker","command","args","spawnOptions","options","callback","then","fn","default","catch","spawnTerminal","Promise","resolve","reject","err","result"],"mappings":"AAEA,SAASA,OAAOC,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAA0B;IAC/H,MAAM,CAAC,eACJC,IAAI,CAAC,CAACC;QACLA,GAAGC,OAAO,CAACP,SAASC,MAAMC,cAAcC,SAASC;IACnD,GACCI,KAAK,CAACJ;AACX;AAEA,eAAe,SAASK,cAAcT,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAA4C,EAAEC,QAA2B;IAC1K,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOL,OAAOC,SAASC,MAAMC,cAAcC,SAASC;IACxF,OAAO,IAAIM,QAAQ,CAACC,SAASC,SAC3Bb,OAAOC,SAASC,MAAMC,cAAcC,SAAS,CAACU,KAAKC;YACjDD,MAAMD,OAAOC,OAAOF,QAAQG;QAC9B;AAEJ"}
@@ -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;;IAElB,IAAIA,UAAU,WAAW;QACvBR,SAASU,MAAM,CAAC,CAACC;YACf,MAAMC,KAAKpB,OAAOqB,UAAU;YAC5BF,MAAMG,QA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AS;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;QACvBR,SAASU,MAAM,CAAC,CAACC;YACf,MAAMC,KAAKpB,OAAOqB,UAAU;YAC5BF,MAAMG,UAAU,CAAC;gBAAEF;gBAAI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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.0",
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"}