Skip to content

Commit

Permalink
Merge pull request #58 from moderntribe/fix/npm-scripts-exit-code
Browse files Browse the repository at this point in the history
Fix/npm scripts exit code
  • Loading branch information
lucatume authored Nov 23, 2020
2 parents 510b740 + e88cf9c commit 6c5ce65
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.13] - 2020-11-20
## [0.5.13] - 2020-11-23
### Changed

- Executing `tric use` without a target now attempts to set the current working directory as the target.
- `tric info` now outputs all valid targets, which is what `tric use` without a valid target used to do.
- The Composer prompt from `tric init` no longer appears if `composer.json` is not found, likewise for the NPM prompt if `package.json` is not found.
- Fixed an issue that would prevent the `npm` and `npm_lts` services from correctly returning their exit status.
- Add support for the `--pretty` flag to the `npm` and `npm_lts` commands to print a more human-readable output.

## [0.5.12] - 2020-11-11
### Changed
Expand Down
11 changes: 0 additions & 11 deletions containers/npm/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,3 @@ test "${FIXUID:-1}" != "0" && eval "$( fixuid > /dev/null 2>&1 )"
cd /project/${TRIC_CURRENT_PROJECT_SUBDIR}

npm "$@"

# Output error logs if present.
if compgen -G "/home/node/.npm/_logs/*.log" > /dev/null; then
echo "---------------------------------------"
echo "Error log found. Here are the contents (excluding the overly verbose saveTree lines):"
echo "---------------------------------------"
cat /home/node/.npm/_logs/*.log | grep -v "saveTree"
echo "---------------------------------------"
echo "End of error log"
echo "---------------------------------------"
fi
30 changes: 27 additions & 3 deletions src/commands/npm.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,33 @@
echo light_cyan( "Using {$using}\n" );

$command = $args( '...' );
$pool = build_command_pool( 'npm', $command, [ 'common' ] );
$status = execute_command_pool( $pool );
if ( '--pretty' === end( $command ) ) {
array_pop( $command );
$status = tric_realtime()( array_merge( [ 'run', '--rm', 'npm' ], $command ) );

exit( $status );
// If there is a status other than 0, we have an error. Bail.
if ( $status ) {
exit( $status );
}

if ( ! file_exists( tric_plugins_dir( "{$using}/common" ) ) ) {
return;
}

if ( ask( "\nWould you like to run that npm command against common?", 'no' ) ) {
tric_switch_target( "{$using}/common" );

echo light_cyan( "Temporarily using " . tric_target() . "\n" );

$status = tric_realtime()( array_merge( [ 'run', '--rm', 'npm' ], $npm_command ) );

tric_switch_target( $using );

echo light_cyan( "Using " . tric_target() ." once again\n" );
}

exit( $status );
} else {
$pool = build_command_pool( 'npm', $command, [ 'common' ] );
execute_command_pool( $pool );
}
30 changes: 27 additions & 3 deletions src/commands/npm_lts.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,33 @@
echo light_cyan( "Using {$using}\n" );

$command = $args( '...' );
$pool = build_command_pool( 'npm_lts', $command, [ 'common' ] );
$status = execute_command_pool( $pool );
if ( '--pretty' === end( $command ) ) {
array_pop( $command );
$status = tric_realtime()( array_merge( [ 'run', '--rm', 'npm_lts' ], $command ) );

exit( $status );
// If there is a status other than 0, we have an error. Bail.
if ( $status ) {
exit( $status );
}

if ( ! file_exists( tric_plugins_dir( "{$using}/common" ) ) ) {
return;
}

if ( ask( "\nWould you like to run that npm command against common?", 'no' ) ) {
tric_switch_target( "{$using}/common" );

echo light_cyan( "Temporarily using " . tric_target() . "\n" );

$status = tric_realtime()( array_merge( [ 'run', '--rm', 'npm_lts' ], $npm_command ) );

tric_switch_target( $using );

echo light_cyan( "Using " . tric_target() ." once again\n" );
}

exit( $status );
} else {
$pool = build_command_pool( 'npm_lts', $command, [ 'common' ] );
execute_command_pool( $pool );
}

0 comments on commit 6c5ce65

Please sign in to comment.