Skip to content

Commit 6f50f42

Browse files
authored
Merge pull request #212 from electron-vite/v0.28.2
V0.28.2
2 parents bf215e9 + 61a7e89 commit 6f50f42

File tree

5 files changed

+9
-35
lines changed

5 files changed

+9
-35
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.28.2 (2024-02-11)
2+
3+
- 5b0fc87 feat: use `treeKillSync()` instead `tree-kill`
4+
15
## 0.28.1 (2024-02-06)
26

37
- efc5826 fix: correct `calcEntryCount()` for startup

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,3 @@ Modules in `node_modules` are not bundled during development, it's fast!
358358
│ const log = require('electron-log') │
359359
┗—————————————————————————————————————┛
360360
```
361-
362-
## FAQ
363-
364-
- `electron` does not exit correctly | 使用ctrl + c 停止代码,electron后台不关闭 | [#122](https://github.com/electron-vite/vite-plugin-electron/pull/122), [#168](https://github.com/electron-vite/vite-plugin-electron/issues/168)
365-
366-
* Add `tree-kill` into you dependencies, `npm i -D tree-kill`.
367-

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-electron",
3-
"version": "0.28.1",
3+
"version": "0.28.2",
44
"description": "Electron 🔗 Vite",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/index.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -138,36 +138,13 @@ export async function startup(
138138

139139
if (!startup.hookedProcessExit) {
140140
startup.hookedProcessExit = true
141-
process.once('exit', () => {
142-
startup.exit()
143-
// When the process exits, `tree-kill` does not have enough time to complete execution, so `electronApp` needs to be killed immediately.
144-
// process.electronApp.kill()
145-
treeKillSync(process.electronApp.pid!);
146-
})
141+
process.once('exit', startup.exit)
147142
}
148143
}
149144
startup.hookedProcessExit = false
150145
startup.exit = async () => {
151146
if (process.electronApp) {
152147
process.electronApp.removeAllListeners()
153-
154-
await import('tree-kill')
155-
.then(m => m.default(
156-
process.electronApp.pid!,
157-
'SIGKILL',
158-
error => error && process.electronApp.kill(),
159-
))
160-
.catch(e => {
161-
process.electronApp.kill()
162-
163-
if (e.code === 'ERR_MODULE_NOT_FOUND') {
164-
console.log(
165-
'[vite-plugin-electron]',
166-
'Please install tree-kill to exit all associated processes, run "npm i tree-kill -D".',
167-
)
168-
} else {
169-
console.error(e)
170-
}
171-
})
148+
treeKillSync(process.electronApp.pid!)
172149
}
173150
}

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ export function treeKillSync(pid: number) {
142142
if (process.platform === 'win32') {
143143
cp.execSync(`taskkill /pid ${pid} /T /F`)
144144
} else {
145-
killTree(pidTree())
145+
killTree(pidTree({ pid, ppid: process.pid }))
146146
}
147147
}
148148

149-
function pidTree(tree: PidTree = { pid: process.pid, ppid: process.ppid }) {
149+
function pidTree(tree: PidTree) {
150150
const command = process.platform === 'darwin'
151151
? `pgrep -P ${tree.pid}` // Mac
152152
: `ps -o pid --no-headers --ppid ${tree.ppid}` // Linux

0 commit comments

Comments
 (0)