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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1c3a807  feat!: remove q (#285)
1c3a807 is described below

commit 1c3a8075f31a20b77361dfcf0b5a10e9b00fcde1
Author: エリス <[email protected]>
AuthorDate: Sun Dec 14 14:38:05 2025 +0900

    feat!: remove q (#285)
---
 lib/ParamedicApp.js           |  7 ++--
 lib/ParamedicAppUninstall.js  | 57 +++++++++++++++++++++-----------
 lib/ParamedicTargetChooser.js | 70 +++++++++++++++++----------------------
 lib/paramedic.js              | 77 +++++++++++++++++++++++--------------------
 lib/utils/execWrapper.js      |  3 +-
 main.js                       | 23 +++++--------
 package-lock.json             | 12 -------
 package.json                  |  1 -
 8 files changed, 123 insertions(+), 127 deletions(-)

diff --git a/lib/ParamedicApp.js b/lib/ParamedicApp.js
index f863602..a5cb143 100644
--- a/lib/ParamedicApp.js
+++ b/lib/ParamedicApp.js
@@ -19,7 +19,6 @@
     under the License.
 */
 
-const Q = require('q');
 const tmp = require('tmp');
 const shell = require('shelljs');
 const path = require('path');
@@ -101,7 +100,7 @@ class ParamedicApp {
     }
 
     checkPlatformRequirements () {
-        if (this.isBrowser) return Q();
+        if (this.isBrowser) return Promise.resolve();
 
         logger.normal('cordova-paramedic: checking the requirements for 
platform: ' + this.platformId);
         return execPromise(this.config.getCli() + ' requirements ' + 
this.platformId + utilities.PARAMEDIC_COMMON_CLI_ARGS)
@@ -111,7 +110,7 @@ class ParamedicApp {
     }
 
     checkDumpAndroidManifest () {
-        if (!this.isAndroid) return Q();
+        if (!this.isAndroid) return Promise.resolve();
 
         logger.normal('cordova-paramedic: start AndroidManifest.xml Dump');
         return execPromise('cat 
./platforms/android/app/src/main/AndroidManifest.xml')
@@ -121,7 +120,7 @@ class ParamedicApp {
     }
 
     checkDumpAndroidConfigXml () {
-        if (!this.isAndroid) return Q();
+        if (!this.isAndroid) return Promise.resolve();
 
         logger.normal('cordova-paramedic: start config.xml Dump');
         return execPromise('cat 
./platforms/android/app/src/main/res/xml/config.xml')
diff --git a/lib/ParamedicAppUninstall.js b/lib/ParamedicAppUninstall.js
index febe6a8..f386b95 100644
--- a/lib/ParamedicAppUninstall.js
+++ b/lib/ParamedicAppUninstall.js
@@ -17,8 +17,9 @@
     under the License.
 */
 
-const Q = require('q');
-const { logger, exec, utilities } = require('./utils');
+const { exec } = require('node:child_process');
+
+const { logger, utilities } = require('./utils');
 
 class ParamedicAppUninstall {
     constructor (appPath, platform) {
@@ -26,18 +27,22 @@ class ParamedicAppUninstall {
         this.platform = platform;
     }
 
-    uninstallApp (targetObj, app) {
-        if (!targetObj || !targetObj.target) { return Q(); }
+    async uninstallApp (targetObj, app) {
+        if (!targetObj || !targetObj.target) {
+            return false;
+        }
 
         switch (this.platform) {
         case utilities.ANDROID:
-            return this.uninstallAppAndroid(targetObj, app);
+            await this.uninstallAppAndroid(targetObj, app);
+            return true;
 
         case utilities.IOS:
-            return this.uninstallAppIOS(targetObj, app);
+            await this.uninstallAppIOS(targetObj, app);
+            return true;
 
         default:
-            return Q();
+            return false;
         }
     }
 
@@ -56,22 +61,36 @@ class ParamedicAppUninstall {
         return this.executeUninstallCommand(`xcrun simctl uninstall 
${target.simId} ${appBundleIdentifier}`);
     }
 
-    executeUninstallCommand (uninstallCommand) {
-        return Q.Promise((resolve, reject) => {
-            logger.info('cordova-paramedic: Running command: ' + 
uninstallCommand);
-            exec(uninstallCommand, (code) => {
-                if (code === 0) {
+    // TODO: Remove this for a centralized spawnAsync utility
+    async executeUninstallCommand (uninstallCommand) {
+        logger.info('[paramedic] Running command: ' + uninstallCommand);
+
+        const execPromise = new Promise((resolve, reject) => {
+            exec(uninstallCommand, (error, stdout, stderr) => {
+                if (!error) {
                     resolve();
                 } else {
-                    logger.error('Failed to uninstall the app');
-                    logger.error('Error code: ' + code);
-                    reject();
+                    logger.error('[paramedic] Failed to uninstall the app');
+                    logger.error('[paramedic] Error code: ' + error.code);
+                    logger.error('[paramedic] stderr: ' + stderr);
+                    reject(error);
                 }
             });
-        }).timeout(60000)
-            .fail(() => {
-                logger.warn('cordova-paramedic: App uninstall timed out!');
-            });
+        });
+
+        const timeoutPromise = new Promise((resolve, reject) => {
+            setTimeout(() => reject(new Error('timeout')), 60000);
+        });
+
+        try {
+            await Promise.race([execPromise, timeoutPromise]);
+        } catch (err) {
+            if (err.message === 'timeout') {
+                logger.warn('[paramedic] App uninstall timed out!');
+            } else {
+                logger.warn('[paramedic] App uninstall error: ' + err.message);
+            }
+        }
     }
 }
 
diff --git a/lib/ParamedicTargetChooser.js b/lib/ParamedicTargetChooser.js
index 2e78add..cb031a0 100644
--- a/lib/ParamedicTargetChooser.js
+++ b/lib/ParamedicTargetChooser.js
@@ -17,7 +17,6 @@
     under the License.
 */
 
-const Q = require('q');
 const path = require('path');
 const { logger, utilities } = require('./utils');
 const ParamedicKill = require('./ParamedicKill');
@@ -31,37 +30,30 @@ class ParamedicTargetChooser {
         this.cli = config.getCli();
     }
 
-    chooseTarget (emulator, target) {
-        let targetObj = Q();
-
+    async chooseTarget (emulator, target) {
         switch (this.platform) {
         case utilities.ANDROID:
-            targetObj = this.chooseTargetForAndroid(emulator, target);
-            break;
+            return this.chooseTargetForAndroid(emulator, target);
 
         case utilities.IOS:
-            targetObj = this.chooseTargetForIOS(emulator, target);
-            break;
+            return this.chooseTargetForIOS(emulator, target);
 
         default:
-            break;
         }
-
-        return targetObj;
     }
 
-    chooseTargetForAndroid (emulator, target) {
+    async chooseTargetForAndroid (emulator, target) {
         logger.info('cordova-paramedic: Choosing Target for Android');
 
         if (target) {
             logger.info('cordova-paramedic: Target defined as: ' + target);
-            return Q({ target });
+            return { target };
         }
 
         return this.startAnAndroidEmulator(target).then(emulatorId => ({ 
target: emulatorId }));
     }
 
-    startAnAndroidEmulator (target) {
+    async startAnAndroidEmulator (target) {
         logger.info('cordova-paramedic: Starting an Android emulator');
 
         const emuPathInNodeModules = path.join(this.appPath, 'node_modules', 
'cordova-android', 'lib', 'emulator.js');
@@ -70,43 +62,43 @@ class ParamedicTargetChooser {
         const emuPath = utilities.doesFileExist(emuPathInNodeModules) ? 
emuPathInNodeModules : emuPathInPlatform;
         const emulator = require(emuPath);
 
-        const tryStart = (numberTriesRemaining) => {
-            return emulator.start(target, ANDROID_TIME_OUT)
-                .then((emulatorId) => {
-                    if (emulatorId) {
-                        return emulatorId;
-                    } else if (numberTriesRemaining > 0) {
-                        const paramedicKill = new 
ParamedicKill(utilities.ANDROID);
-                        paramedicKill.kill();
-                        return tryStart(numberTriesRemaining - 1);
-                    } else {
-                        logger.error('cordova-paramedic: Could not start an 
Android emulator');
-                        return null;
-                    }
-                });
+        const tryStart = async (numberTriesRemaining) => {
+            const emulatorId = await emulator.start(target, ANDROID_TIME_OUT);
+
+            if (emulatorId) {
+                return emulatorId;
+            }
+
+            if (numberTriesRemaining > 0) {
+                const paramedicKill = new ParamedicKill(utilities.ANDROID);
+                paramedicKill.kill();
+                return tryStart(numberTriesRemaining - 1);
+            }
+
+            logger.error('cordova-paramedic: Could not start an Android 
emulator');
+            return null;
         };
 
+        const started = await emulator.list_started();
+
         // Check if the emulator has already been started
-        return emulator.list_started()
-            .then((started) => {
-                if (started && started.length > 0) {
-                    return started[0];
-                } else {
-                    return tryStart(ANDROID_RETRY_TIMES);
-                }
-            });
+        if (started && started.length > 0) {
+            return started[0];
+        }
+
+        return await tryStart(ANDROID_RETRY_TIMES);
     }
 
-    chooseTargetForIOS (emulator, target) {
+    async chooseTargetForIOS (emulator, target) {
         logger.info('cordova-paramedic: Choosing Target for iOS');
 
         const simulatorModelId = utilities.getSimulatorModelId(this.cli, 
target);
         const simulatorData = utilities.getSimulatorData(simulatorModelId);
 
-        return Q({
+        return {
             target: simulatorModelId,
             simId: simulatorData.simId
-        });
+        };
     }
 }
 
diff --git a/lib/paramedic.js b/lib/paramedic.js
index 2dfd104..43d549f 100644
--- a/lib/paramedic.js
+++ b/lib/paramedic.js
@@ -21,7 +21,6 @@ const cp = require('child_process');
 const shell = require('shelljs');
 const Server = require('./LocalServer');
 const path = require('path');
-const Q = require('q');
 const fs = require('fs');
 const { logger, exec, execPromise, utilities } = require('./utils');
 const Reporters = require('./Reporters');
@@ -36,8 +35,6 @@ const ParamedicApp = require('./ParamedicApp');
 // If device has not connected within this interval the tests are stopped.
 const INITIAL_CONNECTION_TIMEOUT = 540000; // 9mins
 
-Q.longStackSupport = true;
-
 class ParamedicRunner {
     constructor (config) {
         this.tempFolder = null;
@@ -53,13 +50,14 @@ class ParamedicRunner {
     run () {
         this.checkConfig();
 
-        return Q().then(() => {
-            // create project and prepare (install plugins, setup test 
startpage, install platform, check platform requirements)
-            const paramedicApp = new ParamedicApp(this.config, this.storedCWD, 
this);
-            this.tempFolder = paramedicApp.createTempProject();
-            shell.pushd(this.tempFolder.name);
-            return paramedicApp.prepareProjectToRunTests();
-        })
+        return Promise.resolve()
+            .then(() => {
+                // create project and prepare (install plugins, setup test 
startpage, install platform, check platform requirements)
+                const paramedicApp = new ParamedicApp(this.config, 
this.storedCWD, this);
+                this.tempFolder = paramedicApp.createTempProject();
+                shell.pushd(this.tempFolder.name);
+                return paramedicApp.prepareProjectToRunTests();
+            })
             .then(() => {
                 if (this.config.runMainTests()) {
                     // start server
@@ -81,15 +79,21 @@ class ParamedicRunner {
                     logger.normal('Start building app and running tests at ' + 
(new Date()).toLocaleTimeString());
                 }
                 // run tests
-                return this.runTests();
+                return Promise.race([
+                    this.runTests(),
+                    new Promise((resolve, reject) =>
+                        setTimeout(() => reject(
+                            new Error(`[paramedic] Tests failed to complete in 
${this.config.getTimeout()} ms.`)
+                        ), this.config.getTimeout())
+                    )
+                ]);
             })
-            .timeout(this.config.getTimeout(), 'Timed out after waiting for ' 
+ this.config.getTimeout() + ' ms.')
             .catch((error) => {
                 logger.error(error);
                 console.log(error.stack);
-                throw new Error(error);
+                throw error;
             })
-            .fin((result) => {
+            .then((result) => {
                 
logger.warn('---------------------------------------------------------');
                 logger.warn('6. Collect data and clean up');
                 
logger.warn('---------------------------------------------------------');
@@ -100,16 +104,17 @@ class ParamedicRunner {
                 // collect logs and uninstall app
                     this.collectDeviceLogs();
                     return this.uninstallApp()
-                        .fail(() => { /* do not fail if uninstall fails */ })
-                        .fin(() => {
+                        .catch(() => { /* do not fail if uninstall failed */ })
+                        .finally(() => {
                             this.killEmulatorProcess();
-                        });
+                        })
+                        .then(() => result);
                 }
 
                 // --justbuild does nothing.
-                return Q.resolve(result);
+                return result;
             })
-            .fin(() => {
+            .finally(() => {
                 this.cleanUpProject();
             });
     }
@@ -200,18 +205,18 @@ class ParamedicRunner {
         // will check again a bit lower
         if (!this.config.runMainTests() && this.config.getPlatformId() !== 
utilities.ANDROID) {
             logger.normal('Skipping main tests...');
-            return Q(utilities.TEST_PASSED);
+            return utilities.TEST_PASSED;
         }
 
         logger.info('cordova-paramedic: running tests locally');
 
-        return Q()
+        return Promise.resolve()
             .then(() => this.getCommandForStartingTests())
             .then((command) => {
                 this.setPermissions();
 
-                return Q.all([
-                    Q().then(() => {
+                return Promise.all([
+                    Promise.resolve().then(() => {
                         logger.normal('cordova-paramedic: running command ' + 
command);
 
                         if (this.config.getPlatformId() !== utilities.BROWSER) 
{
@@ -224,7 +229,7 @@ class ParamedicRunner {
                             runProcess = null;
                         });
                     }),
-                    Q().then(() => {
+                    Promise.resolve().then(() => {
                         if (!this.config.runMainTests()) {
                             logger.normal('Skipping main tests...');
                             return utilities.TEST_PASSED;
@@ -232,7 +237,7 @@ class ParamedicRunner {
 
                         // skip tests if it was just build
                         if (this.shouldWaitForTestResult()) {
-                            return Q.promise((resolve, reject) => {
+                            return new Promise((resolve, reject) => {
                             // reject if timed out
                                 this.waitForConnection().catch(reject);
                                 // resolve if got results
@@ -244,17 +249,17 @@ class ParamedicRunner {
                     })
                 ]);
             })
-            .then((results) => {
-                return results[1];
-            })
-            .fin((result) => {
-                return runProcess
-                    ? Q.Promise((resolve) => {
+            .then((results) => results[1])
+            .then((result) => {
+                if (runProcess) {
+                    return new Promise((resolve) => {
                         utilities.killProcess(runProcess.pid, () => {
                             resolve(result);
                         });
-                    })
-                    : result;
+                    });
+                }
+
+                return result;
             });
     }
 
@@ -266,7 +271,7 @@ class ParamedicRunner {
 
     waitForTests () {
         logger.info('cordova-paramedic: waiting for test results');
-        return Q.promise((resolve, reject) => {
+        return new Promise((resolve, reject) => {
             // time out if connection takes too long
             const ERR_MSG = 'waitForTests: Seems like device not connected to 
local server in ' + INITIAL_CONNECTION_TIMEOUT / 1000 + ' secs';
             setTimeout(() => {
@@ -301,7 +306,7 @@ class ParamedicRunner {
             return cmd.join(' ');
         } else if (this.config.getAction() === 'build') {
             // The app is to be run as a store app or just build. So no need 
to choose a target.
-            return Q(cmd.join(' '));
+            return Promise.resolve(cmd.join(' '));
         }
 
         // For now we always trying to run test app on emulator
@@ -329,7 +334,7 @@ class ParamedicRunner {
     waitForConnection () {
         const ERR_MSG = 'waitForConnection: Seems like device not connected to 
local server in ' + INITIAL_CONNECTION_TIMEOUT / 1000 + ' secs';
 
-        return Q.promise((resolve, reject) => {
+        return new Promise((resolve, reject) => {
             setTimeout(() => {
                 if (!this.server.isDeviceConnected()) {
                     reject(new Error(ERR_MSG));
diff --git a/lib/utils/execWrapper.js b/lib/utils/execWrapper.js
index 1e18042..9f29b64 100644
--- a/lib/utils/execWrapper.js
+++ b/lib/utils/execWrapper.js
@@ -18,7 +18,6 @@
 */
 
 const shelljs = require('shelljs');
-const Q = require('q');
 let verbose;
 
 function exec (cmd, onFinish, onData) {
@@ -35,7 +34,7 @@ function exec (cmd, onFinish, onData) {
 }
 
 function execPromise (cmd) {
-    return Q.Promise(function (resolve, reject) {
+    return new Promise(function (resolve, reject) {
         exec(cmd, function (code, output) {
             if (code) {
                 reject(output);
diff --git a/main.js b/main.js
index f1a94ed..131701b 100755
--- a/main.js
+++ b/main.js
@@ -120,20 +120,15 @@ if (argv.version) {
     }
 
     paramedic.run(paramedicConfig)
-    .catch(function (error) {
-        if (error && error.stack) {
-            console.error(error.stack);
-        } else if (error) {
-            console.error(error);
-        }
-        process.exit(1);
-    })
-    .done(function(isTestPassed) {
-        var exitCode = isTestPassed ? 0 : 1;
-
-        console.log('Finished with exit code ' + exitCode);
-        process.exit(exitCode);
-    });
+        .then((isTestPassed) => {
+            var exitCode = isTestPassed ? 0 : 1;
+            console.log('Finished with exit code ' + exitCode);
+            process.exit(exitCode);
+        })
+        .catch((error) => {
+            console.error(error && error.stack ? error.stack : error);
+            process.exit(1);
+        });
 
 } else {
     console.log(USAGE);
diff --git a/package-lock.json b/package-lock.json
index 0bce2ad..a43fa57 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -14,7 +14,6 @@
         "jasmine-reporters": "^2.5.2",
         "jasmine-spec-reporter": "^7.0.0",
         "minimist": "^1.2.8",
-        "q": "^1.5.1",
         "shelljs": "^0.10.0",
         "tcp-port-used": "^1.0.2",
         "tmp": "^0.2.5",
@@ -2983,17 +2982,6 @@
         "node": ">=6"
       }
     },
-    "node_modules/q": {
-      "version": "1.5.1",
-      "resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz";,
-      "integrity": 
"sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==",
-      "deprecated": "You or someone you depend on is using Q, the JavaScript 
Promise library that gave JavaScript developers strong feelings about promises. 
They can almost certainly migrate to the native JavaScript promise now. Thank 
you literally everyone for joining me in this bet against the odds. Be 
excellent to each other.\n\n(For a CapTP with native promises, see 
@endo/eventual-send and @endo/captp)",
-      "license": "MIT",
-      "engines": {
-        "node": ">=0.6.0",
-        "teleport": ">=0.2.0"
-      }
-    },
     "node_modules/queue-microtask": {
       "version": "1.2.3",
       "resolved": 
"https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz";,
diff --git a/package.json b/package.json
index 4764ad9..ced1201 100644
--- a/package.json
+++ b/package.json
@@ -35,7 +35,6 @@
     "jasmine-reporters": "^2.5.2",
     "jasmine-spec-reporter": "^7.0.0",
     "minimist": "^1.2.8",
-    "q": "^1.5.1",
     "shelljs": "^0.10.0",
     "tcp-port-used": "^1.0.2",
     "tmp": "^0.2.5",


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to