Skip to content

Commit e3c6139

Browse files
authored
Merge pull request #18 from moderntribe/fix/npm-subdir
Allow npm install on subdirectory use targets
2 parents e88d208 + 1dcecfa commit e3c6139

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

.env.tric

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ CLI_VERBOSITY=0
1919
# TRIC_CURRENT_PROJECT=the-events-calendar
2020
# When you `here` at the site level, all selected targets via `use` will have a relative path set.
2121
# TRIC_CURRENT_PROJECT_RELATIVE_PATH=
22+
# When you `use` on a supported subdirectory of a plugin, this stores the subdirectory name.
23+
#TRIC_CURRENT_PROJECT_SUBDIR=
2224
# The GitHub handle of the company to clone plugins from.
2325
TRIC_GITHUB_COMPANY_HANDLE=moderntribe
2426

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Changed
1414

15+
- Adjust pathing of subdirectories within the tric stack so that npm can find a `.git` directory when performing `npm install`.
16+
- Suppress the `fixuid` command output in the npm `docker-entrypoint.sh`.
1517
- Separated out poolable (passive) command functions from realtime command functions to prevent issues with interactivity.
1618

1719
## [0.2.0] - 2020-06-24

containers/npm/docker-entrypoint.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
# This file is just a proxy to call the `npm` binary that will, but, take care of fixing file mode issues before.
44

55
# If the `FIXUID` env var is set to `1`, default value, then fix UIDs.
6-
test "${FIXUID:-1}" != "0" && eval "$( fixuid )"
6+
test "${FIXUID:-1}" != "0" && eval "$( fixuid > /dev/null 2>&1 )"
77

8-
npm --prefix /project "$@"
8+
cd /project/${TRIC_CURRENT_PROJECT_SUBDIR}
9+
10+
npm "$@"
911

1012
# Output error logs if present.
1113
if compgen -G "/home/node/.npm/_logs/*.log" > /dev/null; then

src/tric.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,20 @@ function setup_tric_env( $root_dir ) {
178178
* return value will always be a non empty string.
179179
*/
180180
function tric_target( $require = true ) {
181-
$using = getenv( 'TRIC_CURRENT_PROJECT' );
181+
$using = getenv( 'TRIC_CURRENT_PROJECT' );
182+
$using_subdir = getenv( 'TRIC_CURRENT_PROJECT_SUBDIR' );
183+
$using_full = $using . ( $using_subdir ? '/' . $using_subdir : '' );
184+
182185
if ( $require ) {
183-
return $using;
186+
return $using_full;
184187
}
185-
if ( empty( $using ) ) {
188+
189+
if ( empty( $using_full ) ) {
186190
echo magenta( "Use target not set; use the 'use' sub-command to set it.\n" );
187191
exit( 1 );
188192
}
189193

190-
return trim( $using );
194+
return trim( $using_full );
191195
}
192196

193197
/**
@@ -199,14 +203,20 @@ function tric_switch_target( $target ) {
199203
$root = root();
200204
$run_settings_file = "{$root}/.env.tric.run";
201205
$target_relative_path = '';
206+
$subdir = '';
202207

203208
if ( tric_here_is_site() ) {
204209
$target_relative_path = get_target_relative_path( $target );
205210
}
206211

212+
if ( false !== strpos( $target, '/' ) ) {
213+
list( $target, $subdir ) = explode( '/', $target );
214+
}
215+
207216
$env_values = [
208217
'TRIC_CURRENT_PROJECT' => $target,
209218
'TRIC_CURRENT_PROJECT_RELATIVE_PATH' => $target_relative_path,
219+
'TRIC_CURRENT_PROJECT_SUBDIR' => $subdir,
210220
];
211221

212222
write_env_file( $run_settings_file, $env_values, true );

src/wordpress.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static function ( SplFileInfo $file ) {
8181
}
8282
);
8383

84-
$allowed_subdirs = [ 'common' ];
84+
$allowed_subdirs = get_allowed_use_subdirectories();
8585
foreach ( iterator_to_array( $dir ) as $key => $value ) {
8686
$basename = basename( $key );
8787
$dirs[ $basename ] = $value;
@@ -95,3 +95,12 @@ static function ( SplFileInfo $file ) {
9595

9696
return $dirs;
9797
}
98+
99+
/**
100+
* Returns the list of allowed subdirectories for tric use.
101+
*
102+
* @return array<string> Allowed subdirectories for use.
103+
*/
104+
function get_allowed_use_subdirectories() {
105+
return [ 'common' ];
106+
}

tric-stack.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ services:
146146
# XDH=$(ip route | grep docker0 | awk '{print $9}') docker-compose ...
147147
XDEBUG_CONFIG: "idekey=${XDK:-tric} remote_enable=${XDE:-1} remote_host=${XDH:-host.docker.internal} remote_port=${XDP:-9001}"
148148
# Move to the target directory before running the command from the plugins directory.
149-
CODECEPTION_PROJECT_DIR: /var/www/html/wp-content/plugins/${TRIC_CURRENT_PROJECT:-test}
149+
CODECEPTION_PROJECT_DIR: /var/www/html/wp-content/plugins/${TRIC_CURRENT_PROJECT:-test}/${TRIC_CURRENT_PROJECT_SUBDIR}
150150
# When running the container in shell mode (using the tric `shell` command), then use this CC configuration.
151151
CODECEPTION_SHELL_CONFIG: "-c codeception.tric.yml"
152152
# After the WordPress container comes online, wait a further 3s to give it some boot-up time.
@@ -180,7 +180,7 @@ services:
180180
FIXUID: "${FIXUID:-1}"
181181
volumes:
182182
# Set the current plugin as project.
183-
- ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}:/project:cached
183+
- ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}/${TRIC_CURRENT_PROJECT_SUBDIR}:/project:cached
184184
# Share SSH keys with the container to pull from private repositories.
185185
- ${DOCKER_RUN_SSH_AUTH_SOCK}:/ssh-agent:ro
186186

@@ -191,6 +191,7 @@ services:
191191
user: "${DOCKER_RUN_UID:-}:${DOCKER_RUN_GID:-}"
192192
environment:
193193
FIXUID: ${FIXUID:-1}
194+
TRIC_CURRENT_PROJECT_SUBDIR: ${TRIC_CURRENT_PROJECT_SUBDIR}
194195
volumes:
195196
# Set the current plugin as project.
196197
- ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}:/project:cached
@@ -205,7 +206,7 @@ services:
205206
working_dir: /project
206207
volumes:
207208
# Set the current plugin as project.
208-
- ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}:/project:cached
209+
- ${TRIC_PLUGINS_DIR}/${TRIC_CURRENT_PROJECT:-test}/${TRIC_CURRENT_PROJECT_SUBDIR}:/project:cached
209210
# Share SSH keys with the container to pull from private repositories.
210211
- ${DOCKER_RUN_SSH_AUTH_SOCK}:/ssh-agent:ro
211212

0 commit comments

Comments
 (0)