Peel and cut the squash into 2cm cubes.
Thinly slice the onion. Chop the rosemary leaves.
Heat half of the oil in a large, non-stick frying pan and gently fry the onion until soft. Add half of the balsamic vinegar and the sugar and stir until the onion has caramelised. Remove the onion to a plate.
Add the remaining oil to the pan, then the squash cubes and rosemary. Fry them for about 10 minutes, stirring regularly. Season with salt and pepper.
When they are soft and golden, add the garlic and chilli. Stir 2 minutes, then add the balsamic vinegar and the same amount of water. Keep stirring gently for a minute or so, the add the caramelised onion and mix well.
Meanwhile, cook the pasta following the instructions on the packet. Drain and keep warm.
When the squash is sticky, add it to the pasta and toss well.
Serve with fresh herbs and plenty of freshly ground pepper. For a vegetarian version, add Parmesan or feta.