let me make sure. Is your problem that you want to fill extension first ?
If yes, i suggest your change your find targets code, a simple change is
const target = targets[targets.length - 1]; // take the last target, it must not be spawn
and then
if (creep.transfer(target, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}