1
0

release.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /** Immutable version identity shared by one Electron shell and its bundled dsh runtime. */
  2. import { valid } from 'semver'
  3. import { DESKTOP_HOST_PROTOCOL_VERSION } from './host-protocol.ts'
  4. /** Release facts embedded in the bundled runtime descriptor. */
  5. export interface DesktopRelease {
  6. readonly schemaVersion: 1
  7. /** Exact version used by both Electron and `@deepseek-ai/dsh`. */
  8. readonly version: string
  9. readonly hostProtocolVersion: typeof DESKTOP_HOST_PROTOCOL_VERSION
  10. readonly nodeVersion: string
  11. readonly pnpmVersion: string
  12. }
  13. function isRecord(value: unknown): value is Record<string, unknown> {
  14. return typeof value === 'object' && value !== null
  15. }
  16. /** Validate release data read from an installed or packaged filesystem resource. */
  17. export function parseDesktopRelease(value: unknown): DesktopRelease {
  18. if (!isRecord(value) || value.schemaVersion !== 1 || typeof value.version !== 'string'
  19. || valid(value.version) === null || value.hostProtocolVersion !== DESKTOP_HOST_PROTOCOL_VERSION
  20. || typeof value.nodeVersion !== 'string' || valid(value.nodeVersion) === null
  21. || typeof value.pnpmVersion !== 'string' || valid(value.pnpmVersion) === null) {
  22. throw new Error('dsh desktop: invalid desktop release metadata')
  23. }
  24. return {
  25. schemaVersion: 1,
  26. version: value.version,
  27. hostProtocolVersion: DESKTOP_HOST_PROTOCOL_VERSION,
  28. nodeVersion: value.nodeVersion,
  29. pnpmVersion: value.pnpmVersion,
  30. }
  31. }