Skip to content

Commit

Permalink
Merge pull request #196 from stellarwp/fix/playwright-install
Browse files Browse the repository at this point in the history
Fix - run playwright install as root
  • Loading branch information
lucatume authored Aug 20, 2024
2 parents fa20039 + e6f05fa commit 889aa35
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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).

# [1.7.1] - 2024-08-20
* Fixed - Run the `playwright install` command as root
* Change - The `playwright install` command will now install only the Chromium browser and its dependencies.

# [1.7.0] - 2024-06-06
* Fixed - Properly read changes and restart stack after using the `slic php-version set` command.
* Added - PHP 8.3 docker images.
Expand Down
2 changes: 1 addition & 1 deletion slic.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
] );

$cli_name = 'slic';
const CLI_VERSION = '1.7.0';
const CLI_VERSION = '1.7.1';

// If the run-time option `-q`, for "quiet", is specified, then do not print the header.
if ( in_array( '-q', $argv, true ) || ( in_array( 'exec', $argv, true ) && ! in_array( 'help', $argv, true ) ) ) {
Expand Down
48 changes: 34 additions & 14 deletions src/commands/playwright.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,40 @@

setup_id();
$playwright_args = $args( '...' );
$status = slic_realtime()(
array_merge(
[
'exec',
'--user',
sprintf( '"%s:%s"', getenv( 'SLIC_UID' ), getenv( 'SLIC_GID' ) ),
'--workdir',
escapeshellarg( get_project_container_path() ),
'slic',
'node_modules/.bin/playwright',
],
$playwright_args
)
);
$is_install_command = $playwright_args[0] === 'install';

if ( $is_install_command ) {
// Install commands will need to run as root.
$user = '0:0';
} else {
// Other commands will run as the current user.
$user = sprintf( '"%s:%s"', getenv( 'SLIC_UID' ), getenv( 'SLIC_GID' ) );
}

if ( $playwright_args === ['install'] ) {
// It's exactly the `playwright install` command and nothing more.
$command = [
'exec',
'--user',
'0:0',
'--workdir',
escapeshellarg( get_project_container_path() ),
'slic',
'node_modules/.bin/playwright install chromium --with-deps',
];
} else {
$command = array_merge( [
'exec',
'--user',
$user,
'--workdir',
escapeshellarg( get_project_container_path() ),
'slic',
'node_modules/.bin/playwright',
], $playwright_args );
}

$status = slic_realtime()( $command );

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

0 comments on commit 889aa35

Please sign in to comment.