Reputation: 53
When you do npm i electron
I get an electron.exe
in my node modules, thats because I am on a windows machine and the prebuilt C++ binary for electron will be in .exe format, got it. If you install electron on a MAC I assume you get different prebuilt binaries, how does NPM know what prebuilt binary to install? My question is very specific I know, but I am curious how npm gives you different binaries. Does the electron team compile their binaries separately then tell NPM to download which one depending on the developer's OS?
Upvotes: 1
Views: 182
Reputation: 2464
If you look at node_modules/electron/package.json
you will see that the electron
package is running a postinstall
script
"scripts": {
"postinstall": "node install.js"
}
node_modules/electron/install.js
is executed like any normal Node.js script and it can access information about your OS. This script downloads the appropriate electron
binaries automatically
downloadArtifact({
version,
artifactName: 'electron',
force: process.env.force_no_cache === 'true',
cacheRoot: process.env.electron_config_cache,
platform: process.env.npm_config_platform || process.platform,
arch: process.env.npm_config_arch || process.arch
}).then(extractFile).catch(err => {
console.error(err.stack)
process.exit(1)
})
Upvotes: 1