Adam Alton created CB-13627:
-------------------------------

             Summary: findCordovaPath() in cordova.js gets the wrong path if 
multiple cordova.js files exist
                 Key: CB-13627
                 URL: https://issues.apache.org/jira/browse/CB-13627
             Project: Apache Cordova
          Issue Type: Bug
          Components: cordova-js
    Affects Versions: 7.0.1
            Reporter: Adam Alton
            Priority: Minor


If you have a <script> tag in your app which points to a custom JS file called 
cordova.js, e.g. `myapp/js/cordova.js` then (if this custom <script> tag 
appears after the <script> tag for Cordova's cordova.js, which lives in the 
root of the `platforms/<platform>/www` folder) then it causes 
`findCordovaPath()` to return the path as the path to your custom file, rather 
than Cordova's file.  That then breaks other things, such as the loading of 
plugins, causing all your plugins to be silently undefined in JS.

As far as I can tell, there's nothing in the documentation to say that you 
shouldn't have a filed called cordova.js, and it's a perfectly valid thing to 
do in general (in HTML) and both scripts run.  And as it fails silently, 
there's no way of knowing that this is the problem other than spending hours 
debugging it to get down to the cause.

I can think of several ways of tackling this:

1. Change `findCordovaPath` to look for the shortest path that points to a 
cordova.js file (because the auto-generated one lives at the root of your 
platform build, whereas custom ones will always live in some sub-folder).
2. Add something to do the documentation to make it clear that you shouldn't 
name any of your own files cordova.js.
3. Both 1 and 2.
4. Raise an error during the build process to catch this problem.

Here's the `findCordovaPath` code for reference:

{code:javascript}
function findCordovaPath () {
    var path = null;
    var scripts = document.getElementsByTagName('script');
    var term = '/cordova.js';
    for (var n = scripts.length - 1; n > -1; n--) {
        var src = scripts[n].src.replace(/\?.*$/, ''); // Strip any query param 
(CB-6007).
        if (src.indexOf(term) === (src.length - term.length)) {
            path = src.substring(0, src.length - term.length) + '/';
            break;
        }
    }
    return path;
}
{code}




--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

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

Reply via email to