CINXE.COM
Pluggable Resolvers · Bower
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="google-site-verification" content="1XwfuTPiyoCivlUjHLisCr8ukNu3tiv0Ax_wDx3-BhY"> <link rel="apple-touch-icon" href="/apple-touch-icon.png"> <!-- V2 --> <link href='/assets/global-c92e9c719e6e670850368807f772c43c.css' rel='stylesheet' type='text/css' /> <!-- Social Medias --> <meta property="og:url" content="https://bower.io/docs/pluggable-resolvers/"> <meta property="og:image" content="https://bower.io/img/bower-logo.png"> <title>Pluggable Resolvers · Bower</title> <meta property="og:title" content="Pluggable Resolvers · Bower"> </head> <body class="docs-page"> <svg xmlns="http://www.w3.org/2000/svg" width="0" height="0" display="none"> <symbol id="symbol-twitter-logo" viewBox="0 0 512 512"> <path d="M512 97c-19 8-39 14-60 16 22-13 38-34 46-58-20 12-43 21-67 25-19-19-46-32-77-32-58 0-117 52-102 129-87-4-165-46-216-110-24 40-19 107 32 140-17 0-33-5-48-13v1c0 51 36 93 84 103-15 4-34 5-47 2 13 42 52 72 98 73-47 36-96 49-155 44 46 30 102 47 161 47 197 0 306-168 299-312 20-15 38-34 52-55z"/> </symbol> <symbol id="symbol-github-logo" viewBox="0 0 512 512"> <path d="M256 0C115 0 0 115 0 256c0 113 73 209 175 243 13 2 18-5 18-12v-48c-64 12-81-16-86-30-3-7-15-30-26-36-9-5-22-17 0-17 20 0 35 19 39 26 23 39 60 28 75 21 2-17 9-28 16-34-57-6-116-28-116-126 0-28 10-51 26-69-3-6-11-33 3-68 0 0 21-7 70 26 20-6 42-9 64-9s43 3 64 9c49-33 70-26 70-26 14 35 5 61 3 68 16 18 26 41 26 69 0 98-60 120-117 126 9 8 17 23 17 47v70c0 7 5 15 18 12 100-33 173-129 173-242C512 115 397 0 256 0z"/> </symbol> <symbol id="symbol-bountysource-icon" viewBox="0 0 512 512"> <path d="M442 465h-371C58 464 48 454 48 442v-371C48 58 58 48 71 48h371c12 0 23 10 23 23v371c0 13-10 23-22 23zm-272-56c12 5 56 19 91 19 53 0 85-19 102-58 14-31 5-70-21-87-12-8-11-7 1-15 28-17 51-34 51-81 0-52-58-100-143-100-82 0-133 46-133 83 0 3 1 12 4 12 16 0 40-62 123-62 44 0 113 18 113 65 0 43-76 61-98 72-12 6-11 18 0 25 10 6 74 6 74 50 0 32-19 64-78 64-43 0-49-13-49-21 0-11-.5-48 6-85 6-36 17-69 26-90 4-9-2-19-20-19-13 0-17 9-26 26-17 33-32 76-32 179 0 12 3 21 8 23z"/> </symbol> <symbol id="symbol-discord-icon" viewBox="0 0 220 220"> <path d="M104.4 103.9c-5.7 0-10.2 5-10.2 11.1s4.6 11.1 10.2 11.1c5.7 0 10.2-5 10.2-11.1.1-6.1-4.5-11.1-10.2-11.1zM140.9 103.9c-5.7 0-10.2 5-10.2 11.1s4.6 11.1 10.2 11.1c5.7 0 10.2-5 10.2-11.1s-4.5-11.1-10.2-11.1z"/><path class="st0" d="M189.5 20h-134C44.2 20 35 29.2 35 40.6v135.2c0 11.4 9.2 20.6 20.5 20.6h113.4l-5.3-18.5 12.8 11.9 12.1 11.2 21.5 19V40.6c0-11.4-9.2-20.6-20.5-20.6zm-38.6 130.6s-3.6-4.3-6.6-8.1c13.1-3.7 18.1-11.9 18.1-11.9-4.1 2.7-8 4.6-11.5 5.9-5 2.1-9.8 3.5-14.5 4.3-9.6 1.8-18.4 1.3-25.9-.1-5.7-1.1-10.6-2.7-14.7-4.3-2.3-.9-4.8-2-7.3-3.4-.3-.2-.6-.3-.9-.5-.2-.1-.3-.2-.4-.3-1.8-1-2.8-1.7-2.8-1.7s4.8 8 17.5 11.8c-3 3.8-6.7 8.3-6.7 8.3-22.1-.7-30.5-15.2-30.5-15.2 0-32.2 14.4-58.3 14.4-58.3 14.4-10.8 28.1-10.5 28.1-10.5l1 1.2c-18 5.2-26.3 13.1-26.3 13.1s2.2-1.2 5.9-2.9c10.7-4.7 19.2-6 22.7-6.3.6-.1 1.1-.2 1.7-.2 6.1-.8 13-1 20.2-.2 9.5 1.1 19.7 3.9 30.1 9.6 0 0-7.9-7.5-24.9-12.7l1.4-1.6s13.7-.3 28.1 10.5c0 0 14.4 26.1 14.4 58.3 0 0-8.5 14.5-30.6 15.2z"/> </symbol> <symbol id="icon-home" viewBox="0 0 32 32"> <title>home</title> <path class="path1" d="M32 18.451l-16-12.42-16 12.42v-5.064l16-12.42 16 12.42zM28 18v12h-8v-8h-8v8h-8v-12l12-9z"></path> </symbol> </svg> <header id="masthead"> <div class="container"> <ul class="network-nav nav"> <li class="nav-docs"><a href="/">Docs</a></li> <li class="nav-search"><a href="/search/">Search packages</a></li> <li class="nav-blog"><a href="/blog/">Blog</a></li> <li class="nav-stats"><a href="/stats/">Stats</a></li> </ul> <a href="/"> <img class="logo" src="/img/bower-logo.svg" alt="Bower logo" /> </a> <h1 class="page-title">Pluggable Resolvers</h1> </div> </header> <div class="notification"> ...psst! While Bower is maintained, we recommend using <a href="https://yarnpkg.com/">Yarn</a> and <a href="https://vitejs.dev/">Vite</a> for front-end projects. <a href="https://bower.io/blog/2017/how-to-migrate-away-from-bower/">Read how to migrate</a>! </div> <div id="content"> <div class="container"> <div class="btn menu-btn">Menu</div> <div class="sidebar"> <ul class="docs-nav nav"> <li class="nav-home"><a href="/">Home</a></li> <li class="nav-creating"><a href="/docs/creating-packages/">Creating Packages</a></li> <li class="nav-api"><a href="/docs/api/">API</a></li> <li class="nav-config"><a href="/docs/config/">Configuration</a></li> <li class="nav-config"><a href="/docs/pluggable-resolvers/">Pluggable Resolvers</a></li> <li class="nav-tools"><a href="/docs/tools/">Tools</a></li> <li class="nav-about"><a href="/docs/about/">About</a></li> </ul> <h5>Sponsors (<a href="https://opencollective.com/bower">become one</a>):</h5> <a rel="sponsored" href="https://420couponcodes.com/"><img class="sidebar-logo" src="https://i.imgur.com/IbhCD2k.png" alt="420couponcodes.com" /></a> <a rel="sponsored" href="https://www.credimaxx.de/"><img class="sidebar-logo" src="https://i.imgur.com/sf5e7KT.png" alt="credimaxx.de" /></a> <a rel="sponsored" href="https://www.softwaredevelopment.co.uk/"><img class="sidebar-logo" src="https://i.imgur.com/HoU15ep.png" alt="SoftwareDevelopmentUK" /></a> <a rel="sponsored" href="https://www.instinctools.com/cloud-computing/"><img class="sidebar-logo" src="https://i.imgur.com/c56Di42.png" alt="*instinctools" /></a> <a rel="sponsored" href="https://www.cryptonewsz.com/"><img class="sidebar-logo" src="https://i.imgur.com/sYNDuyj.png" alt="CryptoNewsZ" /></a> <a rel="sponsored" href="https://legalbet.uk/"><img class="sidebar-logo" src="https://i.imgur.com/2qQ6Gxf.png" alt="Legalbet" /></a> <a rel="sponsored" href="https://route4me.com/"><img class="sidebar-logo" src="https://i.imgur.com/g5LeC9Q.png" alt="Route4Me Route Planner" /></a> <a rel="sponsored" href="https://www.synetec.co.uk/"><img class="sidebar-logo" src="https://i.imgur.com/FatvhBy.png" alt="Synetec" /></a> <a rel="sponsored" href="https://vpn-review.com/"><img class="sidebar-logo" src="https://i.imgur.com/INf1G7H.png" alt="VPN reviews 2019" /></a> <a rel="sponsored" href="https://faveable.com/"><img class="sidebar-logo" src="https://i.imgur.com/PMqdGyT.png" alt="Faveable" /></a> <a rel="sponsored" href="https://iboysoft.com"><img class="sidebar-logo" src="https://i.imgur.com/eOWcxUr.png" alt="iBoysoft" /></a> <a rel="sponsored" href="https://webpundits.in"><img class="sidebar-logo" src="https://i.imgur.com/IVgnquz.png" alt="Buy RDP online from Web Pundits" /></a> <a rel="sponsored" href="https://sprocketdigital.co.nz/"><img class="sidebar-logo" src="https://i.imgur.com/koJsb0d.png" alt="Matthew Chalk" /></a> <ul class="extra-nav nav"> <li><a href="https://github.com/bower/bower"> <svg class="extra-nav-icon"> <use xlink:href="#symbol-github-logo"></use> </svg> Bower on GitHub </a></li> <li><a href="https://twitter.com/bower"> <svg class="extra-nav-icon"> <use xlink:href="#symbol-twitter-logo"></use> </svg> @bower </a></li> </ul> </div> <div class="main"> <p class="lead">Pluggable resolvers allow you to use resolvers created by 3rd party JavaScript developers — including overriding default resolvers used by Bower.</p> <p>For example, resolvers can be used for:</p> <ul> <li>Handling <a href="https://mercurial.selenic.com/">Mercurial</a> or <a href="http://bazaar.canonical.com/en/">Bazaar</a> repositories</li> <li>Speeding up checkouts of services like <a href="https://about.gitlab.com/">GitLab</a> or <a href="https://bitbucket.org/">Bitbucket</a></li> <li>Allowing to use packages from <a href="https://www.npmjs.com/">npm</a> or <a href="https://github.com/component/component.github.io">component.io</a></li> <li>Proxying downloads through 3rd party service like <a href="http://www.jfrog.com/artifactory/">Artifactory</a> or <a href="http://www.sonatype.com/nexus-repository-oss">Nexus Repository</a></li> <li>Implementing custom private registry (hosted on GitHub?)</li> <li>Adding authentication support for private <a href="https://enterprise.github.com/">GitHub Enterprise</a> instances</li> </ul> <p>Pluggable resolvers were introduced in Bower 1.5. Please make sure your Bower version is correct (<code class="highlighter-rouge">bower --version</code>).</p> <h2 id="using">Using</h2> <p>A Pluggable Resolver is just an npm package that you install as <code class="highlighter-rouge">devDependency</code> in the <code class="highlighter-rouge">package.json</code> of your repository, or install globally with <code class="highlighter-rouge">npm install -g</code>.</p> <p>Declare what Pluggable resolvers your project uses by adding entries to the <code class="highlighter-rouge">resolvers</code> section of <a href="/docs/config">.bowerrc</a>.</p> <figure class="highlight"><pre><code class="language-json" data-lang="json"><span class="p">{</span><span class="w"> </span><span class="s2">"resolvers"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="s2">"bitbucket-resolver"</span><span class="p">,</span><span class="w"> </span><span class="s2">"github-enterprise-resolver"</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">}</span></code></pre></figure> <p>Bower tries to use resolvers in the order specified. If no custom resolver matches the source being processed, Bower fallbacks to default resolvers (git, github, filesystem, svn, registry).</p> <p>You can find the list of available Bower resolvers on <a href="https://www.npmjs.com/search?q=bower-resolver">npm website</a>.</p> <h2 id="creating">Creating</h2> <p>As mentioned, custom resolvers are <a href="https://www.npmjs.com/">npm</a> packages with specific a API described below.</p> <p>The <code class="highlighter-rouge">package.json</code> should not list <code class="highlighter-rouge">bower</code> as a <code class="highlighter-rouge">dependency</code> or <code class="highlighter-rouge">peerDependency</code> (both have undesired behavior in npm 2.x, and we don’t want you to use bower internals). Instead, you can check for proper environment in resolver’s factory by reading provided <code class="highlighter-rouge">bower.version</code> parameter and use any other packages on npm (like <a href="https://www.npmjs.com/package/request">request</a>).</p> <p>Packages should list <code class="highlighter-rouge">bower-resolver</code> as one of the <code class="highlighter-rouge">keywords</code> in <code class="highlighter-rouge">package.json</code>. Resolvers should also follow <a href="http://semver.org/">semver</a> specification.</p> <p>Here is how an example <code class="highlighter-rouge">package.json</code> of a custom resolver can look like:</p> <figure class="highlight"><pre><code class="language-json" data-lang="json"><span class="p">{</span><span class="w"> </span><span class="s2">"name"</span><span class="p">:</span><span class="w"> </span><span class="s2">"custom-bower-resolver"</span><span class="p">,</span><span class="w"> </span><span class="s2">"version"</span><span class="p">:</span><span class="w"> </span><span class="s2">"1.0.0"</span><span class="p">,</span><span class="w"> </span><span class="s2">"keywords"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="s2">"bower-resolver"</span><span class="p">],</span><span class="w"> </span><span class="s2">"main"</span><span class="p">:</span><span class="w"> </span><span class="s2">"index.js"</span><span class="p">,</span><span class="w"> </span><span class="s2">"dependencies"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s2">"request"</span><span class="p">:</span><span class="w"> </span><span class="s2">"^2.61.0"</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span></code></pre></figure> <p>The <code class="highlighter-rouge">index.js</code> should export factory for resolver, as follows:</p> <figure class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span class="kd">var</span> <span class="nx">tmp</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'tmp'</span><span class="p">);</span> <span class="cm">/** * Factory function for resolver * It is called only one time by Bower, to instantiate resolver. * You can instantiate here any caches or create helper functions. */</span> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="kd">function</span> <span class="nx">resolver</span> <span class="p">(</span><span class="nx">bower</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// Resolver factory returns an instance of resolver</span> <span class="k">return</span> <span class="p">{</span> <span class="c1">// Match method tells whether resolver supports given source</span> <span class="c1">// It can return either boolean or promise of boolean</span> <span class="na">match</span><span class="p">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">source</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">source</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'svn://'</span><span class="p">)</span> <span class="o">===</span> <span class="mi">0</span> <span class="p">},</span> <span class="c1">// Optional:</span> <span class="c1">// Can resolve or normalize sources, like:</span> <span class="c1">// "jquery" => "git://github.com/jquery/jquery.git"</span> <span class="na">locate</span><span class="p">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">source</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">source</span><span class="p">;</span> <span class="p">},</span> <span class="c1">// Optional:</span> <span class="c1">// Allows to list available versions of given source.</span> <span class="c1">// Bower chooses matching release and passes it to "fetch"</span> <span class="na">releases</span><span class="p">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">source</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="p">[</span> <span class="p">{</span> <span class="na">target</span><span class="p">:</span> <span class="s1">'v1.0.0'</span><span class="p">,</span> <span class="na">version</span><span class="p">:</span> <span class="s1">'1.0.0'</span> <span class="p">},</span> <span class="p">{</span> <span class="na">target</span><span class="p">:</span> <span class="s1">'v1.0.1'</span><span class="p">,</span> <span class="na">version</span><span class="p">:</span> <span class="s1">'1.0.1'</span> <span class="p">}</span> <span class="p">]</span> <span class="p">},</span> <span class="c1">// It downloads package and extracts it to temporary directory</span> <span class="c1">// You can use npm's "tmp" package to tmp directories</span> <span class="c1">// See the "Resolver API" section for details on this method</span> <span class="na">fetch</span><span class="p">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">endpoint</span><span class="p">,</span> <span class="nx">cached</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// If cached version of package exists, re-use it</span> <span class="k">if</span> <span class="p">(</span><span class="nx">cached</span> <span class="o">&&</span> <span class="nx">cached</span><span class="p">.</span><span class="nx">version</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span> <span class="kd">var</span> <span class="nx">tempDir</span> <span class="o">=</span> <span class="nx">tmp</span><span class="p">.</span><span class="nx">dirSync</span><span class="p">();</span> <span class="c1">// ... download package to tempDir</span> <span class="k">return</span> <span class="p">{</span> <span class="na">tempPath</span><span class="p">:</span> <span class="nx">tempDir</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="na">removeIgnores</span><span class="p">:</span> <span class="kc">true</span> <span class="p">}</span> <span class="p">}</span> <span class="p">}</span> <span class="p">}</span></code></pre></figure> <p>If you need something more solid, see this real world example: <a href="https://github.com/phenomnomnominal/mercurial-bower-resolver" target="_blank">Mercurial Resolver</a>.</p> <h2 id="resolver-api">Resolver API</h2> <h3 id="resolver-package">Resolver package</h3> <figure class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span class="kd">var</span> <span class="nx">plugResolver</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'pluggable-resolver'</span><span class="p">)</span> <span class="kd">var</span> <span class="nx">resolver</span> <span class="o">=</span> <span class="nx">plugResolver</span><span class="p">({</span> <span class="na">version</span><span class="p">:</span> <span class="s1">'1.5.0'</span><span class="p">,</span> <span class="na">config</span><span class="p">:</span> <span class="p">{...},</span> <span class="na">logger</span><span class="p">:</span> <span class="nx">logger</span> <span class="p">})</span></code></pre></figure> <ul> <li><code class="highlighter-rouge">resolver</code>: <code class="highlighter-rouge">Resolver</code> - instance of the resolver.</li> <li><code class="highlighter-rouge">version</code>: <code class="highlighter-rouge">String</code> - Bower’s version that instantiates resolver. You can validate it.</li> <li><code class="highlighter-rouge">config</code>: <code class="highlighter-rouge">Object</code> - Bower’s <a href="/docs/config/">config</a>. You can ask authors to put extra configuration in it.</li> <li><code class="highlighter-rouge">logger</code>: <code class="highlighter-rouge">Object</code> - Bower’s <a href="https://github.com/bower/bower/tree/master/packages/bower-logger">logger</a>. Use it to output important warnings / information.</li> </ul> <p><code class="highlighter-rouge">plugResolver()</code> returns an instance of the resolver with the API described below.</p> <figure class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span class="nx">resolver</span><span class="p">.</span><span class="nx">match</span><span class="p">()</span> <span class="nx">resolver</span><span class="p">.</span><span class="nx">locate</span><span class="p">()</span> <span class="nx">resolver</span><span class="p">.</span><span class="nx">releases</span><span class="p">()</span> <span class="nx">resolver</span><span class="p">.</span><span class="nx">fetch</span><span class="p">()</span></code></pre></figure> <h3 id="resolvermatch">resolver.match()</h3> <p>Tells Bower whether to use or not use this resolver for some source.</p> <figure class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span class="kd">var</span> <span class="nx">isMatched</span> <span class="o">=</span> <span class="nx">resolver</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span> <span class="nx">source</span> <span class="p">)</span></code></pre></figure> <ul> <li><code class="highlighter-rouge">source</code>: <code class="highlighter-rouge">String</code> - source from bower.json, like <code class="highlighter-rouge">git://github.com/jquery/jquery.git</code></li> <li><code class="highlighter-rouge">isMatched</code>: <code class="highlighter-rouge">Boolean</code> - <em>Returns</em> a boolean that tells whether resolver can handle given source (either by locating them with <code class="highlighter-rouge">locate</code> method, or fetching it with <code class="highlighter-rouge">fetch</code> + optional <code class="highlighter-rouge">releases</code> method).</li> </ul> <p><code class="highlighter-rouge">.match()</code> can also return a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> of the result. It’s useful e.g. for filesystem checks.</p> <h3 id="resolverlocate">resolver.locate()</h3> <p>Allows to implement simplified registry.</p> <figure class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span class="kd">var</span> <span class="nx">locatedSource</span> <span class="o">=</span> <span class="nx">resolver</span><span class="p">.</span><span class="nx">locate</span><span class="p">(</span> <span class="nx">source</span> <span class="p">)</span></code></pre></figure> <ul> <li><code class="highlighter-rouge">source</code>: <code class="highlighter-rouge">String</code> - source from bower.json, like <code class="highlighter-rouge">jquery/jquery</code></li> <li><code class="highlighter-rouge">locatedSource</code>: <code class="highlighter-rouge">String</code> - <em>Returns</em> a resolved source string, like <code class="highlighter-rouge">"git://github.com/jquery/jquery.git"</code></li> </ul> <p><code class="highlighter-rouge">.locate()</code> can also return a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> of the result. It’s useful e.g. for remote registry calls.</p> <h3 id="resolverreleases">resolver.releases()</h3> <p>Bower selects one matching <code class="highlighter-rouge">version</code> from the result and passes matching <code class="highlighter-rouge">target</code> field to <code class="highlighter-rouge">fetch</code> method.</p> <figure class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span class="kd">var</span> <span class="nx">resolvedReleases</span> <span class="o">=</span> <span class="nx">resolver</span><span class="p">.</span><span class="nx">releases</span><span class="p">(</span> <span class="nx">source</span> <span class="p">)</span></code></pre></figure> <ul> <li><code class="highlighter-rouge">source</code>: <code class="highlighter-rouge">String</code> - source from bower.json, like <code class="highlighter-rouge">git://github.com/jquery/jquery.git</code></li> <li><code class="highlighter-rouge">resolvedReleases</code>: <code class="highlighter-rouge">Array</code> - <em>Returns</em> available releases for given source (like list of available tags on GitHub) <ul> <li><code class="highlighter-rouge">target</code>: <code class="highlighter-rouge">String</code> - unique target id for release (usually tag name)</li> <li><code class="highlighter-rouge">version</code>: <code class="highlighter-rouge">String</code> - semantic version for the target above</li> </ul> </li> </ul> <p><code class="highlighter-rouge">.releases()</code> can also return a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> of the result.</p> <h3 id="resolverfetch">resolver.fetch()</h3> <p>Downloads given endpoint and returns path to temporary directory.</p> <figure class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span class="kd">var</span> <span class="nx">fetched</span> <span class="o">=</span> <span class="nx">resolver</span><span class="p">.</span><span class="nx">fetch</span><span class="p">(</span> <span class="nx">endPoint</span><span class="p">,</span> <span class="nx">cached</span> <span class="p">)</span></code></pre></figure> <ul> <li><code class="highlighter-rouge">endpoint</code>: <code class="highlighter-rouge">Object</code> - endpoint for the resource to download <ul> <li><code class="highlighter-rouge">name</code>: <code class="highlighter-rouge">String</code> - name of resource (like <code class="highlighter-rouge">jquery</code>)</li> <li><code class="highlighter-rouge">source</code>: <code class="highlighter-rouge">String</code> - where to download resource from (like <code class="highlighter-rouge">git://github.com/jquery/jquery.git</code>)</li> <li><code class="highlighter-rouge">target</code>: <code class="highlighter-rouge">String</code> - the version or release of resource to download (like <code class="highlighter-rouge">v1.0.0</code>)</li> </ul> </li> <li><code class="highlighter-rouge">cached</code>: <code class="highlighter-rouge">Object</code> - contains information about cached resource <ul> <li><code class="highlighter-rouge">endpoint</code>: <code class="highlighter-rouge">Object</code> - endpoint of cached resource (the same format as above)</li> <li><code class="highlighter-rouge">release</code>: <code class="highlighter-rouge">String</code> - release of cached resource</li> <li><code class="highlighter-rouge">releases</code>: <code class="highlighter-rouge">Array</code> - the result of <code class="highlighter-rouge">releases</code> method</li> <li><code class="highlighter-rouge">version</code>: <code class="highlighter-rouge">String</code> - present cached resource has been resolved as version (like <code class="highlighter-rouge">1.0.0</code>)</li> <li><code class="highlighter-rouge">resolution</code>: <code class="highlighter-rouge">String</code> - the “resolution” returned from previous fetch call for same resource</li> </ul> </li> <li><code class="highlighter-rouge">fetched</code>: <code class="highlighter-rouge">Object</code> - <em>Returned</em> <ul> <li><code class="highlighter-rouge">tempPath</code>: <code class="highlighter-rouge">String</code> - path to teporary directory with downloaded resource</li> <li><code class="highlighter-rouge">removeIgnores</code>: <code class="highlighter-rouge">Boolean</code> - tells whether bower should remove files ignores in bower.json.</li> <li><code class="highlighter-rouge">resolution</code>: <code class="highlighter-rouge">Object</code> - extra object that is saved in <code class="highlighter-rouge">.bower.json</code> and passed in <code class="highlighter-rouge">cached</code> field to the next <code class="highlighter-rouge">fetch</code> call. It can be used e.g. to download resources conditionally, for example by storing e-tag or last-modified time.</li> </ul> </li> </ul> <p><code class="highlighter-rouge">.fetch()</code> can also return a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> of the result.</p> <p><strong>If <code class="highlighter-rouge">.fetch()</code> returns <code class="highlighter-rouge">undefined</code>, then Bower re-uses cached package.</strong></p> <footer class="site-footer"> <p class="issue"><a href="https://github.com/bower/bower.github.io/issues">Help improve these docs. Open an issue or pull request.</a></p> <p> Our supporters: <a rel="sponsored" href="https://veepn.com/vpn-apps/vpn-for-chrome/">VeePN VPN</a> | <a rel="sponsored" href="https://www.partitionwizard.com">Partition Wizard</a> | <a rel="sponsored" href="https://www.minitool.com">MiniTool</a> | <a rel="sponsored" href="https://kafidoff.com/">Vasyl Kafidov</a> | <a rel="sponsored" href="https://www.appdrawn.com/">AppDrawn</a> | <a rel="sponsored" href="https://legalbet.uk/">Legalbet</a> | <a rel="sponsored" href="https://swiindex.com/">swiindex.com</a> | <a rel="sponsored" href="https://www.edwinsedibles.com">CBD Gummies</a> | <a rel="sponsored" href="https://cyberogism.com/">Cyberogism</a> | <a rel="sponsored" href="https://talousapu.fi/">Talousapu.fi</a> | <a rel="sponsored" href="https://www.arkiraha.fi/">Arkiraha</a> | <a rel="sponsored" href="https://www.mister-auto.com/">Mister Auto</a> | <a rel="sponsored" href="https://tankpenge.dk">Per Andersen</a> | <a rel="sponsored" href="https://www.bathroomremodelingwesterville.com">Bathroom Remodeling Westerville</a> | <a rel="sponsored" href="https://www.tankcoffee.com">Tank Coffee</a> | <a rel="sponsored" href="https://www.easeus.de/">EaseUS Germany</a> | <a rel="sponsored" href="https://rekteddies.com/">Rekt Eddie's</a> | <a rel="sponsored" href="https://www.firesticktricks.com">Fire Stick Tricks</a> | <a rel="sponsored" href="https://www.upgrow.com/">UpGrow</a> | <a rel="sponsored" href="https://www.upgrow.com/">UpGrow</a> | <a rel="sponsored" href="https://bloomingtoncarpetmn.com/">Bloomington Carpet & Upholstery Cleaning</a> | <a rel="sponsored" href="https://minneapolistowingmn.com/">Minneapolis Towing</a> | <a rel="sponsored" href="https://earthweb.com/">EarthWeb</a> | <a rel="sponsored" href="https://bountii.coupons/">Bountii</a> | <a rel="sponsored" href="https://www.famegear.com">Famegear</a> | <a rel="sponsored" href="https://www.pakstyle.pk/">PakStyle.pk</a> | <a rel="sponsored" href="https://uk-exchange.com/en/usdt-to-paypal.php">UK-Exchange</a> </p> </footer> </div> </div> </div> <script src='/assets/global-e54f86d7a57a76019ff78ea767ebd50b.js' type='text/javascript'></script> <!--GA tracking--> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-43531210-2', 'auto'); ga('require', 'linkid', 'linkid.js'); // Enable enhanced link attribution ga('require', 'displayfeatures'); // Enable Demographics and Interest Reports ga('send', 'pageview'); </script> </body> </html>