|
3 | 3 | # Determine the project root on the host dynamically |
4 | 4 | HOST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
5 | 5 |
|
6 | | -# Extract project name from .ddev/config.yaml to determine container name dynamically |
7 | | -PROJECT_NAME=$(grep '^name:' "$HOST_ROOT/.ddev/config.yaml" | awk '{print $2}') |
| 6 | +# Extract project name; handle potential quotes in config.yaml |
| 7 | +PROJECT_NAME=$(grep '^name:' "$HOST_ROOT/.ddev/config.yaml" | awk '{print $2}' | tr -d '"' | tr -d "'") |
8 | 8 | CONTAINER_NAME="ddev-${PROJECT_NAME}-web" |
9 | 9 |
|
10 | | -# Define the project root in the container |
11 | | -CONTAINER_ROOT="/var/www/html" |
12 | | - |
13 | 10 | # Initialize an array for the new arguments |
14 | 11 | NEW_ARGS=() |
15 | 12 |
|
16 | | -# Loop through all arguments passed to the script |
17 | 13 | for arg in "$@"; do |
18 | | - # Skip if the argument is the psalm script itself |
19 | | - if [[ "$arg" == *"psalm.phar" ]] || [[ "$arg" == *"vendor/bin/psalm" ]]; then |
20 | | - continue |
21 | | - fi |
22 | | - |
23 | | - # Skip PHP arguments passed by the extension (starting with -d or -f) |
24 | | - if [[ "$arg" == -d* ]] || [[ "$arg" == -f* ]]; then |
25 | | - continue |
26 | | - fi |
27 | | - |
28 | | - # Skip the double dash separator often used to separate options |
29 | | - if [[ "$arg" == "--" ]]; then |
30 | | - continue |
31 | | - fi |
32 | | - |
33 | | - # Check if the argument contains the host root path |
34 | | - # if [[ "$arg" == *"$HOST_ROOT"* ]]; then |
35 | | - # Replace the host root path with the container root path |
36 | | - # NEW_ARGS+=("${arg//$HOST_ROOT/$CONTAINER_ROOT}") |
37 | | - # else |
38 | | - # Keep the argument as is |
39 | | - NEW_ARGS+=("$arg") |
40 | | - # fi |
| 14 | + # Skip arguments that would confuse the Psalm Phar inside the container |
| 15 | + [[ "$arg" == *"psalm.phar" ]] && continue |
| 16 | + [[ "$arg" == *"vendor/bin/psalm" ]] && continue |
| 17 | + [[ "$arg" == -d* ]] && continue |
| 18 | + [[ "$arg" == -f* ]] && continue |
| 19 | + [[ "$arg" == "--" ]] && continue |
| 20 | + |
| 21 | + NEW_ARGS+=("$arg") |
41 | 22 | done |
42 | 23 |
|
43 | | -# Execute Psalm inside the DDEV container with the modified arguments |
44 | | -# Use docker exec for better performance than ddev exec |
45 | | -# -i is required to keep STDIN open for the Language Server protocol |
46 | | -docker exec -i -w /var/www/html "$CONTAINER_NAME" ./vendor/bin/psalm.phar "${NEW_ARGS[@]}" |
| 24 | +# Execute Psalm |
| 25 | +# -i: keeps STDIN open (critical for Language Server Protocol) |
| 26 | +# -w: sets the working dir to the HOST path (which is symlinked in the container) |
| 27 | +# exec: replaces the bash process with docker so signals (like SIGTERM) are passed through |
| 28 | +exec docker exec -i -w "$HOST_ROOT" "$CONTAINER_NAME" ./vendor/bin/psalm.phar "${NEW_ARGS[@]}" |
0 commit comments