You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by vladimir-kotikov <gi...@git.apache.org> on 2016/02/10 15:52:16 UTC

[GitHub] cordova-lib pull request: CB-10519 Wrap all sync calls inside of `...

GitHub user vladimir-kotikov opened a pull request:

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

    CB-10519 Wrap all sync calls inside of `cordova.raw` methods into promises

    This is a fix for [CB-10519](https://issues.apache.org/jira/browse/CB-10519)
    
    This PR fixes the issue when promise returned from `cordova.raw` API would never be rejected if command is ran outside of cordova project. Instead syncronous exception will be thrown (by `util.preProcessOptions`), which is definitely unexpected for promise based API.

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

    $ git pull https://github.com/MSOpenTech/cordova-lib CB-10519

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

    https://github.com/apache/cordova-lib/pull/384.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 #384
    
----
commit 747c26e64a491645fad1dd109afb734bc9a5ce4a
Author: Vladimir Kotikov <v-...@microsoft.com>
Date:   2016-02-10T12:45:19Z

    CB-10519 Wrap all sync calls inside of `cordova.raw` methods into promises

----


---
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: CB-10519 Wrap all sync calls inside of `...

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/384#discussion_r52985929
  
    --- Diff: cordova-lib/src/cordova/build.js ---
    @@ -17,22 +17,26 @@
         under the License.
     */
     
    -var cordovaUtil      = require('./util'),
    -    HooksRunner           = require('../hooks/HooksRunner');
    +var Q = require('q'),
    +    cordovaUtil = require('./util'),
    +    HooksRunner = require('../hooks/HooksRunner');
     
     // Returns a promise.
     module.exports = function build(options) {
    -    var projectRoot = cordovaUtil.cdProjectRoot();
    -    options = cordovaUtil.preProcessOptions(options);
    -
    -    // fire build hooks
    -    var hooksRunner = new HooksRunner(projectRoot);
    -    return hooksRunner.fire('before_build', options)
    -    .then(function() {
    -        return require('./cordova').raw.prepare(options);
    -    }).then(function() {
    -        return require('./cordova').raw.compile(options);
    -    }).then(function() {
    -        return hooksRunner.fire('after_build', options);
    +    return Q().then(function() {
    +        var opts = cordovaUtil.preProcessOptions(options);
    +        var projectRoot = cordovaUtil.cdProjectRoot();
    +        return [new HooksRunner(projectRoot), opts];
    +    })
    +    .spread(function (hooksRunner, options) {
    --- End diff --
    
    > Why can't we just essentially wrap the entire method in return `Q().then(function() { ... };`?
    
    We can and basically this would be same. I think it's just a matter of taste..
    If you wish, i can update the PR in the manner you proposed


---
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: CB-10519 Wrap all sync calls inside of `...

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

    https://github.com/apache/cordova-lib/pull/384#issuecomment-185703661
  
    @TimBarham, ping


---
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: CB-10519 Wrap all sync calls inside of `...

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

    https://github.com/apache/cordova-lib/pull/384#issuecomment-185747825
  
    The return value of `Q.then(thePromise)` is the same as for `thePromise()` due to its' (promise) nature, so i think there is nothing changed for caller.


---
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: CB-10519 Wrap all sync calls inside of `...

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

    https://github.com/apache/cordova-lib/pull/384#issuecomment-184667609
  
    @TimBarham, updated


---
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: CB-10519 Wrap all sync calls inside of `...

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

    https://github.com/apache/cordova-lib/pull/384#issuecomment-185719821
  
    Oops, sorry :smile: ... LGTM. There's nowhere we call these directly internally and expect an actual value in return?


---
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: CB-10519 Wrap all sync calls inside of `...

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

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


---
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: CB-10519 Wrap all sync calls inside of `...

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

    https://github.com/apache/cordova-lib/pull/384#issuecomment-184676141
  
    Thanks @vladimir-kotikov. Looks good on a quick look through. Will take a closer look in the morning.


---
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: CB-10519 Wrap all sync calls inside of `...

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/384#discussion_r52984062
  
    --- Diff: cordova-lib/src/cordova/build.js ---
    @@ -17,22 +17,26 @@
         under the License.
     */
     
    -var cordovaUtil      = require('./util'),
    -    HooksRunner           = require('../hooks/HooksRunner');
    +var Q = require('q'),
    +    cordovaUtil = require('./util'),
    +    HooksRunner = require('../hooks/HooksRunner');
     
     // Returns a promise.
     module.exports = function build(options) {
    -    var projectRoot = cordovaUtil.cdProjectRoot();
    -    options = cordovaUtil.preProcessOptions(options);
    -
    -    // fire build hooks
    -    var hooksRunner = new HooksRunner(projectRoot);
    -    return hooksRunner.fire('before_build', options)
    -    .then(function() {
    -        return require('./cordova').raw.prepare(options);
    -    }).then(function() {
    -        return require('./cordova').raw.compile(options);
    -    }).then(function() {
    -        return hooksRunner.fire('after_build', options);
    +    return Q().then(function() {
    +        var opts = cordovaUtil.preProcessOptions(options);
    +        var projectRoot = cordovaUtil.cdProjectRoot();
    +        return [new HooksRunner(projectRoot), opts];
    +    })
    +    .spread(function (hooksRunner, options) {
    --- End diff --
    
    Hey @vladimir-kotikov - what's the purpose of using `spread()` here (and elsewhere)? Why can't we just essentially wrap the entire method in `return Q().then(function() { ... };`?


---
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: CB-10519 Wrap all sync calls inside of `...

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/384#discussion_r52993992
  
    --- Diff: cordova-lib/src/cordova/build.js ---
    @@ -17,22 +17,26 @@
         under the License.
     */
     
    -var cordovaUtil      = require('./util'),
    -    HooksRunner           = require('../hooks/HooksRunner');
    +var Q = require('q'),
    +    cordovaUtil = require('./util'),
    +    HooksRunner = require('../hooks/HooksRunner');
     
     // Returns a promise.
     module.exports = function build(options) {
    -    var projectRoot = cordovaUtil.cdProjectRoot();
    -    options = cordovaUtil.preProcessOptions(options);
    -
    -    // fire build hooks
    -    var hooksRunner = new HooksRunner(projectRoot);
    -    return hooksRunner.fire('before_build', options)
    -    .then(function() {
    -        return require('./cordova').raw.prepare(options);
    -    }).then(function() {
    -        return require('./cordova').raw.compile(options);
    -    }).then(function() {
    -        return hooksRunner.fire('after_build', options);
    +    return Q().then(function() {
    +        var opts = cordovaUtil.preProcessOptions(options);
    +        var projectRoot = cordovaUtil.cdProjectRoot();
    +        return [new HooksRunner(projectRoot), opts];
    +    })
    +    .spread(function (hooksRunner, options) {
    --- End diff --
    
    Well, that'd be my preference, as the code ends up much simpler and easy to read, to my mind. Otherwise we're arbitrarily splitting out the synchronous part of the process into its own separate promise, when there's no need to. But ultimately it's up to you :smile:.


---
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