feat: add first-class theme support for slic here and slic run#243
feat: add first-class theme support for slic here and slic run#243claudiosanches wants to merge 1 commit intomainfrom
Conversation
When `slic here` is run from a themes directory (without wp-config.php), slic previously entered "plugins directory mode" and set SLIC_PLUGINS_DIR to the themes directory. This caused plugins like WooCommerce to be cloned and installed inside wp-content/themes/, and Docker mounted the themes dir as wp-content/plugins/ in the container. This commit introduces proper theme-directory mode: - Add `slic_here_is_themes()`: returns true when SLIC_HERE_DIR matches SLIC_THEMES_DIR, indicating slic was pointed at a themes directory. - Update `get_valid_targets()`: include themes as valid `slic use` targets when in themes-directory mode (previously only included when slic_here_is_site()). - Fix `run.php`: replace `slic_plugins_dir(slic_target())` with `get_project_local_path()` so the host-side Codeception config lookup resolves to SLIC_THEMES_DIR/<theme> for theme targets instead of always falling back to SLIC_PLUGINS_DIR. - Fix `using.php`: same path resolution fix for the displayed target path. - Fix `build_command_pool()` and `maybe_build_install_command_pool()` in slic.php: use `get_project_local_path()` for composer/npm build file detection so these commands work correctly for theme targets. `get_project_local_path()` and `get_project_container_path()` in project.php already handled the 'theme' project type correctly — this change ensures the rest of the codebase uses them consistently. - Update README: document the themes directory as a first-class `slic here` option (option 2, before the WordPress root option), including the correct WPLoader suite config pattern for activating a theme under test. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bordoni
left a comment
There was a problem hiding this comment.
Lets wait until we get a couple more approvals.
Create a PR for testing this.
|
I used this branch to create some tests for the portal theme, and it seems to be working great! Here is the commit for reference: https://github.com/stellarwp/commerce-portal-theme/pull/86/changes/4e965e65b9baffc4869132a16fb4b773968f890d |
|
@claudiosanches Yesterday I ran the tests on my macOS machine using this branch and it worked fine, but today when running on my WSL/Ubuntu setup I hit a few problems. I documented everything here: https://github.com/stellarwp/commerce-portal-planning/blob/main/epics/10-checkout/backups-quota-implementation-plan.md#test-10--automated-wpunit-tests One thing that still required a manual step after setup was editing The root cause is in A small addition to the } else {
$sibling_plugins_dir = realpath( dirname( $here_dir ) . '/plugins' );
if ( $sibling_plugins_dir && is_dir( $sibling_plugins_dir ) ) {
// Themes-directory mode: set SLIC_THEMES_DIR = current dir and
// SLIC_PLUGINS_DIR = sibling plugins/ so SLIC_HERE_DIR == SLIC_THEMES_DIR
// and get_project_type() correctly returns 'theme'.
$env_values['SLIC_HERE_DIR'] = $here_dir;
$env_values['SLIC_WP_DIR'] = $wp_dir;
$env_values['SLIC_PLUGINS_DIR'] = $sibling_plugins_dir;
$env_values['SLIC_THEMES_DIR'] = $here_dir;
} else {
$env_values['SLIC_HERE_DIR'] = $here_dir;
$env_values['SLIC_WP_DIR'] = $wp_dir;
$env_values['SLIC_PLUGINS_DIR'] = $here_dir;
$env_values['SLIC_THEMES_DIR'] = $themes_dir;
}
}This covers both standard WordPress ( cd content/themes
slic here # auto-detects themes mode — no manual edit needed
slic use commerce-portal-theme
slic composer install
slic run wpunit |
Summary
slic herefrom a themes directory setSLIC_PLUGINS_DIRto the themes dir, causing plugins (WooCommerce, etc.) to be installed/cloned insidewp-content/themes/and mounted aswp-content/plugins/in the container.slic runalso broke because host path resolution always usedSLIC_PLUGINS_DIReven for theme targets.slic_here_is_themes()) that is detected whenSLIC_HERE_DIR == SLIC_THEMES_DIR, and replace all directslic_plugins_dir(slic_target())calls in command files withget_project_local_path(), which already handled the'theme'project type correctly inproject.php.slic hereoption in the README, including the correct WPLoader suite config pattern for activating a theme under test.Changes
src/slic.phpslic_here_is_themes()helper — returnstruewhenSLIC_HERE_DIRequalsSLIC_THEMES_DIRget_valid_targets()to include theme targets when in themes-directory mode (previously they were only included in site mode)build_command_pool()andmaybe_build_install_command_pool()to useget_project_local_path()for build-file detection instead ofslic_plugins_dir(target)src/commands/run.phpslic_plugins_dir(slic_target())withget_project_local_path()so the Codeception config lookup resolves correctly for theme targets (SLIC_THEMES_DIR/<theme>rather thanSLIC_PLUGINS_DIR/<theme>)src/commands/using.phpREADME.mdslic hereworkflow for theme development and the WPLoadertheme:config key patternBackwards compatibility
Fully backwards-compatible for plugins.
get_project_local_path()returnsSLIC_PLUGINS_DIR/<target>whenget_project_type()is'plugin'— identical to the previousslic_plugins_dir(target)behaviour. Theslic_here_is_themes()check inget_valid_targets()is additive and only fires when pointed at a themes directory.Test plan
slic herefrom a themes directory:slic infoshowsSLIC_PLUGINS_DIRpointing at the plugins directory andSLIC_THEMES_DIRpointing at the themes directoryslic use <theme>resolves andslic usingdisplays the correct themes-directory pathslic run wpunitexecutes from the correctwp-content/themes/<theme>workdir in the containerslic composer installdetectscomposer.jsoncorrectly for a theme targetslic herefrom a plugins directory or WordPress root) are unaffected🤖 Generated with Claude Code