-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
wp-env: Make env-cwd option work on Windows #56265
Conversation
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
1 similar comment
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
--env-cwd
option not working on Windows OSef777c3
to
41756b1
Compare
Size Change: +805 B (0%) Total Size: 1.72 MB
ℹ️ View Unchanged
|
It's because Windows treats single quotes as a literal character instead of a special one. This is normally fine and interpreted by Linux correctly but here it's a problem because |
Does this mean, for example, removing single quotes on the env package side as shown below? This approach also seems to work on Windows. diff --git a/packages/env/lib/cli.js b/packages/env/lib/cli.js
index 1788315b60..df8d1830e7 100644
--- a/packages/env/lib/cli.js
+++ b/packages/env/lib/cli.js
@@ -205,6 +205,7 @@ module.exports = function cli() {
default: '.',
describe:
"The command's working directory inside of the container. Paths without a leading slash are relative to the WordPress root.",
+ coerce: ( value ) => value.replace( /'/g, '' ),
} );
args.positional( 'container', {
type: 'string', |
Looks great @t-hamano. One consideration is that this should only remove single quotes from the beginning and end of the path. Another thought along these lines too is whether or not paths with spaces in them work too. |
I changed it to remove the leading and trailing single quotes and spaces. I have confirmed that most commands work on Windows and Linux. {
"scripts": {
"no-quote": "wp-env run tests-wordpress --env-cwd=wp-content/plugins/gutenberg pwd",
"has-quote": "wp-env run tests-wordpress --env-cwd='wp-content/plugins/gutenberg' pwd",
"has-escaped-quote": "wp-env run tests-wordpress --env-cwd=\"wp-content/plugins/gutenberg\" pwd",
"has-quote-inside-with-escaped-quote": "wp-env run tests-wordpress --env-cwd=\"wp-content/plugin's/gutenberg\" pwd"
}
} There are other scenarios where the results differ depending on the OS. The following command works on Windows, but has syntax errors on Linux. {
"scripts": {
"has-quote-inside": "wp-env run tests-wordpress --env-cwd=wp-content/plugin's/gutenberg pwd"
}
} On the other hand, a command like the one below works correctly on Linux, but cannot be processed on Windows because an empty string is passed to coerce. {
"scripts": {
"has-space-before": "wp-env run tests-wordpress --env-cwd=' wp content/plugins/gutenberg' pwd",
"has-space-after": "wp-env run tests-wordpress --env-cwd='wp content/plugins/gutenberg ' pwd"
}
} |
Thanks for the investigation @t-hamano. On the subject of the failures themselves, are these local terminal syntax errors or remote errors? I'm just curious whether or not the problem is the input being passed to |
Another approach: I made the trimming of spaces and quotes to be handled just before
If I understand correctly, this approach is what fixes the latter, right? |
Sounds good to me @t-hamano. The duplication of |
In b512390, I made the transformation to be performed directly at the point where the paths are concatenated. I may not be understanding your intent correctly, but is this correct? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's perfect @t-hamano. I might suggest a comment explaining what the transformation is for but this works.
Thanks!
Indeed, I added a comment 👍 |
What?
This PR fixes an issue where scripts that include the
--env-cwd
option fail when executed on Windows OS. This allows commands such aslint:php
andformat:php
to work correctly on Windows OS.Why?
For example, when you run
lint:php
, theother:update-packages.php
script is executed before that. When running this script, the following error occurs on Windows OS:Notice that the path includes single quotes (
"/var/www/html/'wp-content/plugins/gutenberg'"
). I don't know the exact cause, but I suspect that single quotes are handled differently in Windows OS.How?
I have confirmed that both formats below work on Windows OS. Although I don't have a strong opinion on the format, I chose the first option.
"test": "wp-env run --env-cwd=\"wp-content/plugins/gutenberg\" cli composer update --no-interaction"
(escape double quote)"test": "wp-env run --env-cwd=wp-content/plugins/gutenberg cli composer update --no-interaction"
(don't use quote)Testing Instructions
I only have a Windows machine, but I would be happy if you could confirm that commands such as
lint:php
andformat:php
work as usual on Linux and MacOS.