A custom Bower resolver supporting installation of NPM packages. This resolver should be used if the package (or the version of the package you want to use) is not available on default resolvers (bower registry, github, etc.).
npm install -g bower-npm-resolver
Or, if you use bower locally:
npm install bower-npm-resolver
Add the resolver in your .bowerrc
file:
{
"resolvers": [
"bower-npm-resolver"
]
}
Once configured, your bower.json files may reference packages using npm:
prefix:
{
"dependencies": {
"jquery": "npm:jquery#1.0.0",
"lodash": "4.0.0"
}
}
The resolver will match packages with npm:
prefix.
In the example above, jquery
will be fetched from npm. lodash
will not be matched by this resolver.
Note that you can also specify scope package:
{
"dependencies": {
"angular-core": "npm:@angular/core#~2.0.0"
}
}
The resolver will download the scope package on npm and extract the tarball in the bower_components
directory named [scope]-[name]
(in the example above, scope is angular
, name is core
).
As of v0.2.0, matching were made using npm+
prefix, such as:
{
"dependencies": {
"npm+jquery": "jquery",
"lodash": "4.0.0"
}
}
The resolver will match packages with npm+ prefix, and strip the prefix prior to fetching from npm repo.
In the example above, jquery
will be fetched from npm, lodash
will not be matched by this resolver.
If this is not what you want, you can pass configuration parameters in .bowerrc
.
If you use a private npm repository for all your company's packages, and they all start with a shared prefix, you can change the prefix:
{
"resolvers": [
"bower-npm-resolver"
],
"bowerNpmResolver": {
"matchPrefix": "mycompanynpmpackages-",
"stripPrefix": false
}
}
Then in your bower.json
:
{
"dependencies": {
"mycompanynpmpackages-foobar": "1.0.0",
"other": "1.0.0"
}
}
In the example above, mycompanynpmpackages-foobar
will be fetched from npm. other
will not be matched by this resolver.
This resolver will:
npm view pkg@version dist.tarball
).If the package you download on NPM does not contains bower.json
, you will not get the
transitive dependencies (and you will have to explicitly add then to your bower.json
file).
MIT License (MIT)
cacache
, pacote
, etc.).requireg
module.cwd
update side effect.npm pack
command to download packages (using npm proxy settings).npm:
prefix.npm+
).npm+
prefix to match packages.If you find a bug or think about enhancement, feel free to contribute and submit an issue or a pull request.
To work in TDD mode, just run: npm run tdd
.
Special thanks to @mhofman & @jakub-g for their contributions!