Skip to content

Commit d844f71

Browse files
authored
fix: use timestamped local-dev dirs to avoid SIGKILL on macOS (#807)
On macOS, overwriting a Mach-O binary in-place (same inode) while it's running causes the kernel's code signature cache to become stale, resulting in SIGKILL (exit 137) for new processes exec'd from that inode. Use `local-dev-<timestamp>` directories instead of a fixed `local-dev` so each `pnpm bootstrap-cli` installs to a fresh path with new inodes. Old local-dev directories are cleaned up before each install.
1 parent b25efbd commit d844f71

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

packages/tools/src/install-global-cli.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ import { fileURLToPath } from 'node:url';
1515
import { parseArgs } from 'node:util';
1616

1717
const isWindows = process.platform === 'win32';
18+
const LOCAL_DEV_PREFIX = 'local-dev';
19+
const pad2 = (n: number) => n.toString().padStart(2, '0');
20+
21+
function localDevVersion(): string {
22+
const now = new Date();
23+
const date = `${now.getFullYear()}${pad2(now.getMonth() + 1)}${pad2(now.getDate())}`;
24+
const time = `${pad2(now.getHours())}${pad2(now.getMinutes())}${pad2(now.getSeconds())}`;
25+
return `${LOCAL_DEV_PREFIX}-${date}-${time}`;
26+
}
1827

1928
// Get repo root from script location (packages/tools/src/install-global-cli.ts -> repo root)
2029
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -80,12 +89,27 @@ export function installGlobalCli() {
8089
process.exit(1);
8190
}
8291

92+
const localDevVer = localDevVersion();
93+
94+
// Clean up old local-dev directories to avoid accumulation
95+
if (existsSync(installDir)) {
96+
for (const entry of readdirSync(installDir)) {
97+
if (entry.startsWith(LOCAL_DEV_PREFIX)) {
98+
try {
99+
rmSync(path.join(installDir, entry), { recursive: true, force: true });
100+
} catch (err) {
101+
console.warn(`Warning: failed to remove old ${entry}: ${(err as Error).message}`);
102+
}
103+
}
104+
}
105+
}
106+
83107
const env: Record<string, string> = {
84108
...(process.env as Record<string, string>),
85109
VITE_PLUS_LOCAL_TGZ: tgzPath,
86110
VITE_PLUS_LOCAL_BINARY: binaryPath,
87111
VITE_PLUS_HOME: installDir,
88-
VITE_PLUS_VERSION: 'local-dev',
112+
VITE_PLUS_VERSION: localDevVer,
89113
CI: 'true',
90114
// Skip vp install in install.sh — we handle deps ourselves:
91115
// - Local dev: symlink monorepo node_modules
@@ -112,7 +136,7 @@ export function installGlobalCli() {
112136

113137
// Set up node_modules for local dev by rewriting workspace deps to file: protocol
114138
// and running pnpm install. Production installs use `vp install` in install.sh directly.
115-
const versionDir = path.join(installDir, 'local-dev');
139+
const versionDir = path.join(installDir, localDevVer);
116140
if (values.tgz) {
117141
installCiDeps(versionDir, tgzPath);
118142
} else {

0 commit comments

Comments
 (0)