Skip to content

Conversation

@asbiin
Copy link
Member

@asbiin asbiin commented Sep 28, 2025

No description provided.

@asbiin asbiin requested a review from djaiss September 28, 2025 15:35
@djaiss
Copy link
Member

djaiss commented Sep 28, 2025

I get this error

Adding VCS repository: https://github.com/monicahq/marketingsite-module
jq: error (at composer.json:99): Cannot iterate over null (null)
Installing module: monicahq/marketingsite-module
./composer.json has been updated
Running composer update monicahq/marketingsite-module
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking monicahq/marketingsite-module (dev-main)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals

In Filesystem.php line 251:
                                          
  Modules exists and is not a directory.  

ChatGPT says this, and suggests this fix:

Perfect. Here’s a fully corrected script that fixes both issues you hit:

- It makes sure composer.json always has a "repositories": [] key before trying to use it.
- It makes sure Modules/ is always a real directory (removes any conflicting file/symlink).
- It also ignores hidden files (like .DS_Store on macOS) when enabling modules.
#!/bin/bash
set -e

# if "--local" is passed, use local path for modules
# otherwise, use VCS repository
if [ "$1" == "--local" ]; then
  local=true
fi

add_vcs_repo() {
  echo "Adding VCS repository: $1"
  repo_url=$1
  type="vcs"

  if [ "$local" == true ]; then
    module_name=$(basename "$repo_url")
    repo_url="../$module_name"
    type="path"
  fi

  # Ensure repositories key exists in composer.json
  jq 'if .repositories == null then .repositories = [] else . end' composer.json > composer.json.tmp
  mv composer.json.tmp composer.json

  # Only add repo if not already present
  if ! jq -e --arg url "$repo_url" '.repositories[]? | select(.url == $url)' composer.json > /dev/null; then
    cp composer.json composer.json.tmp
    jq --arg url "$repo_url" --arg type "$type" \
       '.repositories += [{"type":$type,"url":$url}]' composer.json.tmp > composer.json
    rm -f composer.json.tmp
  fi
}

modules=("monicahq/marketingsite-module")

for module in "${modules[@]}"; do
  add_vcs_repo "https://github.com/$module"
done

for module in "${modules[@]}"; do
  echo "Installing module: $module"
  composer require "$module:@dev"
done

# Ensure Modules directory exists and is actually a directory
if [ -e Modules ] && [ ! -d Modules ]; then
  echo "Removing file/symlink named 'Modules'..."
  rm -rf Modules
fi

if [ ! -d Modules ]; then
  echo "Creating Modules directory..."
  mkdir Modules
fi

# Enable modules (ignore hidden files like .DS_Store)
for module in $(ls Modules | grep -v '^\.' ); do
  echo "Enabling module: $module"
  php artisan module:enable "$module"
done

However, I'm not sure this fixes issues.

I don't really get what we are trying to in this script.

@sonarqubecloud
Copy link

@djaiss
Copy link
Member

djaiss commented Sep 30, 2025

I've changed several things @asbiin

  1. the modules file is now in a /scripts/ folder, since we can't create a folder with the same name as the script called modules.
  2. i've updated the script so when we call it, it's executed at the root of the repo.
  3. i've fixed the indentation of the composer.json file so launching the script doesn't mess with indentation.

I'm unsure if you wanted also to include the new repo in compose.json ("monicahq/marketingsite-module": "@dev",) ?

@djaiss
Copy link
Member

djaiss commented Sep 30, 2025

Yeah, also now, the tests do not work anymore 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants