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

`cordova plugin add` skips directory on windows

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • cordova-lib
    • None
    • Cordova 6.2.0

    Description

      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.

                  /*
                      [CB-10423]
                      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];
                  filenames.splice(filenames.indexOf(relativeRootFolder),1);
      

      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.

       

       

      Attachments

        Issue Links

          Activity

            People

              raphinesse Raphael von der Grün
              jacklu Jack Lu
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: