Skip to content

use the ddev env variable to retrieve the projects docroot - #35

Open
rpkoller wants to merge 2 commits into
UltraBob:mainfrom
rpkoller:20260510-rpkoller-use-ddev-docroot-env-var
Open

use the ddev env variable to retrieve the projects docroot#35
rpkoller wants to merge 2 commits into
UltraBob:mainfrom
rpkoller:20260510-rpkoller-use-ddev-docroot-env-var

Conversation

@rpkoller

Copy link
Copy Markdown
Contributor

The Issue

the manual detection in detect_docroot() had the shortcoming that an empty string within the docroot variable in the ddev config yaml was considered different to . - the docroot is not getting properly set. that way node dependencies are not getting installed in step 3 if the project has the project root as the docroot.

How This PR Solves The Issue

ddev provides a set of env variables https://docs.ddev.com/en/stable/users/extend/custom-commands/#environment-variables-provided . DDEV_DOCROOT which is one of those, contains the docroot set for the project at hand. that way it is possible to drop detect_docroot() and simply set dcq_docroot="${DDEV_DOCROOT}"

Manual Testing Instructions

ddev add-on get https://github.com/UltraBob/ddev-drupal-code-quality/tarball/refs/pull/REPLACE_ME_WITH_THIS_PR_NUMBER/head
ddev restart

Automated Testing Overview

Release/Deployment Notes

@rpkoller

rpkoller commented May 10, 2026

Copy link
Copy Markdown
Contributor Author

hm the PR works locally making the detect_docroot()method obsolete. but the problem, when you create a project with ddev config --project-type=drupal12 and set the value for the docroot to the default value (docroot: "") running ddev config you still run into misbehaviors. in consequence the behavior when you run ddev checks is different compared to if you set the docroot to docroot: ".". i will investigate more.

@rpkoller

Copy link
Copy Markdown
Contributor Author

and i still not have finally figured out what the actual error for the two failing tests is. unable to associate which the test responsible for the test run fail actually is. the output is not necessarily helpful or i am simply blind :(

The installer runs under set -u, so reading DDEV_DOCROOT unguarded
aborts with an unbound-variable error when the script is invoked
outside a DDEV-provided environment, such as the direct-invocation
bats tests. Use the colon-less default expansion so an unset variable
falls back to web while DDEV's set-but-empty value (project-root
docroot) still passes through unchanged.
@UltraBob

UltraBob commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Thanks Ralf, this is the right fix. DDEV_DOCROOT also picks up docroot overrides in config.*.yaml files, which the old awk parse never read.

I pushed a small commit on top of your branch. The installer runs under set -u, and the tests in test-installer-deps-prompt.bats run dcq-install.sh directly, outside a DDEV environment, so the unguarded ${DDEV_DOCROOT} died with an unbound-variable error. That's what CI was failing on. The commit changes it to ${DDEV_DOCROOT-web}: unset falls back to web, but an empty string (project-root docroot) passes through, so your fix behaves the same.

Fair warning for anyone testing on a project-root docroot: this gets node dependencies installed in phase 3, but most of the rest of the code still turns an empty docroot back into web through ${DCQ_DOCROOT:-web}. merge_phpstan_config and merge_phpcs_config in dcq-install.sh substitute __DOCROOT__ with web, rewrite_docroot_config skips its web/ rewrite so .cspell.json keeps its web/... paths, and commands/helpers/path-map.sh plus the wrappers in commands/web/ fall back the same way. That last one is the No files matching the pattern "web" error you saw from ddev eslint. I think the real fix might be for the installer to normalize an empty docroot to . when it records the value, so everything downstream can treat it like any other docroot instead of special-casing empty. Let's keep that under #34 so this PR can land as is.

@UltraBob

UltraBob commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Tests pass now, good progress!

@UltraBob

UltraBob commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Assigned, just for attention. Please don't take it as presumption.

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.

2 participants