Introduction: Take Control of Your Package Management
In the ever-evolving landscape of software development, package management often feels like a necessary evil. While tools like Composer, NPM, and Yarn offer convenience, they also come with their own set of challenges—dependency conflicts, security vulnerabilities, and performance issues, to name a few.
That’s why we’ve put together this hands-on guide to help you take back control. Instead of relying on automated repository pullers, why not use good old Git and some terminal magic to manage your project’s dependencies? Not only does this give you more control over what gets added to your project, but it also allows for better security and performance optimization.
In this guide, we’ll walk you through the exact steps to manually pull your project’s dependencies using Git. Whether you’re on a Linux/Mac system or using Windows, we’ve got you covered.
Prerequisites
- Git installed on your system
- Terminal (Linux/Mac) or Command Prompt (Windows)
- A project folder where you want to pull the dependencies
For Linux/Mac Users
Create a shell script named pull_dependencies.sh
and paste the following code:
#!/bin/bash
echo "Enter the path where you want to save the dependencies:"
read save_path
cd $save_path
# Pull dependencies from composer.json (Composer)
jq -r '.require | keys[]' composer.json | while read i; do
git clone https://github.com/$i.git
done
# Pull dependencies from package.json (NPM)
jq -r '.dependencies | keys[]' package.json | while read i; do
git clone https://github.com/$i.git
done
# Pull dependencies from yarn.lock (Yarn)
grep 'version "' yarn.lock | awk -F '"' '{print $2}' | while read i; do
git clone https://github.com/$i.git
done
Run the script:
chmod +x pull_dependencies.sh
./pull_dependencies.sh
For Windows Users
Create a batch file named pull_dependencies.bat
and paste the following code:
@echo off
set /p save_path="Enter the path where you want to save the dependencies: "
cd %save_path%
:: Pull dependencies from composer.json (Composer)
for /f %%i in ('jq -r ".require | keys[]" composer.json') do (
git clone https://github.com/%%i.git
)
:: Pull dependencies from package.json (NPM)
for /f %%i in ('jq -r ".dependencies | keys[]" package.json') do (
git clone https://github.com/%%i.git
)
:: Pull dependencies from yarn.lock (Yarn)
for /f "tokens=2 delims=\"\"" %%i in ('findstr /R "version \"" yarn.lock') do (
git clone https://github.com/%%i.git
)
Run the batch file:
pull_dependencies.bat
Note: These scripts use jq
to parse JSON files. You’ll need to install it if you haven’t already. For Linux/Mac, you can install it using sudo apt install jq
or brew install jq
. For Windows, you can download it from here.