[Overengineered] Package.swift file with targets as variables and MARK you can jump to using jump bar. #1040
Sajjon
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
TCA is great! One drawback however is the Package.swift file which uses string literals for target dependencies becomes hard to navigate.
Even worse, since vanilla Package declaration uses the Package.init and using TCA we declare lots of targets, this in combination with the fact that we cannot // MARK inside this massive init, making it impossible to use the "jump bar" or even get a meaningful mimimap.
Also we have to remember to add the Target to Product Library declaration! At least that is what Isowords does
Possibly the worst drawback of them all is that if I make a typo in the string literals either when declaring my own targets as a dependency for any other target or a typo for an external dependecy everything breaks, and diagnostics are sometimes not great at producing easy to understand errors.
I have a solution to all of these drawbacks! I recently migrated my 1000 LOC Package.swift file in Zhip (branch: swiftui-tca) which uses these simple ideas:
ExternalDependency
, declare all external dependencies using a function which creates an instance ofExternalDependency
and adds it to a global variablevar externalDependencies: [ExternalDependency]
, we will use this array in the end when creating outProduct
and after appending it toexternalDependencies
array, return it. Capture this new instance in a variable, e.g.let ComposableArchitecture = externalDependency(...)
var target: [Target] = []
, to which we will append declarations of our internal targets.targets
array and returns the name of the new target. E.g.Note that the type of
APIClientLive
is just aString
. Also note that we did not pass in any string literal except the name! MeaninginternalDependencies
parameter indeclareTarget
accepts a String array, but this can easily be upgraded to some tuple of simple struct to accomodatecondition
al inclusion, e.g. depending on platform. We are using variables and we get autocorrect help and compilation error if we made a typo. Even better! WE CAN GO TO DECLARATION of each dependency by CMD clicking! And we get MARK which we can jump to using jump bar.Disadvantage
Beta Was this translation helpful? Give feedback.
All reactions