Just mandate minimum warranty periods like the EU does. If the company wants to only replace whole cars then they can, but they'll bear the cost of doing so.
I don’t see what that’s got to do with after market sale of parts. Of course manufacturers have access to individual components and can stock them during warranty periods as they already have to, but making every single possible component of every product ever sold available indefinitely after the warranty period seems like it would drive costs up through the roof.
I usually find myself arguing against people with what O think is a bit of a blinkered faith in market forces solving all and regulation being the work of the devil. But in this case, unless there really is a demonstrable monopoly position that’s being abused, it should be up to customers to decide if after market parts availability is something they care about in their purchasing decision.
I think the market fails here because consumers don't really have the information to let future part support factor into their purchase decision. Compare lemon laws which are widely accepted as a positive example of regulatory intervention in the market.
"every single possible component of every product ever sold available indefinitely after the warranty period" is a vast overexageration, the limit is generally 10 years for stuff like cars, and it encourages parts to be interchangable to cut down on inventory costs ( and incidentally waste too..)