Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: drop q dependency #860

Merged
merged 2 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/apple_ios_version
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

var versions = require('./templates/scripts/cordova/lib/versions.js');

versions.get_apple_ios_version().done(null, function (err) {
versions.get_apple_ios_version().catch(err => {
console.log(err);
process.exit(2);
});
2 changes: 1 addition & 1 deletion bin/apple_osx_version
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

var versions = require('./templates/scripts/cordova/lib/versions.js');

versions.get_apple_osx_version().done(null, function (err) {
versions.get_apple_osx_version().catch(err => {
console.log(err);
process.exit(2);
});
15 changes: 9 additions & 6 deletions bin/apple_xcode_version
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@

var versions = require('./templates/scripts/cordova/lib/versions.js');

versions.get_apple_xcode_version().done(function (version) {
console.log(version);
}, function (err) {
console.error(err);
process.exit(2);
});
versions.get_apple_xcode_version().then(
version => {
console.log(version);
},
err => {
console.error(err);
process.exit(2);
}
);
2 changes: 1 addition & 1 deletion bin/check_reqs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var check_reqs = require('./templates/scripts/cordova/lib/check_reqs');
if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) > -1) {
console.log('Usage: check_reqs or node check_reqs');
} else {
check_reqs.run().done(null, function (err) {
check_reqs.run().catch(err => {
console.error('Failed to check requirements due to ' + err);
process.exit(2);
});
Expand Down
11 changes: 5 additions & 6 deletions bin/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
under the License.
*/

const Q = require('q');
const path = require('path');
const fs = require('fs-extra');
const xmlescape = require('xml-escape');
const ROOT = path.join(__dirname, '..', '..');
const events = require('cordova-common').events;
const { CordovaError, events } = require('cordova-common');
const utils = require('./utils');

function updateSubprojectHelp () {
Expand Down Expand Up @@ -204,12 +203,12 @@ exports.createProject = (project_path, package_name, project_name, opts, config)

// check that project path doesn't exist
if (fs.existsSync(project_path)) {
return Q.reject('Project already exists');
return Promise.reject(new CordovaError('Project already exists'));
}

// check that parent directory does exist so cp -r will not fail
if (!fs.existsSync(project_parent)) {
return Q.reject(`Parent directory "${project_parent}" of given project path does not exist`);
return Promise.reject(new CordovaError(`Parent directory "${project_parent}" of given project path does not exist`));
}

events.emit('log', 'Creating Cordova project for the iOS platform:');
Expand All @@ -235,7 +234,7 @@ exports.createProject = (project_path, package_name, project_name, opts, config)
copyScripts(project_path, project_name);

events.emit('log', generateDoneMessage('create', use_shared));
return Q.resolve();
return Promise.resolve();
};

exports.updateProject = (projectPath, opts) => {
Expand All @@ -248,7 +247,7 @@ exports.updateProject = (projectPath, opts) => {
'\tcordova platform rm ios\n' +
'\tcordova platform add ios\n';

return Q.reject(errorString);
return Promise.reject(new CordovaError(errorString));
};

function generateDoneMessage (type, link) {
Expand Down
15 changes: 6 additions & 9 deletions bin/templates/scripts/cordova/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const CordovaError = require('cordova-common').CordovaError;
const CordovaLogger = require('cordova-common').CordovaLogger;
const events = require('cordova-common').events;
const PluginManager = require('cordova-common').PluginManager;
const Q = require('q');
const util = require('util');
const xcode = require('xcode');
const ConfigParser = require('cordova-common').ConfigParser;
Expand Down Expand Up @@ -279,9 +278,8 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
return this.addPodSpecs(plugin, podSpecs, frameworkPods, installOptions);
}
})
// CB-11022 return non-falsy value to indicate
// that there is no need to run prepare after
.thenResolve(true);
erisu marked this conversation as resolved.
Show resolved Hide resolved
// CB-11022 Return truthy value to prevent running prepare after
.then(() => true);
};

/**
Expand Down Expand Up @@ -328,9 +326,8 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
return this.removePodSpecs(plugin, podSpecs, frameworkPods, uninstallOptions);
}
})
// CB-11022 return non-falsy value to indicate
// that there is no need to run prepare after
.thenResolve(true);
erisu marked this conversation as resolved.
Show resolved Hide resolved
// CB-11022 Return truthy value to prevent running prepare after
.then(() => true);
};

/**
Expand Down Expand Up @@ -449,7 +446,7 @@ Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods, installOp
events.emit('verbose', 'Podfile unchanged, skipping `pod install`');
}
}
return Q.when();
return Promise.resolve();
};

/**
Expand Down Expand Up @@ -567,7 +564,7 @@ Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods, uninst
events.emit('verbose', 'Podfile unchanged, skipping `pod install`');
}
}
return Q.when();
return Promise.resolve();
};

/**
Expand Down
17 changes: 10 additions & 7 deletions bin/templates/scripts/cordova/build
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ buildOpts.argv = buildOpts.argv.remain;

require('./loggingHelper').adjustLoggerLevel(buildOpts);

new Api().build(buildOpts).done(function () {
console.log('** BUILD SUCCEEDED **');
}, function (err) {
var errorMessage = (err && err.stack) ? err.stack : err;
console.error(errorMessage);
process.exit(2);
});
new Api().build(buildOpts).then(
() => {
console.log('** BUILD SUCCEEDED **');
},
err => {
var errorMessage = (err && err.stack) ? err.stack : err;
console.error(errorMessage);
process.exit(2);
}
);
15 changes: 9 additions & 6 deletions bin/templates/scripts/cordova/clean
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ opts.noPrepare = true;

require('./loggingHelper').adjustLoggerLevel(opts);

new Api().clean(opts).done(function () {
console.log('** CLEAN SUCCEEDED **');
}, function (err) {
console.error(err);
process.exit(2);
});
new Api().clean(opts).then(
() => {
console.log('** CLEAN SUCCEEDED **');
},
err => {
console.error(err);
process.exit(2);
}
);
7 changes: 3 additions & 4 deletions bin/templates/scripts/cordova/lib/Podfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
const fs = require('fs-extra');
const path = require('path');
const util = require('util');
const Q = require('q');
const {
CordovaError,
events,
Expand Down Expand Up @@ -376,7 +375,7 @@ Podfile.prototype.before_install = function (toolOptions) {
fs.writeFileSync(debugConfigPath, debugContents, 'utf8');
fs.writeFileSync(releaseConfigPath, releaseContents, 'utf8');

return Q.resolve(toolOptions);
return Promise.resolve(toolOptions);
};

Podfile.prototype.install = function (requirementsCheckerFunction) {
Expand All @@ -387,7 +386,7 @@ Podfile.prototype.install = function (requirementsCheckerFunction) {
let first = true;

if (!requirementsCheckerFunction) {
requirementsCheckerFunction = Q();
requirementsCheckerFunction = Promise.resolve();
}

return requirementsCheckerFunction()
Expand All @@ -396,7 +395,7 @@ Podfile.prototype.install = function (requirementsCheckerFunction) {
if (toolOptions.ignore) {
events.emit('verbose', '==== pod install start ====\n');
events.emit('verbose', toolOptions.ignoreMessage);
return Q.resolve();
return Promise.resolve();
} else {
return spawn('pod', ['install', '--verbose'], opts)
.progress(stdio => {
Expand Down
16 changes: 8 additions & 8 deletions bin/templates/scripts/cordova/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* under the License.
*/

const Q = require('q');
const path = require('path');
const which = require('which');
const {
CordovaError,
events,
superspawn: { spawn }
} = require('cordova-common');
Expand Down Expand Up @@ -112,16 +112,16 @@ module.exports.run = buildOpts => {
buildOpts = buildOpts || {};

if (buildOpts.debug && buildOpts.release) {
return Q.reject('Cannot specify "debug" and "release" options together.');
return Promise.reject(new CordovaError('Cannot specify "debug" and "release" options together.'));
}

if (buildOpts.device && buildOpts.emulator) {
return Q.reject('Cannot specify "device" and "emulator" options together.');
return Promise.reject(new CordovaError('Cannot specify "device" and "emulator" options together.'));
}

if (buildOpts.buildConfig) {
if (!fs.existsSync(buildOpts.buildConfig)) {
return Q.reject(`Build config file does not exist: ${buildOpts.buildConfig}`);
return Promise.reject(new CordovaError(`Build config file does not exist: ${buildOpts.buildConfig}`));
}
events.emit('log', `Reading build config file: ${path.resolve(buildOpts.buildConfig)}`);
const contents = fs.readFileSync(buildOpts.buildConfig, 'utf-8');
Expand Down Expand Up @@ -211,7 +211,7 @@ module.exports.run = buildOpts => {
writeCodeSignStyle('Automatic');
}

return Q.nfcall(fs.writeFile, path.join(__dirname, '..', 'build-extras.xcconfig'), extraConfig, 'utf-8');
return fs.writeFile(path.join(__dirname, '..', 'build-extras.xcconfig'), extraConfig, 'utf-8');
}).then(() => {
const configuration = buildOpts.release ? 'Release' : 'Debug';

Expand Down Expand Up @@ -277,7 +277,7 @@ module.exports.run = buildOpts => {
return spawn('xcodebuild', xcodearchiveArgs, { cwd: projectPath, printCommand: true, stdio: 'inherit' });
}

return Q.nfcall(fs.writeFile, exportOptionsPath, exportOptionsPlist, 'utf-8')
return fs.writeFile(exportOptionsPath, exportOptionsPlist, 'utf-8')
.then(checkSystemRuby)
.then(packageArchive);
});
Expand All @@ -293,14 +293,14 @@ function findXCodeProjectIn (projectPath) {
const xcodeProjFiles = fs.readdirSync(projectPath).filter(name => path.extname(name) === '.xcodeproj');

if (xcodeProjFiles.length === 0) {
return Q.reject(`No Xcode project found in ${projectPath}`);
return Promise.reject(new CordovaError(`No Xcode project found in ${projectPath}`));
}
if (xcodeProjFiles.length > 1) {
events.emit('warn', `Found multiple .xcodeproj directories in \n${projectPath}\nUsing first one`);
}

const projectName = path.basename(xcodeProjFiles[0], '.xcodeproj');
return Q.resolve(projectName);
return Promise.resolve(projectName);
}

module.exports.findXCodeProjectIn = findXCodeProjectIn;
Expand Down
16 changes: 8 additions & 8 deletions bin/templates/scripts/cordova/lib/check_reqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

'use strict';

const Q = require('q');
const which = require('which');
const versions = require('./versions');
const { CordovaError } = require('cordova-common');

const SUPPORTED_OS_PLATFORMS = ['darwin'];

Expand Down Expand Up @@ -55,8 +55,8 @@ module.exports.check_ios_deploy = () => {
module.exports.check_os = () => {
// Build iOS apps available for OSX platform only, so we reject on others platforms
return os_platform_is_supported()
? Q.resolve(process.platform)
: Q.reject('Cordova tooling for iOS requires Apple macOS');
? Promise.resolve(process.platform)
: Promise.reject(new CordovaError('Cordova tooling for iOS requires Apple macOS'));
};

function os_platform_is_supported () {
Expand Down Expand Up @@ -85,15 +85,15 @@ function checkTool (tool, minVersion, message, toolFriendlyName) {
// Check whether tool command is available at all
const tool_command = which.sync(tool, { nothrow: true });
if (!tool_command) {
return Q.reject(`${toolFriendlyName} was not found. ${message || ''}`);
return Promise.reject(new CordovaError(`${toolFriendlyName} was not found. ${message || ''}`));
}

// check if tool version is greater than specified one
return versions.get_tool_version(tool).then(version => {
version = version.trim();
return versions.compareVersions(version, minVersion) >= 0
? Q.resolve({ version })
: Q.reject(`Cordova needs ${toolFriendlyName} version ${minVersion} or greater, you have version ${version}. ${message || ''}`);
? Promise.resolve({ version })
: Promise.reject(new CordovaError(`Cordova needs ${toolFriendlyName} version ${minVersion} or greater, you have version ${version}. ${message || ''}`));
});
}

Expand Down Expand Up @@ -141,7 +141,7 @@ module.exports.check_all = () => {
return promise.then(() => {
// If fatal requirement is failed,
// we don't need to check others
if (fatalIsHit) return Q();
if (fatalIsHit) return Promise.resolve();

const requirement = requirements[idx];
return checkFn()
Expand All @@ -155,7 +155,7 @@ module.exports.check_all = () => {
result.push(requirement);
});
});
}, Q())
}, Promise.resolve())
// When chain is completed, return requirements array to upstream API
.then(() => result);
};
8 changes: 5 additions & 3 deletions bin/templates/scripts/cordova/lib/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
* under the License.
*/

const Q = require('q');
const path = require('path');
const fs = require('fs-extra');
const { superspawn: { spawn } } = require('cordova-common');
const {
CordovaError,
superspawn: { spawn }
} = require('cordova-common');

const projectPath = path.join(__dirname, '..', '..');

module.exports.run = () => {
const projectName = fs.readdirSync(projectPath).filter(name => path.extname(name) === '.xcodeproj');

if (!projectName) {
return Q.reject(`No Xcode project found in ${projectPath}`);
return Promise.reject(new CordovaError(`No Xcode project found in ${projectPath}`));
}

const xcodebuildClean = configName => {
Expand Down
3 changes: 1 addition & 2 deletions bin/templates/scripts/cordova/lib/listEmulatorImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
under the License.
*/

var Q = require('q');
var iossim = require('ios-sim');

/**
* Gets list of iOS devices available for simulation
* @return {Promise} Promise fulfilled with list of devices available for simulation
*/
function listEmulatorImages () {
return Q.resolve(iossim.getdevicetypes());
return Promise.resolve(iossim.getdevicetypes());
}

exports.run = listEmulatorImages;
Loading