Skip to content

Commit 9327992

Browse files
committed
tree-kill
1 parent ae9c182 commit 9327992

3 files changed

Lines changed: 30 additions & 24 deletions

File tree

package-lock.json

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
},
6464
"dependencies": {
6565
"@fontsource/michroma": "5.2.6",
66-
"@geode/opengeodeweb-front": "latest",
6766
"@geode/opengeodeweb-back": "latest",
67+
"@geode/opengeodeweb-front": "latest",
6868
"@geode/opengeodeweb-viewer": "latest",
6969
"@geode/vease-back": "latest",
7070
"@geode/vease-viewer": "latest",
@@ -74,7 +74,7 @@
7474
"get-port-please": "3.2.0",
7575
"h3-formidable": "1.0.0",
7676
"nuxt": "3.13.2",
77-
"pidtree": "0.6.0",
77+
"tree-kill": "1.2.2",
7878
"vuetify": "3.8.12"
7979
}
80-
}
80+
}

utils/local.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import os from "os"
99
import pkg from "electron"
1010
const { app, dialog } = pkg
1111
import { getPort } from "get-port-please"
12-
import pidtree from "pidtree"
12+
import kill from "tree-kill"
1313
import isElectron from "is-electron"
1414
import { fileURLToPath } from "url"
1515

@@ -72,28 +72,24 @@ async function kill_processes() {
7272
await processes.forEach(async function (proc) {
7373
console.log(`Process ${proc} will be killed!`)
7474
try {
75-
process.kill(proc)
75+
kill(proc)
7676
} catch (error) {
7777
console.log(`${error} Process ${proc} could not be killed!`)
7878
}
7979
})
8080
}
8181

82-
function register_children_processes(proc) {
83-
pidtree(proc.pid, { root: true }, function (err, pids) {
84-
if (err) {
85-
console.log("err", err)
86-
return
87-
}
88-
processes.push(...pids)
89-
})
82+
function register_process(proc) {
83+
if (!processes.includes(proc.pid)) {
84+
processes.push(proc.pid)
85+
}
9086
}
9187

9288
async function run_script(
9389
command,
9490
args,
9591
expected_response,
96-
timeout_seconds = 30,
92+
timeout_seconds = 30
9793
) {
9894
return new Promise((resolve, reject) => {
9995
setTimeout(() => {
@@ -103,7 +99,7 @@ async function run_script(
10399
encoding: "utf8",
104100
shell: true,
105101
})
106-
register_children_processes(child)
102+
register_process(child)
107103

108104
// You can also use a variable to save the output for when the script closes later
109105
child.stderr.setEncoding("utf8")
@@ -119,7 +115,6 @@ async function run_script(
119115
//Here is the output
120116
data = data.toString()
121117
if (data.includes(expected_response)) {
122-
register_children_processes(child)
123118
resolve(child)
124119
}
125120
console.log(data)
@@ -145,7 +140,7 @@ async function run_back(port, project_folder_path) {
145140
return new Promise(async (resolve, reject) => {
146141
const back_command = path.join(
147142
executable_path(path.join("microservices", "back")),
148-
executable_name("vease-back"),
143+
executable_name("vease-back")
149144
)
150145
const back_port = await get_available_port(port)
151146
const back_args = [
@@ -164,7 +159,7 @@ async function run_viewer(port, data_folder_path) {
164159
return new Promise(async (resolve, reject) => {
165160
const viewer_command = path.join(
166161
executable_path(path.join("microservices", "viewer")),
167-
executable_name("vease-viewer"),
162+
executable_name("vease-viewer")
168163
)
169164
const viewer_port = await get_available_port(port)
170165
const viewer_args = [
@@ -224,7 +219,7 @@ async function run_browser(script_name) {
224219
const output = data.toString()
225220
console.log("NUXT OUTPUT", output)
226221
const portMatch = output.match(
227-
/Accepting\ connections\ at\ http:\/\/localhost:(\d+)/,
222+
/Accepting\ connections\ at\ http:\/\/localhost:(\d+)/
228223
)
229224
if (portMatch) {
230225
resolve(portMatch[1])
@@ -240,7 +235,7 @@ export {
240235
executable_path,
241236
get_available_port,
242237
kill_processes,
243-
register_children_processes,
238+
register_process,
244239
run_script,
245240
run_back,
246241
run_viewer,

0 commit comments

Comments
 (0)