spawn-term 0.1.17 → 0.1.19
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/ChildProcess.cjs +2 -10
- package/dist/cjs/components/ChildProcess.cjs.map +1 -1
- package/dist/cjs/worker.cjs +1 -1
- package/dist/cjs/worker.cjs.map +1 -1
- package/dist/esm/components/ChildProcess.mjs +2 -10
- package/dist/esm/components/ChildProcess.mjs.map +1 -1
- package/dist/esm/worker.mjs +1 -1
- package/dist/esm/worker.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -77,10 +77,6 @@ var spinner = {
|
|
|
77
77
|
'⠏'
|
|
78
78
|
]
|
|
79
79
|
};
|
|
80
|
-
var _RUNS = [
|
|
81
|
-
_figures.default.cross,
|
|
82
|
-
_figures.default.tick
|
|
83
|
-
].concat(spinner.frames);
|
|
84
80
|
var ICONS = {
|
|
85
81
|
error: /*#__PURE__*/ _react.default.createElement(_ink.Text, {
|
|
86
82
|
color: "red"
|
|
@@ -139,10 +135,8 @@ function ChildProcess(param) {
|
|
|
139
135
|
lines: lines
|
|
140
136
|
}));
|
|
141
137
|
}
|
|
142
|
-
// const runs = lines.filter((line) => RUNS.some((run) => line.text[0] === run));
|
|
143
|
-
var runs = [];
|
|
144
138
|
var errors = lines.filter(function(line) {
|
|
145
|
-
return line.type === _types.LineType.stderr
|
|
139
|
+
return line.type === _types.LineType.stderr;
|
|
146
140
|
});
|
|
147
141
|
var output = lines.filter(function(line) {
|
|
148
142
|
return line.text.length > 0;
|
|
@@ -151,9 +145,7 @@ function ChildProcess(param) {
|
|
|
151
145
|
flexDirection: "column"
|
|
152
146
|
}, /*#__PURE__*/ _react.default.createElement(Header, {
|
|
153
147
|
item: item
|
|
154
|
-
}),
|
|
155
|
-
lines: runs
|
|
156
|
-
}), state === 'running' && output && runs.indexOf(output) < 0 && /*#__PURE__*/ _react.default.createElement(Output, {
|
|
148
|
+
}), state === 'running' && output && /*#__PURE__*/ _react.default.createElement(Output, {
|
|
157
149
|
output: output
|
|
158
150
|
}), errors.length > 0 && /*#__PURE__*/ _react.default.createElement(Lines, {
|
|
159
151
|
lines: errors
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box, Text } from '../ink.mjs';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type { AppState } from '../types';\nimport { LineType } from '../types';\n\n// From: https://github.com/sindresorhus/cli-spinners/blob/00de8fbeee16fa49502fa4f687449f70f2c8ca2c/spinners.json#L2\nconst spinner = {\n interval: 80,\n frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],\n};\n\nconst
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box, Text } from '../ink.mjs';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type { AppState } from '../types';\nimport { LineType } from '../types';\n\n// From: https://github.com/sindresorhus/cli-spinners/blob/00de8fbeee16fa49502fa4f687449f70f2c8ca2c/spinners.json#L2\nconst spinner = {\n interval: 80,\n frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],\n};\n\nconst ICONS = {\n error: <Text color=\"red\">{figures.cross}</Text>,\n success: <Text color=\"green\">{figures.tick}</Text>,\n running: <Spinner {...spinner} />,\n};\n\ntype ChildProcessProps = {\n id: string;\n};\n\nfunction Header({ item }) {\n const { group, title, state } = item;\n const icon = ICONS[state];\n\n return (\n <Box>\n <Box marginRight={1}>{icon}</Box>\n {group && <Text>{`${group}${figures.pointer} `}</Text>}\n <Text>{title}</Text>\n </Box>\n );\n}\n\nfunction Output({ output }) {\n return (\n <Box marginLeft={2}>\n <Text color=\"gray\">{`${figures.arrowRight} ${output.text}`}</Text>\n </Box>\n );\n}\n\nfunction Lines({ lines }) {\n return (\n <Box flexDirection=\"column\" marginLeft={2}>\n {lines.map((line, index) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>\n <Box key={index} flexDirection=\"column\" height={1}>\n <Text color={line.type === LineType.stderr ? 'red' : 'black'}>{line.text}</Text>\n </Box>\n ))}\n </Box>\n );\n}\n\nexport default function ChildProcess({ id }: ChildProcessProps) {\n const store = useContext(StoreContext);\n const appState = useStore(store) as AppState;\n const item = appState.processes.find((x) => x.id === id);\n const { state, lines, expanded } = item;\n\n if (expanded) {\n return (\n <Box flexDirection=\"column\">\n <Header item={item} />\n <Lines lines={lines} />\n </Box>\n );\n }\n const errors = lines.filter((line) => line.type === LineType.stderr);\n const output = lines.filter((line) => line.text.length > 0).pop();\n\n return (\n <Box flexDirection=\"column\">\n <Header item={item} />\n {state === 'running' && output && <Output output={output} />}\n {errors.length > 0 && <Lines lines={errors} />}\n </Box>\n );\n}\n"],"names":["ChildProcess","spinner","interval","frames","ICONS","error","Text","color","figures","cross","success","tick","running","Spinner","Header","item","group","title","state","icon","Box","marginRight","pointer","Output","output","marginLeft","arrowRight","text","Lines","lines","flexDirection","map","line","index","key","height","type","LineType","stderr","id","store","useContext","StoreContext","appState","useStore","processes","find","x","expanded","errors","filter","length","pop"],"mappings":";;;;+BA4DA;;;eAAwBA;;;6DA5DU;uBACT;4DACA;mBACC;8DACN;8DACA;qBAGK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzB,oHAAoH;AACpH,IAAMC,UAAU;IACdC,UAAU;IACVC,QAAQ;QAAC;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;KAAI;AAC5D;AAEA,IAAMC,QAAQ;IACZC,qBAAO,6BAAC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AO4B,SAASE,SAAS,CAACC,IAAI,CAAC,SAACC;eAAMA,EAAER,EAAE,KAAKA;;IACrD,IAAQrB,QAA2BH,KAA3BG,OAAOW,QAAoBd,KAApBc,OAAOmB,WAAajC,KAAbiC;IAEtB,IAAIA,UAAU;QACZ,qBACE,6BAAC5B,QAAG;YAACU,eAAc;yBACjB,6BAAChB;YAAOC,MAAMA;0BACd,6BAACa;YAAMC,OAAOA;;IAGpB;IACA,IAAMoB,SAASpB,MAAMqB,MAAM,CAAC,SAAClB;eAASA,KAAKI,IAAI,KAAKC,eAAQ,CAACC,MAAM;;IACnE,IAAMd,SAASK,MAAMqB,MAAM,CAAC,SAAClB;eAASA,KAAKL,IAAI,CAACwB,MAAM,GAAG;OAAGC,GAAG;IAE/D,qBACE,6BAAChC,QAAG;QAACU,eAAc;qBACjB,6BAAChB;QAAOC,MAAMA;QACbG,UAAU,aAAaM,wBAAU,6BAACD;QAAOC,QAAQA;QACjDyB,OAAOE,MAAM,GAAG,mBAAK,6BAACvB;QAAMC,OAAOoB;;AAG1C"}
|
package/dist/cjs/worker.cjs
CHANGED
|
@@ -265,7 +265,7 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
265
265
|
]));
|
|
266
266
|
}
|
|
267
267
|
queue.defer(_crossspawncb.default.worker.bind(null, cp, _object_spread_props(_object_spread({}, csOptions), {
|
|
268
|
-
encoding: 'utf8'
|
|
268
|
+
encoding: encoding || 'utf8'
|
|
269
269
|
})));
|
|
270
270
|
queue.await(function(err) {
|
|
271
271
|
var res = err ? err : {};
|
package/dist/cjs/worker.cjs.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 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';\nimport formatArguments from './lib/formatArguments';\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 if (stdio === 'inherit') {\n terminal.retain((store) => {\n const id = uuid();\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((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 queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\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 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 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 // let rendering complete\n setTimeout(() => {\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: 'utf8' }));\n queue.await((err) => {\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","uuid","getState","addProcess","title","concat","formatArguments","join","state","lines","cp","crossSpawn","outputs","stdout","stderr","queue","Queue","addLines","texts","item","processes","find","x","map","text","type","LineType","updateProcess","defer","oo","bind","pipe","spawn","worker","await","err","res","output","setTimeout","release","concatWritable","toString"],"mappings":"AAAA,aAAa;;;;;+BAgBb;;;eAAwBA;;;oEAf4B;8DACnC;4DACF;8DACG;gEAEI;+DACD;qEACM;sEACC;qBAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzB,IAAMC,WAAWC,IAAAA,kBAAS;AAEX,SAASF,cAAcG,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAAQ;IACnI,IAAQC,WAAkCH,aAAlCG,UAAUC,QAAwBJ,aAAxBI,OAAUC,uCAAcL;QAAlCG;QAAUC;;IAElB,IAAIA,UAAU,WAAW;QACvBR,SAASU,MAAM,CAAC,S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,MAAM,GAAG2B,IAAAA,uBAAc,EAAC,SAACH;gBAC/BzB,QAAQC,MAAM,CAACwB,MAAM,GAAGA,OAAOI,QAAQ,CAAC9C,YAAY;YACtD;YACAoB,MAAMa,KAAK,CAACC,cAAE,CAACC,IAAI,CAAC,MAAMpB,GAAGG,MAAM,CAACkB,IAAI,CAACnB,QAAQC,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACA,IAAIH,GAAGI,MAAM,EAAE;YACbF,QAAQE,MAAM,GAAG0B,IAAAA,uBAAc,EAAC,SAACH;gBAC/BzB,QAAQE,MAAM,CAACuB,MAAM,GAAGA,OAAOI,QAAQ,CAAC9C,YAAY;YACtD;YACAoB,MAAMa,KAAK,CAACC,cAAE,CAACC,IAAI,CAAC,MAAMpB,GAAGI,MAAM,CAACiB,IAAI,CAACnB,QAAQE,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACAC,MAAMa,KAAK,CAACI,qBAAK,CAACC,MAAM,CAACH,IAAI,CAAC,MAAMpB,IAAI,wCAAKb;YAAWF,
|
|
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';\nimport formatArguments from './lib/formatArguments';\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 if (stdio === 'inherit') {\n terminal.retain((store) => {\n const id = uuid();\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((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 queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\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 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 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 // let rendering complete\n setTimeout(() => {\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) => {\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","uuid","getState","addProcess","title","concat","formatArguments","join","state","lines","cp","crossSpawn","outputs","stdout","stderr","queue","Queue","addLines","texts","item","processes","find","x","map","text","type","LineType","updateProcess","defer","oo","bind","pipe","spawn","worker","await","err","res","output","setTimeout","release","concatWritable","toString"],"mappings":"AAAA,aAAa;;;;;+BAgBb;;;eAAwBA;;;oEAf4B;8DACnC;4DACF;8DACG;gEAEI;+DACD;qEACM;sEACC;qBAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzB,IAAMC,WAAWC,IAAAA,kBAAS;AAEX,SAASF,cAAcG,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAAQ;IACnI,IAAQC,WAAkCH,aAAlCG,UAAUC,QAAwBJ,aAAxBI,OAAUC,uCAAcL;QAAlCG;QAAUC;;IAElB,IAAIA,UAAU,WAAW;QACvBR,SAASU,MAAM,CAAC,SAACC;YACf,IAAMC,KAAKC,IAAAA,gBAAI;YACfF,MAAMG,QAAQ,GAAGC,UAAU,CAAC;gBAAEH,IAAAA;gBAAII,OAAO;oBAACd;iBAAQ,CAACe,MAAM,CAACC,IAAAA,wBAAe,EAACf,OAAOgB,IAAI,CAAC;gBAAMC,OAAO;gBAAWC,OAAO,EAAE;eAAKhB;YAE5H,IAAMiB,KAAKC,IAAAA,wBAAU,EAACrB,SAASC,MAAMM;YACrC,IAAMe,UAAU;gBAAEC,QAAQ;gBAA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AM,GAAG0B,IAAAA,uBAAc,EAAC,SAACH;gBAC/BzB,QAAQE,MAAM,CAACuB,MAAM,GAAGA,OAAOI,QAAQ,CAAC9C,YAAY;YACtD;YACAoB,MAAMa,KAAK,CAACC,cAAE,CAACC,IAAI,CAAC,MAAMpB,GAAGI,MAAM,CAACiB,IAAI,CAACnB,QAAQE,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACAC,MAAMa,KAAK,CAACI,qBAAK,CAACC,MAAM,CAACH,IAAI,CAAC,MAAMpB,IAAI,wCAAKb;YAAWF,UAAUA,YAAY;;QAC9EoB,MAAMmB,KAAK,CAAC,SAACC;YACX,IAAMC,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAIvB,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACwB,MAAM,GAAG;YACtDD,IAAItB,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACuB,MAAM,GAAG;YACtDD,IAAIC,MAAM,GAAG;gBAACD,IAAIvB,MAAM;gBAAEuB,IAAItB,MAAM;gBAAE;aAAK;YAC3CqB,MAAMzC,SAASyC,OAAOzC,SAAS,MAAM0C;QACvC;IACF;AACF"}
|
|
@@ -21,10 +21,6 @@ const spinner = {
|
|
|
21
21
|
'⠏'
|
|
22
22
|
]
|
|
23
23
|
};
|
|
24
|
-
const _RUNS = [
|
|
25
|
-
figures.cross,
|
|
26
|
-
figures.tick
|
|
27
|
-
].concat(spinner.frames);
|
|
28
24
|
const ICONS = {
|
|
29
25
|
error: /*#__PURE__*/ React.createElement(Text, {
|
|
30
26
|
color: "red"
|
|
@@ -75,17 +71,13 @@ export default function ChildProcess({ id }) {
|
|
|
75
71
|
lines: lines
|
|
76
72
|
}));
|
|
77
73
|
}
|
|
78
|
-
|
|
79
|
-
const runs = [];
|
|
80
|
-
const errors = lines.filter((line)=>line.type === LineType.stderr && runs.indexOf(line) < 0);
|
|
74
|
+
const errors = lines.filter((line)=>line.type === LineType.stderr);
|
|
81
75
|
const output = lines.filter((line)=>line.text.length > 0).pop();
|
|
82
76
|
return /*#__PURE__*/ React.createElement(Box, {
|
|
83
77
|
flexDirection: "column"
|
|
84
78
|
}, /*#__PURE__*/ React.createElement(Header, {
|
|
85
79
|
item: item
|
|
86
|
-
}),
|
|
87
|
-
lines: runs
|
|
88
|
-
}), state === 'running' && output && runs.indexOf(output) < 0 && /*#__PURE__*/ React.createElement(Output, {
|
|
80
|
+
}), state === 'running' && output && /*#__PURE__*/ React.createElement(Output, {
|
|
89
81
|
output: output
|
|
90
82
|
}), errors.length > 0 && /*#__PURE__*/ React.createElement(Lines, {
|
|
91
83
|
lines: errors
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box, Text } from '../ink.mjs';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type { AppState } from '../types';\nimport { LineType } from '../types';\n\n// From: https://github.com/sindresorhus/cli-spinners/blob/00de8fbeee16fa49502fa4f687449f70f2c8ca2c/spinners.json#L2\nconst spinner = {\n interval: 80,\n frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],\n};\n\nconst
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box, Text } from '../ink.mjs';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type { AppState } from '../types';\nimport { LineType } from '../types';\n\n// From: https://github.com/sindresorhus/cli-spinners/blob/00de8fbeee16fa49502fa4f687449f70f2c8ca2c/spinners.json#L2\nconst spinner = {\n interval: 80,\n frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],\n};\n\nconst ICONS = {\n error: <Text color=\"red\">{figures.cross}</Text>,\n success: <Text color=\"green\">{figures.tick}</Text>,\n running: <Spinner {...spinner} />,\n};\n\ntype ChildProcessProps = {\n id: string;\n};\n\nfunction Header({ item }) {\n const { group, title, state } = item;\n const icon = ICONS[state];\n\n return (\n <Box>\n <Box marginRight={1}>{icon}</Box>\n {group && <Text>{`${group}${figures.pointer} `}</Text>}\n <Text>{title}</Text>\n </Box>\n );\n}\n\nfunction Output({ output }) {\n return (\n <Box marginLeft={2}>\n <Text color=\"gray\">{`${figures.arrowRight} ${output.text}`}</Text>\n </Box>\n );\n}\n\nfunction Lines({ lines }) {\n return (\n <Box flexDirection=\"column\" marginLeft={2}>\n {lines.map((line, index) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>\n <Box key={index} flexDirection=\"column\" height={1}>\n <Text color={line.type === LineType.stderr ? 'red' : 'black'}>{line.text}</Text>\n </Box>\n ))}\n </Box>\n );\n}\n\nexport default function ChildProcess({ id }: ChildProcessProps) {\n const store = useContext(StoreContext);\n const appState = useStore(store) as AppState;\n const item = appState.processes.find((x) => x.id === id);\n const { state, lines, expanded } = item;\n\n if (expanded) {\n return (\n <Box flexDirection=\"column\">\n <Header item={item} />\n <Lines lines={lines} />\n </Box>\n );\n }\n const errors = lines.filter((line) => line.type === LineType.stderr);\n const output = lines.filter((line) => line.text.length > 0).pop();\n\n return (\n <Box flexDirection=\"column\">\n <Header item={item} />\n {state === 'running' && output && <Output output={output} />}\n {errors.length > 0 && <Lines lines={errors} />}\n </Box>\n );\n}\n"],"names":["React","useContext","useStore","StoreContext","Box","Text","figures","Spinner","LineType","spinner","interval","frames","ICONS","error","color","cross","success","tick","running","Header","item","group","title","state","icon","marginRight","pointer","Output","output","marginLeft","arrowRight","text","Lines","lines","flexDirection","map","line","index","key","height","type","stderr","ChildProcess","id","store","appState","processes","find","x","expan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Q;yBAC9C,oBAAClC;YAAKS,OAAOsB,KAAKI,IAAI,KAAKhC,SAASiC,MAAM,GAAG,QAAQ;WAAUL,KAAKL,IAAI;AAKlF;AAEA,eAAe,SAASW,aAAa,EAAEC,EAAE,EAAqB;IAC5D,MAAMC,QAAQ3C,WAAWE;IACzB,MAAM0C,WAAW3C,SAAS0C;IAC1B,MAAMxB,OAAOyB,SAASC,SAAS,CAACC,IAAI,CAAC,CAACC,IAAMA,EAAEL,EAAE,KAAKA;IACrD,MAAM,EAAEpB,KAAK,EAAEU,KAAK,EAAEgB,QAAQ,EAAE,GAAG7B;IAEnC,IAAI6B,UAAU;QACZ,qBACE,oBAAC7C;YAAI8B,eAAc;yBACjB,oBAACf;YAAOC,MAAMA;0BACd,oBAACY;YAAMC,OAAOA;;IAGpB;IACA,MAAMiB,SAASjB,MAAMkB,MAAM,CAAC,CAACf,OAASA,KAAKI,IAAI,KAAKhC,SAASiC,MAAM;IACnE,MAAMb,SAASK,MAAMkB,MAAM,CAAC,CAACf,OAASA,KAAKL,IAAI,CAACqB,MAAM,GAAG,GAAGC,GAAG;IAE/D,qBACE,oBAACjD;QAAI8B,eAAc;qBACjB,oBAACf;QAAOC,MAAMA;QACbG,UAAU,aAAaK,wBAAU,oBAACD;QAAOC,QAAQA;QACjDsB,OAAOE,MAAM,GAAG,mBAAK,oBAACpB;QAAMC,OAAOiB;;AAG1C"}
|
package/dist/esm/worker.mjs
CHANGED
|
@@ -199,7 +199,7 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
199
199
|
]));
|
|
200
200
|
}
|
|
201
201
|
queue.defer(spawn.worker.bind(null, cp, _object_spread_props(_object_spread({}, csOptions), {
|
|
202
|
-
encoding: 'utf8'
|
|
202
|
+
encoding: encoding || 'utf8'
|
|
203
203
|
})));
|
|
204
204
|
queue.await((err)=>{
|
|
205
205
|
const res = err ? err : {};
|
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 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';\nimport formatArguments from './lib/formatArguments';\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 if (stdio === 'inherit') {\n terminal.retain((store) => {\n const id = uuid();\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((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 queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\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 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 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 // let rendering complete\n setTimeout(() => {\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: 'utf8' }));\n queue.await((err) => {\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","uuid","oo","Queue","createApp","addLines","concatWritable","formatArguments","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","queue","texts","item","processes","find","x","map","text","type","updateProcess","defer","bind","pipe","worker","await","err","res","output","setTimeout","release","toString"],"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,uBAA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MAAMpB,KAAK7B,WAAWW,SAASC,MAAMM;QACrC,MAAMY,UAAU;YAAEC,QAAQ;YAAMC,QAAQ;QAAK;QAE7C,MAAMC,QAAQ,IAAI9B;QAClB,IAAI0B,GAAGE,MAAM,EAAE;YACbD,QAAQC,MAAM,GAAGzB,eAAe,CAAC4C;gBAC/BpB,QAAQC,MAAM,CAACmB,MAAM,GAAGA,OAAOG,QAAQ,CAACrC,YAAY;YACtD;YACAiB,MAAMU,KAAK,CAACzC,GAAG0C,IAAI,CAAC,MAAMf,GAAGE,MAAM,CAACc,IAAI,CAACf,QAAQC,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACA,IAAIF,GAAGG,MAAM,EAAE;YACbF,QAAQE,MAAM,GAAG1B,eAAe,CAAC4C;gBAC/BpB,QAAQE,MAAM,CAACkB,MAAM,GAAGA,OAAOG,QAAQ,CAACrC,YAAY;YACtD;YACAiB,MAAMU,KAAK,CAACzC,GAAG0C,IAAI,CAAC,MAAMf,GAAGG,MAAM,CAACa,IAAI,CAACf,QAAQE,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACAC,MAAMU,KAAK,CAAC5C,MAAM+C,MAAM,CAACF,IAAI,CAAC,MAAMf,IAAI,wCAAKX;YAAWF,
|
|
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';\nimport formatArguments from './lib/formatArguments';\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 if (stdio === 'inherit') {\n terminal.retain((store) => {\n const id = uuid();\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((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 queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\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 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 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 // let rendering complete\n setTimeout(() => {\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) => {\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","uuid","oo","Queue","createApp","addLines","concatWritable","formatArguments","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","queue","texts","item","processes","find","x","map","text","type","updateProcess","defer","bind","pipe","worker","await","err","res","output","setTimeout","release","toString"],"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;AAClD,OAAOC,qBAAqB,wBAAwB;AAGpD,SAASC,QAAQ,QAAQ,UAAU;AAEnC,MAAMC,WAAWL;AAEjB,eAAe,SAASM,cAAcC,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAAQ;IACnI,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAgB,GAAGJ,cAAdK,uCAAcL;QAAlCG;QAAUC;;IAElB,IAAIA,UAAU,WAAW;QACvBR,SAASU,MAAM,CAAC,CAACC;YACf,MAAMC,KAAKpB;YACXmB,MAAME,QAAQ,GAAGC,UAAU,CAAC;gBAAEF;gBAAIG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