Reputation: 18427
I have a module and I'd like to let the user decide which version he wants to use, the purely written in javascript or the native written in C (so he needs to compile it first).
The npm install command doesn't have any option but you can choose the version so I can create two branches: v1.x for the js and v2.x for the native.
If the user wants to install the module written in javascript:
"dependencies": {
"my-module": "1.x"
}
If the user wants to install the native module:
"dependencies": {
"my-module": "2.x"
}
Are there other better ways to publish the purely and native modules with the same module name?
Upvotes: 0
Views: 873
Reputation: 14881
OK, that's not exactly what you are looking for, but here goes…
You are trying to find an NPM equivalent to Gentoo Use Flags, which doesn't exist. The closest thing you could do it publish your pure-JS version and have users directly link to the git repo instead if they want to use the native version.
In package.json
:
"dependencies": { "mymodule": "1.2.3" // js version } "dependencies": { "mymodule": "http://github.com/mymodule-native" // native version }
You users won't have to change their require
to switch between versions, only a single line in package.json.
Another solution would be to attempt to build the native version without raising an error if it fails. Then you can have a simple setting in your module to switch between implementations. You can have a look at this other stackoverflow thread.
Upvotes: 1