triflux 6.0.0 → 6.0.1
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 +1 -1
- package/scripts/preinstall.mjs +80 -43
package/package.json
CHANGED
package/scripts/preinstall.mjs
CHANGED
|
@@ -1,43 +1,80 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// npm install 전 Hub를 안전하게 중지하여 EBUSY 방지
|
|
3
|
-
// better-sqlite3.node 파일이 Hub 프로세스에 의해 잠기면 npm이 덮어쓸 수 없음
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// PID 파일 정리
|
|
33
|
-
try { unlinkSync(HUB_PID_FILE); } catch {}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// npm install 전 Hub를 안전하게 중지하여 EBUSY 방지
|
|
3
|
+
// better-sqlite3.node 파일이 Hub 프로세스에 의해 잠기면 npm이 덮어쓸 수 없음
|
|
4
|
+
//
|
|
5
|
+
// v6.0.0: taskkill /T /F + Atomics.wait sleep + 파일 잠금 확인
|
|
6
|
+
// (bin/triflux.mjs stopHubForUpdate 패턴과 동일)
|
|
7
|
+
|
|
8
|
+
import { existsSync, readFileSync, unlinkSync, openSync, closeSync } from "fs";
|
|
9
|
+
import { join, dirname } from "path";
|
|
10
|
+
import { homedir } from "os";
|
|
11
|
+
import { execFileSync } from "child_process";
|
|
12
|
+
import { fileURLToPath } from "url";
|
|
13
|
+
|
|
14
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const PKG_ROOT = join(__dirname, "..");
|
|
16
|
+
const HUB_PID_FILE = join(homedir(), ".claude", "cache", "tfx-hub", "hub.pid");
|
|
17
|
+
|
|
18
|
+
function sleepMs(ms) {
|
|
19
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function stopHub() {
|
|
23
|
+
if (!existsSync(HUB_PID_FILE)) return;
|
|
24
|
+
|
|
25
|
+
let info;
|
|
26
|
+
try {
|
|
27
|
+
info = JSON.parse(readFileSync(HUB_PID_FILE, "utf8"));
|
|
28
|
+
const pid = Number(info?.pid);
|
|
29
|
+
if (!Number.isFinite(pid) || pid <= 0) return;
|
|
30
|
+
process.kill(pid, 0); // 프로세스 존재 확인
|
|
31
|
+
} catch {
|
|
32
|
+
// 프로세스 없음 또는 PID 파일 손상 — PID 파일만 정리
|
|
33
|
+
try { unlinkSync(HUB_PID_FILE); } catch {}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const pid = Number(info.pid);
|
|
38
|
+
|
|
39
|
+
// 1단계: 프로세스 종료 — Windows는 taskkill, Unix는 SIGTERM
|
|
40
|
+
try {
|
|
41
|
+
if (process.platform === "win32") {
|
|
42
|
+
execFileSync("taskkill", ["/PID", String(pid), "/T", "/F"], {
|
|
43
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
44
|
+
timeout: 10000,
|
|
45
|
+
windowsHide: true,
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
process.kill(pid, "SIGTERM");
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
// taskkill 실패 시 SIGKILL fallback
|
|
52
|
+
try { process.kill(pid, "SIGKILL"); } catch {}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 2단계: 프로세스 종료 대기 (최대 5초, 500ms 간격)
|
|
56
|
+
for (let i = 0; i < 10; i++) {
|
|
57
|
+
sleepMs(500);
|
|
58
|
+
try { process.kill(pid, 0); } catch { break; }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 3단계: better-sqlite3.node 파일 잠금 해제 확인 (최대 3초)
|
|
62
|
+
const sqliteNode = join(PKG_ROOT, "node_modules", "better-sqlite3", "build", "Release", "better_sqlite3.node");
|
|
63
|
+
if (existsSync(sqliteNode)) {
|
|
64
|
+
for (let i = 0; i < 6; i++) {
|
|
65
|
+
try {
|
|
66
|
+
const fd = openSync(sqliteNode, "r");
|
|
67
|
+
closeSync(fd);
|
|
68
|
+
break; // 열림 = 잠금 해제됨
|
|
69
|
+
} catch {
|
|
70
|
+
sleepMs(500);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 4단계: PID 파일 정리 (종료 확인 후)
|
|
76
|
+
try { unlinkSync(HUB_PID_FILE); } catch {}
|
|
77
|
+
console.log(`[triflux preinstall] Hub 중지 완료 (PID ${pid})`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
stopHub();
|