Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed wp-env start On Windows #50895

Merged
merged 8 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/env/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions packages/env/lib/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
? '/'
Expand Down
6 changes: 5 additions & 1 deletion packages/env/lib/config/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -233,7 +234,10 @@ async function getDefaultConfig(
env: {
development: {},
tests: {
config: { WP_DEBUG: false, SCRIPT_DEBUG: false },
config: {
WP_DEBUG: false,
SCRIPT_DEBUG: false,
},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/env/lib/config/test/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const DEFAULT_CONFIG = {
pluginSources: [],
themeSources: [],
config: {
FS_METHOD: 'direct',
WP_DEBUG: true,
SCRIPT_DEBUG: true,
WP_ENVIRONMENT_TYPE: 'local',
Expand Down
12 changes: 4 additions & 8 deletions packages/env/lib/get-host-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 9 additions & 4 deletions packages/env/lib/init-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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`;

Expand Down