From 908996dac0cdd4852c06fe8f0b771ec1f01ce76c Mon Sep 17 00:00:00 2001 From: Genyus Date: Mon, 16 Nov 2026 18:18:55 -0400 Subject: [PATCH] chore(deps): install plugin dependencies with one script Replace the cd chains in install-ssp and update-ssp with scripts/local-deps.sh, which runs composer and npm in each web/app/plugins/cbf-* plugin. The semantic glossary plugins now get their npm dependencies too, and cbf-multisite's own npm hooks go. Plugins follow root --no-dev, and npm is skipped under --no-dev and in CI, which builds assets separately. Failures now stop the run instead of being ignored. --- .github/workflows/deploy-push.yml | 4 +- composer.json | 8 ++-- scripts/local-deps.sh | 52 +++++++++++++++++++++ web/app/plugins/cbf-multisite/composer.json | 6 --- 4 files changed, 58 insertions(+), 12 deletions(-) create mode 100755 scripts/local-deps.sh diff --git a/.github/workflows/deploy-push.yml b/.github/workflows/deploy-push.yml index a222fe85..e2b0844c 100644 --- a/.github/workflows/deploy-push.yml +++ b/.github/workflows/deploy-push.yml @@ -43,8 +43,8 @@ jobs: key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} # Composer runs on the runner, not in a container, so the plugin installs - # in install-ssp get the PHP extensions above, npm and a git checkout the - # runner owns + # in scripts/local-deps.sh get the PHP extensions above and a git checkout + # the runner owns. The script skips npm in CI. - name: Install dependencies run: composer install --no-interaction --no-progress --prefer-dist diff --git a/composer.json b/composer.json index 51df4ad2..95534dc1 100644 --- a/composer.json +++ b/composer.json @@ -168,15 +168,15 @@ "php -r \"copy('.env.example', '.env');\"" ], "post-install-cmd": [ - "@install-ssp", + "@local-deps:install", "if [ ! -e .env ]; then cp .env.dist .env; fi", "if [ ! -e wp-cli.yml ]; then cp wp-cli.yml.dist wp-cli.yml; fi" ], "post-update-cmd": [ - "@update-ssp" + "@local-deps:update" ], - "install-ssp": "cd web/app/plugins/cbf-multisite && composer install && cd ../cbf-slides-importer && composer install && cd ../cbf-semantic-glossary && composer install && cd ../cbf-semantic-glossary-learndash && composer install && cd ../../../..", - "update-ssp": "cd web/app/plugins/cbf-multisite && composer update && cd ../cbf-slides-importer && composer update && cd ../cbf-semantic-glossary && composer update && cd ../cbf-semantic-glossary-learndash && composer update && cd ../../../..", + "local-deps:install": "bash scripts/local-deps.sh install", + "local-deps:update": "bash scripts/local-deps.sh update", "lint": "phpcs --standard=phpcs.xml", "lint:all": "@lint ./web/app/plugins/cbf-multisite ./web/app/plugins/cbf-slides-importer ./web/app/plugins/cbf-semantic-glossary ./web/app/plugins/cbf-semantic-glossary-learndash ./web/app/themes/cbf-academy ./web/app/themes/cbf-jobs", "fix": "phpcbf --standard=phpcs.xml", diff --git a/scripts/local-deps.sh b/scripts/local-deps.sh new file mode 100755 index 00000000..09b81131 --- /dev/null +++ b/scripts/local-deps.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# +# Install or update the Composer and npm dependencies of each in-repo plugin +# (web/app/plugins/cbf-*). Root Composer runs this after its own install or +# update; run it directly to refresh the plugins alone. +# +# Usage: scripts/local-deps.sh install|update +# +# Under `composer install --no-dev`, as on the servers, plugins get --no-dev +# too and npm is skipped. npm is also skipped in CI, which builds plugin assets +# in its own step. + +set -euo pipefail + +action=${1:-} +if [ "$action" != install ] && [ "$action" != update ]; then + echo "Usage: $0 install|update" >&2 + exit 1 +fi + +cd "$(dirname "$0")/.." + +# Composer sets this for its hook scripts: 0 under --no-dev, 1 otherwise +dev=${COMPOSER_DEV_MODE:-1} + +composer_args=(--no-interaction) +if [ "$dev" = 0 ]; then + composer_args+=(--no-dev) +fi + +run_npm=0 +if [ "$dev" = 1 ] && [ -z "${CI:-}" ]; then + if command -v npm >/dev/null 2>&1; then + run_npm=1 + else + echo "npm not found: skipping plugin npm dependencies" >&2 + fi +fi + +for dir in web/app/plugins/cbf-*/; do + name=$(basename "$dir") + + if [ -f "$dir/composer.json" ]; then + echo "> $name: composer $action" + composer "$action" --working-dir="$dir" "${composer_args[@]}" + fi + + if [ "$run_npm" = 1 ] && [ -f "$dir/package.json" ]; then + echo "> $name: npm $action" + npm "$action" --prefix "$dir" --no-audit --no-fund + fi +done diff --git a/web/app/plugins/cbf-multisite/composer.json b/web/app/plugins/cbf-multisite/composer.json index 7f9762a8..3252148f 100644 --- a/web/app/plugins/cbf-multisite/composer.json +++ b/web/app/plugins/cbf-multisite/composer.json @@ -30,12 +30,6 @@ ], "phpcbf": [ "../../../../vendor/bin/phpcbf --standard=../../../../phpcs.xml -p ." - ], - "post-install-cmd": [ - "npm install || true" - ], - "post-update-cmd": [ - "npm update || true" ] }, "extra": {