Last active
September 28, 2025 12:15
-
-
Save s-h-a-d-o-w/d1be4eb4ecad3576af8fa69c248be615 to your computer and use it in GitHub Desktop.
Batch script - "smart" package manager command for JS projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal EnableDelayedExpansion | |
set "DIR=%CD%" | |
:FIND_ROOT | |
if exist "!DIR!\package-lock.json" ( | |
set PM=npm | |
) else if exist "!DIR!\yarn.lock" ( | |
set PM=yarn | |
) else if exist "!DIR!\pnpm-lock.yaml" ( | |
set PM=pnpm | |
) else if exist "!DIR!\bun.lockb" ( | |
set PM=bun | |
) else ( | |
if "!DIR!" == "!DIR:~0,3!" ( | |
echo No recognized lockfile found in hierarchy. Exiting... | |
exit /b 1 | |
) | |
for %%I in ("!DIR!") do set "DIR=%%~dpI" | |
set "DIR=!DIR:~0,-1!" | |
goto FIND_ROOT | |
) | |
call %PM% %* | |
endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment