Skip to content

[RRFC] Support --cpu and --os flag to specify platform specific install #612

Closed
npm/cli
#6755
@archfz

Description

@archfz

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

  • n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions