This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
Fix getResourcePath so more apm commands work on Windows #906
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
This fixes getResourcePath so it finds the installation location on Windows. It results in the correct behavior of several
apm
commands (such as apm --version) when apm isn't bundled with Atom.It also optimizes getResourcePath by storing a cache of the asarPath. This means asarPath is only calculated once.
Benefits
Allows more
apm
commands (examples:apm --version
,apm install [package-name]
)to work on Windows, even outside of a full Atom installation. For example:
apm --version
to work during the Atom bootstrap script.Possible Drawbacks
None.
Verification Process
The tests are included: https://github.com/atom/apm/pull/906/files#diff-845586f656569b8df7748376c8e75465R47
Manual tests:
Manually ran
apm --version
in theapm
Git repo. Output is useful and not blank.Sample output (click to expand):
Manually ran
.\bin\apm.cmd install hydrogen
. Package now installs. (Before this PR, the command quickly exits with no logging or output.)Also, CI should pass.
Applicable Issues
None.
Extra info
TL;DR
Info about what getResourcePath() does
The
getResourcePath()
function's job is to find an install of Atom on the disk. (Specifically, it gives the path to theapp.asar
application package/archive that holds most of Atom's JS code, bundled packages, various binaries, and so on.Because Atom install paths on Windows are version-specific, and because at least the previous version is meant to stay around after an update, users may have more than one Atom install, and we have to pick one of the multiple installs. In this case, I just made sure to pick the newest install (among installs having a
resources/app.asar
file).Long explanation (click to expand):
After adding this fallback behavior, apm should be able to find stable installations of Atom on the disk, even when apm isn't bundled with the Atom install it's looking for.
(This mostly requires that the user have an Atom installation on disk. But it also makes
apm
behave slightly better even when there is no Atom installed to disk. For example,apm --version
used to print nothing at all on Windows when apm wasn't bundled with Atom. Now it will print all versions it can find. If there was no Atom install found on disk, the Atom version will now print as "unknown
".apm install
will give you the relevant error messageCould not determine Electron version
rather than exiting with no logging or output at all.)