Skip to content

Commit 333f9bd

Browse files
cdervclaude
andcommitted
Extract deno detection logic to separate script
Refactored configure.cmd to call package/scripts/windows/check-deno-in-use.cmd for better maintainability and testability. The extracted script handles directory-specific deno.exe process detection on Windows. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d36c4ea commit 333f9bd

File tree

2 files changed

+74
-12
lines changed

2 files changed

+74
-12
lines changed

configure.cmd

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ REM Variables set dynamically (including being read from a file) should be ev
66
REM using ! ! instead of % %. However, this only allows one level of expansion. Do not
77
REM try to create a variable that derives from a derived variable. It will be empty.
88

9-
REM First Check that Deno isn't running since this causes weird and confusing errors
10-
REM find can conflict with one provided in bash with other args so use absolute path
11-
tasklist /fi "ImageName eq deno.exe" /fo csv 2>NUL | "%WINDIR%/system32/find" /I "deno.exe">NUL
12-
if "%ERRORLEVEL%"=="0" goto :denoRunning
13-
149
call package\src\store_win_configuration.bat
1510
call win_configuration.bat
1611

@@ -19,7 +14,27 @@ if NOT DEFINED QUARTO_VENDOR_BINARIES (
1914
)
2015

2116
if "%QUARTO_VENDOR_BINARIES%" == "true" (
22-
RMDIR /S /Q "!QUARTO_DIST_PATH!"
17+
18+
REM Windows-specific: Check if deno.exe is running before deleting package/dist
19+
REM Extracted to package/scripts/windows/check-deno-in-use.cmd for maintainability
20+
call package\scripts\windows\check-deno-in-use.cmd "!QUARTO_DIST_PATH!"
21+
if "!ERRORLEVEL!"=="1" exit /B 1
22+
23+
echo Removing package/dist/ directory...
24+
RMDIR /S /Q "!QUARTO_DIST_PATH!" 2>NUL
25+
26+
REM Fallback: Verify deletion succeeded (defense in depth)
27+
if exist "!QUARTO_DIST_PATH!" (
28+
echo.
29+
echo ============================================================
30+
echo Error: Could not delete package/dist/ directory
31+
echo A process may be holding files open
32+
echo ============================================================
33+
echo.
34+
echo Try closing applications and run configure.cmd again
35+
exit /B 1
36+
)
37+
2338
MKDIR !QUARTO_BIN_PATH!\tools
2439
PUSHD !QUARTO_BIN_PATH!\tools
2540

@@ -97,9 +112,3 @@ COPY package\typst-gather\target\release\typst-gather.exe "!QUARTO_BIN_PATH!\too
97112
endlocal & set QUARTO_BIN_DEV=%QUARTO_BIN_PATH%
98113

99114
GOTO :eof
100-
101-
:denoRunning
102-
103-
echo Please ensure no instances of `deno.exe` are running before configuring.
104-
echo (Deno might be running as an LSP if you have Visual Studio Code open.)
105-
GOTO :eof
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

Comments
 (0)