Files
orca/src/main/ssh/ssh-remote-node-toolchain-probe.ts
T
Neil 991a3fe963 chore(lint): update oxlint to 1.77 and enable no-op cleanup rules (#13901)
Enable eleven oxlint rules that simplify code without changing behavior, and fix
every existing violation. Each candidate was gated on measured cost rather than
assumption, so rules that regressed runtime performance or type checking were
dropped instead of suppressed.

typescript/no-redundant-type-constituents is the largest addition: 113 sites, no
autofix. Dead constituents are deleted. Where the redundant literal existed to
document intent (`string | 'all'`), it is preserved as `(string & {})`, which
keeps the autocomplete hint the original code was reaching for instead of
flattening it away. The rule also caught a broken import —
remote-shared-control-retirement-probe.ts pulled RuntimeStatus from
src/shared/types, which does not export it, so the type silently degraded to
`any`; no tsconfig covers that file, so tsc never saw it.

oxlint stays at 1.77.0 rather than 1.78.0 because .npmrc sets
minimum-release-age=4320 and 1.78.0 is younger than that window.

Rules evaluated and rejected, with what disqualified each:
- prefer-string-raw: String.raw is a runtime call, not a literal (184x slower)
- prefer-string-replace-all: 26% slower
- text-encoding-identifier-case: ~5% slower, reproducible
- prefer-spread: [...str] is 110% slower than split('') and differs on surrogates
- no-implicit-coercion: `!!x` narrows types and `Boolean(x)` does not (22 tsc errors)
- prefer-arrow-callback: arrows are not constructible, breaking `new` on mocks
- object-shorthand: rewrites source text asserted by a tracked reliability gate
- switch-case-braces: pushes ten files past max-lines, which cannot be suppressed
- no-useless-switch-case: drops `case undefined:` that switch-exhaustiveness-check needs
- arrow-body-style: 115 violations have no fix, and it breaks max-lines
- newline-after-import: false-positives on the leading-semicolon ASI idiom

electron-vite-output-contract asserted on the literal
Object.prototype.hasOwnProperty.call text; retarget it to Object.hasOwn, which
rejects inherited keys identically.
2026-08-11 18:19:43 -07:00

67 lines
2.6 KiB
TypeScript

import { posix as posixPath } from 'node:path'
import { shellEscape } from './ssh-connection-utils'
import { powerShellLiteral } from './ssh-remote-powershell'
const MIN_NODE_MAJOR = 18
const NODE_VERSION_MARKER = '__ORCA_NODE_VERSION__'
const NPM_VERSION_MARKER = '__ORCA_NPM_VERSION__'
export function buildPosixNodeToolchainProbe(nodePath: string): string {
const nodeBinDir = posixPath.dirname(nodePath)
return [
`printf '%s\\n' '${NODE_VERSION_MARKER}'`,
`${shellEscape(nodePath)} --version`,
`printf '%s\\n' '${NPM_VERSION_MARKER}'`,
// Why: deploy prepends nodeBinDir before running bare npm; requiring a
// colocated executable rejects valid split layouts (#9165).
`PATH=${shellEscape(nodeBinDir)}:$PATH npm --version`
].join(' && ')
}
export function buildWindowsNodeToolchainProbe(nodePath: string): string {
const nodeBinDir = posixPath.dirname(nodePath)
const windowsNodeBinDir = nodeBinDir.replace(/\//g, '\\')
return [
// Why: mirror deploy's PATH-prepend + bare npm resolution so split
// Node/npm layouts are not rejected solely for lacking npm.cmd (#9165).
`$env:PATH = ${powerShellLiteral(windowsNodeBinDir)} + ';' + $env:PATH`,
`Write-Output ${powerShellLiteral(NODE_VERSION_MARKER)}`,
`& ${powerShellLiteral(nodePath)} --version`,
'if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }',
`Write-Output ${powerShellLiteral(NPM_VERSION_MARKER)}`,
'& npm --version',
'exit $LASTEXITCODE'
].join('; ')
}
export function nodeToolchainVersionsMeetRequirements(versionOutput: string): boolean {
const nodeMajor = markedVersionMajor(versionOutput, NODE_VERSION_MARKER)
const npmMajor = markedVersionMajor(versionOutput, NPM_VERSION_MARKER)
if (versionOutput.includes(NODE_VERSION_MARKER)) {
return nodeMajor !== null && nodeMajor >= MIN_NODE_MAJOR && npmMajor !== null
}
// Why: existing proxy integrations and tests may return only the Node
// version even though production probes now emit both version markers.
const legacyMatch = versionOutput.trim().match(/^v?(\d+)/)
return legacyMatch ? Number.parseInt(legacyMatch[1]!, 10) >= MIN_NODE_MAJOR : false
}
function markedVersionMajor(output: string, marker: string): number | null {
const lines = output.split(/\r?\n/)
const markerIndex = lines.indexOf(marker)
if (markerIndex === -1) {
return null
}
for (const line of lines.slice(markerIndex + 1)) {
if (line.startsWith('__ORCA_')) {
return null
}
const match = line.trim().match(/^v?(\d+)(?:\.\d+){1,2}(?:[-+].*)?$/)
if (match) {
return Number.parseInt(match[1]!, 10)
}
}
return null
}