github-advanced-security[bot] commented on code in PR #1583:
URL: https://github.com/apache/cordova-ios/pull/1583#discussion_r2506074157


##########
lib/runSimulator.js:
##########
@@ -0,0 +1,208 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+
+const path = require('node:path');
+const fs = require('node:fs');
+const { events } = require('cordova-common');
+const bplist = require('bplist-parser');
+const plist = require('plist');
+
+const {
+    fetchSimCtlList,
+    findAvailableRuntimes,
+    filterDeviceName,
+    fixRuntimeName,
+    findRuntimesGroupByDeviceProperty,
+    startSimulator
+} = require('./simctlHelper');
+
+/**
+ * Finds the first available device name, udid, and normalized runtime.
+ *
+ * Example result:
+ *  {
+ *      name : 'iPhone 6',
+ *      id : 'A1193D97-F5EE-468D-9DBA-786F403766E6',
+ *      runtime : 'iOS 8.3'
+ *  }
+ *
+ * @param {object} list
+ * @returns {object}
+ */
+function findFirstAvailableDevice (list) {
+    const availableRuntimes = findAvailableRuntimes(list.runtimes);
+
+    for (const [deviceGroup, devices] of Object.entries(list.devices)) {
+        // Normalizies the runtime name since deviceGroup can be either 
namespaced or human-readable.
+        const normalizedRuntimeName = fixRuntimeName(deviceGroup);
+
+        // Skip when the runtime is not available.
+        if (!availableRuntimes[normalizedRuntimeName]) {
+            continue;
+        }
+
+        const [firstDevice] = devices;
+        if (firstDevice) {
+            return {
+                name: firstDevice.name,
+                id: firstDevice.udid,
+                runtime: normalizedRuntimeName
+            };
+        }
+    }
+
+    // Nothing was found so returning null values
+    return { name: null, id: null, runtime: null };
+}
+
+/**
+ * Find and return available runtime by device name.
+ *
+ * @param {object} list
+ * @param {string} deviceName
+ * @returns
+ */
+function findAvailableRuntime (list, deviceName) {
+    deviceName = deviceName.toLowerCase();
+
+    const allDeviceRuntimes = findRuntimesGroupByDeviceProperty(list, 'name', 
true, { lowerCase: true });
+    const deviceRuntime = allDeviceRuntimes[filterDeviceName(deviceName)] || 
allDeviceRuntimes[deviceName];
+    const foundRuntime = deviceRuntime && deviceRuntime.length > 0;
+
+    if (!foundRuntime) {
+        throw new Error(`No available runtimes could be found for 
"${deviceName}".`);
+    }
+
+    // return most modern runtime
+    return deviceRuntime.sort().pop();
+}
+
+/**
+ * Example result:
+ *  {
+ *      name : 'iPhone 6',
+ *      id : 'A1193D97-F5EE-468D-9DBA-786F403766E6',
+ *      runtime : 'iOS 8.3'
+ *  }
+ *
+ * @param {string} deviceTypeId
+ * @returns {object}
+ */
+function getDeviceFromDeviceTypeId (deviceTypeId = null) {
+    const list = fetchSimCtlList();
+
+    if (!deviceTypeId) {
+        const device = findFirstAvailableDevice(list);
+        events.emmit('warn', `--devicetypeid was not specified, using first 
available device: ${device.name}.`);
+        return device;
+    }
+
+    const [
+        deviceTypeRaw = null,
+        runtimeRaw = null
+    ] = deviceTypeId ? deviceTypeId.split(',') : [];

Review Comment:
   ## Useless conditional
   
   This use of variable 'deviceTypeId' always evaluates to true.
   
   [Show more 
details](https://github.com/apache/cordova-ios/security/code-scanning/25)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to