Derive the plugin directory name in the wp-env scripts - #276
Merged
Conversation
wp-env mounts the checkout at wp-content/plugins/<directory name>, but the scripts passed a fixed --env-cwd of wp-content/plugins/phpdoc-parser. A checkout in a differently named directory, such as a git worktree, ran the commands in a path that does not exist in the container. Build the path from the current directory name so the scripts work wherever the repository is checked out.
This was referenced Aug 18, 2026
sirreal
commented
Aug 20, 2026
sirreal
left a comment
Member
Author
There was a problem hiding this comment.
Note
This is an agentic review, generated by Claude Code at the repository owner's request.
Ready to land after #283. No defects; the only thing holding it is merge ordering.
Verified
- CI green on 7.4 and 8.4; mergeable, clean, based on
master. - The premise is exactly right.
@wordpress/env'sparse-source-string.jsderives a local source's mount name withpath.basename( sourcePath )(line 58) and mounts it atwp-content/plugins/<basename>. Both.wp-env.jsonand.wp-env.test.jsonlist"."as the plugin source, so the container path is the basename of the checkout directory — hardcodingphpdoc-parserreally does break worktrees and renamed clones. $PWDis safe here, which was my main worry. npm runs scripts with cwd set to the package root, and a script invoked from a subdirectory still sees the package root in$PWD: I rannpm runfrom a subdir and gotPWD=<package root>,base=<package root basename>. A stale inheritedPWDis also reset byshat startup (verified withenv PWD=/some/where/else sh -c 'echo $PWD'). No need for$(pwd).- The nested quoting is valid POSIX. The shell sees
--env-cwd="wp-content/plugins/$(basename "$PWD")"; inside$( )the quoting context restarts, so the inner"$PWD"is a properly quoted word, and directory names containing spaces survive. Verified by execution, not just by reading. - In GitHub Actions the workspace basename is
phpdoc-parser, sonpm run test:phpunit:setup/npm run testare unchanged there — consistent with CI passing.
Worth noting
- Not a regression, but for the record: these scripts are already broken under
cmd.exeon Windows (npm's default script shell there), where the pre-existing single quotes are not quotes either.$(basename "$PWD")does not make that worse. If Windows support ever matters,"script-shell"in.npmrcis the fix, not this line.
Ordering
#283 changes the composer passthrough line in the same file (dropping --no-security-blocking, which is an install-only option). Land #283 first, then rebase this one by removing that flag from the rewritten passthrough line:
"composer": "wp-env --config .wp-env.test.json run --env-cwd=\"wp-content/plugins/$(basename \"$PWD\")\" wordpress composer --no-interaction"
composer:setup keeps --no-security-blocking as it does today. Expect a one-line conflict, nothing more.
sirreal
added a commit
that referenced
this pull request
Aug 20, 2026
`--no-security-blocking` is an install/update option, but the generic `composer` passthrough script passes it to every command, so anything else fails — e.g. `npm run composer -- validate`. The flag stays on `composer:setup` (install), and the passthrough keeps only `--no-interaction`. Verified in the PHP 7.4 wordpress container: `composer --no-interaction --no-security-blocking validate` exits 1; without the flag it reports `./composer.json is valid`. `composer install --no-interaction --no-security-blocking` continues to work (unchanged `composer:setup` path). Overlaps trivially with #276, which rewrites the same lines to derive the plugin directory; whichever lands second rebases in seconds. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
# Conflicts: # package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The wp-env npm scripts (
composer,composer:setup,test:phpunit) hardcodewp-content/plugins/phpdoc-parseras the container path. wp-env mounts the checkout under its directory basename, so the scripts break for any checkout not named exactlyphpdoc-parser— git worktrees, renamed clones.Derive the path with
$(basename "$PWD")so the scripts work for any checkout name. Verified by running the suite throughnpm run test:phpunitfrom a worktree namedphpdoc-parser-pr262-fixes.Extracted from #262 to keep that PR focused on export semantics.
🤖 Generated with Claude Code