Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.6 KB
Raw Blame
import { copyFileSync, lstatSync } from 'node:fs'
import { createRequire } from 'node:module'
import { join } from 'node:path'
import { ORCAD_WINDOWS_PROCESS_TREE_FILENAME } from '../../src/shared/orcad-artifacts.ts'
import {
  inspectWindowsProcessTreeAddon,
  windowsProcessTreeAddonPath
} from './windows-process-tree-gyp-rebuild.mjs'

const { PE_MACHINE, describePeMachine, readPeMachine } = createRequire(import.meta.url)(
  './windows-pe-machine.cjs'
)

export function stageOrcadWindowsProcessTree(
  root,
  outputDir,
  target,
  host = { platform: process.platform, arch: process.arch }
) {
  if (!target.startsWith('win32-')) {
    return
  }
  const arch = target.slice('win32-'.length)
  let source = join(
    root,
    '.build',
    'windows-process-tree',
    arch,
    ORCAD_WINDOWS_PROCESS_TREE_FILENAME
  )
  // Ordinary Windows installs already compile this N-API addon for the host.
  if (target === `${host.platform}-${host.arch}` && !lstatSync(source, { throwIfNoEntry: false })) {
    source = windowsProcessTreeAddonPath(
      join(root, 'node_modules', '@vscode', 'windows-process-tree')
    )
  }
  if (inspectWindowsProcessTreeAddon(source) !== 'clean') {
    throw new Error(
      `Orcad ${target} requires a patched process reader. On Windows, run: ` +
        `node config/scripts/build-windows-process-tree-addon.mjs --arch=${arch}`
    )
  }
  const machine = readPeMachine(source)
  if (machine !== PE_MACHINE[arch]) {
    throw new Error(`Orcad ${target} process reader has ${describePeMachine(machine)}`)
  }
  copyFileSync(source, join(outputDir, ORCAD_WINDOWS_PROCESS_TREE_FILENAME))
}