lirichard commented on pull request #874:
URL: https://github.com/apache/cordova-lib/pull/874#issuecomment-916956023


   It's not that the platform package is in both `dependencies` and 
`devDependencies`—it's that the platform package is in `devDependencies` and 
some other unrelated package(s) are in `dependencies`.
   
   For example you can replicate by creating this test project:
   
   ```
   cordova create testProject
   cd testProject
   npm i [email protected]
   cordova platform add [email protected]
   rm -r platforms
   cordova prepare android
   ```
   
   The package.json ends up with these `dependencies` and `devDependencies` 
(I've omitted everything else in the package.json for brevity):
   
   ```json
   // package.json
   {
       "dependencies": {
           "lodash": "^4.17.21"
       },
       "devDependencies": {
           "cordova-android": "^10.1.0",
           "cordova-plugin-whitelist": "^1.3.4"
       }
   }
   ```
   
   However, the last `cordova prepare android` outputs `Using cordova-fetch for 
cordova-android@^9.0.0` instead of the expected `10.1.0` from `devDependencies`.
   
   Here, when you run `cordova prepare android`, the current code tries to look 
inside `dependencies` for `cordova-android` ([`pkgJson.dependencies` is 
truthy](https://github.com/apache/cordova-lib/blob/dd872f044211592b11c17d23d56cd17192e4b51f/src/cordova/platform/addHelper.js#L96)).
 Naturally, it doesn't find `cordova-android`. It then _skips_ the 
`devDependencies` ([because of the `else 
if`](https://github.com/apache/cordova-lib/blob/dd872f044211592b11c17d23d56cd17192e4b51f/src/cordova/platform/addHelper.js#L102)),
 which is the bug we're addressing here.
   
   The `else if` is a little misleading because the code does a sequential 
process to find the `spec` value. See:
   1. `if (spec === undefined ...)` on 
[addHelper.js#L96](https://github.com/apache/cordova-lib/blob/dd872f044211592b11c17d23d56cd17192e4b51f/src/cordova/platform/addHelper.js#L96)
 to look inside `package.json` `dependencies`; then
   2. `if (... spec === undefined ...)` on 
[addHelper.js#L110](https://github.com/apache/cordova-lib/blob/dd872f044211592b11c17d23d56cd17192e4b51f/src/cordova/platform/addHelper.js#L110)
 to look inside `config.xml`; then finally
   3. `if (!spec ...)` on 
[addHelper.js#L116](https://github.com/apache/cordova-lib/blob/dd872f044211592b11c17d23d56cd17192e4b51f/src/cordova/platform/addHelper.js#L116])
 to fall back to the pinned platform version.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to