@take-out/scripts 0.1.37 → 0.1.38-1772439111798
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 +2 -2
- package/src/run-pty.mjs +24 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@take-out/scripts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.38-1772439111798",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/run.ts",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -30,7 +30,7 @@
|
|
|
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.38-1772439111798",
|
|
34
34
|
"picocolors": "^1.1.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
package/src/run-pty.mjs
CHANGED
|
@@ -258,7 +258,7 @@ function handleInput(data) {
|
|
|
258
258
|
pendingAction = null
|
|
259
259
|
console.log(match.shortcut)
|
|
260
260
|
match.killed = true
|
|
261
|
-
match.terminal.
|
|
261
|
+
killProcessTree(match.terminal.pid)
|
|
262
262
|
setTimeout(() => {
|
|
263
263
|
spawnScript(match.name, match.cwd, match.label, match.extraArgs, match.index)
|
|
264
264
|
console.log(`${getPrefix(match.index)} restarted`)
|
|
@@ -268,7 +268,7 @@ function handleInput(data) {
|
|
|
268
268
|
console.log(match.shortcut)
|
|
269
269
|
if (!match.killed) {
|
|
270
270
|
match.killed = true
|
|
271
|
-
match.terminal.
|
|
271
|
+
killProcessTree(match.terminal.pid)
|
|
272
272
|
console.log(`${getPrefix(match.index)} killed`)
|
|
273
273
|
}
|
|
274
274
|
} else {
|
|
@@ -286,6 +286,24 @@ function handleInput(data) {
|
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
+
// kill entire process group to prevent orphans
|
|
290
|
+
function killProcessTree(pid) {
|
|
291
|
+
if (!pid) return
|
|
292
|
+
// try killing process group first (negative pid)
|
|
293
|
+
try {
|
|
294
|
+
process.kill(-pid, 'SIGTERM')
|
|
295
|
+
} catch {}
|
|
296
|
+
// also kill direct process
|
|
297
|
+
try {
|
|
298
|
+
process.kill(pid, 'SIGTERM')
|
|
299
|
+
} catch {}
|
|
300
|
+
// schedule force kill
|
|
301
|
+
setTimeout(() => {
|
|
302
|
+
try { process.kill(-pid, 'SIGKILL') } catch {}
|
|
303
|
+
try { process.kill(pid, 'SIGKILL') } catch {}
|
|
304
|
+
}, 100)
|
|
305
|
+
}
|
|
306
|
+
|
|
289
307
|
function cleanup() {
|
|
290
308
|
// restore terminal to cooked mode before exiting
|
|
291
309
|
if (process.stdin.isTTY && process.stdin.setRawMode) {
|
|
@@ -299,10 +317,12 @@ function cleanup() {
|
|
|
299
317
|
for (const p of processes) {
|
|
300
318
|
if (!p.killed) {
|
|
301
319
|
p.killed = true
|
|
302
|
-
p.terminal.
|
|
320
|
+
killProcessTree(p.terminal.pid)
|
|
303
321
|
}
|
|
304
322
|
}
|
|
305
|
-
|
|
323
|
+
|
|
324
|
+
// wait for kills to complete before exit
|
|
325
|
+
setTimeout(() => process.exit(0), 150)
|
|
306
326
|
}
|
|
307
327
|
|
|
308
328
|
async function main() {
|