From 9f2fbbb4c01cabdf43bc97db172fa21ba2e544a7 Mon Sep 17 00:00:00 2001 From: Erisu Date: Wed, 20 May 2020 15:58:02 +0900 Subject: [PATCH] breaking: remove q dependency --- bin/apple_ios_version | 2 +- bin/apple_osx_version | 2 +- bin/apple_xcode_version | 15 ++++++---- bin/check_reqs | 2 +- bin/lib/create.js | 11 ++++---- bin/templates/scripts/cordova/Api.js | 15 +++------- bin/templates/scripts/cordova/build | 17 ++++++----- bin/templates/scripts/cordova/clean | 15 ++++++---- bin/templates/scripts/cordova/lib/Podfile.js | 7 ++--- bin/templates/scripts/cordova/lib/build.js | 16 +++++------ .../scripts/cordova/lib/check_reqs.js | 16 +++++------ bin/templates/scripts/cordova/lib/clean.js | 8 ++++-- .../scripts/cordova/lib/listEmulatorImages.js | 3 +- bin/templates/scripts/cordova/lib/prepare.js | 20 +++++++------ bin/templates/scripts/cordova/lib/run.js | 6 ++-- bin/templates/scripts/cordova/lib/versions.js | 8 ++++-- bin/templates/scripts/cordova/run | 17 ++++++----- bin/update | 5 +++- package.json | 1 - tests/spec/component/versions.spec.js | 2 +- tests/spec/unit/Api.spec.js | 7 ++--- tests/spec/unit/build.spec.js | 28 ++++++------------- tests/spec/unit/lib/check_reqs.spec.js | 4 +-- tests/spec/unit/lib/run.spec.js | 8 ++---- tests/spec/unit/versions.spec.js | 2 +- 25 files changed, 116 insertions(+), 121 deletions(-) diff --git a/bin/apple_ios_version b/bin/apple_ios_version index 720fbb4004..1e8671b46d 100755 --- a/bin/apple_ios_version +++ b/bin/apple_ios_version @@ -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); }); diff --git a/bin/apple_osx_version b/bin/apple_osx_version index 439202fef9..60292ad257 100755 --- a/bin/apple_osx_version +++ b/bin/apple_osx_version @@ -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); }); diff --git a/bin/apple_xcode_version b/bin/apple_xcode_version index a1e55f756a..b49b975578 100755 --- a/bin/apple_xcode_version +++ b/bin/apple_xcode_version @@ -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); + } +); diff --git a/bin/check_reqs b/bin/check_reqs index 0a4b777f0e..21d7f3056b 100755 --- a/bin/check_reqs +++ b/bin/check_reqs @@ -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); }); diff --git a/bin/lib/create.js b/bin/lib/create.js index 7d00d11a18..0ba44ef475 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -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 () { @@ -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:'); @@ -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) => { @@ -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) { diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 0241dd0a9e..9dbaa72188 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -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; @@ -278,10 +277,7 @@ Api.prototype.addPlugin = function (plugin, installOptions) { const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec'); 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); + }); }; /** @@ -327,10 +323,7 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) { const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec'); 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); + }); }; /** @@ -449,7 +442,7 @@ Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods, installOp events.emit('verbose', 'Podfile unchanged, skipping `pod install`'); } } - return Q.when(); + return Promise.resolve(); }; /** @@ -567,7 +560,7 @@ Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods, uninst events.emit('verbose', 'Podfile unchanged, skipping `pod install`'); } } - return Q.when(); + return Promise.resolve(); }; /** diff --git a/bin/templates/scripts/cordova/build b/bin/templates/scripts/cordova/build index 507e80e617..f4b0d9a045 100755 --- a/bin/templates/scripts/cordova/build +++ b/bin/templates/scripts/cordova/build @@ -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); + } +); diff --git a/bin/templates/scripts/cordova/clean b/bin/templates/scripts/cordova/clean index 6699e47419..f36a648e52 100755 --- a/bin/templates/scripts/cordova/clean +++ b/bin/templates/scripts/cordova/clean @@ -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); + } +); diff --git a/bin/templates/scripts/cordova/lib/Podfile.js b/bin/templates/scripts/cordova/lib/Podfile.js index 465ed6ff34..b66dc2e372 100644 --- a/bin/templates/scripts/cordova/lib/Podfile.js +++ b/bin/templates/scripts/cordova/lib/Podfile.js @@ -21,7 +21,6 @@ const fs = require('fs-extra'); const path = require('path'); const util = require('util'); -const Q = require('q'); const { CordovaError, events, @@ -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) { @@ -387,7 +386,7 @@ Podfile.prototype.install = function (requirementsCheckerFunction) { let first = true; if (!requirementsCheckerFunction) { - requirementsCheckerFunction = Q(); + requirementsCheckerFunction = Promise.resolve(); } return requirementsCheckerFunction() @@ -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 => { diff --git a/bin/templates/scripts/cordova/lib/build.js b/bin/templates/scripts/cordova/lib/build.js index 0126f5901a..3c8bd278b8 100644 --- a/bin/templates/scripts/cordova/lib/build.js +++ b/bin/templates/scripts/cordova/lib/build.js @@ -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'); @@ -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'); @@ -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'; @@ -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); }); @@ -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; diff --git a/bin/templates/scripts/cordova/lib/check_reqs.js b/bin/templates/scripts/cordova/lib/check_reqs.js index fb9af9f317..33dc684fc0 100644 --- a/bin/templates/scripts/cordova/lib/check_reqs.js +++ b/bin/templates/scripts/cordova/lib/check_reqs.js @@ -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']; @@ -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 () { @@ -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 || ''}`)); }); } @@ -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() @@ -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); }; diff --git a/bin/templates/scripts/cordova/lib/clean.js b/bin/templates/scripts/cordova/lib/clean.js index ddfc52da9e..72aac0bafa 100644 --- a/bin/templates/scripts/cordova/lib/clean.js +++ b/bin/templates/scripts/cordova/lib/clean.js @@ -17,10 +17,12 @@ * 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, '..', '..'); @@ -28,7 +30,7 @@ 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 => { diff --git a/bin/templates/scripts/cordova/lib/listEmulatorImages.js b/bin/templates/scripts/cordova/lib/listEmulatorImages.js index 81d346cdd0..09e1434029 100644 --- a/bin/templates/scripts/cordova/lib/listEmulatorImages.js +++ b/bin/templates/scripts/cordova/lib/listEmulatorImages.js @@ -17,7 +17,6 @@ under the License. */ -var Q = require('q'); var iossim = require('ios-sim'); /** @@ -25,7 +24,7 @@ var iossim = require('ios-sim'); * @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; diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 8e091c1228..1b8bb51097 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -18,7 +18,7 @@ */ 'use strict'; -const Q = require('q'); + const fs = require('fs-extra'); const path = require('path'); const unorm = require('unorm'); @@ -49,7 +49,7 @@ module.exports.prepare = function (cordovaProject, options) { this._config = updateConfigFile(cordovaProject.projectConfig, munger, this.locations); // Update own www dir with project's www assets and plugins' assets and js-files - return Q.when(updateWww(cordovaProject, this.locations)) + return updateWww(cordovaProject, this.locations) // update project according to config.xml changes. .then(() => updateProject(this._config, this.locations)) .then(() => { @@ -75,12 +75,12 @@ module.exports.clean = function (options) { const projectConfigFile = path.join(projectRoot, 'config.xml'); if ((options && options.noPrepare) || !fs.existsSync(projectConfigFile) || !fs.existsSync(this.locations.configXml)) { - return Q(); + return Promise.resolve(); } const projectConfig = new ConfigParser(this.locations.configXml); - return Q().then(() => { + return Promise.resolve().then(() => { cleanWww(projectRoot, this.locations); cleanIcons(projectRoot, projectConfig, this.locations); cleanSplashScreens(projectRoot, projectConfig, this.locations); @@ -158,6 +158,8 @@ function updateWww (cordovaProject, destinations) { 'verbose', `Merging and updating files from [${sourceDirs.join(', ')}] to ${targetDir}`); FileUpdater.mergeAndUpdateDir( sourceDirs, targetDir, { rootDir: cordovaProject.root }, logFileOp); + + return Promise.resolve(); } /** @@ -229,7 +231,7 @@ function updateProject (platformConfig, locations) { return handleBuildSettings(platformConfig, locations, infoPlist).then(() => { if (name === originalName) { events.emit('verbose', `iOS Product Name has not changed (still "${originalName}")`); - return Q(); + return Promise.resolve(); } else { // CB-11712 was changed, we don't support it' const errorString = 'The product name change ( tag) in config.xml is not supported dynamically.\n' + @@ -239,7 +241,7 @@ function updateProject (platformConfig, locations) { '\tcordova platform rm ios\n' + '\tcordova platform add ios\n'; - return Q.reject(new CordovaError(errorString)); + return Promise.reject(new CordovaError(errorString)); } }); } @@ -280,7 +282,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { try { project = projectFile.parse(locations); } catch (err) { - return Q.reject(new CordovaError(`Could not parse ${locations.pbxproj}: ${err}`)); + return Promise.reject(new CordovaError(`Could not parse ${locations.pbxproj}: ${err}`)); } const origPkg = project.xcode.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', undefined, platformConfig.name()); @@ -288,7 +290,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { // no build settings provided and we don't need to update build settings for launch storyboards, // then we don't need to parse and update .pbxproj file if (origPkg === pkg && !targetDevice && !deploymentTarget && !needUpdatedBuildSettingsForLaunchStoryboard && !swiftVersion) { - return Q(); + return Promise.resolve(); } if (origPkg !== pkg) { @@ -315,7 +317,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { project.write(); - return Q(); + return Promise.resolve(); } function mapIconResources (icons, iconsDir) { diff --git a/bin/templates/scripts/cordova/lib/run.js b/bin/templates/scripts/cordova/lib/run.js index 19d3dfa607..bfee64f06a 100644 --- a/bin/templates/scripts/cordova/lib/run.js +++ b/bin/templates/scripts/cordova/lib/run.js @@ -17,10 +17,10 @@ under the License. */ -const Q = require('q'); const path = require('path'); const build = require('./build'); const { + CordovaError, events, superspawn: { spawn } } = require('cordova-common'); @@ -33,7 +33,7 @@ const projectPath = path.join(__dirname, '..', '..'); module.exports.run = runOptions => { // Validate args if (runOptions.device && runOptions.emulator) { - return Q.reject('Only one of "device"/"emulator" options should be specified'); + return Promise.reject(new CordovaError('Only one of "device"/"emulator" options should be specified')); } // support for CB-8168 `cordova/run --list` @@ -59,7 +59,7 @@ module.exports.run = runOptions => { if (!runOptions.nobuild) { return build.run(runOptions); } else { - return Q.resolve(); + return Promise.resolve(); } }).then(() => build.findXCodeProjectIn(projectPath)) .then(projectName => { diff --git a/bin/templates/scripts/cordova/lib/versions.js b/bin/templates/scripts/cordova/lib/versions.js index 318e8dfffb..f89147854c 100644 --- a/bin/templates/scripts/cordova/lib/versions.js +++ b/bin/templates/scripts/cordova/lib/versions.js @@ -17,8 +17,10 @@ under the License. */ -const { superspawn: { spawn } } = require('cordova-common'); -const Q = require('q'); +const { + CordovaError, + superspawn: { spawn } +} = require('cordova-common'); const semver = require('semver'); function fetchSdkVersionByType (sdkType) { @@ -93,7 +95,7 @@ exports.get_tool_version = toolName => { case 'ios-sim': return exports.get_ios_sim_version(); case 'ios-deploy': return exports.get_ios_deploy_version(); case 'pod': return exports.get_cocoapods_version(); - default: return Q.reject(`${toolName} is not valid tool name. Valid names are: 'xcodebuild', 'ios-sim', 'ios-deploy', and 'pod'`); + default: return Promise.reject(new CordovaError(`${toolName} is not valid tool name. Valid names are: 'xcodebuild', 'ios-sim', 'ios-deploy', and 'pod'`)); } }; diff --git a/bin/templates/scripts/cordova/run b/bin/templates/scripts/cordova/run index e42df50756..9e6c8f91eb 100755 --- a/bin/templates/scripts/cordova/run +++ b/bin/templates/scripts/cordova/run @@ -54,10 +54,13 @@ opts.argv = opts.argv.remain; require('./loggingHelper').adjustLoggerLevel(opts); -new Api().run(opts).done(function () { - console.log('** RUN SUCCEEDED **'); -}, function (err) { - var errorMessage = (err && err.stack) ? err.stack : err; - console.error(errorMessage); - process.exit(2); -}); +new Api().run(opts).then( + () => { + console.log('** RUN SUCCEEDED **'); + }, + err => { + var errorMessage = (err && err.stack) ? err.stack : err; + console.error(errorMessage); + process.exit(2); + } +); diff --git a/bin/update b/bin/update index abaf87f36a..1087c4a00e 100755 --- a/bin/update +++ b/bin/update @@ -34,4 +34,7 @@ if (args.help || args.argv.remain.length === 0) { require('./templates/scripts/cordova/loggingHelper').adjustLoggerLevel(args); -Api.updatePlatform(args.argv.remain[0], { link: (args.link || args.shared) }).done(); +Api.updatePlatform(args.argv.remain[0], { link: (args.link || args.shared) }).catch(err => { + console.log(err); + process.exit(2); +}); diff --git a/package.json b/package.json index d52ad21012..7dfaa5d242 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,6 @@ "ios-sim": "^9.0.0", "nopt": "^4.0.3", "plist": "^3.0.1", - "q": "^1.5.1", "semver": "^7.3.2", "unorm": "^1.6.0", "which": "^2.0.2", diff --git a/tests/spec/component/versions.spec.js b/tests/spec/component/versions.spec.js index 9ce2b5a34a..5f9e32c3f0 100644 --- a/tests/spec/component/versions.spec.js +++ b/tests/spec/component/versions.spec.js @@ -27,7 +27,7 @@ if (process.platform === 'darwin') { it('should not have found tool by name.', () => { return versions.get_tool_version('unknown').then( () => fail('expected promise rejection'), - error => expect(error).toContain('is not valid tool name') + error => expect(error.message).toContain('is not valid tool name') ); }); diff --git a/tests/spec/unit/Api.spec.js b/tests/spec/unit/Api.spec.js index 1e6a1998bc..c1e4d2a9ba 100644 --- a/tests/spec/unit/Api.spec.js +++ b/tests/spec/unit/Api.spec.js @@ -38,7 +38,6 @@ const projectFile = require('../../../bin/templates/scripts/cordova/lib/projectF const BridgingHeader_mod = require('../../../bin/templates/scripts/cordova/lib/BridgingHeader.js'); const Podfile_mod = require('../../../bin/templates/scripts/cordova/lib/Podfile'); const PodsJson_mod = require('../../../bin/templates/scripts/cordova/lib/PodsJson'); -const Q = require('q'); const FIXTURES = path.join(__dirname, 'fixtures'); const iosProjectFixture = path.join(FIXTURES, 'ios-config-xml'); @@ -84,7 +83,7 @@ describe('Platform Api', () => { if (process.platform === 'darwin') { describe('run', () => { beforeEach(() => { - spyOn(check_reqs, 'run').and.returnValue(Q.resolve()); + spyOn(check_reqs, 'run').and.returnValue(Promise.resolve()); }); it('should call into lib/run module', () => { spyOn(run_mod, 'run'); @@ -103,7 +102,7 @@ describe('Platform Api', () => { }; beforeEach(() => { spyOn(PluginManager, 'get').and.returnValue({ - addPlugin: function () { return Q(); } + addPlugin: function () { return Promise.resolve(); } }); spyOn(BridgingHeader_mod, 'BridgingHeader'); spyOn(Podfile_mod, 'Podfile'); @@ -360,7 +359,7 @@ describe('Platform Api', () => { }; beforeEach(() => { spyOn(PluginManager, 'get').and.returnValue({ - removePlugin: function () { return Q(); } + removePlugin: function () { return Promise.resolve(); } }); spyOn(Podfile_mod, 'Podfile'); spyOn(PodsJson_mod, 'PodsJson'); diff --git a/tests/spec/unit/build.spec.js b/tests/spec/unit/build.spec.js index c931bc9039..7ecf40eace 100644 --- a/tests/spec/unit/build.spec.js +++ b/tests/spec/unit/build.spec.js @@ -20,7 +20,7 @@ const path = require('path'); const fs = require('fs-extra'); const rewire = require('rewire'); -const { events } = require('cordova-common'); +const { CordovaError, events } = require('cordova-common'); const build = rewire('../../../bin/templates/scripts/cordova/lib/build'); describe('build', () => { @@ -322,14 +322,8 @@ describe('build', () => { }); describe('run method', () => { - let rejectSpy; - beforeEach(() => { - rejectSpy = jasmine.createSpy('reject'); - - build.__set__('Q', { - reject: rejectSpy - }); + spyOn(Promise, 'reject'); }); it('should not accept debug and release options together', () => { @@ -338,7 +332,7 @@ describe('build', () => { release: true }); - expect(rejectSpy).toHaveBeenCalledWith('Cannot specify "debug" and "release" options together.'); + expect(Promise.reject).toHaveBeenCalledWith(new CordovaError('Cannot specify "debug" and "release" options together.')); }); it('should not accept device and emulator options together', () => { @@ -347,20 +341,16 @@ describe('build', () => { emulator: true }); - expect(rejectSpy).toHaveBeenCalledWith('Cannot specify "device" and "emulator" options together.'); + expect(Promise.reject).toHaveBeenCalledWith(new CordovaError('Cannot specify "device" and "emulator" options together.')); }); it('should reject when build config file missing', () => { - const existsSyncSpy = jasmine.createSpy('existsSync').and.returnValue(false); - build.__set__('fs', { - existsSync: existsSyncSpy - }); + spyOn(fs, 'existsSync').and.returnValue(false); - build.run({ - buildConfig: './some/config/path' - }); + const buildConfig = './some/config/path'; + build.run({ buildConfig: './some/config/path' }); - expect(rejectSpy).toHaveBeenCalledWith(jasmine.stringMatching(/^Build config file does not exist:/)); + expect(Promise.reject).toHaveBeenCalledWith(new CordovaError(`Build config file does not exist: ${buildConfig}`)); }); }); @@ -414,7 +404,7 @@ describe('build', () => { return buildRequire.findXCodeProjectIn(fakePath).then( () => {}, (error) => { - expect(error).toBe(`No Xcode project found in ${fakePath}`); + expect(error.message).toBe(`No Xcode project found in ${fakePath}`); } ); }); diff --git a/tests/spec/unit/lib/check_reqs.spec.js b/tests/spec/unit/lib/check_reqs.spec.js index 9fe573b35d..3a16f1586f 100644 --- a/tests/spec/unit/lib/check_reqs.spec.js +++ b/tests/spec/unit/lib/check_reqs.spec.js @@ -42,7 +42,7 @@ describe('check_reqs', () => { return checkTool('node', '1.0.0').then( () => fail('Expected promise to be rejected'), - reason => expect(reason).toContain('node was not found.') + reason => expect(reason.message).toContain('node was not found.') ); }); @@ -62,7 +62,7 @@ describe('check_reqs', () => { 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') + reason => expect(reason.message).toContain('version 1.0.1 or greater, you have version 1.0.0') ); }); }); diff --git a/tests/spec/unit/lib/run.spec.js b/tests/spec/unit/lib/run.spec.js index c44d4a015f..28d1f38046 100644 --- a/tests/spec/unit/lib/run.spec.js +++ b/tests/spec/unit/lib/run.spec.js @@ -23,16 +23,12 @@ // Windows+Linux we are bound to not-have-that. if (process.platform === 'darwin') { const run = require('../../../../bin/templates/scripts/cordova/lib/run'); - const Q = require('q'); describe('cordova/lib/run', () => { describe('--list option', () => { - let deferred; beforeEach(() => { - deferred = Q.defer(); - deferred.resolve(); - spyOn(run, 'listDevices').and.returnValue(deferred.promise); - spyOn(run, 'listEmulators').and.returnValue(deferred.promise); + spyOn(run, 'listDevices').and.returnValue(Promise.resolve()); + spyOn(run, 'listEmulators').and.returnValue(Promise.resolve()); }); it('should delegate to listDevices method if `options.device` specified', () => { return run.run({ list: true, device: true }).then(() => { diff --git a/tests/spec/unit/versions.spec.js b/tests/spec/unit/versions.spec.js index 792a1ae58b..679a2e3093 100644 --- a/tests/spec/unit/versions.spec.js +++ b/tests/spec/unit/versions.spec.js @@ -32,7 +32,7 @@ if (process.platform === 'darwin') { return versions.get_apple_ios_version().then(() => { expect(console.log).not.toHaveBeenCalledWith(undefined); }); - }); + }, 10000); }); describe('get_apple_osx_version method', () => {