feat(scripts): add local package linking for PHP dependency testing#8
feat(scripts): add local package linking for PHP dependency testing#8
Conversation
Adds cross-platform scripts (bash/PowerShell) that generate composer.local.json files for each package. This allows packages with host-uk/* dependencies to install via symlinked path repositories instead of failing on missing private packages from Packagist. Usage: ./scripts/setup-local-packages.sh # macOS/Linux .\scripts\setup-local-packages.ps1 # Windows Then: COMPOSER=composer.local.json composer install Closes #7 Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Free Tier AI AnalysisMultiple AI services analyzed this PR:
Add API keys to your fork secrets to enable more services. |
📝 WalkthroughWalkthroughIntroduces local package linking for PHP dependency testing by adding setup scripts (PowerShell and Bash) that automatically configure composer.local.json files to use local path repositories for inter-package dependencies, with supporting documentation in CLAUDE.md. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Fix all issues with AI agents
In `@CLAUDE.md`:
- Around line 140-149: Add a short prerequisite note to the Quick Setup section
stating that jq is required on macOS/Linux before running
./scripts/setup-local-packages.sh (or any call to that script), so users install
jq (e.g., via brew or apt) to avoid JSON parsing errors; update the text near
the macOS/Linux example and mention jq is only required for macOS/Linux
invocations of ./scripts/setup-local-packages.sh.
In `@scripts/setup-local-packages.ps1`:
- Around line 59-64: The current script unconditionally overwrites the
"repositories" property, which drops existing Composer VCS/private entries;
update the logic that sets $original.repositories so it merges $PathRepositories
before any existing $original.repositories (i.e., if $original.repositories
exists, create a new array with $PathRepositories elements followed by the
existing entries, otherwise set it to $PathRepositories), then proceed to
ConvertTo-Json and WriteAllText($target, ...) as before using the UTF‑8 no‑BOM
encoding; reference the symbols $original, $PathRepositories, "repositories",
ConvertTo-Json and [System.IO.File]::WriteAllText to locate and modify the code.
In `@scripts/setup-local-packages.sh`:
- Around line 35-38: The jq presence check (the if ! command -v jq &> /dev/null
block) only tells users to run "brew install jq", which is macOS-specific;
update the error message to show cross-platform install guidance for macOS
(brew), common Linux package managers (apt-get, yum/dnf, pacman) and Windows
(choco or scoop) and optionally point to installing via WSL or the jq binary
download. Modify the echo in that block to include these platform-specific
commands and a short note to choose the appropriate installer for their OS so
users on Linux and Windows get correct instructions.
- Around line 65-67: The jq invocation that writes composer.local.json currently
replaces any existing .repositories with $REPOSITORIES; change it to merge the
new repositories into the existing .repositories (prepending $REPOSITORIES
before existing entries) instead of overwriting so VCS/private sources are
preserved. Update the jq expression used with variables composer_json,
REPOSITORIES and target to read the original .repositories (or use an empty
array if missing) and produce a combined array with $REPOSITORIES first, then
the original entries, then write to "$target". Ensure the updated command still
handles missing .repositories gracefully.
| ```bash | ||
| # macOS/Linux - setup all packages | ||
| ./scripts/setup-local-packages.sh | ||
|
|
||
| # Windows (PowerShell) | ||
| .\scripts\setup-local-packages.ps1 | ||
|
|
||
| # Or setup a specific package | ||
| ./scripts/setup-local-packages.sh core-tenant | ||
| ``` |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Find and examine the setup script
fd setup-local-packages.shRepository: host-uk/core-devops
Length of output: 94
🏁 Script executed:
# Read CLAUDE.md to see the context around lines 140-149
wc -l CLAUDE.md && sed -n '130,160p' CLAUDE.mdRepository: host-uk/core-devops
Length of output: 873
🏁 Script executed:
# Search for any existing jq mentions in CLAUDE.md
rg -n "jq" CLAUDE.mdRepository: host-uk/core-devops
Length of output: 45
🏁 Script executed:
# Read the setup script
cat scripts/setup-local-packages.shRepository: host-uk/core-devops
Length of output: 3669
Add a short jq prerequisite note for macOS/Linux.
The setup script requires jq for JSON manipulation, but the Quick Setup section doesn't mention it. Add a brief prerequisite line to prevent users from encountering errors.
📚 Suggested doc tweak
### Quick Setup
+macOS/Linux requires `jq` for JSON merging (install via `brew install jq` or your package manager).
+
```bash
# macOS/Linux - setup all packages
./scripts/setup-local-packages.sh🤖 Prompt for AI Agents
In `@CLAUDE.md` around lines 140 - 149, Add a short prerequisite note to the Quick
Setup section stating that jq is required on macOS/Linux before running
./scripts/setup-local-packages.sh (or any call to that script), so users install
jq (e.g., via brew or apt) to avoid JSON parsing errors; update the text near
the macOS/Linux example and mention jq is only required for macOS/Linux
invocations of ./scripts/setup-local-packages.sh.
| # Add repositories array (path repos must come first) | ||
| $original | Add-Member -NotePropertyName "repositories" -NotePropertyValue $PathRepositories -Force | ||
|
|
||
| # Write merged composer.local.json (UTF-8 without BOM for Composer compatibility) | ||
| $json = $original | ConvertTo-Json -Depth 10 | ||
| [System.IO.File]::WriteAllText($target, $json, [System.Text.UTF8Encoding]::new($false)) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n scripts/setup-local-packages.ps1Repository: host-uk/core-devops
Length of output: 4965
Preserve any existing Composer repositories when generating composer.local.json.
Overwriting repositories can drop required VCS/private entries and break installs for packages that already define them. Merge path repos ahead of existing ones instead.
🛠️ Suggested merge (path repos first)
- $original | Add-Member -NotePropertyName "repositories" -NotePropertyValue $PathRepositories -Force
+ $existing = @()
+ if ($original.PSObject.Properties.Name -contains "repositories") {
+ $existing = $original.repositories
+ }
+ $merged = @($PathRepositories + $existing)
+ $original | Add-Member -NotePropertyName "repositories" -NotePropertyValue $merged -Force🤖 Prompt for AI Agents
In `@scripts/setup-local-packages.ps1` around lines 59 - 64, The current script
unconditionally overwrites the "repositories" property, which drops existing
Composer VCS/private entries; update the logic that sets $original.repositories
so it merges $PathRepositories before any existing $original.repositories (i.e.,
if $original.repositories exists, create a new array with $PathRepositories
elements followed by the existing entries, otherwise set it to
$PathRepositories), then proceed to ConvertTo-Json and WriteAllText($target,
...) as before using the UTF‑8 no‑BOM encoding; reference the symbols $original,
$PathRepositories, "repositories", ConvertTo-Json and
[System.IO.File]::WriteAllText to locate and modify the code.
| # Check for jq (required for JSON manipulation) | ||
| if ! command -v jq &> /dev/null; then | ||
| echo "Error: jq is required but not installed. Install it with: brew install jq" | ||
| exit 1 |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Locate and examine the setup-local-packages.sh file
find . -name "setup-local-packages.sh" -type f 2>/dev/null | head -5Repository: host-uk/core-devops
Length of output: 96
🏁 Script executed:
#!/bin/bash
# Read the setup-local-packages.sh file with line numbers
cat -n ./scripts/setup-local-packages.shRepository: host-uk/core-devops
Length of output: 4474
Provide cross-platform installation guidance for jq.
The error message at line 37 references only brew install jq, which is misleading for Linux and Windows users. Provide guidance for all supported platforms.
📝 Suggested fix
# Check for jq (required for JSON manipulation)
if ! command -v jq &> /dev/null; then
- echo "Error: jq is required but not installed. Install it with: brew install jq"
+ echo "Error: jq is required but not installed."
+ echo "Install: macOS (brew install jq) | Debian/Ubuntu (sudo apt-get install jq) | Fedora (sudo dnf install jq)"
exit 1
fiPer coding guidelines: scripts/** must ensure cross-platform compatibility (macOS, Linux, Windows).
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # Check for jq (required for JSON manipulation) | |
| if ! command -v jq &> /dev/null; then | |
| echo "Error: jq is required but not installed. Install it with: brew install jq" | |
| exit 1 | |
| # Check for jq (required for JSON manipulation) | |
| if ! command -v jq &> /dev/null; then | |
| echo "Error: jq is required but not installed." | |
| echo "Install: macOS (brew install jq) | Debian/Ubuntu (sudo apt-get install jq) | Fedora (sudo dnf install jq)" | |
| exit 1 | |
| fi |
🤖 Prompt for AI Agents
In `@scripts/setup-local-packages.sh` around lines 35 - 38, The jq presence check
(the if ! command -v jq &> /dev/null block) only tells users to run "brew
install jq", which is macOS-specific; update the error message to show
cross-platform install guidance for macOS (brew), common Linux package managers
(apt-get, yum/dnf, pacman) and Windows (choco or scoop) and optionally point to
installing via WSL or the jq binary download. Modify the echo in that block to
include these platform-specific commands and a short note to choose the
appropriate installer for their OS so users on Linux and Windows get correct
instructions.
| # Merge repositories into composer.json and write to composer.local.json | ||
| jq --argjson repos "$REPOSITORIES" '. + {repositories: $repos}' "$composer_json" > "$target" | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Read the setup script to examine lines 65-67 and surrounding context
wc -l scripts/setup-local-packages.shRepository: host-uk/core-devops
Length of output: 98
🏁 Script executed:
# View the file around lines 65-67 with context
sed -n '50,80p' scripts/setup-local-packages.sh | cat -nRepository: host-uk/core-devops
Length of output: 1106
🏁 Script executed:
# Also check what REPOSITORIES variable contains and how it's defined
cat scripts/setup-local-packages.sh | cat -nRepository: host-uk/core-devops
Length of output: 4474
Merge path repositories before existing entries instead of replacing them.
The current jq command completely overwrites any pre-existing repositories configuration in composer.json when creating composer.local.json. If the original composer.json defines VCS or private sources, they will be lost when using COMPOSER=composer.local.json composer install, causing dependency resolution to fail.
🛠️ Suggested fix
- jq --argjson repos "$REPOSITORIES" '. + {repositories: $repos}' "$composer_json" > "$target"
+ jq --argjson repos "$REPOSITORIES" '.repositories = ($repos + (.repositories // []))' "$composer_json" > "$target"🤖 Prompt for AI Agents
In `@scripts/setup-local-packages.sh` around lines 65 - 67, The jq invocation that
writes composer.local.json currently replaces any existing .repositories with
$REPOSITORIES; change it to merge the new repositories into the existing
.repositories (prepending $REPOSITORIES before existing entries) instead of
overwriting so VCS/private sources are preserved. Update the jq expression used
with variables composer_json, REPOSITORIES and target to read the original
.repositories (or use an empty array if missing) and produce a combined array
with $REPOSITORIES first, then the original entries, then write to "$target".
Ensure the updated command still handles missing .repositories gracefully.
Summary
scripts/setup-local-packages.sh(macOS/Linux) andscripts/setup-local-packages.ps1(Windows)composer.local.jsonfor each package by merging original composer.json with path repositorieshost-uk/*dependencies to install locally via symlinksChanges
setup-local-packages.sh- Bash script requiringjqfor JSON manipulationsetup-local-packages.ps1- PowerShell script using native JSON cmdletsCLAUDE.mdwith Local Package Linking documentation sectionTest Plan
Tested on Windows:
Verification
ls -la packages/core-tenant/vendor/host-uk/ # core -> /c/Users/user/github/core-devops/packages/core-php (symlink)Closes #7
Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.