Usually a Shipyard or a Starbase isn't looking for a fight because it's an import piece of space real estate however, when you have an unarmed transport ship coming in to invade one of my undefended planets and that my planet is within the influence area of armed starbases or near a armed shipyard then the Starbases / Shipyards should open fire on the transport ship.
Starbases or Shipyards are not as important as colony planets so they should be involved in defense.
The influence of a Shipyard could be calculated the same way it is for a Star base.