For those modules its more of a manufacturing decision to build a module with PCB or external antenna.
Many cheap RF SoCs only have a single antenna port. If you want to select during "run-time", you could use a SPDT RF switch to switch between either ports. Analog Devices has plenty of such devices, among others vendors. Do select one that can support the maximum transmit power, as some parts are limited to only +10dBm or so. Oh and some parts have real PITA supply rails.. but there are also parts that can run of regular 1.8V or 3.3V supplies
It does mean custom hardware so a custom board design though...