You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by audreyso <gi...@git.apache.org> on 2017/02/27 17:30:01 UTC

[GitHub] cordova-lib pull request #521: CB-12425 : Auto-create package.json if it doe...

GitHub user audreyso opened a pull request:

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

    CB-12425 : Auto-create package.json if it doesn't exist yet (during prepare)

    <!--
    Please make sure the checklist boxes are all checked before submitting the PR. The checklist
    is intended as a quick reference, for complete details please see our Contributor Guidelines:
    
    http://cordova.apache.org/contribute/contribute_guidelines.html
    
    Thanks!
    -->
    
    ### Platforms affected
    
    
    ### What does this PR do?
    
    Auto-creates package.json if it doesn't exist yet (during prepare)
    
    ### What testing has been done on this change?
    
    
    ### 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.
    - [X] Added automated test coverage as appropriate for this change.


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

    $ git pull https://github.com/audreyso/cordova-lib CB-12425

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

    https://github.com/apache/cordova-lib/pull/521.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 #521
    
----
commit 12fea8d3cb40efe567aeca19108f4536942ca801
Author: Audrey So <au...@apache.org>
Date:   2017-02-23T00:24:48Z

    CB-12425 : autocreate a package.json if it doesn't exist during restore

commit 6818e91739ab963e1cd12c9115c9dd943c57b466
Author: Audrey So <au...@apache.org>
Date:   2017-02-23T21:25:58Z

    CB-12425 : moved auto-create pkg.json code from restore-util to platform.js and plugin.js

commit f29236ba7b528fe60bf86b1424ee8e9650621647
Author: Audrey So <au...@apache.org>
Date:   2017-02-24T00:36:05Z

    CB-12425 : added testing for pkgJson being auto-created

----


---
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 #521: CB-12425 : Auto-create package.json if it doesn't ex...

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

    https://github.com/apache/cordova-lib/pull/521
  
    # [Codecov](https://codecov.io/gh/apache/cordova-lib/pull/521?src=pr&el=h1) Report
    > Merging [#521](https://codecov.io/gh/apache/cordova-lib/pull/521?src=pr&el=desc) into [master](https://codecov.io/gh/apache/cordova-lib/commit/b0402b9e51bf2d97488fedd39d13348b29f81c3c?src=pr&el=desc) will **increase** coverage by `0.11%`.
    > The diff coverage is `100%`.
    
    
    ```diff
    @@            Coverage Diff             @@
    ##           master     #521      +/-   ##
    ==========================================
    + Coverage    81.9%   82.01%   +0.11%     
    ==========================================
      Files          68       68              
      Lines        5504     5516      +12     
      Branches     1090     1094       +4     
    ==========================================
    + Hits         4508     4524      +16     
    + Misses        996      992       -4
    ```
    
    
    | [Impacted Files](https://codecov.io/gh/apache/cordova-lib/pull/521?src=pr&el=tree) | Coverage \u0394 | |
    |---|---|---|
    | [cordova-lib/src/cordova/platform.js](https://codecov.io/gh/apache/cordova-lib/compare/b0402b9e51bf2d97488fedd39d13348b29f81c3c...f7b36842eb5b4d1a5df00492c24589acebd377e5?src=pr&el=tree#diff-Y29yZG92YS1saWIvc3JjL2NvcmRvdmEvcGxhdGZvcm0uanM=) | `78.31% <100%> (+0.06%)` | :white_check_mark: |
    | [cordova-lib/src/cordova/plugin.js](https://codecov.io/gh/apache/cordova-lib/compare/b0402b9e51bf2d97488fedd39d13348b29f81c3c...f7b36842eb5b4d1a5df00492c24589acebd377e5?src=pr&el=tree#diff-Y29yZG92YS1saWIvc3JjL2NvcmRvdmEvcGx1Z2luLmpz) | `88.72% <100%> (-0.08%)` | :x: |
    | [cordova-lib/src/cordova/restore-util.js](https://codecov.io/gh/apache/cordova-lib/compare/b0402b9e51bf2d97488fedd39d13348b29f81c3c...f7b36842eb5b4d1a5df00492c24589acebd377e5?src=pr&el=tree#diff-Y29yZG92YS1saWIvc3JjL2NvcmRvdmEvcmVzdG9yZS11dGlsLmpz) | `96.09% <100%> (+0.48%)` | :white_check_mark: |
    | [cordova-lib/src/plugman/fetch.js](https://codecov.io/gh/apache/cordova-lib/compare/b0402b9e51bf2d97488fedd39d13348b29f81c3c...f7b36842eb5b4d1a5df00492c24589acebd377e5?src=pr&el=tree#diff-Y29yZG92YS1saWIvc3JjL3BsdWdtYW4vZmV0Y2guanM=) | `83.14% <0%> (+1.68%)` | :white_check_mark: |
    | [cordova-lib/src/plugman/registry/registry.js](https://codecov.io/gh/apache/cordova-lib/compare/b0402b9e51bf2d97488fedd39d13348b29f81c3c...f7b36842eb5b4d1a5df00492c24589acebd377e5?src=pr&el=tree#diff-Y29yZG92YS1saWIvc3JjL3BsdWdtYW4vcmVnaXN0cnkvcmVnaXN0cnkuanM=) | `82.85% <0%> (+5.71%)` | :white_check_mark: |
    
    ------
    
    [Continue to review full report at Codecov](https://codecov.io/gh/apache/cordova-lib/pull/521?src=pr&el=continue).
    > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
    > `\u0394 = absolute <relative> (impact)`, `� = not affected`, `? = missing data`
    > Powered by [Codecov](https://codecov.io/gh/apache/cordova-lib/pull/521?src=pr&el=footer). Last update [b0402b9...f7b3684](https://codecov.io/gh/apache/cordova-lib/compare/b0402b9e51bf2d97488fedd39d13348b29f81c3c...f7b36842eb5b4d1a5df00492c24589acebd377e5?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r108229542
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -63,7 +64,27 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 // Combining arrays and checking duplicates.
                 comboArray = pkgJsonPlatforms.slice();
             }
    +
             engines = cfg.getEngines(projectHome);
    +
    +        if(fs.existsSync(pkgJsonPath)) {
    +            pkgJson = require(pkgJsonPath);
    +
    +        // If package.json doesn't exist, auto-create one.
    +        } else if (engines.length > 0 && !fs.existsSync(pkgJsonPath)) {
    --- End diff --
    
    Hmm taking that check out causes test 016 to fail 
    ```Expected Error: Cannot find module '/private/var/folders/13/dkz30nws1dv3dzlh6dvthwzm0000gn/T/e2e-test/platform_test_pkgjson/project/package.json' to be undefined.```


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r107840945
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -63,7 +64,27 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 // Combining arrays and checking duplicates.
                 comboArray = pkgJsonPlatforms.slice();
             }
    +
             engines = cfg.getEngines(projectHome);
    +
    +        if(fs.existsSync(pkgJsonPath)) {
    +            pkgJson = require(pkgJsonPath);
    +        // TODO: Eventually refactor out to pacakge manager module.
    --- End diff --
    
    what is this TODO comment about


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r107840862
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -114,13 +135,19 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 events.emit('verbose', 'Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.');
                 comboArray.forEach(function(item) {
                     var prefixItem = ('cordova-'+item);
    +
                     // Modify package.json if any of these cases are true:
    -                if((pkgJson.dependencies === undefined && Object.keys(mergedPlatformSpecs).length)||
    -                    (pkgJson.dependencies[item] === undefined && mergedPlatformSpecs[item]) ||
    -                    (pkgJson.dependencies[prefixItem] === undefined && mergedPlatformSpecs[prefixItem])) {
    +                if((pkgJson.dependencies === undefined && Object.keys(mergedPlatformSpecs).length) ||
    +                (pkgJson.dependencies && mergedPlatformSpecs && pkgJson.dependencies[item] === undefined && mergedPlatformSpecs[item]) || 
    +                (pkgJson.dependencies && mergedPlatformSpecs && pkgJson.dependencies[prefixItem] === undefined && mergedPlatformSpecs[prefixItem])) {
                         modifiedPkgJson = true;
                     }
     
    +                // if ((pkgJson.dependencies && mergedPlatformSpecs && pkgJson.dependencies[item] === undefined && mergedPlatformSpecs[item]) || 
    --- End diff --
    
    We can delete line 146-150


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

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


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r108492723
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -64,7 +64,25 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 // Combining arrays and checking duplicates.
                 comboArray = pkgJsonPlatforms.slice();
             }
    +
             engines = cfg.getEngines(projectHome);
    +
    +        // TODO: CB-12592: Eventually refactor out to pacakge manager module.
    +        // If package.json doesn't exist, auto-create one.
    +        if (engines.length > 0 && !fs.existsSync(pkgJsonPath)) {
    --- End diff --
    
    Hmm same errors!


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r108737235
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -64,7 +64,25 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 // Combining arrays and checking duplicates.
                 comboArray = pkgJsonPlatforms.slice();
             }
    +
             engines = cfg.getEngines(projectHome);
    +
    +        // TODO: CB-12592: Eventually refactor out to pacakge manager module.
    +        // If package.json doesn't exist, auto-create one.
    +        if (engines.length > 0 && !fs.existsSync(pkgJsonPath)) {
    --- End diff --
    
    oo i think it should have been `(engines.length > 0 && pkgJson === undefined)`. Does that work?


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r107994895
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -63,7 +64,27 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 // Combining arrays and checking duplicates.
                 comboArray = pkgJsonPlatforms.slice();
             }
    +
             engines = cfg.getEngines(projectHome);
    +
    +        if(fs.existsSync(pkgJsonPath)) {
    +            pkgJson = require(pkgJsonPath);
    +        // TODO: Eventually refactor out to pacakge manager module.
    --- End diff --
    
    oo you can keep it. Would be good practice to include the issue number in the todo. 


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r108489174
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -64,7 +64,25 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 // Combining arrays and checking duplicates.
                 comboArray = pkgJsonPlatforms.slice();
             }
    +
             engines = cfg.getEngines(projectHome);
    +
    +        // TODO: CB-12592: Eventually refactor out to pacakge manager module.
    +        // If package.json doesn't exist, auto-create one.
    +        if (engines.length > 0 && !fs.existsSync(pkgJsonPath)) {
    --- End diff --
    
    maybe try `(engines.length > 0 && pkgJson !== undefined)`


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r108751887
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -64,7 +64,25 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 // Combining arrays and checking duplicates.
                 comboArray = pkgJsonPlatforms.slice();
             }
    +
             engines = cfg.getEngines(projectHome);
    +
    +        // TODO: CB-12592: Eventually refactor out to pacakge manager module.
    +        // If package.json doesn't exist, auto-create one.
    +        if (engines.length > 0 && !fs.existsSync(pkgJsonPath)) {
    --- End diff --
    
    hmm yes i think that will work!


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r108009309
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -63,7 +64,27 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 // Combining arrays and checking duplicates.
                 comboArray = pkgJsonPlatforms.slice();
             }
    +
             engines = cfg.getEngines(projectHome);
    +
    +        if(fs.existsSync(pkgJsonPath)) {
    --- End diff --
    
    I don't think you need lines 70-72 because you check if pkgJson exists at line 54. 


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r108485285
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -64,7 +64,25 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 // Combining arrays and checking duplicates.
                 comboArray = pkgJsonPlatforms.slice();
             }
    +
             engines = cfg.getEngines(projectHome);
    +
    +        // TODO: CB-12592: Eventually refactor out to pacakge manager module.
    +        // If package.json doesn't exist, auto-create one.
    +        if (engines.length > 0 && !fs.existsSync(pkgJsonPath)) {
    --- End diff --
    
    Was able to remove the duplicated lines:
    ```    if(fs.existsSync(pkgJsonPath)) {
            pkgJson = require(pkgJsonPath);```
    
    But if you update restore-util from:
    ```} else if (engines.length > 0 && !fs.existsSync(pkgJsonPath)) {```
    to
    ```} else if (engines.length > 0 && pkgJson) {```
    there will be many failures... will look into them


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r107954943
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -114,13 +135,19 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 events.emit('verbose', 'Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.');
                 comboArray.forEach(function(item) {
                     var prefixItem = ('cordova-'+item);
    +
                     // Modify package.json if any of these cases are true:
    -                if((pkgJson.dependencies === undefined && Object.keys(mergedPlatformSpecs).length)||
    -                    (pkgJson.dependencies[item] === undefined && mergedPlatformSpecs[item]) ||
    -                    (pkgJson.dependencies[prefixItem] === undefined && mergedPlatformSpecs[prefixItem])) {
    +                if((pkgJson.dependencies === undefined && Object.keys(mergedPlatformSpecs).length) ||
    +                (pkgJson.dependencies && mergedPlatformSpecs && pkgJson.dependencies[item] === undefined && mergedPlatformSpecs[item]) || 
    +                (pkgJson.dependencies && mergedPlatformSpecs && pkgJson.dependencies[prefixItem] === undefined && mergedPlatformSpecs[prefixItem])) {
                         modifiedPkgJson = true;
                     }
     
    +                // if ((pkgJson.dependencies && mergedPlatformSpecs && pkgJson.dependencies[item] === undefined && mergedPlatformSpecs[item]) || 
    --- End diff --
    
    Good catch! thanks! 


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r107954295
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -63,7 +64,27 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 // Combining arrays and checking duplicates.
                 comboArray = pkgJsonPlatforms.slice();
             }
    +
             engines = cfg.getEngines(projectHome);
    +
    +        if(fs.existsSync(pkgJsonPath)) {
    +            pkgJson = require(pkgJsonPath);
    +        // TODO: Eventually refactor out to pacakge manager module.
    --- End diff --
    
    Reminder to  ---> https://issues.apache.org/jira/browse/CB-12592. Want me to take it out?


---
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 #521: CB-12425 : Auto-create package.json if it doe...

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

    https://github.com/apache/cordova-lib/pull/521#discussion_r108009704
  
    --- Diff: cordova-lib/src/cordova/restore-util.js ---
    @@ -63,7 +64,27 @@ function installPlatformsFromConfigXML(platforms, opts) {
                 // Combining arrays and checking duplicates.
                 comboArray = pkgJsonPlatforms.slice();
             }
    +
             engines = cfg.getEngines(projectHome);
    +
    +        if(fs.existsSync(pkgJsonPath)) {
    +            pkgJson = require(pkgJsonPath);
    +
    +        // If package.json doesn't exist, auto-create one.
    +        } else if (engines.length > 0 && !fs.existsSync(pkgJsonPath)) {
    --- End diff --
    
    It would be better to change this from `if (engines.length > 0 && !fs.existsSync(pkgJsonPath))` to `if (engines.length > 0 && pkgJson))` Since you already check for `pkgJsonPath` and `require pkgjson` on lines 53-54, you don't have to do another `existsSync` operation (which is expensive).


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