Allow custom platform handling, DMG files, more Darwin aliases#56
Allow custom platform handling, DMG files, more Darwin aliases#56doesdev wants to merge 4 commits intovercel:masterfrom
Conversation
In editorconfig `max_line_length = null` is invalid and results in an error. Removing it corrects that. Additionally, the `lint-staged` command was running `yarn test` on the staged js files individually, resulting in it failing with a no test found message. Instead the tests are run before the lint-staged command.
In aliases we put all the possible values into a map, respecting the initial design of having the top level platform name checked first then checking the aliases. More importantly this adds the ability to specify custom platforms, more on that below. In platforms we move the logic for each extension into a handler function that takes the filename as an argument and either returns the platform or false. More importantly, as above, we add the ability to handle custom platforms. Custom platforms will be passed from the config (not here, coming in next commit) and will be an object with the platform name as the key and value a handler that takes the file name and returns true if it's a match or false. If true is returned then we return the custom platform name. This commit also allows `mac`, `osx`, or `darwin` to be mapped to `darwin`.
This moves the logic that was previously duplicated in `download` and `downloadPlatform` into `cache.getLatestForPlatform`. Additionally, it adds the ability to set custom platforms. To set a specify custom platforms you pass an object into the config as `customPlatforms` where the key is the platform name and the value is a function that takes the file name and returns true if that asset should be used for the custom platform. This also adds prioritization of .dmg files in the download handlers for `darwin`. It does so by specifying `zip` as the filetype for `darwin` update URLs for private repos and for public repos simply getting the zip asset in the update handler.
|
This pull request is automatically deployed with Now. |
|
I should probably also mention use cases for custom platforms, since it's not entirely obvious why someone would want this. For my particular use case there are actually a couple different uses. Firstly, we have an alternate installer package that we use for Windows environments don't which meet the .NET requirements of Squirrel. That is packaged using a custom installer and updater built in Go. That's something I intend to open source, but I need to allocate time to extract the logic out so it's more configurable. Also we have client specific builds that are distributed in the releases of the main repo. No sense in having the code and build processes separated when the only thing needed is the ability to distribute releases and updates dynamically based on the client. There are other use cases that come to mind as well. Another PR implements bitness / architecture based platforms. If that were not something you wanted baked in (though I think it makes sense to include) it could be easily implemented using custom platforms. |
|
This PR is probably a bit heavy handed. The needs it fills are also fairly edge case. Based on that I'm going to close this here. |
This is a pretty exhaustive PR so I totally understand if it doesn't make sense as is. Several of the pieces are pretty tightly interwoven which is why I thought I'd try a first pass as a single PR.
Let me know if there are pieces that would be merged and others that wouldn't and I'll try to break it up respectively.
So, here's all that going on. I've also tried to keep extensive notes on each commit:
customPlatformsobject into config.dmgfiles for darwinyarn testagainst each staged JS file, run it beforelint-stagedIn addition to these functional enhancements I did rework some things to make the implementation of each more streamlined. The aliases, platform, and routes all underwent significant changes. The logic for
downloadanddownloadPlatformwere mostly duplicated and I needed to add more to them each, so I extracted much of the shared logic into an instance method inCache, namelycache.getLatestForPlatform. NowdownloadPlatformis simply an alias fordownload.I think that covers all the changes.
dmgvszipfor private repos I needed a way to specify on the return download to use a zip file for the update action. For that I copied thenutsapproach of appending a query string "?filetype=zip". For parsing that I added my own moduletiny-paramsbut ultimately for the limited parsing that's begin done that could just as easily be manually checked. I'll be glad to add a commit changing that to exclude added dependencies.