apache / cordova-lib

Apache Cordova Tooling Library
https://cordova.apache.org/
Apache License 2.0
221 stars 243 forks source link

Wrong platform version is detected when dependencies and devDependencies are both present #866

Closed zoltan-mihalyi closed 3 years ago

zoltan-mihalyi commented 3 years ago

Bug Report

Problem

When dependencies and devDependencies are both present, running cordova prepare installs the wrong platform version.

What is expected to happen?

Using cordova-fetch for cordova-electron@2.0.0 is printed

What does actually happen?

Using cordova-fetch for cordova-electron@1.0.0 is printed

Information

Environment, Platform, Device

the relevant part of my package.json:

{
  "devDependencies": {
    "cordova-electron": "2.0.0"
  },
  "dependencies": {
    "cordova-plugin-googleplus": "8.5.1"
  },
  "cordova": {
    "plugins": {
      "cordova-plugin-googleplus": {}
    },
    "platforms": [
      "electron"
    ]
  }
}

Solution

I managed to find the problem in this line: https://github.com/apache/cordova-lib/blob/master/src/cordova/platform/addHelper.js#L102

If "dependencies" exists, the code skips the devDependencies.

Version information

cordova-lib@10.0.0

Checklist

lirichard commented 3 years ago

@aidanas proposed a fix in PR #874. I forked his fork and contributed a unit test as well for completeness: PR aidanas/cordova-lib#1.

See also previous closed issue which partially fixed the problem, and a follow-up comment which likely is about this same issue: https://github.com/apache/cordova-lib/issues/832#issuecomment-901946362.