Skip to content

Commit 20d72cd

Browse files
gobaamateescuCopilotpenyaskitoclaude
authored
fix: Make canvas paths docroot-aware in host commands (#72)
Derive the canvas module location from composer installer-paths so xb-setup, xb-cypress, and xb-playwright work with both docroot=web and docroot="" projects (including Drupal core-style checkouts with drupal-dev). Also update README setup/usage wording to reflect docroot-agnostic behavior. LLM assistance was used to build this PR --------- Co-authored-by: Gábor Hojtsy <goba@users.noreply.github.com> Co-authored-by: Andrei Mateescu <amateescu@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Christian Lopez Espinola <penyaskito@computer.org> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 77b6e99 commit 20d72cd

6 files changed

Lines changed: 63 additions & 18 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ mkdir ~/Sites/xb-dev
3232
cd ~/Sites/xb-dev
3333

3434
# Configure the new DDEV project.
35-
ddev config --project-type=drupal11 --docroot=web
35+
ddev config --project-type=drupal11
3636

3737
# Create the Drupal project.
3838
ddev composer create-project drupal/recommended-project:11.x@dev --no-install
3939

4040
# Install the add-on.
4141
ddev add-on get drupal-canvas/ddev-drupal-xb-dev
4242

43-
# Perform one-time setup operations.
43+
# Perform one-time setup operations, including composer installing Drupal Canvas itself.
4444
ddev xb-setup
4545

4646
# Optionally add some convenience extras for development.
@@ -56,7 +56,7 @@ ddev xb-workspaces-dev
5656

5757
The resulting DDEV project is just like any other one. Interact with it using the [the built-in commands](https://ddev.readthedocs.io/en/stable/users/usage/commands/), e.g., `ddev launch` to browse the site.
5858

59-
The installation process clones [the Drupal Canvas module](https://www.drupal.org/project/canvas) into `web/modules/contrib/canvas`. Develop and contribute from either location like you would any other Git repo for a normal Drupal project.
59+
The installation process clones [the Drupal Canvas module](https://www.drupal.org/project/canvas) into the project installer path for contrib modules (typically `web/modules/contrib/canvas` for `docroot: web`, or `modules/contrib/canvas` for `docroot: ""`). Develop and contribute from there like you would any other Git repo for a normal Drupal project.
6060

6161
Any time you update the Drupal Canvas module or modify its front-end code, be sure to rebuild the UI app assets:
6262

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
## #ddev-generated
4+
5+
# Shared helpers for host-side xb commands.
6+
7+
resolve_canvas_dir() {
8+
ddev exec -- php -r '
9+
$composer = json_decode((string) file_get_contents("composer.json"), true);
10+
$paths = $composer["extra"]["installer-paths"] ?? [];
11+
foreach ($paths as $path => $conditions) {
12+
if (in_array("type:drupal-module", $conditions, true)) {
13+
echo str_replace("{\$name}", "canvas", $path);
14+
exit(0);
15+
}
16+
}
17+
echo "modules/contrib/canvas";
18+
'
19+
}
20+
21+
init_canvas_paths() {
22+
local script_dir="$1"
23+
local docroot_prefix
24+
25+
CANVAS_DIR_RELATIVE="$(resolve_canvas_dir)"
26+
CANVAS_DIR_ON_HOST="$script_dir/../../../$CANVAS_DIR_RELATIVE"
27+
CANVAS_DIR_INSIDE_CONTAINER="/var/www/html/$CANVAS_DIR_RELATIVE"
28+
CANVAS_UI_DIR_INSIDE_CONTAINER="$CANVAS_DIR_INSIDE_CONTAINER/ui"
29+
30+
docroot_prefix="${CANVAS_DIR_RELATIVE%/modules/contrib/canvas}"
31+
if [ "$docroot_prefix" = "$CANVAS_DIR_RELATIVE" ]; then
32+
docroot_prefix=""
33+
fi
34+
SETTINGS_DDEV_PATH="${docroot_prefix:+$docroot_prefix/}sites/default/settings.ddev.php"
35+
CORE_DIR_IN_CONTAINER="/var/www/html/${docroot_prefix:+$docroot_prefix/}core"
36+
}

‎commands/host/xb-cypress‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
## OSTypes: darwin,linux
1010
## ExecRaw: true
1111

12-
cd "$(dirname "$0")" || exit 1
12+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
13+
. "$SCRIPT_DIR/.xb-command-helpers.sh"
14+
init_canvas_paths "$SCRIPT_DIR"
1315

14-
CYPRESS_BIN="$(dirname "$0")/../../../web/modules/contrib/canvas/node_modules/cypress/bin/cypress"
15-
CYPRESS_BIN_INSIDE_CONTAINER="/var/www/html/web/modules/contrib/canvas/node_modules/cypress/bin/cypress"
16+
CYPRESS_BIN="$CANVAS_DIR_ON_HOST/node_modules/cypress/bin/cypress"
17+
CYPRESS_BIN_INSIDE_CONTAINER="$CANVAS_DIR_INSIDE_CONTAINER/node_modules/cypress/bin/cypress"
1618

1719
# Check for the presence of Cypress.
1820
if ! command -v "$CYPRESS_BIN" &>/dev/null; then
@@ -61,7 +63,7 @@ xhost +
6163
function xb_cypress {
6264
# This needs to be the binary path inside the container.
6365
ddev exec \
64-
--dir /var/www/html/web/modules/contrib/canvas/ui \
66+
--dir "$CANVAS_UI_DIR_INSIDE_CONTAINER" \
6567
"$CYPRESS_BIN_INSIDE_CONTAINER $1"
6668
}
6769

‎commands/host/xb-playwright‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
## OSTypes: darwin,linux
1010
## ExecRaw: true
1111

12-
CANVAS_DIR_INSIDE_CONTAINER="/var/www/html/web/modules/contrib/canvas"
13-
CANVAS_DIR_ON_HOST="$(dirname "$0")/../../../web/modules/contrib/canvas"
12+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
13+
. "$SCRIPT_DIR/.xb-command-helpers.sh"
14+
init_canvas_paths "$SCRIPT_DIR"
1415

1516
# Check that Playwright is installed (npm install has run).
1617
if [[ ! -x "$CANVAS_DIR_ON_HOST/node_modules/.bin/playwright" ]]; then

‎commands/host/xb-setup‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
## Flags: [{"Name":"force","Shorthand":"f","Usage":"Completely reset an existing environment if present and start over"}]
88
## ExecRaw: true
99

10-
cd "$(dirname "$0")" || exit
11-
cd ../../../
10+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
11+
. "$SCRIPT_DIR/.xb-command-helpers.sh"
12+
13+
cd "$SCRIPT_DIR/../../../" || exit
1214
set -e
1315

16+
init_canvas_paths "$SCRIPT_DIR"
17+
CANVAS_DIR="$CANVAS_DIR_RELATIVE"
18+
1419
# Flag-handling.
1520
while :; do
1621
case ${1:-} in
@@ -28,7 +33,7 @@ while :; do
2833
done
2934

3035
# Exit early if the environment is already set up.
31-
if [ -d web/modules/contrib/canvas/.git ] && [ ! "$FORCE" ]; then
36+
if [ -d "$CANVAS_DIR/.git" ] && [ ! "$FORCE" ]; then
3237
GREEN="\033[0;32m"
3338
NO_COLOR="\033[0m"
3439
printf "%bThe Drupal Canvas development environment is already set up.%b\n" "$GREEN" "$NO_COLOR"
@@ -40,14 +45,14 @@ if [ -d web/modules/contrib/canvas/.git ] && [ ! "$FORCE" ]; then
4045
fi
4146

4247
# Remove the Drupal Canvas module if it's there.
43-
rm -rf web/modules/contrib/canvas
44-
mkdir -p web/modules/contrib
48+
rm -rf "$CANVAS_DIR"
49+
mkdir -p "$(dirname "$CANVAS_DIR")"
4550

4651
# Place the Drupal Canvas module via Git for development. Require
4752
# it with Composer to test its composer.json and place dependencies.
4853
git clone \
4954
git@git.drupal.org:project/canvas.git \
50-
web/modules/contrib/canvas
55+
"$CANVAS_DIR"
5156

5257
# Allow all Composer plugins.
5358
ddev composer config \
@@ -66,7 +71,7 @@ ddev composer require \
6671
ddev composer config \
6772
repositories.xb \
6873
path \
69-
web/modules/contrib/canvas
74+
"$CANVAS_DIR"
7075
ddev composer require \
7176
--no-install \
7277
--update-with-all-dependencies \
@@ -87,13 +92,13 @@ ddev composer require \
8792
# Allow test modules and themes to be installed.
8893
# shellcheck disable=SC2016
8994
printf '\n# Allow test modules and themes to be installed.\n$settings["extension_discovery_scan_tests"] = TRUE;' \
90-
>> web/sites/default/settings.ddev.php
95+
>> "$SETTINGS_DDEV_PATH"
9196

9297
# Install Drupal and enable the Drupal Canvas module.
9398
ddev xb-site-install
9499

95100
# Install Drupal core NPM packages.
96-
ddev exec --dir /var/www/html/web/core -- npm install
101+
ddev exec --dir "$CORE_DIR_IN_CONTAINER" -- npm install
97102

98103
# Build front-end assets.
99104
ddev xb-ui-build

‎install.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
name: drupal-xb-dev
66

77
project_files:
8+
- commands/host/.xb-command-helpers.sh
89
- commands/host/xb-cypress
910
- commands/host/xb-fix
1011
- commands/host/xb-playwright

0 commit comments

Comments
 (0)