@hanzo/dev 3.0.1 → 3.0.2
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/README.md +358 -0
- package/bin/dev.js +90 -97
- package/package.json +15 -27
- package/postinstall.js +229 -305
- package/scripts/preinstall.js +69 -0
- package/scripts/windows-cleanup.ps1 +31 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Windows-friendly preinstall: proactively free file locks from prior installs
|
|
3
|
+
// so npm/yarn/pnpm can stage the new package. No-ops on non-Windows.
|
|
4
|
+
|
|
5
|
+
import { platform } from 'os';
|
|
6
|
+
import { execSync } from 'child_process';
|
|
7
|
+
import { existsSync, readdirSync, rmSync, readFileSync, statSync } from 'fs';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
|
|
11
|
+
function isWSL() {
|
|
12
|
+
if (platform() !== 'linux') return false;
|
|
13
|
+
try {
|
|
14
|
+
const rel = readFileSync('/proc/version', 'utf8').toLowerCase();
|
|
15
|
+
return rel.includes('microsoft') || !!process.env.WSL_DISTRO_NAME;
|
|
16
|
+
} catch { return false; }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const isWin = platform() === 'win32';
|
|
20
|
+
const wsl = isWSL();
|
|
21
|
+
const isWinLike = isWin || wsl;
|
|
22
|
+
|
|
23
|
+
// Scope: only run for global installs, unless explicitly forced. Allow opt-out.
|
|
24
|
+
const isGlobal = process.env.npm_config_global === 'true';
|
|
25
|
+
const force = process.env.DEV_FORCE_PREINSTALL === '1';
|
|
26
|
+
const skip = process.env.DEV_SKIP_PREINSTALL === '1';
|
|
27
|
+
if (!isWinLike || skip || (!isGlobal && !force)) process.exit(0);
|
|
28
|
+
|
|
29
|
+
function tryExec(cmd, opts = {}) {
|
|
30
|
+
try { execSync(cmd, { stdio: ['ignore', 'ignore', 'ignore'], shell: true, ...opts }); } catch { /* ignore */ }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 1) Stop our native binary if it is holding locks. Avoid killing unrelated tools.
|
|
34
|
+
// Only available on native Windows; skip entirely on WSL to avoid noise.
|
|
35
|
+
if (isWin) {
|
|
36
|
+
tryExec('taskkill /IM dev-x86_64-pc-windows-msvc.exe /F');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 2) Remove stale staging dirs from previous failed installs under the global
|
|
40
|
+
// @hanzo scope, which npm will reuse (e.g., .dev-XXXXX). Remove only
|
|
41
|
+
// old entries and never the current staging or live package.
|
|
42
|
+
try {
|
|
43
|
+
let scopeDir = '';
|
|
44
|
+
try {
|
|
45
|
+
const root = execSync('npm root -g', { stdio: ['ignore', 'pipe', 'ignore'], shell: true }).toString().trim();
|
|
46
|
+
scopeDir = path.join(root, '@hanzo');
|
|
47
|
+
} catch {
|
|
48
|
+
// Fall back to guessing from this script location: <staging>\..\..\
|
|
49
|
+
const here = path.resolve(path.dirname(fileURLToPath(import.meta.url)));
|
|
50
|
+
scopeDir = path.resolve(here, '..');
|
|
51
|
+
}
|
|
52
|
+
if (existsSync(scopeDir)) {
|
|
53
|
+
const now = Date.now();
|
|
54
|
+
const maxAgeMs = 2 * 60 * 60 * 1000; // 2 hours
|
|
55
|
+
const currentDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
56
|
+
for (const name of readdirSync(scopeDir)) {
|
|
57
|
+
if (!name.startsWith('.dev-')) continue;
|
|
58
|
+
const p = path.join(scopeDir, name);
|
|
59
|
+
if (path.resolve(p) === currentDir) continue; // never remove our current dir
|
|
60
|
+
try {
|
|
61
|
+
const st = statSync(p);
|
|
62
|
+
const age = now - st.mtimeMs;
|
|
63
|
+
if (age > maxAgeMs) rmSync(p, { recursive: true, force: true });
|
|
64
|
+
} catch { /* ignore */ }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} catch { /* ignore */ }
|
|
68
|
+
|
|
69
|
+
process.exit(0);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<#
|
|
2
|
+
Helper to recover from EBUSY/EPERM during global npm upgrades on Windows.
|
|
3
|
+
Closes running processes and removes stale package folders.
|
|
4
|
+
|
|
5
|
+
Usage (PowerShell):
|
|
6
|
+
Set-ExecutionPolicy -Scope Process Bypass -Force
|
|
7
|
+
./dev-cli/scripts/windows-cleanup.ps1
|
|
8
|
+
#>
|
|
9
|
+
|
|
10
|
+
$ErrorActionPreference = 'SilentlyContinue'
|
|
11
|
+
|
|
12
|
+
Write-Host "Stopping running Hanzo Dev processes..."
|
|
13
|
+
taskkill /IM dev-x86_64-pc-windows-msvc.exe /F 2>$null | Out-Null
|
|
14
|
+
taskkill /IM dev.exe /F 2>$null | Out-Null
|
|
15
|
+
taskkill /IM hanzo.exe /F 2>$null | Out-Null
|
|
16
|
+
|
|
17
|
+
Write-Host "Removing old global package (if present)..."
|
|
18
|
+
$npmRoot = (& npm root -g).Trim()
|
|
19
|
+
$pkgPath = Join-Path $npmRoot "@hanzo\dev"
|
|
20
|
+
if (Test-Path $pkgPath) {
|
|
21
|
+
try { Remove-Item -LiteralPath $pkgPath -Recurse -Force -ErrorAction Stop } catch {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
Write-Host "Removing temp staging directories (if present)..."
|
|
25
|
+
Get-ChildItem -LiteralPath (Join-Path $npmRoot "@hanzo") -Force -ErrorAction SilentlyContinue |
|
|
26
|
+
Where-Object { $_.Name -like '.dev-*' } |
|
|
27
|
+
ForEach-Object {
|
|
28
|
+
try { Remove-Item -LiteralPath $_.FullName -Recurse -Force -ErrorAction Stop } catch {}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Write-Host "Cleanup complete. You can now run: npm install -g @hanzo/dev@latest"
|