Skip to content

Instantly share code, notes, and snippets.

@s-h-a-d-o-w
Last active September 28, 2025 12:15
Show Gist options
  • Save s-h-a-d-o-w/d1be4eb4ecad3576af8fa69c248be615 to your computer and use it in GitHub Desktop.
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
@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