@take-out/scripts 0.1.26 → 0.1.28
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/package.json +4 -4
- package/src/helpers/handleProcessExit.ts +14 -0
- package/src/run-pty.mjs +26 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@take-out/scripts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/run.ts",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@clack/prompts": "^0.8.2",
|
|
32
32
|
"@lydell/node-pty": "^1.2.0-beta.3",
|
|
33
|
-
"@take-out/helpers": "0.1.
|
|
33
|
+
"@take-out/helpers": "0.1.28",
|
|
34
34
|
"picocolors": "^1.1.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"vxrn": "^1.
|
|
37
|
+
"vxrn": "^1.9.5"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"vxrn": {
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"vxrn": "1.
|
|
45
|
+
"vxrn": "1.9.5"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -5,6 +5,18 @@ import {
|
|
|
5
5
|
type ProcessType,
|
|
6
6
|
} from './run'
|
|
7
7
|
|
|
8
|
+
// reset terminal to sane state
|
|
9
|
+
function resetTerminal() {
|
|
10
|
+
try {
|
|
11
|
+
// restore cooked mode if we have a TTY
|
|
12
|
+
if (process.stdin.isTTY && process.stdin.setRawMode) {
|
|
13
|
+
process.stdin.setRawMode(false)
|
|
14
|
+
}
|
|
15
|
+
} catch {}
|
|
16
|
+
// reset ANSI attributes
|
|
17
|
+
process.stdout.write('\x1b[0m')
|
|
18
|
+
}
|
|
19
|
+
|
|
8
20
|
type ExitCallback = (info: { signal: NodeJS.Signals | string }) => void | Promise<void>
|
|
9
21
|
|
|
10
22
|
interface HandleProcessExitReturn {
|
|
@@ -128,6 +140,8 @@ export function handleProcessExit({
|
|
|
128
140
|
}
|
|
129
141
|
|
|
130
142
|
const sigintHandler = () => {
|
|
143
|
+
// restore terminal to sane state
|
|
144
|
+
resetTerminal()
|
|
131
145
|
// immediately print newline and reset cursor for clean terminal
|
|
132
146
|
process.stdout.write('\n')
|
|
133
147
|
// reset terminal attributes
|
package/src/run-pty.mjs
CHANGED
|
@@ -15,8 +15,6 @@ const colors = [
|
|
|
15
15
|
]
|
|
16
16
|
const reset = '\x1b[0m'
|
|
17
17
|
const dim = '\x1b[2m'
|
|
18
|
-
const bold = '\x1b[1m'
|
|
19
|
-
const inverse = '\x1b[7m'
|
|
20
18
|
|
|
21
19
|
const args = process.argv.slice(2)
|
|
22
20
|
const ownFlags = ['--no-root', '--bun', '--watch', '--flags=last']
|
|
@@ -289,7 +287,15 @@ function handleInput(data) {
|
|
|
289
287
|
}
|
|
290
288
|
|
|
291
289
|
function cleanup() {
|
|
292
|
-
|
|
290
|
+
// restore terminal to cooked mode before exiting
|
|
291
|
+
if (process.stdin.isTTY && process.stdin.setRawMode) {
|
|
292
|
+
try {
|
|
293
|
+
process.stdin.setRawMode(false)
|
|
294
|
+
} catch {}
|
|
295
|
+
}
|
|
296
|
+
// reset terminal attributes (colors, etc)
|
|
297
|
+
process.stdout.write('\x1b[0m\n')
|
|
298
|
+
|
|
293
299
|
for (const p of processes) {
|
|
294
300
|
if (!p.killed) {
|
|
295
301
|
p.killed = true
|
|
@@ -360,7 +366,24 @@ async function main() {
|
|
|
360
366
|
process.on('SIGTERM', cleanup)
|
|
361
367
|
}
|
|
362
368
|
|
|
369
|
+
// restore terminal on any unexpected exit
|
|
370
|
+
function restoreTerminal() {
|
|
371
|
+
if (process.stdin.isTTY && process.stdin.setRawMode) {
|
|
372
|
+
try {
|
|
373
|
+
process.stdin.setRawMode(false)
|
|
374
|
+
} catch {}
|
|
375
|
+
}
|
|
376
|
+
process.stdout.write('\x1b[0m')
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
process.on('uncaughtException', (e) => {
|
|
380
|
+
restoreTerminal()
|
|
381
|
+
console.error(e)
|
|
382
|
+
process.exit(1)
|
|
383
|
+
})
|
|
384
|
+
|
|
363
385
|
main().catch((e) => {
|
|
386
|
+
restoreTerminal()
|
|
364
387
|
console.error(e)
|
|
365
388
|
process.exit(1)
|
|
366
389
|
})
|