Skip to content
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
5 changes: 1 addition & 4 deletions src/doctor/data-access/check-android-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { basename, join } from 'node:path'
import { join } from 'node:path'
import type { DoctorCheckResult } from './doctor-check-result.ts'
import { type DoctorEnvironment, findExecutable, parseVersion, sortVersions } from './doctor-environment.ts'

Expand Down Expand Up @@ -201,6 +201,3 @@ export function selectHighestBuildToolsVersion(entries: string[]) {
export function parseEmulatorVersion(output: string) {
return output.match(/Android emulator version\s+(\d+(?:\.\d+)*)/i)?.[1] ?? parseVersion(output)
}
export function sdkComponentName(path: string) {
return basename(path)
}
6 changes: 1 addition & 5 deletions src/doctor/data-access/doctor-environment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execFile } from 'node:child_process'
import { access, readdir, realpath, statfs } from 'node:fs/promises'
import { homedir, platform, release } from 'node:os'
import { delimiter, dirname, extname, join, resolve, sep } from 'node:path'
import { delimiter, join, sep } from 'node:path'

export type CommandResult = { path: string; stderr: string; stdout: string }
export type CommandRunner = (command: string, args?: string[]) => Promise<CommandResult>
Expand Down Expand Up @@ -89,7 +89,3 @@ export function compareVersions(left: string, right: string) {
}
return 0
}

export function executableDirectory(path: string) {
return extname(path) ? dirname(path) : resolve(path)
}
20 changes: 1 addition & 19 deletions src/localnet/data-access/apply-forwards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createAdbReverse, listAdbReverses, removeAdbReverse } from '../../devic
import type { AdbDependencies, AdbDevice, AdbReverseEntry } from '../../device/data-access/device-types.ts'
import { isUsableDevice, listAdbDevices } from '../../device/data-access/list-adb-devices.ts'
import type { ForwardAction, OwnedForward, ResolvedLocalnetPort } from './localnet-types.ts'
import { ownedForwards, pendingForwards, planForwards } from './plan-forwards.ts'
import { pendingForwards, planForwards } from './plan-forwards.ts'

export async function collectExistingReverses(
devices: readonly AdbDevice[],
Expand All @@ -23,24 +23,6 @@ export async function collectExistingReverses(
return new Map(entries)
}

/**
* The forwards a run would create, computed without applying anything.
*
* A detached session records this on the container before starting it, because once it exits there is no
* process left to remember what it claimed. Computing it early means a device that appears in between is
* simply not claimed — `stop` then leaves that forward alone, which is the safe direction to err.
*/
export async function planOwnedForwards(
{ devices: only, ports }: { devices?: readonly string[]; ports: readonly ResolvedLocalnetPort[] },
{ runCommand = runExecutable }: AdbDependencies = {},
): Promise<OwnedForward[]> {
const all = await listAdbDevices({ runCommand })
const devices = only?.length ? all.filter(({ serial }) => only.includes(serial)) : all
const existing = await collectExistingReverses(devices, { runCommand })

return ownedForwards(planForwards({ devices, existing, ports }))
}

/**
* `onApplied` fires as each reverse lands, rather than once at the end.
*
Expand Down
Loading