Skip to content

Commit

Permalink
breaking(pod): remove unused API & bump minimum version requirements …
Browse files Browse the repository at this point in the history
…to 1.8.0 (apache#849)

* breaking: remove unused API check_cocoapods_repo_size
* breaking(pod): bump minimum version requirements to 1.8.0
  • Loading branch information
erisu authored and Antony Gelberg committed Jun 3, 2021
1 parent 7c1c997 commit 8896a99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 98 deletions.
70 changes: 4 additions & 66 deletions bin/templates/scripts/cordova/lib/check_reqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

const Q = require('q');
const shell = require('shelljs');
const util = require('util');
const versions = require('./versions');

const SUPPORTED_OS_PLATFORMS = [ 'darwin' ];
Expand All @@ -35,15 +34,8 @@ const IOS_DEPLOY_NOT_FOUND_MESSAGE =
'Please download, build and install version ' + IOS_DEPLOY_MIN_VERSION + ' or greater' +
' from https://github.com/phonegap/ios-deploy into your path, or do \'npm install -g ios-deploy\'';

const COCOAPODS_MIN_VERSION = '1.0.1';
const COCOAPODS_NOT_FOUND_MESSAGE =
'Please install version ' + COCOAPODS_MIN_VERSION + ' or greater from https://cocoapods.org/';
const COCOAPODS_NOT_SYNCED_MESSAGE =
'The CocoaPods repo has not been synced yet, this will take a long time (approximately 500MB as of Sept 2016). Please run `pod setup` first to sync the repo.';
const COCOAPODS_SYNCED_MIN_SIZE = 475; // in megabytes
const COCOAPODS_SYNC_ERROR_MESSAGE =
'The CocoaPods repo has been created, but there appears to be a sync error. The repo size should be at least ' + COCOAPODS_SYNCED_MIN_SIZE + '. Please run `pod setup --verbose` to sync the repo.';
const COCOAPODS_REPO_NOT_FOUND_MESSAGE = 'The CocoaPods repo at ~/.cocoapods was not found.';
const COCOAPODS_MIN_VERSION = '1.8.0';
const COCOAPODS_NOT_FOUND_MESSAGE = `Please install version ${COCOAPODS_MIN_VERSION} or greater from https://cocoapods.org/`;

/**
* Checks if xcode util is available
Expand Down Expand Up @@ -72,66 +64,12 @@ function os_platform_is_supported () {
return (SUPPORTED_OS_PLATFORMS.indexOf(process.platform) !== -1);
}

function check_cocoapod_tool (toolChecker) {
toolChecker = toolChecker || checkTool;
if (os_platform_is_supported()) { // CB-12856
return toolChecker('pod', COCOAPODS_MIN_VERSION, COCOAPODS_NOT_FOUND_MESSAGE, 'CocoaPods');
} else {
return Q.resolve({
'ignore': true,
'ignoreMessage': `CocoaPods check and installation ignored on ${process.platform}`
});
}
}

/**
* Checks if cocoapods repo size is what is expected
* @return {Promise} Returns a promise either resolved or rejected
*/
module.exports.check_cocoapods_repo_size = function () {
return check_cocoapod_tool()
.then(function (toolOptions) {
// check size of ~/.cocoapods repo
let commandString = util.format('du -sh %s/.cocoapods', process.env.HOME);
let command = shell.exec(commandString, { silent: true });
// command.output is e.g "750M path/to/.cocoapods", we just scan the number
let size = toolOptions.ignore ? 0 : parseFloat(command.output);

if (toolOptions.ignore || command.code === 0) { // success, parse output
return Q.resolve(size, toolOptions);
} else { // error, perhaps not found
return Q.reject(util.format('%s (%s)', COCOAPODS_REPO_NOT_FOUND_MESSAGE, command.output));
}
})
.then(function (repoSize, toolOptions) {
if (toolOptions.ignore || COCOAPODS_SYNCED_MIN_SIZE <= repoSize) { // success, expected size
return Q.resolve(toolOptions);
} else {
return Q.reject(COCOAPODS_SYNC_ERROR_MESSAGE);
}
});
};

/**
* Checks if cocoapods is available, and whether the repo is synced (because it takes a long time to download)
* @return {Promise} Returns a promise either resolved or rejected
*/
module.exports.check_cocoapods = function (toolChecker) {
return check_cocoapod_tool(toolChecker)
// check whether the cocoapods repo has been synced through `pod repo` command
// a value of '0 repos' means it hasn't been synced
.then(function (toolOptions) {
let code = shell.exec('pod repo | grep -e "^0 repos"', { silent: true }).code;
let repoIsSynced = (code !== 0);

if (toolOptions.ignore || repoIsSynced) {
// return check_cocoapods_repo_size();
// we could check the repo size above, but it takes too long.
return Q.resolve(toolOptions);
} else {
return Q.reject(COCOAPODS_NOT_SYNCED_MESSAGE);
}
});
module.exports.check_cocoapods = toolChecker => {
return checkTool('pod', COCOAPODS_MIN_VERSION, COCOAPODS_NOT_FOUND_MESSAGE, 'CocoaPods');
};

/**
Expand Down
40 changes: 8 additions & 32 deletions tests/spec/unit/lib/check_reqs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,41 +73,17 @@ describe('check_reqs', function () {
});
});

it('should resolve passing back tool version.', (done) => {
shellWhichSpy.and.returnValue('/bin/node');
const checkTool = checkReqs.__get__('checkTool');

checkReqs.__set__('versions', {
get_tool_version: getToolVersionSpy.and.returnValue(new Promise((resolve) => {
return resolve('1.0.0');
})),
compareVersions: originalVersion.compareVersions
});

checkTool('node', '1.0.0').then(() => {
let actual = resolveSpy.calls.argsFor(0)[0];
expect(actual).toEqual({ version: '1.0.0' });
done();
it('should resolve passing back tool version.', () => {
return checkTool('node', '1.0.0').then(result => {
expect(result).toEqual({ version: '1.0.0' });
});
});

it('should reject because tool does not meet minimum requirement.', (done) => {
shellWhichSpy.and.returnValue('/bin/node');
const checkTool = checkReqs.__get__('checkTool');

checkReqs.__set__('versions', {
get_tool_version: getToolVersionSpy.and.returnValue(new Promise((resolve) => {
return resolve('1.0.0');
})),
compareVersions: originalVersion.compareVersions
});

checkTool('node', '1.0.1').then(() => {
let actual = rejectSpy.calls.argsFor(0)[0];
expect(actual).toContain('version 1.0.1 or greater');
expect(actual).toContain('you have version 1.0.0');
done();
});
it('should reject because tool does not meet minimum requirement.', () => {
return checkTool('node', '1.0.1').then(
() => fail('Expected promise to be rejected'),
reason => expect(reason).toContain('version 1.0.1 or greater, you have version 1.0.0')
);
});
});
});

0 comments on commit 8896a99

Please sign in to comment.