Motivation ("The Why")
Given the os and cpu package.json attributes, and the rise on usage of optionalDependencies for native modules, and also given cross platform building of certain applications like electron, it would be nice to be able to install npm packages for a given platform, disregarding current platform.
Example
My case is having a thrid party native module using optionalDependencies to install platform specific node bindings for itself. One good example for this is napi-rs modules (see https://github.com/napi-rs/package-template). Now this module is bundled together with an electron app, and the build pipeline uses wine to build it for windows as well from debian. The issue is that the thrid party native module will always be installed with linux native bindings.
How
Current Behaviour
Currently optionalDependencies only matching current platform will be installed, and it's not configurable.
Desired Behaviour
The proposal is to have two extra possible arguments for npm install. --os would specify for what operating system to install packages, --cpu for what cpu. The defaults for these options would be from current platform.
Example: npm i --os win32 --cpu x64
References
Motivation ("The Why")
Given the
osandcpupackage.json attributes, and the rise on usage ofoptionalDependenciesfor native modules, and also given cross platform building of certain applications likeelectron, it would be nice to be able to install npm packages for a given platform, disregarding current platform.Example
My case is having a thrid party native module using
optionalDependenciesto install platform specific node bindings for itself. One good example for this isnapi-rsmodules (see https://github.com/napi-rs/package-template). Now this module is bundled together with anelectronapp, and the build pipeline useswineto build it for windows as well from debian. The issue is that the thrid party native module will always be installed withlinuxnative bindings.How
Current Behaviour
Currently
optionalDependenciesonly matching current platform will be installed, and it's not configurable.Desired Behaviour
The proposal is to have two extra possible arguments for
npm install.--oswould specify for what operating system to install packages,--cpufor what cpu. The defaults for these options would be from current platform.Example:
npm i --os win32 --cpu x64References