magento-cache-clean icon indicating copy to clipboard operation
magento-cache-clean copied to clipboard

Windows Compatibility: [ERROR] Command failed

Open rafal-kos opened this issue 7 years ago โ€ข 38 comments

Hello,

I am trying to run the tool on windows Git Bash : vendor/bin/cache-clean.js config full_page but in result I have this error : [ERROR] Command failed: php -r 'echo json_encode((require "D:\projects\example\magento/app/etc/env.php") ?? []);'

Looks like there a problem with slash. When I run this command php -r 'echo json_encode((require "D:/projects/example/magento/app/etc/env.php") ?? []);' I am getting correct results.

Is it possible to get some fix for hat? Thanks in advance.

rafal-kos avatar Oct 26 '18 09:10 rafal-kos

Thanks for opening the issue, Iโ€˜ll push a branch some time soon and then would like to ask you to test if it works for you.

Vinai avatar Oct 31 '18 05:10 Vinai

OK. Thanks for info.

rafal-kos avatar Oct 31 '18 08:10 rafal-kos

I require your help to get the tool working on windows. Can you please install the win-compatibility branch and let me know how that works?

composer remove --dev mage2tv/magento-cache-clean
composer require --dev mage2tv/magento-cache-clean:dev-win-compatibility

I expect a new error to occur. I'll try to fix one after the other until it works on windows too. Please be patient with me until it works. I appreciate your help.

Vinai avatar Oct 31 '18 20:10 Vinai

I checked the new branch. Still the same issue :

[ERROR] Command failed: php -r 'echo json_encode((require "D:\projects\example\magento/app\etc\env.php") ?? []);'

rafal-kos avatar Nov 01 '18 11:11 rafal-kos

I see in file system.cljs

(defn- win? []
  (= "win32" (.-platform process)))

On my machine I am using GIT Bash (mingw64). Maybe different platform is used here? Any chance to add some debug here?

rafal-kos avatar Nov 01 '18 11:11 rafal-kos

According to the documentation win32 is the operating identifier returned by nodejs on any windows host.

You can see the value on your host by running the following command in your teminal

node -e 'console.log(process.platform)'

Vinai avatar Nov 01 '18 11:11 Vinai

Got info from third party using Win10:

aaron@AVALANCHE MINGW64 ~
$ node -e 'console.log(process.platform)'
win32

Vinai avatar Nov 05 '18 14:11 Vinai

Yes. It looks the same on my machine. Any chance to get not minified cache-clean.js? I tried to build it on WIN without success.

rafal-kos avatar Nov 05 '18 17:11 rafal-kos

I've pushed an update to the win-compatibility branch.
This time all file system methods get path arguments on windows with backslashes instead of slashes. There still might be other issues though.

Could you please do me a favor and update the branch again?

composer remove --dev mage2tv/magento-cache-clean
composer require --dev mage2tv/magento-cache-clean:dev-win-compatibility

Please also run cache-clean.js --version to confirm the correct build is being used. It should display the release name 0.0.22-dev-win-compat.

I can look into creating an un-minified build, but right now I don't have the time.

Vinai avatar Nov 07 '18 09:11 Vinai

OK. There is still the same problem. I had some time to make some debug. So... problem is not directly with path but how the php is processed from the windows cmd.exe. cmd.exe is run when you call child_process.execSync(cmd)

On windows this one will not work : php -r 'echo json_encode((require "D:\projects\example\magento\app/etc/env.php") ?? []);' when this one works fine : php -r "echo json_encode((require 'D:\projects\example\magento\app/etc/env.php') ?? []);"

After changing the command and running bin/cache-clean.js cache was cleaned up ๐Ÿ˜ƒ

Problem is when I ran bin/cache-clean.js -w. Below the error [ERROR] Command failed: php -r 'require "D:\projects\example\magento\vendor/autoload.php"; foreach ((new \Magento\Framework\Component\ComponentRegistrar)->getPaths("module") as $m) echo $m.PHP_EOL;'

In this case I suppose that you have to change slightly how the commands are run on windows. I would like to help more but closure is just out of my scope ๐Ÿ˜„

rafal-kos avatar Nov 07 '18 16:11 rafal-kos

Thanks for the input! So executed command arguments have to be quoted with double strings. That sounds possible. I'll see that I get a version ready some time soon that does that.

Vinai avatar Nov 07 '18 18:11 Vinai

Okay, so I threw away the slash-to-backslash in file system paths conversion code, and instead made command line arguments to php be wrapped in double quotes. Can you please update the dev-win-compatibility branch and give it another go?

Vinai avatar Nov 08 '18 18:11 Vinai

๐Ÿ‘ it works almost perfect but.. still problem with --watch. Below the command

php -d display_errors -r "require 'D:\projects\example\magento/vendor/autoload.php'; foreach ((new \Magento\Framework\Component\ComponentRegistrar)->getPaths('module') as \$m) echo \$m.PHP_EOL;"

and error I am receiving Parse error: syntax error, unexpected '$m' (T_VARIABLE), expecting identifier (T_STRING) in Command line code on line 1

rafal-kos avatar Nov 08 '18 19:11 rafal-kos

Thanks for trying that out. Interesting. When I run that exact command on OS X or Linux it works. Maybe the $ of $m has to be escaped with a different character than \ on windows? Or maybe it doesn't have to be escaped at all? In my shell it is required so it isn't interpreted as a bash variable that needs to be interpolated into the string.

Vinai avatar Nov 09 '18 00:11 Vinai

After a bit of googling it seems like it might be the ^ character. Could you please try running the command?

php -d display_errors -r "require 'D:\projects\example\magento/vendor/autoload.php'; foreach ((new \Magento\Framework\Component\ComponentRegistrar)->getPaths('module') as ^$m) echo ^$m.PHP_EOL;"

Vinai avatar Nov 09 '18 00:11 Vinai

I've got this error then : Parse error: syntax error, unexpected '^' in Command line code on line 1

This command works fine : php -d display_errors -r "require 'D:\projects\example\magento/vendor/autoload.php'; foreach ((new \Magento\Framework\Component\ComponentRegistrar)->getPaths('module') as $m) echo $m.PHP_EOL;"

Is there a need for \ or ^?

rafal-kos avatar Nov 09 '18 06:11 rafal-kos

Well, thatโ€™s what Iโ€™m trying to figure out. I know the $ needs quoting on unix systems. Can you try running the command without any quotes for the $ and let me know if that works on windows?

Vinai avatar Nov 09 '18 11:11 Vinai

As I said in my last comment. It works fine without "" and I see list of directories in output.

rafal-kos avatar Nov 09 '18 11:11 rafal-kos

Oh, I didn't see that part, sorry. Thanks for your answer, I'll remove the quoting of the $ on windows.

Vinai avatar Nov 09 '18 12:11 Vinai

New build available on the win-compatibility branch without quoting of PHP variables in command line arguments on windows. Hope this solves the issue of executing PHP on windows finally.

Vinai avatar Nov 09 '18 13:11 Vinai

OK. Cleaning speciific type of cache is working fine. Now I am testing "watch" action. For now I few times this kind of issue

Error: ENOENT: no such file or directory, unlink 'D:\projects\example\magento\generated\code\Vendor\Module\Controller\Adminhtml\Artist\Edit\Interceptor.php'
    at Object.fs.unlinkSync (fs.js:1061:18)
    at Jh (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:318:201)
    at D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:303:275
    at Xc (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:103:185)
    at Nd.f.ca (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:126:67)
    at eb (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:104:349)
    at og (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:303:238)
    at yk (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:399:271)
    at D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:400:101
    at FSWatcher.<anonymous> (D:\projects\example\magento\vendor\mage2tv\magento-cache-clean\bin\cache-clean.js:320:138

After checking the path file was deleted but watcher was stopped and I had to run it again.

I will do more tests next week and probably be back in case of any additional issues.

rafal-kos avatar Nov 09 '18 13:11 rafal-kos

Cool, one step further towards supporting windows ๐Ÿ‘ Thanks for your help. I wonder why the file already was gone by the time fs.unlinkSync is called. As a reference for myself, maybe this is helpful: https://stackoverflow.com/a/20801823/485589

Vinai avatar Nov 09 '18 15:11 Vinai

@rafal-kos Any news on this topic by chance? I could wrap the unlink in a check to see if the file still exists. When does that exception occur? When changing a file?

Vinai avatar Nov 15 '18 13:11 Vinai

I added regexes that match file paths with backslashes instead of regular slashes, added a check if a file exists before unlinking it, and merged the result into master and published it as release 0.0.25. It would be cool if you could try how that works for you...

Vinai avatar Nov 18 '18 09:11 Vinai

Sorry for late response but I didn't had time to check it. I have installed latest version from master branch. No error about missing file but I suppose it doesn't work correctly. Example output of command run with options "-w -vv":

Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\example/var/cache}
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\example/var/cache}
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\example/var/cache}
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\example/var/cache}
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/etc\adminhtml\menu.xml
Processing D:\projects\example\app\code\Vendor\Artist/etc\adminhtml
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\example/var/cache}
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\example/var/cache}
Processing D:\projects\example\app\code\Vendor\Artist/view\adminhtml\ui_component

After change in ui component or menu file I see info about processing but cache is not cleared.

For example I am changing title in menu.xml. I see "processing" output but no info about clearing of cache.

rafal-kos avatar Nov 28 '18 17:11 rafal-kos

Thanks for trying out the new version and giving an update @rafal-kos! In order to be able to work on windows support more effectively I'll add a new trace log level that will give more details when enabled with -vvv. Also, could you please try editing a di.xml file? The difference is that editing ui_component files clears a single cache ID, while editing a di.xml file will clear the whole config cache segment.

Thanks for your help.

Vinai avatar Nov 29 '18 09:11 Vinai

Update to the win-compatibility branch pushed. When you have a moment, please update with

composer remove --dev mage2tv/magento-cache-clean
composer require --dev mage2tv/magento-cache-clean:dev-win-compatibility

Then check the release matches this:

$ cache-clean.js --version
Release 0.0.27-dev-win-compat sponsored by https://www.mage2.tv

0.0.27-dev-win-compat

If that is true, please run the command with the -w -vvv options to enable trace level logging.

Then edit a ui_component XML file and a di.xml file and post the (probably long) output here in the thread.

Again, thank you for your help, I appreciate you doing that.

Vinai avatar Nov 29 '18 10:11 Vinai

Still the same :(

First I am changing the ui_component XML file. Output :

Watcher initialized (Ctrl-C to quit)
Processing D:\projects\magento\app\code\Vendor\Artist/view\adminhtml\ui_component\artist_form.xml
Cleaning id(s): ui_component_configuration_data_artist_form
Cache storage  {:backend Cm_Cache_Backend_File, :cache_dir D:\projects\magento/var/cache}
Delete cache record if exists: D:\projects\magento/var/cache/mage--3/mage---fa7_UI_COMPONENT_CONFIGURATION_DATA
_ARTIST_FORM

Then some changes in di.xml is done. Output :

Processing D:\projects\magento\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\magento\app\code\Vendor\Artist/view\adminhtml\ui_component
Processing D:\projects\magento\app\code\Vendor\Artist/etc\di.xml
Processing D:\projects\magento\app\code\Vendor\Artist/etc

I don't see any change on form after reloading the page.

rafal-kos avatar Nov 30 '18 15:11 rafal-kos

@rafal-kos Thanks again for your help and your patience.

The paths still contain forward slashes. I'll focus next on making them consistent - then the regex to fingerprint the file names should work more reliable.

Vinai avatar Dec 01 '18 07:12 Vinai

I've updated the win-compatibility branch accordingly. The release string now is 0.0.28-dev-win-compat

For reference, to install the current version of the branch, please use:

composer remove --dev mage2tv/magento-cache-clean
composer require --dev mage2tv/magento-cache-clean:dev-win-compatibility

@rafal-kos Can you please try it when you get a chance and let me know if there is some progress?

Thank you!

Vinai avatar Dec 01 '18 16:12 Vinai