You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by TimBarham <gi...@git.apache.org> on 2016/10/08 03:32:22 UTC

[GitHub] cordova-lib pull request #498: CB-11985 Check if cached platform/plugin exis...

GitHub user TimBarham opened a pull request:

    https://github.com/apache/cordova-lib/pull/498

    CB-11985 Check if cached platform/plugin exists before 'npm cache'

    ### What does this PR do?
    Before calling `npm cache add` when installing a platform or plugin, look for an existing `package.tgz` file in the cache directory. This avoids unnecessary `npm` call with long timeout if not connected to the internet.
    
    Background: First time build failures in Cordova tools in Visual Studio are primarily due to `npm` failures. Therefore we are working to avoid any requirement for `npm` to hit the internet in simple build scenarios. This includes pre-installing cached versions of certain platforms and plugins. But we only get the full benefit if Cordova uses these cached versions if it finds them, without calling npm cache add.
    
    A couple of things to note:
    * This change uses shared code for platforms and plugins, and means plugins will also be cached to the `.cordova` directory rather than the global npm cache directory. Is that a concern?
    * It is likely this change will be meaningless with the proposed changes to installing platforms and plugins in Cordova 7.x. We'll cross the bridge when we come to it \U0001f604.
    
    ### What testing has been done on this change?
    Local testing.
    
    ### Checklist
    - [x] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database
    - [x] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/TimBarham/cordova-lib use-cached-platform

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cordova-lib/pull/498.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #498
    
----
commit 667e774d46399cf97a9481c3890fa7a862871d46
Author: TimBarham <ti...@microsoft.com>
Date:   2016-10-07T22:58:35Z

    CB-11985 Check if cached platform/plugin exists before 'npm cache'
    
    This avoids unnecessary npm call with long timeout if not connected to the internet.

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-lib issue #498: CB-11985 Check if cached platform/plugin exists befo...

Posted by codecov-io <gi...@git.apache.org>.
Github user codecov-io commented on the issue:

    https://github.com/apache/cordova-lib/pull/498
  
    ## [Current coverage](https://codecov.io/gh/apache/cordova-lib/pull/498?src=pr) is 80.57% (diff: 100%)
    > Merging [#498](https://codecov.io/gh/apache/cordova-lib/pull/498?src=pr) into [master](https://codecov.io/gh/apache/cordova-lib/branch/master?src=pr) will increase coverage by **0.17%**
    
    ```diff
    @@             master       #498   diff @@
    ==========================================
      Files            67         67          
      Lines          5189       5205    +16   
      Methods         836        840     +4   
      Messages          0          0          
      Branches       1005       1007     +2   
    ==========================================
    + Hits           4172       4194    +22   
    + Misses         1017       1011     -6   
      Partials          0          0          
    ```
    
    > Powered by [Codecov](https://codecov.io?src=pr). Last update [4ca3b4c...83540e7](https://codecov.io/gh/apache/cordova-lib/compare/4ca3b4ca12a01ded923734e4d92d7f9325d540dc...83540e74027fa44769ff8b3e80bf35b3cba152dc?src=pr)


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-lib pull request #498: CB-11985 Check if cached platform/plugin exis...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/cordova-lib/pull/498


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-lib pull request #498: CB-11985 Check if cached platform/plugin exis...

Posted by vladimir-kotikov <gi...@git.apache.org>.
Github user vladimir-kotikov commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/498#discussion_r82563870
  
    --- Diff: cordova-lib/src/plugman/registry/registry.js ---
    @@ -114,19 +113,11 @@ function initThenLoadSettingsWithRestore(promises) {
     }
     
     /**
    -* @param {Array} with one element - the plugin id or "id@version"
    +* @param {string} plugin - the plugin id or "id@version"
     * @return {Promise.<string>} Promised path to fetched package.
     */
     function fetchPlugin(plugin) {
    -    return initThenLoadSettingsWithRestore(function () {
    -        events.emit('log', 'Fetching plugin "' + plugin + '" via npm');
    -        return Q.ninvoke(npm.commands, 'cache', ['add', plugin])
    -        .then(function (info) {
    -            var unpack = require('../../util/unpack');
    -            var pluginDir = path.resolve(npm.cache, info.name, info.version, 'package');
    -            // Unpack the plugin that was added to the cache (CB-8154)
    -            var package_tgz = path.resolve(npm.cache, info.name, info.version, 'package.tgz');
    -            return unpack.unpackTgz(package_tgz, pluginDir);
    -        });
    -    });
    +    events.emit('log', 'Fetching plugin "' + plugin + '" via npm');
    +    var pluginSplit = plugin.split('@');
    +    return npmhelper.fetchPackage(pluginSplit[0], pluginSplit[1]);
    --- End diff --
    
    Looks like this will not work for scoped NPM packages (like `@scope/cordova-plugin-camera@2.0.0`). `pluginSplit[0]` and `pluginSplit[1]` would become `''` and `'scope/cordova-plugin-camera'` in this case.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-lib issue #498: CB-11985 Check if cached platform/plugin exists befo...

Posted by brodybits <gi...@git.apache.org>.
Github user brodybits commented on the issue:

    https://github.com/apache/cordova-lib/pull/498
  
    Thanks @TimBarham for the explanation


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-lib issue #498: CB-11985 Check if cached platform/plugin exists befo...

Posted by TimBarham <gi...@git.apache.org>.
Github user TimBarham commented on the issue:

    https://github.com/apache/cordova-lib/pull/498
  
    @brodybits - that hasn't changed. At the point where we're looking for a cached version, we have already determined the latest version that matches the requested range (for both platforms and plugins). If a version range is specified, we have to hit the internet to determine the latest version that matches that range (and this change doesn't provide any real benefit). If a specific version is specified (which will be the case in VS), then that is the version we'll get (cached if it is there, otherwise have to download).
    
    The only change here from a user's perspective should be that plugins are cached in the same place as platforms (in the `.cordova` directory).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-lib issue #498: CB-11985 Check if cached platform/plugin exists befo...

Posted by brodybits <gi...@git.apache.org>.
Github user brodybits commented on the issue:

    https://github.com/apache/cordova-lib/pull/498
  
    I would personally favor this change to be "opt-in". I like the idea that npm checks for a newer release before using the cached version of a package.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-lib pull request #498: CB-11985 Check if cached platform/plugin exis...

Posted by TimBarham <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-lib pull request #498: CB-11985 Check if cached platform/plugin exis...

Posted by vladimir-kotikov <gi...@git.apache.org>.
Github user vladimir-kotikov commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/498#discussion_r82563323
  
    --- 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 --
    
    If `packageVersion` is not provided, this will throw the following error: 'TypeError: Path must be a string. Received undefined'. IMO while this is legitimate error, it probably needs to be wrapped into promise, since this function return a promised result.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-lib issue #498: CB-11985 Check if cached platform/plugin exists befo...

Posted by vladimir-kotikov <gi...@git.apache.org>.
Github user vladimir-kotikov commented on the issue:

    https://github.com/apache/cordova-lib/pull/498
  
    Looks good! 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-lib pull request #498: CB-11985 Check if cached platform/plugin exis...

Posted by TimBarham <gi...@git.apache.org>.
Github user TimBarham commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/498#discussion_r82568768
  
    --- Diff: cordova-lib/src/plugman/registry/registry.js ---
    @@ -114,19 +113,11 @@ function initThenLoadSettingsWithRestore(promises) {
     }
     
     /**
    -* @param {Array} with one element - the plugin id or "id@version"
    +* @param {string} plugin - the plugin id or "id@version"
     * @return {Promise.<string>} Promised path to fetched package.
     */
     function fetchPlugin(plugin) {
    -    return initThenLoadSettingsWithRestore(function () {
    -        events.emit('log', 'Fetching plugin "' + plugin + '" via npm');
    -        return Q.ninvoke(npm.commands, 'cache', ['add', plugin])
    -        .then(function (info) {
    -            var unpack = require('../../util/unpack');
    -            var pluginDir = path.resolve(npm.cache, info.name, info.version, 'package');
    -            // Unpack the plugin that was added to the cache (CB-8154)
    -            var package_tgz = path.resolve(npm.cache, info.name, info.version, 'package.tgz');
    -            return unpack.unpackTgz(package_tgz, pluginDir);
    -        });
    -    });
    +    events.emit('log', 'Fetching plugin "' + plugin + '" via npm');
    +    var pluginSplit = plugin.split('@');
    +    return npmhelper.fetchPackage(pluginSplit[0], pluginSplit[1]);
    --- End diff --
    
    Hah, look at that. I didn't know @riknoll had added support for scoped packages. I'll switch this to use `plugin-spec-parser`.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org