spawn-term 1.1.6 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/App.js +17 -3
- package/dist/cjs/components/App.js.map +1 -1
- package/dist/cjs/createApp.js +25 -33
- package/dist/cjs/createApp.js.map +1 -1
- package/dist/cjs/index-esm.js +1 -1
- package/dist/cjs/index-esm.js.map +1 -1
- package/dist/cjs/lib/figures.js +1 -1
- package/dist/cjs/lib/figures.js.map +1 -1
- package/dist/cjs/spawnTerminal.js +3 -0
- package/dist/cjs/spawnTerminal.js.map +1 -1
- package/dist/cjs/src/components/App.d.ts +1 -5
- package/dist/cjs/src/createApp.d.ts +4 -5
- package/dist/cjs/src/state/processStore.d.ts +21 -0
- package/dist/cjs/state/processStore.js +143 -0
- package/dist/cjs/state/processStore.js.map +1 -0
- package/dist/cjs/worker.js +70 -113
- package/dist/cjs/worker.js.map +1 -1
- package/dist/esm/components/App.js +18 -3
- package/dist/esm/components/App.js.map +1 -1
- package/dist/esm/createApp.js +26 -32
- package/dist/esm/createApp.js.map +1 -1
- package/dist/esm/index-esm.js +1 -1
- package/dist/esm/index-esm.js.map +1 -1
- package/dist/esm/spawnTerminal.js +3 -0
- package/dist/esm/spawnTerminal.js.map +1 -1
- package/dist/esm/src/components/App.d.ts +1 -5
- package/dist/esm/src/createApp.d.ts +4 -5
- package/dist/esm/src/state/processStore.d.ts +21 -0
- package/dist/esm/state/processStore.js +84 -0
- package/dist/esm/state/processStore.js.map +1 -0
- package/dist/esm/worker.js +59 -96
- package/dist/esm/worker.js.map +1 -1
- package/package.json +2 -2
- package/dist/cjs/src/state/Store.d.ts +0 -11
- package/dist/cjs/state/Store.js +0 -40
- package/dist/cjs/state/Store.js.map +0 -1
- package/dist/esm/src/state/Store.d.ts +0 -11
- package/dist/esm/state/Store.js +0 -19
- package/dist/esm/state/Store.js.map +0 -1
package/dist/cjs/worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["import spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport crypto from 'crypto';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp.ts';\nimport addLines from './lib/addLines.ts';\nimport concatWritable from './lib/concatWritable.ts';\nimport formatArguments from './lib/formatArguments.ts';\n\nimport type { SpawnError, SpawnOptions, TerminalCallback, TerminalOptions } from './types.ts';\nimport { LineType } from './types.ts';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n if (stdio === 'inherit') {\n terminal.retain(
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["import spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport crypto from 'crypto';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp.ts';\nimport addLines from './lib/addLines.ts';\nimport concatWritable from './lib/concatWritable.ts';\nimport formatArguments from './lib/formatArguments.ts';\n\nimport type { SpawnError, SpawnOptions, TerminalCallback, TerminalOptions } from './types.ts';\nimport { LineType } from './types.ts';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n if (stdio === 'inherit') {\n const store = terminal.retain();\n const id = crypto.randomUUID();\n store.addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = addLines((lines) => {\n store.appendLines(\n id,\n lines.map((text) => ({ type: LineType.stdout, text }))\n );\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = addLines((lines) => {\n store.appendLines(\n id,\n lines.map((text) => ({ type: LineType.stderr, text }))\n );\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, csOptions));\n queue.await((err?: SpawnError) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n store.updateProcess(id, { state: err ? 'error' : 'success' });\n\n terminal.release(() => {\n err ? callback(err) : callback(null, res);\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, csOptions));\n queue.await((err?: SpawnError) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n err ? callback(err) : callback(null, res);\n });\n }\n}\n"],"names":["spawnTerminal","terminal","createApp","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","store","retain","id","crypto","randomUUID","addProcess","title","concat","formatArguments","join","state","lines","cp","crossSpawn","outputs","stdout","stderr","queue","Queue","addLines","appendLines","map","text","type","LineType","defer","oo","bind","pipe","spawn","worker","await","err","res","output","updateProcess","release","concatWritable","toString"],"mappings":";;;;+BAeA;;;eAAwBA;;;oEAf4B;6DACjC;4DACJ;8DACG;kEAEI;iEACD;uEACM;wEACC;uBAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzB,IAAMC,WAAWC,IAAAA,oBAAS;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;QACvB,IAAME,QAAQV,SAASW,MAAM;QAC7B,IAAMC,KAAKC,eAAM,CAACC,UAAU;QAC5BJ,MAAMK,UAAU,CAAC;YAAEH,IAAAA;YAAII,OAAO;gBAACd;aAAQ,CAACe,MAAM,CAACC,IAAAA,0BAAe,EAACf,OAAOgB,IAAI,CAAC;YAAMC,OAAO;YAAWC,OAAO,EAAE;WAAKhB;QAEjH,IAAMiB,KAAKC,IAAAA,wBAAU,EAACrB,SAASC,MAAMM;QACrC,IAAMe,UAAU;YAAEC,QAAQ;YAAMC,QAAQ;QAAK;QAE7C,IAAMC,QAAQ,IAAIC,gBAAK;QACvB,IAAIN,GAAGG,MAAM,EAAE;YACbD,QAAQC,MAAM,GAAGI,IAAAA,mBAAQ,EAAC,SAACR;gBACzBX,MAAMoB,WAAW,CACflB,IACAS,MAAMU,GAAG,CAAC,SAACC;2BAAU;wBAAEC,MAAMC,iBAAQ,CAACT,MAAM;wBAAEO,MAAAA;oBAAK;;YAEvD;YACAL,MAAMQ,KAAK,CAACC,cAAE,CAACC,IAAI,CAAC,MAAMf,GAAGG,MAAM,CAACa,IAAI,CAACd,QAAQC,MAAM,GAAG;gBAAC;g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,CAACmB,MAAM,GAAGA,OAAOI,QAAQ,CAACzC,YAAY;YACtD;YACAoB,OAAMQ,KAAK,CAACC,cAAE,CAACC,IAAI,CAAC,MAAMf,IAAGG,MAAM,CAACa,IAAI,CAACd,SAAQC,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACA,IAAIH,IAAGI,MAAM,EAAE;YACbF,SAAQE,MAAM,GAAGqB,IAAAA,yBAAc,EAAC,SAACH;gBAC/BpB,SAAQE,MAAM,CAACkB,MAAM,GAAGA,OAAOI,QAAQ,CAACzC,YAAY;YACtD;YACAoB,OAAMQ,KAAK,CAACC,cAAE,CAACC,IAAI,CAAC,MAAMf,IAAGI,MAAM,CAACY,IAAI,CAACd,SAAQE,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACAC,OAAMQ,KAAK,CAACI,qBAAK,CAACC,MAAM,CAACH,IAAI,CAAC,MAAMf,KAAIb;QACxCkB,OAAMc,KAAK,CAAC,SAACC;YACX,IAAMC,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAIlB,MAAM,GAAGD,SAAQC,MAAM,GAAGD,SAAQC,MAAM,CAACmB,MAAM,GAAG;YACtDD,IAAIjB,MAAM,GAAGF,SAAQE,MAAM,GAAGF,SAAQE,MAAM,CAACkB,MAAM,GAAG;YACtDD,IAAIC,MAAM,GAAG;gBAACD,IAAIlB,MAAM;gBAAEkB,IAAIjB,MAAM;gBAAE;aAAK;YAC3CgB,MAAMpC,SAASoC,OAAOpC,SAAS,MAAMqC;QACvC;IACF;AACF"}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Box } from 'ink';
|
|
2
|
+
import { Box, useApp } from 'ink';
|
|
3
|
+
import { useEffect, useSyncExternalStore } from 'react';
|
|
4
|
+
import { processStore } from '../state/processStore.js';
|
|
3
5
|
import ChildProcess from './ChildProcess.js';
|
|
4
|
-
export default function App(
|
|
6
|
+
export default function App() {
|
|
7
|
+
const { exit } = useApp();
|
|
8
|
+
// Subscribe to process state
|
|
9
|
+
const processes = useSyncExternalStore(processStore.subscribe, processStore.getSnapshot);
|
|
10
|
+
// Handle exit signal
|
|
11
|
+
const shouldExit = useSyncExternalStore(processStore.subscribe, processStore.getShouldExit);
|
|
12
|
+
useEffect(()=>{
|
|
13
|
+
if (shouldExit) {
|
|
14
|
+
exit();
|
|
15
|
+
}
|
|
16
|
+
}, [
|
|
17
|
+
shouldExit,
|
|
18
|
+
exit
|
|
19
|
+
]);
|
|
5
20
|
return /*#__PURE__*/ _jsx(Box, {
|
|
6
21
|
flexDirection: "column",
|
|
7
|
-
children:
|
|
22
|
+
children: processes.map((item)=>/*#__PURE__*/ _jsx(ChildProcess, {
|
|
8
23
|
item: item
|
|
9
24
|
}, item.id))
|
|
10
25
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import { Box } from 'ink';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import { Box, useApp } from 'ink';\nimport { useEffect, useSyncExternalStore } from 'react';\nimport { processStore } from '../state/processStore.ts';\nimport type { ChildProcess as ChildProcessT } from '../types.ts';\nimport ChildProcess from './ChildProcess.ts';\n\nexport default function App(): React.JSX.Element {\n const { exit } = useApp();\n\n // Subscribe to process state\n const processes = useSyncExternalStore(processStore.subscribe, processStore.getSnapshot);\n\n // Handle exit signal\n const shouldExit = useSyncExternalStore(processStore.subscribe, processStore.getShouldExit);\n\n useEffect(() => {\n if (shouldExit) {\n exit();\n }\n }, [shouldExit, exit]);\n\n return (\n <Box flexDirection=\"column\">\n {processes.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} item={item} />\n ))}\n </Box>\n );\n}\n"],"names":["Box","useApp","useEffect","useSyncExternalStore","processStore","ChildProcess","App","exit","processes","subscribe","getSnapshot","shouldExit","getShouldExit","flexDirection","map","item","id"],"mappings":";AAAA,SAASA,GAAG,EAAEC,MAAM,QAAQ,MAAM;AAClC,SAASC,SAAS,EAAEC,oBAAoB,QAAQ,QAAQ;AACxD,SAASC,YAAY,QAAQ,2BAA2B;AAExD,OAAOC,kBAAkB,oBAAoB;AAE7C,eAAe,SAASC;IACtB,MAAM,EAAEC,IAAI,EAAE,GAAGN;IAEjB,6BAA6B;IAC7B,MAAMO,YAAYL,qBAAqBC,aAAaK,SAAS,EAAEL,aAAaM,WAAW;IAEvF,qBAAqB;IACrB,MAAMC,aAAaR,qBAAqBC,aAAaK,SAAS,EAAEL,aAAaQ,aAAa;IAE1FV,UAAU;QACR,IAAIS,YAAY;YACdJ;QACF;IACF,GAAG;QAACI;QAAYJ;KAAK;IAErB,qBACE,KAACP;QAAIa,eAAc;kBAChBL,UAAUM,GAAG,CAAC,CAACC,qBACd,KAACV;gBAA2BU,MAAMA;eAAfA,KAAKC,EAAE;;AAIlC"}
|
package/dist/esm/createApp.js
CHANGED
|
@@ -1,44 +1,38 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render } from 'ink';
|
|
3
|
-
import throttle from 'lodash.throttle';
|
|
4
3
|
import App from './components/App.js';
|
|
5
|
-
import {
|
|
6
|
-
const THROTTLE = 100;
|
|
4
|
+
import { processStore } from './state/processStore.js';
|
|
7
5
|
export default function createApp() {
|
|
8
6
|
let refCount = 0;
|
|
9
|
-
let store = null;
|
|
10
7
|
let inkApp = null;
|
|
11
|
-
let previousData = null;
|
|
12
|
-
const rerender = throttle(()=>{
|
|
13
|
-
if (!inkApp || !store) return;
|
|
14
|
-
if (store.data() === previousData) return;
|
|
15
|
-
previousData = store.data();
|
|
16
|
-
inkApp.rerender(/*#__PURE__*/ _jsx(App, {
|
|
17
|
-
store: store
|
|
18
|
-
}));
|
|
19
|
-
}, THROTTLE, {
|
|
20
|
-
leading: false
|
|
21
|
-
});
|
|
22
8
|
return {
|
|
23
|
-
retain (
|
|
24
|
-
if (++refCount > 1) return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
store: store
|
|
29
|
-
}));
|
|
30
|
-
fn(store);
|
|
9
|
+
retain () {
|
|
10
|
+
if (++refCount > 1) return processStore;
|
|
11
|
+
// Render once - React handles all subsequent updates via useSyncExternalStore
|
|
12
|
+
inkApp = render(/*#__PURE__*/ _jsx(App, {}));
|
|
13
|
+
return processStore;
|
|
31
14
|
},
|
|
32
|
-
release (
|
|
33
|
-
if (--refCount > 0)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
inkApp
|
|
38
|
-
|
|
15
|
+
release (callback) {
|
|
16
|
+
if (--refCount > 0) {
|
|
17
|
+
callback();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!inkApp) throw new Error('Expecting inkApp');
|
|
21
|
+
// Signal exit to React component, provide callback for after cleanup
|
|
22
|
+
processStore.signalExit(()=>{
|
|
23
|
+
processStore.reset();
|
|
24
|
+
process.stdout.write('\x1b[?25h'); // show cursor
|
|
25
|
+
callback();
|
|
26
|
+
});
|
|
27
|
+
// Wait for Ink to finish, then call the callback
|
|
28
|
+
inkApp.waitUntilExit().then(()=>{
|
|
29
|
+
const cb = processStore.getExitCallback();
|
|
30
|
+
cb === null || cb === void 0 ? void 0 : cb();
|
|
31
|
+
}).catch(()=>{
|
|
32
|
+
const cb = processStore.getExitCallback();
|
|
33
|
+
cb === null || cb === void 0 ? void 0 : cb();
|
|
34
|
+
});
|
|
39
35
|
inkApp = null;
|
|
40
|
-
store = null;
|
|
41
|
-
process.stdout.write('\x1b[?25h'); // show cursor
|
|
42
36
|
}
|
|
43
37
|
};
|
|
44
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import { render } from 'ink';\nimport App from './components/App.ts';\nimport { type ProcessStore, processStore } from './state/processStore.ts';\n\nexport type ReleaseCallback = () => void;\n\nexport default function createApp() {\n let refCount = 0;\n let inkApp: ReturnType<typeof render> | null = null;\n\n return {\n retain(): ProcessStore {\n if (++refCount > 1) return processStore;\n\n // Render once - React handles all subsequent updates via useSyncExternalStore\n inkApp = render(<App />);\n return processStore;\n },\n\n release(callback: ReleaseCallback): void {\n if (--refCount > 0) {\n callback();\n return;\n }\n if (!inkApp) throw new Error('Expecting inkApp');\n\n // Signal exit to React component, provide callback for after cleanup\n processStore.signalExit(() => {\n processStore.reset();\n process.stdout.write('\\x1b[?25h'); // show cursor\n callback();\n });\n\n // Wait for Ink to finish, then call the callback\n inkApp\n .waitUntilExit()\n .then(() => {\n const cb = processStore.getExitCallback();\n cb?.();\n })\n .catch(() => {\n const cb = processStore.getExitCallback();\n cb?.();\n });\n\n inkApp = null;\n },\n };\n}\n"],"names":["render","App","processStore","createApp","refCount","inkApp","retain","release","callback","Error","signalExit","reset","process","stdout","write","waitUntilExit","then","cb","getExitCallback","catch"],"mappings":";AAAA,SAASA,MAAM,QAAQ,MAAM;AAC7B,OAAOC,SAAS,sBAAsB;AACtC,SAA4BC,YAAY,QAAQ,0BAA0B;AAI1E,eAAe,SAASC;IACtB,IAAIC,WAAW;IACf,IAAIC,SAA2C;IAE/C,OAAO;QACLC;YACE,IAAI,EAAEF,WAAW,GAAG,OAAOF;YAE3B,8EAA8E;YAC9EG,SAASL,qBAAO,KAACC;YACjB,OAAOC;QACT;QAEAK,SAAQC,QAAyB;YAC/B,IAAI,EAAEJ,WAAW,GAAG;gBAClBI;gBACA;YACF;YACA,IAAI,CAACH,QAAQ,MAAM,IAAII,MAAM;YAE7B,qEAAqE;YACrEP,aAAaQ,UAAU,CAAC;gBACtBR,aAAaS,KAAK;gBAClBC,QAAQC,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;gBACjDN;YACF;YAEA,iDAAiD;YACjDH,OACGU,aAAa,GACbC,IAAI,CAAC;gBACJ,MAAMC,KAAKf,aAAagB,eAAe;gBACvCD,eAAAA,yBAAAA;YACF,GACCE,KAAK,CAAC;gBACL,MAAMF,KAAKf,aAAagB,eAAe;gBACvCD,eAAAA,yBAAAA;YACF;YAEFZ,SAAS;QACX;IACF;AACF"}
|
package/dist/esm/index-esm.js
CHANGED
|
@@ -3,4 +3,4 @@ export { default as formatArguments } from './lib/formatArguments.js';
|
|
|
3
3
|
export * from './types.js';
|
|
4
4
|
const major = +process.versions.node.split('.')[0];
|
|
5
5
|
import { default as spawnTerminal } from './spawnTerminal.js';
|
|
6
|
-
export default major >
|
|
6
|
+
export default major > 18 ? spawnTerminal : undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/index-esm.ts"],"sourcesContent":["export { default as figures } from './lib/figures.ts';\nexport { default as formatArguments } from './lib/formatArguments.ts';\nexport * from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\n\nimport { default as spawnTerminal } from './spawnTerminal.ts';\nexport default major >
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/index-esm.ts"],"sourcesContent":["export { default as figures } from './lib/figures.ts';\nexport { default as formatArguments } from './lib/formatArguments.ts';\nexport * from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\n\nimport { default as spawnTerminal } from './spawnTerminal.ts';\nexport default major > 18 ? spawnTerminal : (undefined as typeof spawnTerminal);\n"],"names":["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"}
|
|
@@ -4,6 +4,9 @@ function worker(command, args, spawnOptions, options, callback) {
|
|
|
4
4
|
}).catch(callback);
|
|
5
5
|
}
|
|
6
6
|
export default function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
7
|
+
if (spawnOptions.stdio === 'inherit' && spawnOptions.encoding) {
|
|
8
|
+
throw new Error("Options 'stdio: inherit' and 'encoding' are mutually exclusive. Use 'stdio: inherit' to display output, or 'encoding' to collect output.");
|
|
9
|
+
}
|
|
7
10
|
if (typeof options === 'function') {
|
|
8
11
|
callback = options;
|
|
9
12
|
options = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/spawnTerminal.ts"],"sourcesContent":["import type { SpawnOptions, SpawnResult, TerminalCallback, TerminalOptions } from './types.ts';\n\nfunction worker(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n import('./worker.js')\n .then((fn) => {\n fn.default(command, args, spawnOptions, options, callback);\n })\n .catch(callback);\n}\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options?: TerminalOptions | TerminalCallback, callback?: TerminalCallback): undefined | Promise<SpawnResult> {\n if (typeof options === 'function') {\n callback = options as TerminalCallback;\n options = {};\n }\n options = options || {};\n\n if (typeof callback === 'function') return worker(command, args, spawnOptions, options, callback as TerminalCallback);\n return new Promise((resolve, reject) =>\n worker(command, args, spawnOptions, options, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n}\n"],"names":["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,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/spawnTerminal.ts"],"sourcesContent":["import type { SpawnOptions, SpawnResult, TerminalCallback, TerminalOptions } from './types.ts';\n\nfunction worker(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n import('./worker.js')\n .then((fn) => {\n fn.default(command, args, spawnOptions, options, callback);\n })\n .catch(callback);\n}\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options?: TerminalOptions | TerminalCallback, callback?: TerminalCallback): undefined | Promise<SpawnResult> {\n if (spawnOptions.stdio === 'inherit' && spawnOptions.encoding) {\n throw new Error(\"Options 'stdio: inherit' and 'encoding' are mutually exclusive. Use 'stdio: inherit' to display output, or 'encoding' to collect output.\");\n }\n\n if (typeof options === 'function') {\n callback = options as TerminalCallback;\n options = {};\n }\n options = options || {};\n\n if (typeof callback === 'function') return worker(command, args, spawnOptions, options, callback as TerminalCallback);\n return new Promise((resolve, reject) =>\n worker(command, args, spawnOptions, options, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n}\n"],"names":["worker","command","args","spawnOptions","options","callback","then","fn","default","catch","spawnTerminal","stdio","encoding","Error","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,IAAIF,aAAaQ,KAAK,KAAK,aAAaR,aAAaS,QAAQ,EAAE;QAC7D,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAI,OAAOT,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,IAAIS,QAAQ,CAACC,SAASC,SAC3BhB,OAAOC,SAASC,MAAMC,cAAcC,SAAS,CAACa,KAAKC;YACjDD,MAAMD,OAAOC,OAAOF,QAAQG;QAC9B;AAEJ"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type
|
|
3
|
-
export type ReleaseCallback = () => undefined;
|
|
1
|
+
import { type ProcessStore } from './state/processStore.js';
|
|
2
|
+
export type ReleaseCallback = () => void;
|
|
4
3
|
export default function createApp(): {
|
|
5
|
-
retain(
|
|
6
|
-
release(
|
|
4
|
+
retain(): ProcessStore;
|
|
5
|
+
release(callback: ReleaseCallback): void;
|
|
7
6
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ChildProcess, Line } from '../types.js';
|
|
2
|
+
type Listener = () => void;
|
|
3
|
+
declare class ProcessStore {
|
|
4
|
+
private processes;
|
|
5
|
+
private listeners;
|
|
6
|
+
private shouldExit;
|
|
7
|
+
private exitCallback;
|
|
8
|
+
subscribe: (listener: Listener) => (() => void);
|
|
9
|
+
getSnapshot: () => ChildProcess[];
|
|
10
|
+
addProcess(process: ChildProcess): void;
|
|
11
|
+
updateProcess(id: string, update: Partial<ChildProcess>): void;
|
|
12
|
+
appendLines(id: string, newLines: Line[]): void;
|
|
13
|
+
getProcess(id: string): ChildProcess | undefined;
|
|
14
|
+
signalExit(callback: () => void): void;
|
|
15
|
+
getShouldExit: () => boolean;
|
|
16
|
+
getExitCallback: () => (() => void) | null;
|
|
17
|
+
reset(): void;
|
|
18
|
+
private notify;
|
|
19
|
+
}
|
|
20
|
+
export declare const processStore: ProcessStore;
|
|
21
|
+
export type { ProcessStore };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _object_spread(target) {
|
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_define_property(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
29
|
+
class ProcessStore {
|
|
30
|
+
// Mutations - Ink handles render throttling at 30 FPS
|
|
31
|
+
addProcess(process) {
|
|
32
|
+
this.processes = [
|
|
33
|
+
...this.processes,
|
|
34
|
+
process
|
|
35
|
+
];
|
|
36
|
+
this.notify();
|
|
37
|
+
}
|
|
38
|
+
updateProcess(id, update) {
|
|
39
|
+
this.processes = this.processes.map((p)=>p.id === id ? _object_spread({}, p, update) : p);
|
|
40
|
+
this.notify();
|
|
41
|
+
}
|
|
42
|
+
appendLines(id, newLines) {
|
|
43
|
+
const process = this.processes.find((p)=>p.id === id);
|
|
44
|
+
if (process) {
|
|
45
|
+
this.updateProcess(id, {
|
|
46
|
+
lines: process.lines.concat(newLines)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
getProcess(id) {
|
|
51
|
+
return this.processes.find((p)=>p.id === id);
|
|
52
|
+
}
|
|
53
|
+
// Exit signaling
|
|
54
|
+
signalExit(callback) {
|
|
55
|
+
this.shouldExit = true;
|
|
56
|
+
this.exitCallback = callback;
|
|
57
|
+
this.notify();
|
|
58
|
+
}
|
|
59
|
+
reset() {
|
|
60
|
+
this.processes = [];
|
|
61
|
+
this.shouldExit = false;
|
|
62
|
+
this.exitCallback = null;
|
|
63
|
+
}
|
|
64
|
+
notify() {
|
|
65
|
+
this.listeners.forEach((l)=>{
|
|
66
|
+
l();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
constructor(){
|
|
70
|
+
this.processes = [];
|
|
71
|
+
this.listeners = new Set();
|
|
72
|
+
this.shouldExit = false;
|
|
73
|
+
this.exitCallback = null;
|
|
74
|
+
// useSyncExternalStore API
|
|
75
|
+
this.subscribe = (listener)=>{
|
|
76
|
+
this.listeners.add(listener);
|
|
77
|
+
return ()=>this.listeners.delete(listener);
|
|
78
|
+
};
|
|
79
|
+
this.getSnapshot = ()=>this.processes;
|
|
80
|
+
this.getShouldExit = ()=>this.shouldExit;
|
|
81
|
+
this.getExitCallback = ()=>this.exitCallback;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export const processStore = new ProcessStore();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/state/processStore.ts"],"sourcesContent":["import type { ChildProcess, Line } from '../types.ts';\n\ntype Listener = () => void;\n\nclass ProcessStore {\n private processes: ChildProcess[] = [];\n private listeners = new Set<Listener>();\n private shouldExit = false;\n private exitCallback: (() => void) | null = null;\n\n // useSyncExternalStore API\n subscribe = (listener: Listener): (() => void) => {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n };\n\n getSnapshot = (): ChildProcess[] => this.processes;\n\n // Mutations - Ink handles render throttling at 30 FPS\n addProcess(process: ChildProcess): void {\n this.processes = [...this.processes, process];\n this.notify();\n }\n\n updateProcess(id: string, update: Partial<ChildProcess>): void {\n this.processes = this.processes.map((p) => (p.id === id ? { ...p, ...update } : p));\n this.notify();\n }\n\n appendLines(id: string, newLines: Line[]): void {\n const process = this.processes.find((p) => p.id === id);\n if (process) {\n this.updateProcess(id, { lines: process.lines.concat(newLines) });\n }\n }\n\n getProcess(id: string): ChildProcess | undefined {\n return this.processes.find((p) => p.id === id);\n }\n\n // Exit signaling\n signalExit(callback: () => void): void {\n this.shouldExit = true;\n this.exitCallback = callback;\n this.notify();\n }\n\n getShouldExit = (): boolean => this.shouldExit;\n getExitCallback = (): (() => void) | null => this.exitCallback;\n\n reset(): void {\n this.processes = [];\n this.shouldExit = false;\n this.exitCallback = null;\n }\n\n private notify(): void {\n this.listeners.forEach((l) => {\n l();\n });\n }\n}\n\nexport const processStore = new ProcessStore();\nexport type { ProcessStore };\n"],"names":["ProcessStore","addProcess","process","processes","notify","updateProcess","id","update","map","p","appendLines","newLines","find","lines","concat","getProcess","signalExit","callback","shouldExit","exitCallback","reset","listeners","forEach","l","Set","subscribe","listener","add","delete","getSnapshot","getShouldExit","getExitCallback","processStore"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAMA;IAcJ,sDAAsD;IACtDC,WAAWC,OAAqB,EAAQ;QACtC,IAAI,CAACC,SAAS,GAAG;eAAI,IAAI,CAACA,SAAS;YAAED;SAAQ;QAC7C,IAAI,CAACE,MAAM;IACb;IAEAC,cAAcC,EAAU,EAAEC,MAA6B,EAAQ;QAC7D,IAAI,CAACJ,SAAS,GAAG,IAAI,CAACA,SAAS,CAACK,GAAG,CAAC,CAACC,IAAOA,EAAEH,EAAE,KAAKA,KAAK,mBAAKG,GAAMF,UAAWE;QAChF,IAAI,CAACL,MAAM;IACb;IAEAM,YAAYJ,EAAU,EAAEK,QAAgB,EAAQ;QAC9C,MAAMT,UAAU,IAAI,CAACC,SAAS,CAACS,IAAI,CAAC,CAACH,IAAMA,EAAEH,EAAE,KAAKA;QACpD,IAAIJ,SAAS;YACX,IAAI,CAACG,aAAa,CAACC,IAAI;gBAAEO,OAAOX,QAAQW,KAAK,CAACC,MAAM,CAACH;YAAU;QACjE;IACF;IAEAI,WAAWT,EAAU,EAA4B;QAC/C,OAAO,IAAI,CAACH,SAAS,CAACS,IAAI,CAAC,CAACH,IAAMA,EAAEH,EAAE,KAAKA;IAC7C;IAEA,iBAAiB;IACjBU,WAAWC,QAAoB,EAAQ;QACrC,IAAI,CAACC,UAAU,GAAG;QAClB,IAAI,CAACC,YAAY,GAAGF;QACpB,IAAI,CAACb,MAAM;IACb;IAKAgB,QAAc;QACZ,IAAI,CAACjB,SAAS,GAAG,EAAE;QACnB,IAAI,CAACe,UAAU,GAAG;QAClB,IAAI,CAACC,YAAY,GAAG;IACtB;IAEQf,SAAe;QACrB,IAAI,CAACiB,SAAS,CAACC,OAAO,CAAC,CAACC;YACtBA;QACF;IACF;;aAvDQpB,YAA4B,EAAE;aAC9BkB,YAAY,IAAIG;aAChBN,aAAa;aACbC,eAAoC;QAE5C,2BAA2B;aAC3BM,YAAY,CAACC;YACX,IAAI,CAACL,SAAS,CAACM,GAAG,CAACD;YACnB,OAAO,IAAM,IAAI,CAACL,SAAS,CAACO,MAAM,CAACF;QACrC;aAEAG,cAAc,IAAsB,IAAI,CAAC1B,SAAS;aA+BlD2B,gBAAgB,IAAe,IAAI,CAACZ,UAAU;aAC9Ca,kBAAkB,IAA2B,IAAI,CAACZ,YAAY;;AAahE;AAEA,OAAO,MAAMa,eAAe,IAAIhC,eAAe"}
|
package/dist/esm/worker.js
CHANGED
|
@@ -26,30 +26,6 @@ function _object_spread(target) {
|
|
|
26
26
|
}
|
|
27
27
|
return target;
|
|
28
28
|
}
|
|
29
|
-
function ownKeys(object, enumerableOnly) {
|
|
30
|
-
var keys = Object.keys(object);
|
|
31
|
-
if (Object.getOwnPropertySymbols) {
|
|
32
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
33
|
-
if (enumerableOnly) {
|
|
34
|
-
symbols = symbols.filter(function(sym) {
|
|
35
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
keys.push.apply(keys, symbols);
|
|
39
|
-
}
|
|
40
|
-
return keys;
|
|
41
|
-
}
|
|
42
|
-
function _object_spread_props(target, source) {
|
|
43
|
-
source = source != null ? source : {};
|
|
44
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
45
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
46
|
-
} else {
|
|
47
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
48
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return target;
|
|
52
|
-
}
|
|
53
29
|
function _object_without_properties(source, excluded) {
|
|
54
30
|
if (source == null) return {};
|
|
55
31
|
var target = _object_without_properties_loose(source, excluded);
|
|
@@ -93,76 +69,65 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
93
69
|
"stdio"
|
|
94
70
|
]);
|
|
95
71
|
if (stdio === 'inherit') {
|
|
96
|
-
terminal.retain(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
res.stderr,
|
|
156
|
-
null
|
|
157
|
-
];
|
|
158
|
-
const item = store.processes.find((x)=>x.id === id);
|
|
159
|
-
store.updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
160
|
-
state: err ? 'error' : 'success'
|
|
161
|
-
}));
|
|
162
|
-
// ensure rendering completes
|
|
163
|
-
terminal.release(()=>{
|
|
164
|
-
err ? callback(err) : callback(null, res);
|
|
165
|
-
});
|
|
72
|
+
const store = terminal.retain();
|
|
73
|
+
const id = crypto.randomUUID();
|
|
74
|
+
store.addProcess(_object_spread({
|
|
75
|
+
id,
|
|
76
|
+
title: [
|
|
77
|
+
command
|
|
78
|
+
].concat(formatArguments(args)).join(' '),
|
|
79
|
+
state: 'running',
|
|
80
|
+
lines: []
|
|
81
|
+
}, options));
|
|
82
|
+
const cp = crossSpawn(command, args, csOptions);
|
|
83
|
+
const outputs = {
|
|
84
|
+
stdout: null,
|
|
85
|
+
stderr: null
|
|
86
|
+
};
|
|
87
|
+
const queue = new Queue();
|
|
88
|
+
if (cp.stdout) {
|
|
89
|
+
outputs.stdout = addLines((lines)=>{
|
|
90
|
+
store.appendLines(id, lines.map((text)=>({
|
|
91
|
+
type: LineType.stdout,
|
|
92
|
+
text
|
|
93
|
+
})));
|
|
94
|
+
});
|
|
95
|
+
queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
96
|
+
'error',
|
|
97
|
+
'end',
|
|
98
|
+
'close',
|
|
99
|
+
'finish'
|
|
100
|
+
]));
|
|
101
|
+
}
|
|
102
|
+
if (cp.stderr) {
|
|
103
|
+
outputs.stderr = addLines((lines)=>{
|
|
104
|
+
store.appendLines(id, lines.map((text)=>({
|
|
105
|
+
type: LineType.stderr,
|
|
106
|
+
text
|
|
107
|
+
})));
|
|
108
|
+
});
|
|
109
|
+
queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
110
|
+
'error',
|
|
111
|
+
'end',
|
|
112
|
+
'close',
|
|
113
|
+
'finish'
|
|
114
|
+
]));
|
|
115
|
+
}
|
|
116
|
+
queue.defer(spawn.worker.bind(null, cp, csOptions));
|
|
117
|
+
queue.await((err)=>{
|
|
118
|
+
const res = err ? err : {};
|
|
119
|
+
res.stdout = outputs.stdout ? outputs.stdout.output : null;
|
|
120
|
+
res.stderr = outputs.stderr ? outputs.stderr.output : null;
|
|
121
|
+
res.output = [
|
|
122
|
+
res.stdout,
|
|
123
|
+
res.stderr,
|
|
124
|
+
null
|
|
125
|
+
];
|
|
126
|
+
store.updateProcess(id, {
|
|
127
|
+
state: err ? 'error' : 'success'
|
|
128
|
+
});
|
|
129
|
+
terminal.release(()=>{
|
|
130
|
+
err ? callback(err) : callback(null, res);
|
|
166
131
|
});
|
|
167
132
|
});
|
|
168
133
|
} else {
|
|
@@ -194,8 +159,6 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
194
159
|
'finish'
|
|
195
160
|
]));
|
|
196
161
|
}
|
|
197
|
-
// FIX: Don't buffer output when pipes are already consuming streams
|
|
198
|
-
// Adding data listeners to already-piped streams prevents 'close' event from firing
|
|
199
162
|
queue.defer(spawn.worker.bind(null, cp, csOptions));
|
|
200
163
|
queue.await((err)=>{
|
|
201
164
|
const res = err ? err : {};
|
package/dist/esm/worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["import spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport crypto from 'crypto';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp.ts';\nimport addLines from './lib/addLines.ts';\nimport concatWritable from './lib/concatWritable.ts';\nimport formatArguments from './lib/formatArguments.ts';\n\nimport type { SpawnError, SpawnOptions, TerminalCallback, TerminalOptions } from './types.ts';\nimport { LineType } from './types.ts';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n if (stdio === 'inherit') {\n terminal.retain(
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["import spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport crypto from 'crypto';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp.ts';\nimport addLines from './lib/addLines.ts';\nimport concatWritable from './lib/concatWritable.ts';\nimport formatArguments from './lib/formatArguments.ts';\n\nimport type { SpawnError, SpawnOptions, TerminalCallback, TerminalOptions } from './types.ts';\nimport { LineType } from './types.ts';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: TerminalCallback): undefined {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n if (stdio === 'inherit') {\n const store = terminal.retain();\n const id = crypto.randomUUID();\n store.addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = addLines((lines) => {\n store.appendLines(\n id,\n lines.map((text) => ({ type: LineType.stdout, text }))\n );\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = addLines((lines) => {\n store.appendLines(\n id,\n lines.map((text) => ({ type: LineType.stderr, text }))\n );\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, csOptions));\n queue.await((err?: SpawnError) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n store.updateProcess(id, { state: err ? 'error' : 'success' });\n\n terminal.release(() => {\n err ? callback(err) : callback(null, res);\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, csOptions));\n queue.await((err?: SpawnError) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n err ? callback(err) : callback(null, res);\n });\n }\n}\n"],"names":["spawn","crossSpawn","crypto","oo","Queue","createApp","addLines","concatWritable","formatArguments","LineType","terminal","spawnTerminal","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","store","retain","id","randomUUID","addProcess","title","concat","join","state","lines","cp","outputs","stdout","stderr","queue","appendLines","map","text","type","defer","bind","pipe","worker","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AAY;YACtD;YACAiB,MAAMK,KAAK,CAACpC,GAAGqC,IAAI,CAAC,MAAMV,GAAGE,MAAM,CAACS,IAAI,CAACV,QAAQC,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACA,IAAIF,GAAGG,MAAM,EAAE;YACbF,QAAQE,MAAM,GAAG1B,eAAe,CAACuC;gBAC/Bf,QAAQE,MAAM,CAACa,MAAM,GAAGA,OAAOG,QAAQ,CAAChC,YAAY;YACtD;YACAiB,MAAMK,KAAK,CAACpC,GAAGqC,IAAI,CAAC,MAAMV,GAAGG,MAAM,CAACQ,IAAI,CAACV,QAAQE,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACAC,MAAMK,KAAK,CAACvC,MAAM0C,MAAM,CAACF,IAAI,CAAC,MAAMV,IAAIX;QACxCe,MAAMS,KAAK,CAAC,CAACC;YACX,MAAMC,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAIb,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACc,MAAM,GAAG;YACtDD,IAAIZ,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACa,MAAM,GAAG;YACtDD,IAAIC,MAAM,GAAG;gBAACD,IAAIb,MAAM;gBAAEa,IAAIZ,MAAM;gBAAE;aAAK;YAC3CW,MAAM5B,SAAS4B,OAAO5B,SAAS,MAAM6B;QACvC;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spawn-term",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "Formats spawn with for terminal grouping",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"spawn",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsds build",
|
|
37
37
|
"format": "biome check --write --unsafe",
|
|
38
|
+
"prepublishOnly": "tsds validate",
|
|
38
39
|
"test": "mocha --no-timeouts test/**/*.test.*",
|
|
39
40
|
"test:engines": "nvu engines tsds test:node --no-timeouts",
|
|
40
41
|
"version": "tsds version"
|
|
@@ -42,7 +43,6 @@
|
|
|
42
43
|
"dependencies": {
|
|
43
44
|
"cross-spawn-cb": "*",
|
|
44
45
|
"ink": "*",
|
|
45
|
-
"lodash.throttle": "*",
|
|
46
46
|
"on-one": "*",
|
|
47
47
|
"queue-cb": "*",
|
|
48
48
|
"react": "*"
|