diff --git a/packages/env/CHANGELOG.md b/packages/env/CHANGELOG.md index d69eea93d50ab..c97e2d48fb917 100644 --- a/packages/env/CHANGELOG.md +++ b/packages/env/CHANGELOG.md @@ -17,6 +17,10 @@ - Support using double dashes in `wp-env run ...` to pass arguments that would otherwise be consumed by `wp-env`. For example, while normally `--help` would provide the `wp-env` help text, if you use `npx wp-env run cli php -- --help` you will see the PHP help text. - Validate whether or not config options exist to prevent accidentally including ones that don't. +### Bug fix + +- Support Windows without requiring the use of WSL. + ## 7.0.0 (2023-05-10) ### Breaking Change diff --git a/packages/env/lib/commands/run.js b/packages/env/lib/commands/run.js index 8feadfa98eda3..def29b6523139 100644 --- a/packages/env/lib/commands/run.js +++ b/packages/env/lib/commands/run.js @@ -67,8 +67,9 @@ function spawnCommandDirectly( config, container, command, envCwd, spinner ) { // to interact with the files mounted from the host. const hostUser = getHostUser(); - // We need to pass absolute paths to the container. - envCwd = path.resolve( + // Since Docker requires absolute paths, we should resolve the input to a POSIX path. + // This is needed because Windows resolves relative paths from the C: drive. + envCwd = path.posix.resolve( // Not all containers have the same starting working directory. container === 'mysql' || container === 'tests-mysql' ? '/' diff --git a/packages/env/lib/config/parse-config.js b/packages/env/lib/config/parse-config.js index 064ec368c31c1..743db97896344 100644 --- a/packages/env/lib/config/parse-config.js +++ b/packages/env/lib/config/parse-config.js @@ -87,6 +87,7 @@ const DEFAULT_ENVIRONMENT_CONFIG = { testsPort: 8889, mappings: {}, config: { + FS_METHOD: 'direct', WP_DEBUG: true, SCRIPT_DEBUG: true, WP_ENVIRONMENT_TYPE: 'local', @@ -233,7 +234,10 @@ async function getDefaultConfig( env: { development: {}, tests: { - config: { WP_DEBUG: false, SCRIPT_DEBUG: false }, + config: { + WP_DEBUG: false, + SCRIPT_DEBUG: false, + }, }, }, }; diff --git a/packages/env/lib/config/test/__snapshots__/config-integration.js.snap b/packages/env/lib/config/test/__snapshots__/config-integration.js.snap index d9d0883589aff..53a2d652c740f 100644 --- a/packages/env/lib/config/test/__snapshots__/config-integration.js.snap +++ b/packages/env/lib/config/test/__snapshots__/config-integration.js.snap @@ -8,6 +8,7 @@ exports[`Config Integration should load local and override configuration files 1 "env": { "development": { "config": { + "FS_METHOD": "direct", "SCRIPT_DEBUG": true, "WP_DEBUG": true, "WP_ENVIRONMENT_TYPE": "local", @@ -35,6 +36,7 @@ exports[`Config Integration should load local and override configuration files 1 }, "tests": { "config": { + "FS_METHOD": "direct", "SCRIPT_DEBUG": false, "WP_DEBUG": false, "WP_ENVIRONMENT_TYPE": "local", @@ -79,6 +81,7 @@ exports[`Config Integration should load local configuration file 1`] = ` "env": { "development": { "config": { + "FS_METHOD": "direct", "SCRIPT_DEBUG": true, "WP_DEBUG": true, "WP_ENVIRONMENT_TYPE": "local", @@ -106,6 +109,7 @@ exports[`Config Integration should load local configuration file 1`] = ` }, "tests": { "config": { + "FS_METHOD": "direct", "SCRIPT_DEBUG": false, "WP_DEBUG": false, "WP_ENVIRONMENT_TYPE": "local", @@ -150,6 +154,7 @@ exports[`Config Integration should use default configuration 1`] = ` "env": { "development": { "config": { + "FS_METHOD": "direct", "SCRIPT_DEBUG": true, "WP_DEBUG": true, "WP_ENVIRONMENT_TYPE": "local", @@ -177,6 +182,7 @@ exports[`Config Integration should use default configuration 1`] = ` }, "tests": { "config": { + "FS_METHOD": "direct", "SCRIPT_DEBUG": false, "WP_DEBUG": false, "WP_ENVIRONMENT_TYPE": "local", @@ -221,6 +227,7 @@ exports[`Config Integration should use environment variables over local and over "env": { "development": { "config": { + "FS_METHOD": "direct", "SCRIPT_DEBUG": true, "WP_DEBUG": true, "WP_ENVIRONMENT_TYPE": "local", @@ -249,6 +256,7 @@ exports[`Config Integration should use environment variables over local and over }, "tests": { "config": { + "FS_METHOD": "direct", "SCRIPT_DEBUG": false, "WP_DEBUG": false, "WP_ENVIRONMENT_TYPE": "local", diff --git a/packages/env/lib/config/test/parse-config.js b/packages/env/lib/config/test/parse-config.js index 5052199a983d5..0e71f57f56fc2 100644 --- a/packages/env/lib/config/test/parse-config.js +++ b/packages/env/lib/config/test/parse-config.js @@ -40,6 +40,7 @@ const DEFAULT_CONFIG = { pluginSources: [], themeSources: [], config: { + FS_METHOD: 'direct', WP_DEBUG: true, SCRIPT_DEBUG: true, WP_ENVIRONMENT_TYPE: 'local', diff --git a/packages/env/lib/get-host-user.js b/packages/env/lib/get-host-user.js index 7c7f095de1715..79104fa2e9838 100644 --- a/packages/env/lib/get-host-user.js +++ b/packages/env/lib/get-host-user.js @@ -13,14 +13,10 @@ module.exports = function getHostUser() { const hostUser = os.userInfo(); // On Windows the uid and gid will be -1. Since there isn't a great way to handle this, - // we're just going to say that the host user is root. On Windows you'll likely be - // using WSL to run commands inside the container, which has a uid and gid. If - // you aren't, you'll be mounting directories from Windows, to a Linux - // VM (Docker Desktop uses one), to the guest OS. I assume that - // when dealing with this configuration that file ownership - // has the same kind of magic handling that macOS uses. - const uid = ( hostUser.uid === -1 ? 0 : hostUser.uid ).toString(); - const gid = ( hostUser.gid === -1 ? 0 : hostUser.gid ).toString(); + // we're just going to assign them to 1000. Docker Desktop already takes care of + // permission-related issues using magic, so this should be fine. + const uid = ( hostUser.uid === -1 ? 1000 : hostUser.uid ).toString(); + const gid = ( hostUser.gid === -1 ? 1000 : hostUser.gid ).toString(); return { name: hostUser.username, diff --git a/packages/env/lib/init-config.js b/packages/env/lib/init-config.js index 4a573c97aae7e..ee26ade75c665 100644 --- a/packages/env/lib/init-config.js +++ b/packages/env/lib/init-config.js @@ -202,15 +202,20 @@ RUN apt-get -qy install $PHPIZE_DEPS && touch /usr/local/etc/php/php.ini # Set up sudo so they can have root access. RUN apt-get -qy install sudo -RUN echo "$HOST_USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers`; +RUN echo "#$HOST_UID ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers`; break; } case 'cli': { dockerFileContent += ` +# Make sure we're working with the latest packages. RUN apk update + +# Install some basic PHP dependencies. RUN apk --no-cache add $PHPIZE_DEPS && touch /usr/local/etc/php/php.ini + +# Set up sudo so they can have root access. RUN apk --no-cache add sudo linux-headers -RUN echo "$HOST_USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers`; +RUN echo "#$HOST_UID ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers`; break; } default: { @@ -238,8 +243,8 @@ RUN rm /tmp/composer-setup.php`; // Install any Composer packages we might need globally. // Make sure to do this as the user and ensure the binaries are available in the $PATH. dockerFileContent += ` -USER $HOST_USERNAME -ENV PATH="\${PATH}:/home/$HOST_USERNAME/.composer/vendor/bin" +USER $HOST_UID:$HOST_GID +ENV PATH="\${PATH}:~/.composer/vendor/bin" RUN composer global require --dev yoast/phpunit-polyfills:"^1.0" USER root`;