|
| 1 | +@ECHO OFF |
| 2 | +SETLOCAL ENABLEDELAYEDEXPANSION |
| 3 | + |
| 4 | +REM check-deno-in-use.cmd - Check if deno.exe is running from specified directory |
| 5 | +REM |
| 6 | +REM This script checks if any deno.exe processes are running from the specified |
| 7 | +REM directory path. It is used by configure.cmd to prevent errors when trying to |
| 8 | +REM delete the package/dist directory while deno is still running from it. |
| 9 | +REM |
| 10 | +REM Usage: check-deno-in-use.cmd <directory-path> |
| 11 | +REM |
| 12 | +REM Exit codes: |
| 13 | +REM 0 - No deno process found at path (safe to proceed) |
| 14 | +REM 1 - Deno process found at path (blocking condition) |
| 15 | +REM |
| 16 | +REM This check is directory-specific to support multiple worktrees - it only |
| 17 | +REM blocks if deno.exe is running from the specified directory, not from other |
| 18 | +REM locations (e.g., system deno in PATH or deno from another worktree). |
| 19 | + |
| 20 | +SET "TARGET_PATH=%~1" |
| 21 | + |
| 22 | +REM Validate that a path was provided |
| 23 | +IF "%TARGET_PATH%"=="" ( |
| 24 | + echo Error: No directory path provided |
| 25 | + echo Usage: check-deno-in-use.cmd ^<directory-path^> |
| 26 | + EXIT /B 1 |
| 27 | +) |
| 28 | + |
| 29 | +REM Remove trailing backslash if present (for consistent path matching) |
| 30 | +IF "!TARGET_PATH:~-1!"=="\" SET "TARGET_PATH=!TARGET_PATH:~0,-1!" |
| 31 | + |
| 32 | +REM Check if deno.exe is running from target path using PowerShell |
| 33 | +REM Uses .StartsWith() for exact prefix matching (not wildcard matching) |
| 34 | +REM Case-insensitive comparison appropriate for Windows file paths |
| 35 | +powershell -NoProfile -Command "if (Get-Process -Name deno -ErrorAction SilentlyContinue | Where-Object { $_.Path -and $_.Path.StartsWith('!TARGET_PATH!', [System.StringComparison]::CurrentCultureIgnoreCase) }) { exit 1 } else { exit 0 }" >NUL 2>&1 |
| 36 | + |
| 37 | +IF "!ERRORLEVEL!"=="1" ( |
| 38 | + REM Deno process found - show error message and process list |
| 39 | + echo. |
| 40 | + echo ============================================================ |
| 41 | + echo Deno is running from this directory |
| 42 | + echo Please close Deno processes before running configure.cmd |
| 43 | + echo ============================================================ |
| 44 | + echo. |
| 45 | + echo Directory: !TARGET_PATH! |
| 46 | + echo. |
| 47 | + echo Deno processes from this directory: |
| 48 | + powershell -NoProfile -Command "Get-Process -Name deno -ErrorAction SilentlyContinue | Where-Object { $_.Path -and $_.Path.StartsWith('!TARGET_PATH!', [System.StringComparison]::CurrentCultureIgnoreCase) } | Format-Table Id, Path -AutoSize" |
| 49 | + EXIT /B 1 |
| 50 | +) |
| 51 | + |
| 52 | +REM No blocking deno process found |
| 53 | +EXIT /B 0 |
0 commit comments