refactor: improve Options types#1830
Conversation
|
Thanks for filing this issue/PR! It would be much appreciated if you could provide us with more information so we can effectively analyze the situation in context. |
Options types
MarshallOfSound
left a comment
There was a problem hiding this comment.
Seems fine at a glance, will be hard to know how it plays until the PR integrating into forge shows up
felixrieseberg
left a comment
There was a problem hiding this comment.
Code looks overall good!
This is some real bike-shedding and feel free to just ignore me, but I don't love Official as a prefix, simply because it doesn't really mean much. We might as well call them Platform and Arch. Just a silly note though.
Yeah, the naming for the Either way, we're not tied to a naming scheme yet as long as we haven't flipped the |
|
🎉 This PR is included in version 19.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR attempts to simplify how we handle the
Optionsinterface in Electron Packager.There are two main problems to address:
TargetArchandTargetPlatformtypes used in theOptionsinterface are aliases tostring. This is because we acceptstringvalues for custom mirrors of Electron, so any string const value passed in gets swallowed by the resulting type.Optionsinterface defines what options can be passed in as values, but also serves as the interface that we use to pass to the final packaging function. Along the way, many optional properties inOptionsare inferred and mutated. This approach makes our types inaccurate internally because we're usingOptionseverywhere, even after inference occurs and some optional properties become required.At a high level, we're addressing the two problems with some type refactors.
stringvalues asplatformandarchinputs in the types. This removes the superfluousArchOption,PlatformOption,TargetArch, andTargetPlatformtypes. Users passing custom arch/platform values can still do so, but must cast their parameters using theOfficalArchandOfficialPlatformtypes.Optionsnow explicitly refers to the options that are passed in by the user.ProcessedOptionsrefers to the Options object after it is processed/inferred via metadata.ProcessedOptionsWithSinglePlatformArchrefers to the ProcessedOptions object once it is guaranteed to have a single platform or arch value (rather than an array or comma-separated string). We use a fresh opts object every time the shape of our options changes rather than mutating the initial Options being passed in.Note
There are some additional refactors we can make for future work to make this delineation clearer.
For example, the
Packagerclass takes inProcessedOptionsas a parameter, which meansopts.archandopts.platformcan be an array. However, these values are never used—Packagerinstance functions are only ever called with a separateProcessedOptionsWithSinglePlatformArcharg.