Github user TimBarham commented on a diff in the pull request: https://github.com/apache/cordova-lib/pull/498#discussion_r82566198 --- Diff: cordova-lib/src/util/npm-helper.js --- @@ -72,4 +75,53 @@ function restoreSettings() { } } +/** + * Fetches the latest version of a package from NPM that matches the specified version. Returns a promise that + * resolves to the directory the NPM package is located in. + * @param packageName - name of an npm package + * @param packageVersion - requested version or version range + */ +function fetchPackage(packageName, packageVersion) { + // Get the latest matching version from NPM if a version range is specified + return util.getLatestMatchingNpmVersion(packageName, packageVersion).then( + function (latestVersion) { + return cachePackage(packageName, latestVersion); + } + ); +} + +/** + * Invokes "npm cache add," and then returns a promise that resolves to a directory containing the downloaded, + * or cached package. + * @param packageName - name of an npm package + * @param packageVersion - requested version (not a version range) + */ +function cachePackage(packageName, packageVersion) { + var cacheDir = path.join(util.libDirectory, 'npm_cache'); + + // If already cached, use that rather than calling 'npm cache add' again. + var packageCacheDir = path.resolve(cacheDir, packageName, packageVersion); --- End diff -- Sure I'll wrap the whole method in a promise.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org For additional commands, e-mail: dev-h...@cordova.apache.org