spawn-term 0.0.2 → 0.0.3
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.
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import eos from 'end-of-stream';
|
|
2
1
|
import { Writable } from 'readable-stream';
|
|
3
2
|
const regEx = /\r\n|[\n\v\f\r\x85\u2028\u2029]/g;
|
|
4
3
|
export default function addLines(addLine) {
|
|
@@ -12,7 +11,7 @@ export default function addLines(addLine) {
|
|
|
12
11
|
callback();
|
|
13
12
|
}
|
|
14
13
|
});
|
|
15
|
-
|
|
14
|
+
stream.on('finish', ()=>{
|
|
16
15
|
if (last.length) addLine(last);
|
|
17
16
|
last = '';
|
|
18
17
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/addLines.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/addLines.ts"],"sourcesContent":["import { Writable } from 'readable-stream';\n\nconst regEx = /\\r\\n|[\\n\\v\\f\\r\\x85\\u2028\\u2029]/g;\n\nexport default function addLines(addLine) {\n let last = '';\n\n const stream = new Writable({\n write(chunk, _enc, callback) {\n const more = last + chunk.toString('utf8');\n const lines = more.split(regEx);\n last = lines.pop();\n lines.forEach((line) => addLine(line));\n callback();\n },\n });\n stream.on('finish', () => {\n if (last.length) addLine(last);\n last = '';\n });\n return stream;\n}\n"],"names":["Writable","regEx","addLines","addLine","last","stream","write","chunk","_enc","callback","more","toString","lines","split","pop","forEach","line","on","length"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,kBAAkB;AAE3C,MAAMC,QAAQ;AAEd,eAAe,SAASC,SAASC,OAAO;IACtC,IAAIC,OAAO;IAEX,MAAMC,SAAS,IAAIL,SAAS;QAC1BM,OAAMC,KAAK,EAAEC,IAAI,EAAEC,QAAQ;YACzB,MAAMC,OAAON,OAAOG,MAAMI,QAAQ,CAAC;YACnC,MAAMC,QAAQF,KAAKG,KAAK,CAACZ;YACzBG,OAAOQ,MAAME,GAAG;YAChBF,MAAMG,OAAO,CAAC,CAACC,OAASb,QAAQa;YAChCP;QACF;IACF;IACAJ,OAAOY,EAAE,CAAC,UAAU;QAClB,IAAIb,KAAKc,MAAM,EAAEf,QAAQC;QACzBA,OAAO;IACT;IACA,OAAOC;AACT"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import eos from 'end-of-stream';
|
|
2
1
|
import { Writable } from 'readable-stream';
|
|
3
2
|
export default function concatWritable(callback) {
|
|
4
3
|
const chunks = [];
|
|
@@ -8,6 +7,6 @@ export default function concatWritable(callback) {
|
|
|
8
7
|
next();
|
|
9
8
|
}
|
|
10
9
|
});
|
|
11
|
-
|
|
10
|
+
stream.on('finish', ()=>callback(Buffer.concat(chunks.splice(0))));
|
|
12
11
|
return stream;
|
|
13
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/concatWritable.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/concatWritable.ts"],"sourcesContent":["import { Writable } from 'readable-stream';\n\nexport default function concatWritable(callback) {\n const chunks = [];\n const stream = new Writable({\n write: (chunk, _encoding, next) => {\n chunks.push(chunk);\n next();\n },\n });\n stream.on('finish', () => callback(Buffer.concat(chunks.splice(0))));\n return stream;\n}\n"],"names":["Writable","concatWritable","callback","chunks","stream","write","chunk","_encoding","next","push","on","Buffer","concat","splice"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,kBAAkB;AAE3C,eAAe,SAASC,eAAeC,QAAQ;IAC7C,MAAMC,SAAS,EAAE;IACjB,MAAMC,SAAS,IAAIJ,SAAS;QAC1BK,OAAO,CAACC,OAAOC,WAAWC;YACxBL,OAAOM,IAAI,CAACH;YACZE;QACF;IACF;IACAJ,OAAOM,EAAE,CAAC,UAAU,IAAMR,SAASS,OAAOC,MAAM,CAACT,OAAOU,MAAM,CAAC;IAC/D,OAAOT;AACT"}
|
package/dist/esm/worker.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
import spawn, { crossSpawn } from 'cross-spawn-cb';
|
|
3
|
-
import
|
|
3
|
+
import oo from 'on-one';
|
|
4
4
|
import Queue from 'queue-cb';
|
|
5
5
|
import createApp from './createApp.mjs';
|
|
6
6
|
import addLines from './lib/addLines.mjs';
|
|
@@ -41,13 +41,17 @@ export default function spawnTerminal(command, args, spawnOptions, _options, cal
|
|
|
41
41
|
});
|
|
42
42
|
rerender();
|
|
43
43
|
});
|
|
44
|
-
queue.defer(eos.bind(null, cp.stdout.pipe(outputs.stdout)));
|
|
45
44
|
} else {
|
|
46
45
|
outputs.stdout = concatWritable((output)=>{
|
|
47
46
|
outputs.stdout.output = output.toString(encoding || 'utf8');
|
|
48
47
|
});
|
|
49
|
-
queue.defer(eos.bind(null, cp.stdout.pipe(outputs.stdout)));
|
|
50
48
|
}
|
|
49
|
+
queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
50
|
+
'error',
|
|
51
|
+
'end',
|
|
52
|
+
'close',
|
|
53
|
+
'finish'
|
|
54
|
+
]));
|
|
51
55
|
}
|
|
52
56
|
if (cp.stderr) {
|
|
53
57
|
if (stdio === 'inherit') {
|
|
@@ -59,13 +63,17 @@ export default function spawnTerminal(command, args, spawnOptions, _options, cal
|
|
|
59
63
|
rerender();
|
|
60
64
|
});
|
|
61
65
|
cp.stderr.pipe(outputs.stderr);
|
|
62
|
-
queue.defer(eos.bind(null, cp.stderr.pipe(outputs.stderr)));
|
|
63
66
|
} else {
|
|
64
67
|
outputs.stderr = concatWritable((output)=>{
|
|
65
68
|
outputs.stderr.output = output.toString(encoding || 'utf8');
|
|
66
69
|
});
|
|
67
|
-
queue.defer(eos.bind(null, cp.stderr.pipe(outputs.stderr)));
|
|
68
70
|
}
|
|
71
|
+
queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
72
|
+
'error',
|
|
73
|
+
'end',
|
|
74
|
+
'close',
|
|
75
|
+
'finish'
|
|
76
|
+
]));
|
|
69
77
|
}
|
|
70
78
|
queue.defer(spawn.worker.bind(null, cp, {
|
|
71
79
|
...csOptions,
|
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
|
|
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.js';\nimport addLines from './lib/addLines.js';\nimport concatWritable from './lib/concatWritable.js';\n\nimport type { SpawnOptions, TerminalOptions } from './types.js';\nimport { LineType } from './types.js';\n\nconst terminal = createApp();\n\nimport throttle from 'lodash.throttle';\nconst THROTTLE = 100;\nconst rerender = throttle(() => {\n terminal.rerender();\n}, THROTTLE);\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, _options: TerminalOptions, callback) {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n terminal.retain();\n const item = terminal.addItem({ title: [command].concat(args).join(' '), state: 'running' });\n terminal.rerender();\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((text) => {\n item.lines.push({ type: LineType.stdout, text });\n rerender();\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((text) => {\n item.lines.push({ type: LineType.stderr, text });\n rerender();\n });\n cp.stderr.pipe(outputs.stderr);\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 item.state = err ? 'error' : 'success';\n terminal.rerender();\n terminal.release();\n err ? callback(err) : callback(null, res);\n });\n}\n"],"names":["spawn","crossSpawn","oo","Queue","createApp","addLines","concatWritable","LineType","terminal","throttle","THROTTLE","rerender","spawnTerminal","command","args","spawnOptions","_options","callback","encoding","stdio","csOptions","retain","item","addItem","title","concat","join","state","cp","outputs","stdout","stderr","process","getMaxListeners","setMaxListeners","queue","text","lines","push","type","output","toString","defer","bind","pipe","worker","await","err","res","release"],"mappings":"AAAA,aAAa;AACb,OAAOA,SAASC,UAAU,QAA0B,iBAAiB;AACrE,OAAOC,QAAQ,SAAS;AACxB,OAAOC,WAAW,WAAW;AAE7B,OAAOC,eAAe,iBAAiB;AACvC,OAAOC,cAAc,oBAAoB;AACzC,OAAOC,oBAAoB,0BAA0B;A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;SAAK;QAC3CT,KAAKK,KAAK,GAAGoB,MAAM,UAAU;QAC7BvC,SAASG,QAAQ;QACjBH,SAASyC,OAAO;QAChBF,MAAM9B,SAAS8B,OAAO9B,SAAS,MAAM+B;IACvC;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spawn-term",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Formats spawn with for terminal grouping",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"spawn",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"version": "tsds version"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"cross-spawn-cb": "^2.1.
|
|
40
|
-
"end-of-stream": "^1.4.4",
|
|
39
|
+
"cross-spawn-cb": "^2.1.14",
|
|
41
40
|
"ink": "^5.1.0",
|
|
42
41
|
"is-unicode-supported": "^2.1.0",
|
|
43
42
|
"lodash.throttle": "^4.1.1",
|
|
43
|
+
"on-one": "^0.1.1",
|
|
44
44
|
"queue-cb": "^1.4.13",
|
|
45
45
|
"react": "^18.3.1",
|
|
46
46
|
"readable-stream": "^2.3.8"
|