Use variable for common isNodeOrEdgeCompilation condition (#54763)
Noticed this condition was repeated quite often, this pulls it out to the top and reuses the variable.
Also made a small change to `getDefineEnv` to sort the argument similarly between all calls and change optional properties to be required with `undefined` in order to make the list explicit. Looking at the code it seems that `getDefineEnv` in `setup-dev.ts` is missing some information and that will break when `.env` / tsconfig changes 🤔