1
0

build-exe-for-python-sdk-native-pty.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /** Resolve the native node-pty input used by the Python SDK runtime builder. */
  2. import { existsSync } from 'node:fs'
  3. import { join } from 'node:path'
  4. /**
  5. * Prefer the workflow's manylinux build and fall back to node-pty's target prebuild.
  6. * @param packageDirectory - installed node-pty package directory.
  7. * @param arch - Linux target architecture.
  8. * @returns the existing addon path.
  9. */
  10. export function resolveLinuxNodePtyAddon(
  11. packageDirectory: string,
  12. arch: 'x64' | 'arm64',
  13. ): string {
  14. const built = join(packageDirectory, 'build', 'Release', 'pty.node')
  15. if (existsSync(built)) return built
  16. const prebuilt = join(packageDirectory, 'prebuilds', `linux-${arch}`, 'pty.node')
  17. if (existsSync(prebuilt)) return prebuilt
  18. throw new Error(
  19. `build-exe-for-python-sdk: node-pty addon is absent from both ${built} and ${prebuilt}.`,
  20. )
  21. }
  22. /**
  23. * Require both node-pty addons used by the Windows ConPTY backend.
  24. * @param packageDirectory - staged node-pty package directory.
  25. * @param arch - Windows target architecture.
  26. * @returns the existing addon paths in load order.
  27. */
  28. export function resolveWindowsNodePtyAddons(
  29. packageDirectory: string,
  30. arch: 'x64',
  31. ): string[] {
  32. const directory = join(packageDirectory, 'prebuilds', `win32-${arch}`)
  33. const addons = [
  34. join(directory, 'conpty.node'),
  35. join(directory, 'conpty_console_list.node'),
  36. ]
  37. const missing = addons.filter(path => !existsSync(path))
  38. if (missing.length > 0) {
  39. throw new Error(`build-exe-for-python-sdk: Windows node-pty addons are missing: ${missing.join(', ')}.`)
  40. }
  41. return addons
  42. }