0
# Platform Detection
1
2
Core platform detection functionality that identifies the current operating system, CPU architecture, and detailed Linux distribution information. This module provides comprehensive system analysis to determine appropriate binary targets for Prisma engines.
3
4
## Capabilities
5
6
### Get Binary Target for Current Platform
7
8
Gets the binary target string for the current platform, which determines which Prisma engine binary to use.
9
10
```typescript { .api }
11
/**
12
* Get the binary target for the current platform
13
* @returns Promise resolving to the appropriate binary target string
14
* @example "linux-musl-arm64-openssl-3.0.x" for Linux Alpine on ARM64
15
*/
16
function getBinaryTargetForCurrentPlatform(): Promise<BinaryTarget>;
17
```
18
19
**Usage Examples:**
20
21
```typescript
22
import { getBinaryTargetForCurrentPlatform } from "@prisma/get-platform";
23
24
// Get binary target for current platform
25
const target = await getBinaryTargetForCurrentPlatform();
26
console.log(target);
27
// Possible outputs:
28
// "darwin-arm64" (macOS on Apple Silicon)
29
// "linux-musl-arm64-openssl-3.0.x" (Alpine Linux on ARM64)
30
// "debian-openssl-1.1.x" (Debian/Ubuntu with OpenSSL 1.1)
31
// "windows" (Windows)
32
```
33
34
### Get Platform Information
35
36
Gets comprehensive platform information including binary target and detailed system characteristics.
37
38
```typescript { .api }
39
/**
40
* Get the binary target and other system information for the current platform
41
* @returns Promise resolving to complete platform information
42
*/
43
function getPlatformInfo(): Promise<PlatformInfo>;
44
```
45
46
**Usage Examples:**
47
48
```typescript
49
import { getPlatformInfo } from "@prisma/get-platform";
50
51
const info = await getPlatformInfo();
52
console.log(info);
53
// Example output on Linux:
54
// {
55
// platform: "linux",
56
// arch: "x64",
57
// binaryTarget: "debian-openssl-1.1.x",
58
// targetDistro: "debian",
59
// familyDistro: "debian",
60
// originalDistro: "ubuntu",
61
// archFromUname: "x86_64",
62
// libssl: "1.1.x"
63
// }
64
```
65
66
### Get OS Information
67
68
For internal use. Gets detailed OS information without the binary target resolution.
69
70
```typescript { .api }
71
/**
72
* Get detailed operating system information
73
* @returns Promise resolving to OS detection results
74
* @internal This function is for internal use and may change without notice
75
*/
76
function getos(): Promise<GetOSResult>;
77
```
78
79
**Usage Examples:**
80
81
```typescript
82
import { getos } from "@prisma/get-platform";
83
84
const osInfo = await getos();
85
console.log(osInfo);
86
// Example output on Linux:
87
// {
88
// platform: "linux",
89
// arch: "arm64",
90
// archFromUname: "aarch64",
91
// libssl: "3.0.x",
92
// targetDistro: "musl",
93
// familyDistro: "alpine",
94
// originalDistro: "alpine"
95
// }
96
97
// Example output on macOS:
98
// {
99
// platform: "darwin",
100
// arch: "arm64"
101
// }
102
```
103
104
### Internal Platform Detection Functions
105
106
These functions are exported for testing purposes but are not part of the official public API:
107
108
```typescript { .api }
109
/**
110
* Internal function for binary target resolution
111
* @internal Testing purposes only
112
*/
113
function getBinaryTargetForCurrentPlatformInternal(args: GetOSResult): BinaryTarget;
114
115
/**
116
* Memoized version of getPlatformInfo
117
* @internal Testing purposes only
118
*/
119
function getPlatformInfoMemoized(): Promise<PlatformInfo & { memoized: boolean }>;
120
121
/**
122
* Parse Linux distribution information from /etc/os-release content
123
* @internal Testing purposes only
124
*/
125
function parseDistro(osReleaseInput: string): DistroInfo;
126
127
/**
128
* Resolve current Linux distribution information
129
* @internal Testing purposes only
130
*/
131
function resolveDistro(): Promise<DistroInfo>;
132
133
/**
134
* Get system architecture from uname command
135
* @internal Testing purposes only
136
*/
137
function getArchFromUname(): Promise<string | undefined>;
138
```
139
140
## Platform Support
141
142
The platform detection system supports:
143
144
**Operating Systems:**
145
- Linux (various distributions)
146
- macOS (Intel and Apple Silicon)
147
- Windows
148
- FreeBSD (versions 11-15)
149
- OpenBSD
150
- NetBSD
151
152
**CPU Architectures:**
153
- x64 (x86_64, amd64)
154
- arm64 (aarch64)
155
- arm (32-bit ARM)
156
- x32, ia32, s390, s390x, mipsel, mips, ppc, ppc64
157
158
**Linux Distribution Families:**
159
- Debian-based (Ubuntu, Debian, etc.)
160
- RHEL-based (CentOS, Fedora, AlmaLinux, etc.)
161
- Alpine/musl-based
162
- Arch-based
163
- NixOS
164
- Raspbian (ARM-specific handling)
165
166
**SSL Library Versions:**
167
- OpenSSL 1.0.x
168
- OpenSSL 1.1.x
169
- OpenSSL 3.0.x (and 3.x normalized to 3.0.x)
170
171
## Error Handling
172
173
The platform detection functions handle various error conditions gracefully:
174
175
- **Unsupported architectures**: Warns but continues with best-effort detection
176
- **SSL detection failure**: Falls back to default OpenSSL 1.1.x with warning
177
- **Distribution detection failure**: Falls back to Debian target with debug logging
178
- **Command execution failure**: Returns undefined for optional information
179
- **File system errors**: Handles missing files and permission issues silently
180
181
Platform detection never throws errors, but may emit warnings via the console for configuration issues that could affect Prisma engine selection.