@take-out/scripts 0.1.38 → 0.1.39-1772567871404
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 +28 -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.39-1772567871404",
|
|
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.39-1772567871404",
|
|
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,28 @@ 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 {
|
|
303
|
+
process.kill(-pid, 'SIGKILL')
|
|
304
|
+
} catch {}
|
|
305
|
+
try {
|
|
306
|
+
process.kill(pid, 'SIGKILL')
|
|
307
|
+
} catch {}
|
|
308
|
+
}, 100)
|
|
309
|
+
}
|
|
310
|
+
|
|
289
311
|
function cleanup() {
|
|
290
312
|
// restore terminal to cooked mode before exiting
|
|
291
313
|
if (process.stdin.isTTY && process.stdin.setRawMode) {
|
|
@@ -299,10 +321,12 @@ function cleanup() {
|
|
|
299
321
|
for (const p of processes) {
|
|
300
322
|
if (!p.killed) {
|
|
301
323
|
p.killed = true
|
|
302
|
-
p.terminal.
|
|
324
|
+
killProcessTree(p.terminal.pid)
|
|
303
325
|
}
|
|
304
326
|
}
|
|
305
|
-
|
|
327
|
+
|
|
328
|
+
// wait for kills to complete before exit
|
|
329
|
+
setTimeout(() => process.exit(0), 150)
|
|
306
330
|
}
|
|
307
331
|
|
|
308
332
|
async function main() {
|