<commit_before>import * as path from "path";
import { ChildProcess } from "child_process";
import { DebugServiceBase } from "./debug-service-base";
import { CONNECTION_ERROR_EVENT_NAME, DeviceConnectionType } from "../constants";
const inspectorAppName = "NativeScript Inspector.app";
const inspectorNpmPackageName = "tns-ios-inspector";
const inspectorUiDir = "WebInspectorUI/";
import { performanceLog } from "../common/decorators";
import { platform } from "os";

export class IOSDeviceDebugService extends DebugServiceBase implements IDeviceDebugService {
	private deviceIdentifier: string;

	constructor(protected device: Mobile.IiOSDevice,
		protected $devicesService: Mobile.IDevicesService,
		private $childProcess: IChildProcess,
		private $hostInfo: IHostInfo,
		private $logger: ILogger,
		private $errors: IErrors,
		private $packageInstallationManager: IPackageInstallationManager,
		private $appDebugSocketProxyFactory: IAppDebugSocketProxyFactory,
		private $projectDataService: IProjectDataService) {

		super(device, $devicesService);
		this.$appDebugSocketProxyFactory.on(CONNECTION_ERROR_EVENT_NAME, (e: Error) => this.emit(CONNECTION_ERROR_EVENT_NAME, e));
		this.deviceIdentifier = this.device.deviceInfo.identifier;
	}

	public get platform(): string {
		return "ios";
	}

	@performanceLog()
	public async debug(debugData: IDebugData, debugOptions: IDebugOptions): Promise<IDebugResultInfo> {
		const result: IDebugResultInfo = { debugUrl: null };
		await this.validateOptions(debugOptions);

		result.debugUrl = await this.wireDebuggerClient(debugData, debugOptions);

		return result;
	}

	public async debugStop(): Promise<void> {
		this.$appDebugSocketProxyFactory.removeAllProxies();
	}

	private async validateOptions(debugOptions: IDebugOptions) {
		if (!this.$hostInfo.isWindows && !this.$hostInfo.isDarwin) {
			this.$errors.fail(`Debugging on iOS devices is not supported for ${platform()} yet.`);
		}

		if (debugOptions.debugBrk && debugOptions.start) {
			this.$errors.fail("Expected exactly one of the --debug-brk or --start options.");
		}

		await this.validateUSBConnectedDevice();
	}

	private async validateUSBConnectedDevice() {
		const device = await this.$devicesService.getDevice(this.deviceIdentifier);
		if (device.deviceInfo.connectionTypes.indexOf(DeviceConnectionType.USB) === -1) {
			const deviceConnectionTypes = device.deviceInfo.connectionTypes.map(type => DeviceConnectionType[type]).join(", ");
			this.$errors.fail(`Debugging application requires a USB connection while the target device "${this.deviceIdentifier}" has connection type "${deviceConnectionTypes}".`);
		}
	}<commit_msg>fix: fix debug on ios simulator<commit_after>import * as path from "path";
import { ChildProcess } from "child_process";
import { DebugServiceBase } from "./debug-service-base";
import { CONNECTION_ERROR_EVENT_NAME, DeviceConnectionType } from "../constants";
const inspectorAppName = "NativeScript Inspector.app";
const inspectorNpmPackageName = "tns-ios-inspector";
const inspectorUiDir = "WebInspectorUI/";
import { performanceLog } from "../common/decorators";
import { platform } from "os";

export class IOSDeviceDebugService extends DebugServiceBase implements IDeviceDebugService {
	private deviceIdentifier: string;

	constructor(protected device: Mobile.IiOSDevice,
		protected $devicesService: Mobile.IDevicesService,
		private $childProcess: IChildProcess,
		private $hostInfo: IHostInfo,
		private $logger: ILogger,
		private $errors: IErrors,
		private $packageInstallationManager: IPackageInstallationManager,
		private $appDebugSocketProxyFactory: IAppDebugSocketProxyFactory,
		private $projectDataService: IProjectDataService) {

		super(device, $devicesService);
		this.$appDebugSocketProxyFactory.on(CONNECTION_ERROR_EVENT_NAME, (e: Error) => this.emit(CONNECTION_ERROR_EVENT_NAME, e));
		this.deviceIdentifier = this.device.deviceInfo.identifier;
	}

	public get platform(): string {
		return "ios";
	}

	@performanceLog()
	public async debug(debugData: IDebugData, debugOptions: IDebugOptions): Promise<IDebugResultInfo> {
		const result: IDebugResultInfo = { debugUrl: null };
		await this.validateOptions(debugOptions);

		result.debugUrl = await this.wireDebuggerClient(debugData, debugOptions);

		return result;
	}

	public async debugStop(): Promise<void> {
		this.$appDebugSocketProxyFactory.removeAllProxies();
	}

	private async validateOptions(debugOptions: IDebugOptions) {
		if (!this.$hostInfo.isWindows && !this.$hostInfo.isDarwin) {
			this.$errors.fail(`Debugging on iOS devices is not supported for ${platform()} yet.`);
		}

		if (debugOptions.debugBrk && debugOptions.start) {
			this.$errors.fail("Expected exactly one of the --debug-brk or --start options.");
		}

		await this.validateUSBConnectedDevice();
	}

	private async validateUSBConnectedDevice() {
		const device = await this.$devicesService.getDevice(this.deviceIdentifier);
		if (device.deviceInfo.connectionTypes.indexOf(DeviceConnectionType.USB) === -1 && device.deviceInfo.connectionTypes.indexOf(DeviceConnectionType.Local) === -1) {
			const deviceConnectionTypes = device.deviceInfo.connectionTypes.map(type => DeviceConnectionType[type]).join(", ");
			this.$errors.fail(`Debugging application requires a USB or LOCAL connection while the target device "${this.deviceIdentifier}" has connection type "${deviceConnectionTypes}".`);
		}
	}
{'fraction_non_alphanumeric': 0.11185308848080133, 'fraction_numerical': 0.0005564830272676684, 'mean_word_length': 6.122853368560106, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5923714', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1501, 'n_words': 357}