Always use LOCALAPPDATA to generate Windows CLI install path#2465
Always use LOCALAPPDATA to generate Windows CLI install path#2465fredrikekelund wants to merge 5 commits intotrunkfrom
Conversation
|
This Sentry issue confirms our theory. It was triggered by me and the error message reads: |
| if ( ! process.env.LOCALAPPDATA ) { | ||
| throw new Error( 'LOCALAPPDATA environment variable is not set' ); | ||
| } |
There was a problem hiding this comment.
An obvious question is, how do we know that process.env.LOCALAPPDATA is defined? Well, there's no official guarantee, and I can't find any Microsoft documentation on this, but it appears the system sets this variable for each process. It's not editable by users either, AFAICT. That's probably as good a guarantee as we'll get.
Still, it makes sense to ensure that we handle errors thrown from here gracefully, so I'll take a look at that now…
📊 Performance Test ResultsComparing 61e372a vs trunk site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change |
There was a problem hiding this comment.
This LGTM and I can consistently see the toggle working correctly now, both on Parallels and on x64. 👍
When trying to open a Command Prompt using the button on the site details page, I see an Access denied message when I try to use the studio command.
Opening a new tab and using the command in a different directory also prints the same message:
The contents of the bat file seems correct to me, I think the issue might be that we don't have rights to run the batch file under WindowsApps:
@echo off
"C:\Program Files\WindowsApps\22490Automattic.StudiobyWordPress.com_1.6.8.0_arm64__9qb1eemr42qj0\app\resources\bin\studio-cli.bat" %*
That seems like a good theory. We probably lack permission to execute that file (but we can read it). I'm not immediately sure what the best way to solve that is… |
|
@fredrikekelund I dug a bit deeper into this, and added a commit that fixes the CLI for the AppX version as far as I could test. The Windows-recommended solution is https://learn.microsoft.com/en-us/uwp/schemas/appxpackage/uapmanifestschema/element-uap5-appexecutionalias. When declared in the manifest, this creates a lightweight stub in The commit adds:
I could test it on Windows by removing all previous installations and also uninstalling the CLI from the dev folder using the Settings dialog. Then, downloading the appx artifact from the build and installing it, invoking the The To package the exe, I also needed to add a new dependency. The alternative would be to use Node's Single Executable Application feature to package the .exe. However, it would produce a larger binary (~70-80MB vs ~40-50MB from pkg) and requires a more complex multi-step build (generate blob, copy node.exe, inject blob, remove signature, re-sign). Still, it could be worth revisiting if we want to drop the @yao-pkg/pkg dependency. What do you think about this approach? |

Related issues
Proposed Changes
As noted by @gcsecsey in #2463 (comment), CLI installation doesn't work when the app was installed using an AppX installer on Windows.
When Studio installs the CLI on Windows, it writes a "proxy
studio.batfile" to a directory relative to its installation directory (as determined by the value Electron returns fromapp.getPath( 'exe' ). However, Microsoft Store installs Studio in a directory likeC:\Program Files\WindowsApps\22490Automattic.StudiobyWordPress.com_1.6.8.0_arm64__9h07f78gwnchpthat has heavy read and write limitations. Therefore, we believe the CLI installation fails because Studio cannot write the file.This PR solves the problem by always writing the proxy batch file to a known stable location in
%LOCALAPPDATA%.Testing Instructions
I haven't figured out how to install an AppX dev build on Windows, so code review might have to suffice
Pre-merge Checklist