* Install a module in an app given a URL * * @return {Promise } resolves with installed version
(app, name, url, version, opts)
| 172 | * @return {Promise<string>} resolves with installed version |
| 173 | */ |
| 174 | function installModuleFromURL (app, name, url, version, opts) { |
| 175 | // we can't silence a clone/fetch in case the user has to enter credentials |
| 176 | logger.log(chalk.cyan('Adding ' + name + (version ? '@' + version : ''))); |
| 177 | |
| 178 | var modulePath = path.join(app.paths.modules, name); |
| 179 | var exists = fs.existsSync(modulePath); |
| 180 | |
| 181 | return Promise |
| 182 | .bind({}) |
| 183 | .then(function () { |
| 184 | if (!exists) { |
| 185 | // if destination path doesn't exist, add module to cache then add |
| 186 | // module to app |
| 187 | return updateCache(name, url, version) |
| 188 | .bind(this) |
| 189 | .then(function (cacheEntry) { |
| 190 | this.cacheEntry = cacheEntry; |
| 191 | return addModuleToApp(app, cacheEntry, name, opts); |
| 192 | }); |
| 193 | } |
| 194 | }) |
| 195 | .then(function () { |
| 196 | // modulePath may be invalid if name is a URL, use the cacheEntry for the |
| 197 | // latest values |
| 198 | if (this.cacheEntry) { |
| 199 | name = this.cacheEntry.name; |
| 200 | modulePath = path.join(app.paths.modules, this.cacheEntry.name); |
| 201 | } |
| 202 | |
| 203 | if (opts.link) { displayLinkWarning(app, modulePath); } |
| 204 | |
| 205 | return Module.setVersion(modulePath, version, { |
| 206 | forceInstall: true, |
| 207 | unsafe: opts.unsafe |
| 208 | }); |
| 209 | }) |
| 210 | .then(function (installedVersion) { |
| 211 | this.installedVersion = installedVersion; |
| 212 | |
| 213 | app.reloadModules(); // synchronous |
| 214 | return app.addDependency(name, { |
| 215 | url: this.cacheEntry && this.cacheEntry.url, |
| 216 | version: this.installedVersion |
| 217 | }); |
| 218 | }) |
| 219 | .then(function () { |
| 220 | // Return value for installModuleFromURL |
| 221 | return this.installedVersion; |
| 222 | }); |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Link module into app's moudles folder |
no test coverage detected
searching dependent graphs…