The short answer is no, the package doesn't contain all of the code from node_modules, yet it contains some very small amount of proven code (mostly css-loader code from corresponding webpack loader).
SharePoint Framework uses webpack to bundle your code into a single file (aka package). Apart your code SharePoint Framework contains a lot of components which you reference in your code via imports (
import smth from '@microsoft/sp-webpart-base' etc.), however, those components are not included in your code. They serve as "externals" and are loaded by SharePoint Framework at runtime.
If you take a look at webpack configuration, you will see below picture:
Everything which is in the external section won't be included into the resulting bundle, yet it will be served at runtime by Microsoft. Your package contains only your code (plus a bit of code from webpack's css-loader like mentioned earlier). You can run
gulp clean then
gulp bundle and open
./dist folder to review the generated bundle. Only your code will be included.
Which basically means that you shouldn't care about such things like viruses, etc. However, Microsoft should care that all externals modules they use (aka
react*) are virus-free and safe.
From your side, you should only care about any external modules you install after scaffolding your project. For example react modules, or helpers, or whatever else.
250+ vulnerabilities in a new SharePoint Framework project
Don't be alarmed by vulnerabilities after running NPM Install
Code Security Audit using “npm audit”