Implement CLI installer for Windows - #1152
Conversation
fredrikekelund
left a comment
There was a problem hiding this comment.
I made a couple of code suggestions that would be great to address, but the fundamentals here look really solid to me and the PR tests well. Nice work 👍
| }); | ||
| }; | ||
|
|
||
| const setPathToRegistry = ( updatedPath: string ): Promise<void> => { |
There was a problem hiding this comment.
| const setPathToRegistry = ( updatedPath: string ): Promise<void> => { | |
| const setPathInRegistry = ( updatedPath: string ): Promise<void> => { |
| const appFolder = path.resolve( process.execPath, '..' ); | ||
| const relativePath = 'resources/bin/studio-cli.bat'; | ||
| const versionedPath = path.relative( localAppBinPath, path.join( appFolder, relativePath ) ); |
There was a problem hiding this comment.
| const appFolder = path.resolve( process.execPath, '..' ); | |
| const relativePath = 'resources/bin/studio-cli.bat'; | |
| const versionedPath = path.relative( localAppBinPath, path.join( appFolder, relativePath ) ); | |
| const versionedCliPath = path.join( | |
| path.dirname( app.getPath( 'exe' ) ), | |
| 'resources/bin/studio-cli.bat' | |
| ); | |
| const relativeVersionedCliPath = path.relative( unversionedBinDirPath, versionedCliPath ); |
I think we can clarify the logic here along these lines.
There was a problem hiding this comment.
Good refactoring, makes sense 👍
| //Example of process.execPath - C:\Users\<USERNAME>\AppData\Local\studio\app-1.3.9-beta1\Studio.exe | ||
| const localAppBinPath = path.resolve(process.execPath, '../../bin'); |
There was a problem hiding this comment.
| //Example of process.execPath - C:\Users\<USERNAME>\AppData\Local\studio\app-1.3.9-beta1\Studio.exe | |
| const localAppBinPath = path.resolve(process.execPath, '../../bin'); | |
| // `unversionedBinDirPath` resolves to C:\Users\<USERNAME>\AppData\Local\studio\bin | |
| const unversionedBinDirPath = path.resolve( path.dirname( app.getPath( 'exe' ) ), '../bin' ); |
A few things:
- I think a variable name like this is a lot clearer.
app.getPathis the official Electron API for retrieving directories related to the current installation.- Using
path.dirnameisn't required, it just clarifies that we we expect the final segment of the path to point at a file rather than a directory. - Not super important, but I think it's preferable to write the resulting path in the comment as opposed to the path returned from
app.getPath
There was a problem hiding this comment.
I think a variable name like this is a lot clearer.
What about binDirPath? I think that mentioning unversioned is a bit extra and just confusing.
Using path.dirname isn't required, it just clarifies that we we expect the final segment of the path to point at a file rather than a directory.
Yeah, initially I considered adding path.dirname but decided that avoid using it make code more readable. But I don't have strong preference, so let's keep it 👌
There was a problem hiding this comment.
What about binDirPath?
There are multiple bin dirs, which is why I think it's helpful to distinguish between them with the "versioned" and "unversioned" labels.
There was a problem hiding this comment.
Oh, yeah, you are right 👍
Updated
| "tar": "^7.4.0", | ||
| "unzipper": "0.10.11", | ||
| "url-loader": "^4.1.1", | ||
| "winreg": "^1.2.4", |
There was a problem hiding this comment.
| "winreg": "^1.2.4", | |
| "winreg": "1.2.4", |
I don't have a strong opinion about this, but regedit seems ever so slightly more well-maintained than winreg. The gotcha you linked to with Electron apps doesn't look too bad either, IMO. The fact that we can't update to the latest version of winreg and that 1.2.4 is 8 years old is a bit of a red flag, IMO.
If we do stick with winreg, we should enforce the "don't upgrade to 1.2.5" constraint in package.json according to my suggestion.
There was a problem hiding this comment.
I don't have a strong opinion about this, but regedit seems ever so slightly more well-maintained than winreg. The gotcha you linked to with Electron apps doesn't look too bad either, IMO. The fact that we can't update to the latest version of winreg and that 1.2.4 is 8 years old is a bit of a red flag, IMO.
The thing that disappointed me is - it supports async, but I got issues with it as soon as I added that fix for Electron. But yeah, maybe it makes sense to try to spend more time with it to make it working well.
What I liked with winreg - it was only one package which started working w/o extra effort and make me feeling reliable.
I think that the best way is to go with winreg ATM, since I tested it well and everything is ready to move forward, And later, if we encounter some issues with it, then we can reconsider to take regedit or maybe even something else. But ARTM winreg does it's job well.
There was a problem hiding this comment.
If we do stick with winreg, we should enforce the "don't upgrade to 1.2.5" constraint in package.json according to my suggestion.
Hm, I did install the exect version, weird that at some point it was reverted... good catch, removed ^👍
There was a problem hiding this comment.
Looks like this file needs to be reformatted for CI to pass
There was a problem hiding this comment.
Yeah, fixed
Later, I will spend some time making a convenient environment for developing on Windows :)
Related issues
Proposed Changes
With this PR we are adding the opportunity to use "studio" command globally on Windows.
Notes: Actually, we need to handle the issue with versioning, so I implemented a proxy to handle it.
Why exactly winreg lib was used
setx PATHand handle everything w/o extra library, but long story short - I messed up my environment variable, lost default, github, vscode, etc, so I was installing all apps again to restore PATH. I made changes blindly with it, it's not a reliable way.2.1 I spent a lot of time installing deps and configuring npm config, and at the end of a day I did it. But, it was feeling, that it's not great that we are complicating Studio dev env, but ok, I decided to proceed.
2.2 Then it turned out that registry-js doesn't support latest node (18+) and electron, and I also found that GitHub Desktop did revert due to it. It was huge cons for this lib. Moreover the lib wasn't updated for more then 1 year. So it doesn't make sense to proceed with this lib.
Testing Instructions
Apply the next diff:
npm run makeout/make/squirrel.windows/x64/studio-setup.exestudioin terminal (Note, you need to restart your terminal and sometimes necessary even to restart Windows)