Skip to content

Commit

Permalink
Remove support for old option format (#686)
Browse files Browse the repository at this point in the history
Remove support for handling pre-5.4.0 style options
  • Loading branch information
raphinesse authored Sep 7, 2018
1 parent f9ab9b0 commit 1bc9dd0
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 146 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 0 additions & 8 deletions spec/cordova/build.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
8 changes: 0 additions & 8 deletions spec/cordova/compile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
9 changes: 1 addition & 8 deletions spec/cordova/emulate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
9 changes: 0 additions & 9 deletions spec/cordova/run.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']})
Expand Down
65 changes: 0 additions & 65 deletions spec/cordova/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
48 changes: 1 addition & 47 deletions src/cordova/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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();

Expand All @@ -311,51 +310,6 @@ function preProcessOptions (inputOptions) {
return result;
}

/**
* 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
*
Expand Down

0 comments on commit 1bc9dd0

Please sign in to comment.