[ 
https://issues.apache.org/jira/browse/CB-13532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16476737#comment-16476737
 ] 

ASF GitHub Bot commented on CB-13532:
-------------------------------------

dpogue closed pull request #609: CB-13532: Find plugins in devDependencies
URL: https://github.com/apache/cordova-lib/pull/609
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/spec/cordova/plugin/add.spec.js b/spec/cordova/plugin/add.spec.js
index 4164f9c5b..eb07adce4 100644
--- a/spec/cordova/plugin/add.spec.js
+++ b/spec/cordova/plugin/add.spec.js
@@ -65,9 +65,10 @@ describe('cordova/plugin/add', function () {
         plugin_info_provider_revert_mock = add.__set__('PluginInfoProvider', 
plugin_info_provider_mock);
         spyOn(fs, 'existsSync').and.returnValue(false);
         spyOn(fs, 'writeFileSync').and.returnValue(false);
-        package_json_mock = jasmine.createSpyObj('package json mock', 
['cordova', 'dependencies']);
+        package_json_mock = jasmine.createSpyObj('package json mock', 
['cordova', 'dependencies', 'devDependencies']);
         package_json_mock.cordova = {};
         package_json_mock.dependencies = {};
+        package_json_mock.devDependencies = {};
         // requireNoCache is used to require package.json
         spyOn(cordova_util, 
'requireNoCache').and.returnValue(package_json_mock);
         spyOn(events, 'emit');
@@ -168,7 +169,7 @@ describe('cordova/plugin/add', function () {
 
                 spyOn(fs, 'readFileSync').and.returnValue('file');
                 add(projectRoot, hook_mock, {plugins: 
['cordova-plugin-device'], cli_variables: cli_plugin_variables, save: 
'true'}).then(function () {
-                    
expect(fs.writeFileSync).toHaveBeenCalledWith(jasmine.any(String), 
JSON.stringify({'cordova': {'plugins': {'cordova-plugin-device': 
cli_plugin_variables}}, 'dependencies': {}}, null, 2), 'utf8');
+                    
expect(fs.writeFileSync).toHaveBeenCalledWith(jasmine.any(String), 
JSON.stringify({'cordova': {'plugins': {'cordova-plugin-device': 
cli_plugin_variables}}, 'dependencies': {}, 'devDependencies': {}}, null, 2), 
'utf8');
                 }).fail(function (e) {
                     fail('fail handler unexpectedly invoked');
                     console.log(e);
@@ -259,6 +260,24 @@ describe('cordova/plugin/add', function () {
                 console.log(e);
             }).done(done);
         });
+        it('should retrieve plugin version from package.json devDependencies 
(if exists)', function (done) {
+            fs.existsSync.and.callFake(function (file_path) {
+                if (path.basename(file_path) === 'package.json') {
+                    return true;
+                } else {
+                    return false;
+                }
+            });
+
+            package_json_mock.devDependencies['cordova-plugin-device'] = 
'^1.0.0';
+
+            add.determinePluginTarget(projectRoot, Cfg_parser_mock, 
'cordova-plugin-device', {}).then(function (target) {
+                expect(target).toEqual('cordova-plugin-device@^1.0.0');
+            }).fail(function (e) {
+                fail('fail handler unexpectedly invoked');
+                console.log(e);
+            }).done(done);
+        });
         it('should retrieve plugin version from config.xml as a last resort', 
function (done) {
             add.getVersionFromConfigFile.and.returnValue('~1.0.0');
             add.determinePluginTarget(projectRoot, Cfg_parser_mock, 
'cordova-plugin-device', {}).then(function (target) {
diff --git a/src/cordova/plugin/add.js b/src/cordova/plugin/add.js
index 65a75812c..8aea7f0a7 100644
--- a/src/cordova/plugin/add.js
+++ b/src/cordova/plugin/add.js
@@ -177,6 +177,8 @@ function add (projectRoot, hooksRunner, opts) {
                             var parsedSpec = pluginSpec.parse(target);
                             if (pkgJson && pkgJson.dependencies && 
pkgJson.dependencies[pluginInfo.id]) {
                                 attributes.spec = 
pkgJson.dependencies[pluginInfo.id];
+                            } else if (pkgJson && pkgJson.devDependencies && 
pkgJson.devDependencies[pluginInfo.id]) {
+                                attributes.spec = 
pkgJson.devDependencies[pluginInfo.id];
                             } else {
                                 if (parsedSpec.scope) {
                                     attributes.spec = parsedSpec.package + '@' 
+ ver;
@@ -232,6 +234,9 @@ function determinePluginTarget (projectRoot, cfg, target, 
fetchOptions) {
         if (pkgJson && pkgJson.dependencies && pkgJson.dependencies[id]) {
             events.emit('verbose', 'No version specified for ' + id + ', 
retrieving version from package.json');
             parsedSpec.version = pkgJson.dependencies[id];
+        } else if (pkgJson && pkgJson.devDependencies && 
pkgJson.devDependencies[id]) {
+            events.emit('verbose', 'No version specified for ' + id + ', 
retrieving version from package.json');
+            parsedSpec.version = pkgJson.devDependencies[id];
         } else {
             // If no version is specified, retrieve the version (or source) 
from config.xml.
             events.emit('verbose', 'No version specified for ' + id + ', 
retrieving version from config.xml');


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Cordova fails to find platform/plugin versions in package.json devDependencies
> ------------------------------------------------------------------------------
>
>                 Key: CB-13532
>                 URL: https://issues.apache.org/jira/browse/CB-13532
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-lib
>            Reporter: Darryl Pogue
>            Assignee: Audrey So
>            Priority: Major
>              Labels: tools-next
>
> Cordova only looks at the {{dependencies}} section of package.json, and 
> ignores anything specified in {{devDependencies}}. This results in the 
> default pinned versions for platforms/plugins being used.
> Code in question: 
> https://github.com/apache/cordova-lib/blob/da8ebf6cb81dd84c22e24fdf0baff9837a544b2d/src/cordova/platform/addHelper.js#L109-L113
> This is wrong because Cordova (and its related bits) is not a dependency of 
> my application code, it is a build tool that belongs in devDependencies.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to