spawn-term 0.1.2 → 0.1.4
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.cjs +54 -36
- package/dist/cjs/components/App.cjs.map +1 -1
- package/dist/cjs/components/ChildProcess.cjs +51 -2
- package/dist/cjs/components/ChildProcess.cjs.map +1 -1
- package/dist/cjs/contexts/Store.cjs +13 -0
- package/dist/cjs/contexts/Store.cjs.map +1 -0
- package/dist/cjs/createApp.cjs +68 -54
- package/dist/cjs/createApp.cjs.map +1 -1
- package/dist/cjs/lib/addLines.cjs +5 -5
- package/dist/cjs/lib/addLines.cjs.map +1 -1
- package/dist/cjs/types.cjs.map +1 -1
- package/dist/cjs/worker.cjs +98 -81
- package/dist/cjs/worker.cjs.map +1 -1
- package/dist/esm/components/App.mjs +16 -38
- package/dist/esm/components/App.mjs.map +1 -1
- package/dist/esm/components/ChildProcess.mjs +8 -2
- package/dist/esm/components/ChildProcess.mjs.map +1 -1
- package/dist/esm/contexts/Store.mjs +2 -0
- package/dist/esm/contexts/Store.mjs.map +1 -0
- package/dist/esm/createApp.mjs +30 -56
- package/dist/esm/createApp.mjs.map +1 -1
- package/dist/esm/lib/addLines.mjs +5 -3
- package/dist/esm/lib/addLines.mjs.map +1 -1
- package/dist/esm/types.mjs.map +1 -1
- package/dist/esm/worker.mjs +88 -81
- package/dist/esm/worker.mjs.map +1 -1
- package/dist/types/components/App.d.ts +1 -5
- package/dist/types/components/ChildProcess.d.ts +2 -6
- package/dist/types/contexts/Store.d.ts +2 -0
- package/dist/types/createApp.d.ts +1 -4
- package/dist/types/lib/addLines.d.ts +1 -1
- package/dist/types/types.d.ts +6 -0
- package/package.json +4 -3
package/dist/esm/worker.mjs
CHANGED
|
@@ -79,6 +79,7 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
79
79
|
return target;
|
|
80
80
|
}
|
|
81
81
|
import spawn, { crossSpawn } from 'cross-spawn-cb';
|
|
82
|
+
import uuid from 'lil-uuid';
|
|
82
83
|
import oo from 'on-one';
|
|
83
84
|
import Queue from 'queue-cb';
|
|
84
85
|
import createApp from './createApp.mjs';
|
|
@@ -86,95 +87,101 @@ import addLines from './lib/addLines.mjs';
|
|
|
86
87
|
import concatWritable from './lib/concatWritable.mjs';
|
|
87
88
|
import { LineType } from './types.mjs';
|
|
88
89
|
const terminal = createApp();
|
|
89
|
-
import throttle from 'lodash.throttle';
|
|
90
|
-
const THROTTLE = 100;
|
|
91
|
-
const rerender = throttle(()=>{
|
|
92
|
-
terminal.rerender();
|
|
93
|
-
}, THROTTLE);
|
|
94
90
|
export default function spawnTerminal(command, args, spawnOptions, _options, callback) {
|
|
95
91
|
const { encoding, stdio } = spawnOptions, csOptions = _object_without_properties(spawnOptions, [
|
|
96
92
|
"encoding",
|
|
97
93
|
"stdio"
|
|
98
94
|
]);
|
|
99
|
-
terminal.retain()
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (cp.stdout) {
|
|
118
|
-
if (stdio === 'inherit') {
|
|
119
|
-
outputs.stdout = addLines((text)=>{
|
|
120
|
-
item.lines.push({
|
|
121
|
-
type: LineType.stdout,
|
|
122
|
-
text
|
|
123
|
-
});
|
|
124
|
-
rerender();
|
|
125
|
-
});
|
|
126
|
-
} else {
|
|
127
|
-
outputs.stdout = concatWritable((output)=>{
|
|
128
|
-
outputs.stdout.output = output.toString(encoding || 'utf8');
|
|
129
|
-
});
|
|
95
|
+
terminal.retain((store)=>{
|
|
96
|
+
const id = uuid();
|
|
97
|
+
store.getState().addProcess({
|
|
98
|
+
id,
|
|
99
|
+
title: [
|
|
100
|
+
command
|
|
101
|
+
].concat(args).join(' '),
|
|
102
|
+
state: 'running',
|
|
103
|
+
lines: []
|
|
104
|
+
});
|
|
105
|
+
const cp = crossSpawn(command, args, csOptions);
|
|
106
|
+
const outputs = {
|
|
107
|
+
stdout: null,
|
|
108
|
+
stderr: null
|
|
109
|
+
};
|
|
110
|
+
if (cp.stdout && process.stdout.getMaxListeners) {
|
|
111
|
+
process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);
|
|
112
|
+
process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);
|
|
130
113
|
}
|
|
131
|
-
queue
|
|
132
|
-
|
|
133
|
-
'
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
text
|
|
114
|
+
const queue = new Queue();
|
|
115
|
+
if (cp.stdout) {
|
|
116
|
+
if (stdio === 'inherit') {
|
|
117
|
+
outputs.stdout = addLines((texts)=>{
|
|
118
|
+
const item = store.getState().processes.find((x)=>x.id === id);
|
|
119
|
+
const lines = item.lines.concat(texts.map((text)=>({
|
|
120
|
+
type: LineType.stdout,
|
|
121
|
+
text
|
|
122
|
+
})));
|
|
123
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
124
|
+
lines
|
|
125
|
+
}));
|
|
144
126
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
127
|
+
} else {
|
|
128
|
+
outputs.stdout = concatWritable((output)=>{
|
|
129
|
+
outputs.stdout.output = output.toString(encoding || 'utf8');
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
133
|
+
'error',
|
|
134
|
+
'end',
|
|
135
|
+
'close',
|
|
136
|
+
'finish'
|
|
137
|
+
]));
|
|
151
138
|
}
|
|
152
|
-
|
|
153
|
-
'
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
139
|
+
if (cp.stderr) {
|
|
140
|
+
if (stdio === 'inherit') {
|
|
141
|
+
outputs.stderr = addLines((texts)=>{
|
|
142
|
+
const item = store.getState().processes.find((x)=>x.id === id);
|
|
143
|
+
const lines = item.lines.concat(texts.map((text)=>({
|
|
144
|
+
type: LineType.stderr,
|
|
145
|
+
text
|
|
146
|
+
})));
|
|
147
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
148
|
+
lines
|
|
149
|
+
}));
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
outputs.stderr = concatWritable((output)=>{
|
|
153
|
+
outputs.stderr.output = output.toString(encoding || 'utf8');
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
157
|
+
'error',
|
|
158
|
+
'end',
|
|
159
|
+
'close',
|
|
160
|
+
'finish'
|
|
161
|
+
]));
|
|
166
162
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
163
|
+
queue.defer(spawn.worker.bind(null, cp, _object_spread_props(_object_spread({}, csOptions), {
|
|
164
|
+
encoding: 'utf8'
|
|
165
|
+
})));
|
|
166
|
+
queue.await((err)=>{
|
|
167
|
+
if (cp.stdout && process.stdout.getMaxListeners) {
|
|
168
|
+
process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);
|
|
169
|
+
process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);
|
|
170
|
+
}
|
|
171
|
+
const res = err ? err : {};
|
|
172
|
+
res.stdout = outputs.stdout ? outputs.stdout.output : null;
|
|
173
|
+
res.stderr = outputs.stderr ? outputs.stderr.output : null;
|
|
174
|
+
res.output = [
|
|
175
|
+
res.stdout,
|
|
176
|
+
res.stderr,
|
|
177
|
+
null
|
|
178
|
+
];
|
|
179
|
+
const item = store.getState().processes.find((x)=>x.id === id);
|
|
180
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
181
|
+
state: err ? 'error' : 'success'
|
|
182
|
+
}));
|
|
183
|
+
terminal.release();
|
|
184
|
+
err ? callback(err) : callback(null, res);
|
|
185
|
+
});
|
|
179
186
|
});
|
|
180
187
|
}
|
package/dist/esm/worker.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["// @ts-ignore\nimport spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp';\nimport addLines from './lib/addLines';\nimport concatWritable from './lib/concatWritable';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst terminal = createApp();\n\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["// @ts-ignore\nimport spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport uuid from 'lil-uuid';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp';\nimport addLines from './lib/addLines';\nimport concatWritable from './lib/concatWritable';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, _options: TerminalOptions, callback) {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n terminal.retain((store) => {\n const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(args).join(' '), state: 'running', lines: [] });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);\n }\n\n const queue = new Queue();\n if (cp.stdout) {\n if (stdio === 'inherit') {\n outputs.stdout = addLines((texts) => {\n const item = store.getState().processes.find((x) => x.id === id);\n const lines = item.lines.concat(texts.map((text) => ({ type: LineType.stdout, text })));\n store.getState().updateProcess({ ...item, lines });\n });\n } else {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n }\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n if (stdio === 'inherit') {\n outputs.stderr = addLines((texts) => {\n const item = store.getState().processes.find((x) => x.id === id);\n const lines = item.lines.concat(texts.map((text) => ({ type: LineType.stderr, text })));\n store.getState().updateProcess({ ...item, lines });\n });\n } else {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\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, encoding: 'utf8' }));\n queue.await((err) => {\n if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);\n }\n\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 terminal.release();\n err ? callback(err) : callback(null, res);\n });\n });\n}\n"],"names":["spawn","crossSpawn","uuid","oo","Queue","createApp","addLines","concatWritable","LineType","terminal","spawnTerminal","command","args","spawnOptions","_options","callback","encoding","stdio","csOptions","retain","store","id","getState","addProcess","title","concat","join","state","lines","cp","outputs","stdout","stderr","process","getMaxListeners","setMaxListeners","queue","texts","item","processes","find","x","map","text","type","updateProcess","output","toString","defer","bind","pipe","worker","await","err","res","release"],"mappings":"AAAA,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,OAAOA,SAASC,UAAU,QAA0B,iBAAiB;AACrE,OAAOC,UAAU,WAAW;AAC5B,OAAOC,QAAQ,SAAS;AACxB,OAAOC,WAAW,WAAW;AAE7B,OAAOC,eAAe,cAAc;AACpC,OAAOC,cAAc,iBAAiB;AACtC,OAAOC,oBAAoB,uBAAuB;AAGlD,SAASC,QAAQ,QAAQ,UAAU;AAEnC,MAAMC,WAAWJ;AAEjB,eAAe,SAASK,cAAcC,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,QAAyB,EAAEC,QAAQ;IACpI,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAgB,GAAGJ,cAAdK,uCAAcL;QAAlCG;QAAUC;;IAElBR,SAASU,MAAM,CAAC,CAACC;QACf,MAAMC,KAAKnB;QACXkB,MAAME,QAAQ,GAAGC,UAAU,CAAC;YAAEF;YAAIG,OAAO;gBAACb;aAAQ,CAACc,MAAM,CAACb,MAAMc,IAAI,CAAC;YAAMC,OAAO;YAAWC,OAAO,EAAE;QAAC;QAEvG,MAAMC,KAAK5B,WAAWU,SAASC,MAAMM;QACrC,MAAMY,UAAU;YAAEC,QAAQ;YAAMC,QAAQ;QAAK;QAE7C,IAAIH,GAAGE,MAAM,IAAIE,QAAQF,MAAM,CAACG,eAAe,EAAE;YAC/CD,QAAQF,MAAM,CAACI,eAAe,CAACF,QAAQF,MAAM,CAACG,eAAe,KAAK;YAClED,QAAQD,MAAM,CAACG,eAAe,CAACF,QAAQD,MAAM,CAACE,eAAe,KAAK;QACpE;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
|
-
lines: Line[];
|
|
6
|
-
isExpanded?: boolean;
|
|
2
|
+
id: string;
|
|
7
3
|
};
|
|
8
|
-
export default function ChildProcess({
|
|
4
|
+
export default function ChildProcess({ id }: ChildProcessProps): any;
|
|
9
5
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function addLines(
|
|
1
|
+
export default function addLines(fn: any): any;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -16,4 +16,10 @@ export type ChildProcess = {
|
|
|
16
16
|
title: string;
|
|
17
17
|
state: State;
|
|
18
18
|
lines: Line[];
|
|
19
|
+
isExpanded: boolean;
|
|
19
20
|
};
|
|
21
|
+
export interface AppState {
|
|
22
|
+
processes: ChildProcess[];
|
|
23
|
+
addProcess: (process: ChildProcess) => void;
|
|
24
|
+
updateProcess: (process: ChildProcess) => void;
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spawn-term",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Formats spawn with for terminal grouping",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"spawn",
|
|
@@ -42,12 +42,13 @@
|
|
|
42
42
|
"core-js": "^3.40.0",
|
|
43
43
|
"cross-spawn-cb": "^2.1.22",
|
|
44
44
|
"lil-uuid": "^0.1.1",
|
|
45
|
-
"lodash.throttle": "^4.1.1",
|
|
46
45
|
"on-one": "^0.1.4",
|
|
47
46
|
"queue-cb": "^1.4.16",
|
|
48
47
|
"react": "^18.3.1",
|
|
49
48
|
"readable-stream": "^2.3.8",
|
|
50
|
-
"
|
|
49
|
+
"resolve-once-cb": "^0.1.14",
|
|
50
|
+
"yoga-wasm-web": "^0.3.3",
|
|
51
|
+
"zustand": "^5.0.3"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@types/mocha": "*",
|