You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2018/09/07 14:38:29 UTC

[cordova-lib] branch master updated: Remove support for old option format (#686)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-lib.git


The following commit(s) were added to refs/heads/master by this push:
     new 1bc9dd0  Remove support for old option format (#686)
1bc9dd0 is described below

commit 1bc9dd050cbc12b046fd7e20628084d79d2f9fe4
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Fri Sep 7 16:38:27 2018 +0200

    Remove support for old option format (#686)
    
    Remove support for handling pre-5.4.0 style options
---
 package.json                 |  1 -
 spec/cordova/build.spec.js   |  8 ------
 spec/cordova/compile.spec.js |  8 ------
 spec/cordova/emulate.spec.js |  9 +-----
 spec/cordova/run.spec.js     |  9 ------
 spec/cordova/util.spec.js    | 65 --------------------------------------------
 src/cordova/util.js          | 48 +-------------------------------
 7 files changed, 2 insertions(+), 146 deletions(-)

diff --git a/package.json b/package.json
index b67368c..9f3bdc2 100644
--- a/package.json
+++ b/package.json
@@ -28,7 +28,6 @@
     "globby": "^8.0.1",
     "indent-string": "^3.2.0",
     "init-package-json": "^1.2.0",
-    "nopt": "4.0.1",
     "q": "^1.5.1",
     "read-chunk": "^3.0.0",
     "semver": "^5.3.0",
diff --git a/spec/cordova/build.spec.js b/spec/cordova/build.spec.js
index 5c9633b..3a6f1b0 100644
--- a/spec/cordova/build.spec.js
+++ b/spec/cordova/build.spec.js
@@ -83,14 +83,6 @@ describe('build command', function () {
                 expect(compile_spy).toHaveBeenCalledWith(opts);
             });
         });
-
-        it('Test 005 : should convert options from old format', function () {
-            return cordova.build({platforms: ['android'], options: ['--release', '--cdvBuildOpt=opt']}).then(function () {
-                var opts = {platforms: ['android'], options: jasmine.objectContaining({release: true, argv: ['--cdvBuildOpt=opt']}), verbose: false};
-                expect(prepare_spy).toHaveBeenCalledWith(opts);
-                expect(compile_spy).toHaveBeenCalledWith(opts);
-            });
-        });
     });
 
     describe('hooks', function () {
diff --git a/spec/cordova/compile.spec.js b/spec/cordova/compile.spec.js
index b86b285..0fb1e38 100644
--- a/spec/cordova/compile.spec.js
+++ b/spec/cordova/compile.spec.js
@@ -79,14 +79,6 @@ describe('compile command', function () {
                     expect(platformApi.build).toHaveBeenCalledWith({release: true});
                 });
         });
-
-        it('Test 005 : should convert options from old format', function () {
-            return cordova.compile({platforms: ['blackberry10'], options: ['--release']})
-                .then(function () {
-                    expect(getPlatformApi).toHaveBeenCalledWith('blackberry10');
-                    expect(platformApi.build).toHaveBeenCalledWith({release: true, argv: []});
-                });
-        });
     });
 
     describe('hooks', function () {
diff --git a/spec/cordova/emulate.spec.js b/spec/cordova/emulate.spec.js
index af19f52..7db8d06 100644
--- a/spec/cordova/emulate.spec.js
+++ b/spec/cordova/emulate.spec.js
@@ -86,14 +86,7 @@ describe('emulate command', function () {
                     expect(platformApi.run).toHaveBeenCalledWith({ device: false, emulator: true, optionTastic: true, nobuild: true });
                 });
         });
-        it('Test 005 : should convert options from old format', function () {
-            return cordova.emulate({platforms: ['ios'], options: ['--optionTastic']})
-                .then(function () {
-                    expect(prepare_spy).toHaveBeenCalledWith(jasmine.objectContaining({platforms: ['ios']}));
-                    expect(getPlatformApi).toHaveBeenCalledWith('ios');
-                    expect(platformApi.run).toHaveBeenCalledWith(jasmine.objectContaining({emulator: true, argv: ['--optionTastic']}));
-                });
-        });
+
         describe('run parameters should not be altered by intermediate build command', function () {
             var originalBuildSpy;
             beforeEach(function () {
diff --git a/spec/cordova/run.spec.js b/spec/cordova/run.spec.js
index f5f0568..77119ec 100644
--- a/spec/cordova/run.spec.js
+++ b/spec/cordova/run.spec.js
@@ -87,15 +87,6 @@ describe('run command', function () {
                 expect(platformApi.run).toHaveBeenCalledWith({password: '1q1q', nobuild: true});
             });
         });
-        it('Test 006 : should convert parameters from old format and warn user about this', function () {
-            return cordova.run({platforms: ['blackberry10'], options: ['--password=1q1q']})
-                .then(function () {
-                    expect(prepare_spy).toHaveBeenCalledWith({ platforms: [ 'blackberry10' ],
-                        options: jasmine.objectContaining({argv: ['--password=1q1q']}),
-                        verbose: false });
-                    expect(platformApi.run).toHaveBeenCalledWith(jasmine.objectContaining({argv: ['--password=1q1q']}));
-                });
-        });
 
         it('Test 007 : should call platform\'s build method', function () {
             return cordova.run({platforms: ['blackberry10']})
diff --git a/spec/cordova/util.spec.js b/spec/cordova/util.spec.js
index 10683ef..dad42c1 100644
--- a/spec/cordova/util.spec.js
+++ b/spec/cordova/util.spec.js
@@ -241,71 +241,6 @@ describe('util module', function () {
                 .toEqual(jasmine.objectContaining({options: {buildConfig: path.join('/fake/path/build.json')}}));
         });
 
-        describe('ensurePlatformOptionsCompatible', function () {
-
-            var unknownOptions = ['--foo', '--appx=uap', '--gradleArg=--no-daemon'];
-            var validOptions = ['--debug', '--release', '--device', '--emulator', '--nobuild', '--list',
-                '--buildConfig=/fake/path/build.json', '--target=foo', '--archs="x86 x64"'];
-
-            it('Test 021 : should return \'options\' unchanged if they are not an array', function () {
-                ['foo', true, {bar: true}].forEach(function (optionValue) {
-                    expect(util.preProcessOptions({options: optionValue}))
-                        .toEqual(jasmine.objectContaining({options: optionValue}));
-                });
-            });
-
-            it('Test 022 : should emit \'warn\' event if \'options\' is an Array', function () {
-                var warnSpy = jasmine.createSpy('warnSpy');
-                events.on('warn', warnSpy);
-                util.preProcessOptions({options: ['foo']});
-                expect(warnSpy).toHaveBeenCalled();
-                expect(warnSpy.calls.argsFor(0)).toMatch('consider updating your cordova.* method calls');
-                events.removeListener('warn', warnSpy);
-            });
-
-            it('Test 023 : should convert options Array into object with \'argv\' field', function () {
-                expect(util.preProcessOptions({options: []}))
-                    .toEqual(jasmine.objectContaining({options: {argv: []}}));
-            });
-
-            it('Test 024 : should convert known options (platform-agnostic) into resultant object\'s fields', function () {
-                var expectedResult = {
-                    'debug': true,
-                    'release': true,
-                    'device': true,
-                    'emulator': true,
-                    'nobuild': true,
-                    'list': true,
-                    'buildConfig': '/fake/path/build.json',
-                    'target': 'foo',
-                    'archs': '"x86 x64"'
-                };
-
-                expect(util.preProcessOptions({options: validOptions}).options)
-                    .toEqual(jasmine.objectContaining(expectedResult));
-
-                validOptions.forEach(function (validOption) {
-                    expect(util.preProcessOptions({options: validOptions}).options.argv)
-                        .not.toContain(validOption);
-                });
-            });
-
-            it('Test 025 : should try to convert unknown options (platform-specific) into resultant object\'s fields', function () {
-                var expectedResult = {
-                    'foo': true, 'appx': 'uap', 'gradleArg': '--no-daemon'
-                };
-
-                expect(util.preProcessOptions({options: unknownOptions}).options)
-                    .toEqual(jasmine.objectContaining(expectedResult));
-            });
-
-            it('Test 026 : should copy unknown options (platform-specific) into resultant object\'s argv field', function () {
-                unknownOptions.forEach(function (validOption) {
-                    expect(util.preProcessOptions({options: unknownOptions}).options.argv).toContain(validOption);
-                });
-            });
-        });
-
         describe('getPlatformApiFunction', function () {
 
             it('Test 030 : successfully find platform Api', function () {
diff --git a/src/cordova/util.js b/src/cordova/util.js
index eddc9e8..8a8810c 100644
--- a/src/cordova/util.js
+++ b/src/cordova/util.js
@@ -22,7 +22,6 @@ var path = require('path');
 var events = require('cordova-common').events;
 var CordovaError = require('cordova-common').CordovaError;
 var url = require('url');
-var nopt = require('nopt');
 var Q = require('q');
 var platforms = require('../platforms/platforms');
 
@@ -289,7 +288,7 @@ function preProcessOptions (inputOptions) {
     }
     result.verbose = result.verbose || false;
     result.platforms = result.platforms || [];
-    result.options = ensurePlatformOptionsCompatible(result.options);
+    result.options = result.options || {};
 
     var projectRoot = this.isCordova();
 
@@ -312,51 +311,6 @@ function preProcessOptions (inputOptions) {
 }
 
 /**
- * Converts options, which is passed to platformApi from old format (array of
- *   plain strings) to new - nopt-parsed object + array of platform-specific
- *   options. If options are already in new the format - returns them unchanged.
- *
- * @param   {Object|String[]}  platformOptions  A platform options (array of
- *   strings or object) which is passed down to platform scripts/platformApi
- *   polyfill.
- *
- * @return  {Object}                            Options, converted to new format
- */
-function ensurePlatformOptionsCompatible (platformOptions) {
-    var opts = platformOptions || {};
-
-    if (!Array.isArray(opts)) { return opts; }
-
-    events.emit('warn', 'The format of cordova.* methods "options" argument was changed in 5.4.0. ' +
-        '"options.options" property now should be an object instead of an array of plain strings. Though the old format ' +
-        'is still supported, consider updating your cordova.* method calls to use new argument format.');
-
-    var knownArgs = [
-        'debug',
-        'release',
-        'device',
-        'emulator',
-        'nobuild',
-        'list',
-        'buildConfig',
-        'target',
-        'archs'
-    ];
-
-    opts = nopt({}, {}, opts, 0);
-    opts.argv = Object.keys(opts)
-        .filter(function (arg) {
-            return arg !== 'argv' && knownArgs.indexOf(arg) === -1;
-        }).map(function (arg) {
-            return opts[arg] === true ?
-                '--' + arg :
-                '--' + arg + '=' + opts[arg].toString();
-        });
-
-    return opts;
-}
-
-/**
  * Checks to see if the argument is a directory
  *
  * @param {string} dir - string representing path of directory


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org