Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-14033

`cordova plugin add` skips directory on windows

VotersStop watchingWatchersLinkUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: cordova-lib
    • Labels:
    • Environment:

      Cordova 6.2.0


      Suppose we have a cordova plugin project and a test project that are under the same directory. The cordova plugin project is in directory p, and the test project in directory t. When I run following command in directory t:


      cordova plugin add ..\p

      the install fails, and I found it's due to the src directory missing during copying.

      After digging into the source, I found it's caused by a special handling in the fetch action on windows. The source is https://github.com/apache/cordova-lib/blob/master/src/plugman/fetch.js#L299.

                      This is a special case. On windows we cannot create a symlink unless we are run as admin
                      The error that we have is because src contains dest, so we end up with a recursive folder explosion
                      This code avoids copy the one folder that will explode, and allows plugins to contain a demo project
                      and to install the plugin via `cordova plugin add ../`
                  var resolvedSrcPath = path.resolve(plugin_dir);
                  var filenames = fs.readdirSync(resolvedSrcPath);
                  var relPath = path.relative(resolvedSrcPath,dest);
                  var relativeRootFolder = relPath.split('\\')[0];

      in this case relPath will be "..\t\plugins{{plugin id}}", relativeRootFolder be "..", then filenames.indexOf(relativeRootFolder) be -1, finally filenames lost the last element, which is the src directory in my case.






            • Assignee:
              raphinesse Raphael von der Grün
              jacklu Jack Lu


              • Created:

                Issue deployment