As I understand it, the RAW file is actually a linear, monochrome image bayer pixel by bayer pixel. The file also includes metadata about the exposure, lens, and other settings.
It is the software that reads the RAW file the does the de-mosaicing, applies curves, noise reduction, sharpening, etc.
Of course, it you tell the camera to produce a jpeg, it has to do that conversion as well.